WIP stock stuff
This commit is contained in:
parent
d47eb1a3ca
commit
d95264743b
@ -93,14 +93,19 @@ let getStoreItems (channelId : uint64) =
|
|||||||
|> Sql.connect
|
|> Sql.connect
|
||||||
|> Sql.parameters [ "cid", Sql.string (string channelId) ]
|
|> Sql.parameters [ "cid", Sql.string (string channelId) ]
|
||||||
|> Sql.query """
|
|> Sql.query """
|
||||||
SELECT i.id,i.symbol,name,description,icon,category,buy_price,sell_price,rate_limit,expiration,drop_chance,can_trade,can_consume,
|
SELECT stock,available,limit_stock,i.id,i.symbol,name,description,icon,category,buy_price,sell_price,rate_limit,expiration,drop_chance,can_trade,can_consume,
|
||||||
attack_power,defense_power,class_name,max_stack,mods
|
attack_power,defense_power,class_name,max_stack,mods
|
||||||
FROM store_item
|
FROM store_item
|
||||||
JOIN store st on store_item.store_id = st.id
|
JOIN store st on store_item.store_id = st.id
|
||||||
JOIN item i on store_item.item_id = i.id
|
JOIN item i on store_item.item_id = i.id
|
||||||
WHERE channel_id = @cid AND available;
|
WHERE channel_id = @cid AND available;
|
||||||
"""
|
"""
|
||||||
|> Sql.executeAsync readItem
|
|> Sql.executeAsync (fun reader -> {
|
||||||
|
Stock = reader.int "stock"
|
||||||
|
LimitStock = reader.bool "limit_stock"
|
||||||
|
Available = reader.bool "available"
|
||||||
|
StoreItem.Item = readItem reader
|
||||||
|
})
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
|
|
||||||
let getWeapons () =
|
let getWeapons () =
|
||||||
|
@ -139,6 +139,13 @@ type Item = {
|
|||||||
Attributes : ItemAttribute list
|
Attributes : ItemAttribute list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StoreItem = {
|
||||||
|
Stock : int
|
||||||
|
LimitStock : bool
|
||||||
|
Available : bool
|
||||||
|
Item : Item
|
||||||
|
}
|
||||||
|
|
||||||
type HackItem = {
|
type HackItem = {
|
||||||
Id : int
|
Id : int
|
||||||
Name : string
|
Name : string
|
||||||
|
@ -10,20 +10,22 @@ open Degenz
|
|||||||
open Degenz.Messaging
|
open Degenz.Messaging
|
||||||
open Degenz.PlayerInteractions
|
open Degenz.PlayerInteractions
|
||||||
|
|
||||||
let getItemEmbeds owned (items : Inventory) =
|
let getItemEmbeds owned (items : StoreItem list) =
|
||||||
items
|
items
|
||||||
|> List.countBy (fun item -> item.Id)
|
|> List.countBy (fun item -> item.Item.Id)
|
||||||
|> List.map (fun (id,count) -> items |> List.find (fun i -> i.Id = id) , count )
|
|> List.map (fun (id,count) -> items |> List.find (fun i -> i.Item.Id = id) , count )
|
||||||
|> List.map (fun (item,count) ->
|
|> List.map (fun (item,count) ->
|
||||||
let embed = DiscordEmbedBuilder()
|
let embed = DiscordEmbedBuilder()
|
||||||
item.Attributes
|
if not owned && item.LimitStock then
|
||||||
|
embed.AddField("Stock", $"{item.Stock}", true) |> ignore
|
||||||
|
item.Item.Attributes
|
||||||
|> List.iter (function
|
|> List.iter (function
|
||||||
| Buyable price -> embed.AddField("Price 💰", (if price = 0<GBT> then "Free" else $"{price} $GBT"), true) |> ignore
|
| Buyable price -> embed.AddField("Price 💰", (if price = 0<GBT> then "Free" else $"{price} $GBT"), true) |> ignore
|
||||||
| Attackable power ->
|
| Attackable power ->
|
||||||
let title = match item.Type with ItemType.Hack -> "$GBT Reward" | _ -> "Power"
|
let title = match item.Item.Type with ItemType.Hack -> "$GBT Reward" | _ -> "Power"
|
||||||
embed.AddField($"{title} |", string power, true) |> ignore
|
embed.AddField($"{title} |", string power, true) |> ignore
|
||||||
| RateLimitable time ->
|
| RateLimitable time ->
|
||||||
let title = match item.Type with ItemType.Hack -> "Cooldown" | ItemType.Shield -> "Active For" | _ -> "Expires"
|
let title = match item.Item.Type with ItemType.Hack -> "Cooldown" | ItemType.Shield -> "Active For" | _ -> "Expires"
|
||||||
let ts = TimeSpan.FromMinutes(int time)
|
let ts = TimeSpan.FromMinutes(int time)
|
||||||
let timeStr = if ts.Hours = 0 then $"{ts.Minutes} mins" else $"{ts.Hours} hours"
|
let timeStr = if ts.Hours = 0 then $"{ts.Minutes} mins" else $"{ts.Hours} hours"
|
||||||
embed.AddField($"{title} |", timeStr, true) |> ignore
|
embed.AddField($"{title} |", timeStr, true) |> ignore
|
||||||
@ -47,23 +49,23 @@ let getItemEmbeds owned (items : Inventory) =
|
|||||||
embed.AddField($"Effect - Amount ", $"{fx}", true) |> ignore
|
embed.AddField($"Effect - Amount ", $"{fx}", true) |> ignore
|
||||||
| _ -> ())
|
| _ -> ())
|
||||||
embed
|
embed
|
||||||
.WithColor(WeaponClass.getClassEmbedColor item)
|
.WithColor(WeaponClass.getClassEmbedColor item.Item)
|
||||||
.WithTitle($"{item.Name}")
|
.WithTitle($"{item.Item.Name}")
|
||||||
|> ignore
|
|> ignore
|
||||||
match Embeds.getItemIcon item.Id with
|
match Embeds.getItemIcon item.Item.Id with
|
||||||
| Some url -> embed.WithThumbnail(url)
|
| Some url -> embed.WithThumbnail(url)
|
||||||
| None -> if String.IsNullOrWhiteSpace(item.IconUrl) then embed else embed.WithThumbnail(item.IconUrl))
|
| None -> if String.IsNullOrWhiteSpace(item.Item.IconUrl) then embed else embed.WithThumbnail(item.Item.IconUrl))
|
||||||
|> List.map (fun e -> e.Build())
|
|> List.map (fun e -> e.Build())
|
||||||
|> Seq.ofList
|
|> Seq.ofList
|
||||||
|
|
||||||
let getBuyItemsEmbed (playerInventory : Inventory) (storeInventory : Inventory) =
|
let getBuyItemsEmbed (playerInventory : Inventory) (storeInventory : StoreItem list) =
|
||||||
let embeds = getItemEmbeds false storeInventory
|
let embeds = getItemEmbeds false storeInventory
|
||||||
let buttons =
|
let buttons =
|
||||||
storeInventory
|
storeInventory
|
||||||
|> List.map (fun item ->
|
|> List.map (fun item ->
|
||||||
if playerInventory |> List.exists (fun i -> i.Id = item.Id)
|
if playerInventory |> List.exists (fun i -> i.Id = item.Item.Id)
|
||||||
then DiscordButtonComponent(WeaponClass.getClassButtonColor item, $"Buy-{item.Id}", $"Own {item.Name}", true)
|
then DiscordButtonComponent(WeaponClass.getClassButtonColor item.Item, $"Buy-{item.Item.Id}", $"Own {item.Item.Name}", true)
|
||||||
else DiscordButtonComponent(WeaponClass.getClassButtonColor item, $"Buy-{item.Id}", $"Buy {item.Name}")
|
else DiscordButtonComponent(WeaponClass.getClassButtonColor item.Item, $"Buy-{item.Item.Id}", $"Buy {item.Item.Name}")
|
||||||
:> DiscordComponent)
|
:> DiscordComponent)
|
||||||
|
|
||||||
let builder =
|
let builder =
|
||||||
@ -174,7 +176,8 @@ let purchaseItemEmbed (item : Item) =
|
|||||||
let handleBuyItem (ctx : IDiscordContext) itemId =
|
let handleBuyItem (ctx : IDiscordContext) itemId =
|
||||||
executePlayerAction ctx (fun player -> async {
|
executePlayerAction ctx (fun player -> async {
|
||||||
let! storeInventory = DbService.getStoreItems (ctx.GetChannel().Id)
|
let! storeInventory = DbService.getStoreItems (ctx.GetChannel().Id)
|
||||||
let item = storeInventory |> Inventory.findItemById itemId
|
// let item = storeInventory |> Inventory.findItemById itemId |> fun i -> { Item = i ; Stock = 1 ; LimitStock = false ; Available = true }
|
||||||
|
let item = storeInventory |> List.map (fun i -> i.Item) |> Inventory.findItemById itemId
|
||||||
do! player
|
do! player
|
||||||
|> checkHasSufficientFunds item
|
|> checkHasSufficientFunds item
|
||||||
>>= checkDoesntExceedStackCap item
|
>>= checkDoesntExceedStackCap item
|
||||||
@ -219,7 +222,8 @@ let consume (ctx : IDiscordContext) = PlayerInteractions.executePlayerAction ctx
|
|||||||
match player.Inventory |> Inventory.getFoods with
|
match player.Inventory |> Inventory.getFoods with
|
||||||
| [] -> do! Messaging.sendFollowUpMessage ctx "You do not have any items to consume"
|
| [] -> do! Messaging.sendFollowUpMessage ctx "You do not have any items to consume"
|
||||||
| items ->
|
| items ->
|
||||||
let embeds = getItemEmbeds true items
|
let items' = items |> List.map (fun i -> { Item = i ; Stock = 1 ; LimitStock = false ; Available = true })
|
||||||
|
let embeds = getItemEmbeds true items'
|
||||||
let builder = DiscordFollowupMessageBuilder().AddEmbeds(embeds).AsEphemeral(true)
|
let builder = DiscordFollowupMessageBuilder().AddEmbeds(embeds).AsEphemeral(true)
|
||||||
do! ctx.FollowUp builder |> Async.AwaitTask
|
do! ctx.FollowUp builder |> Async.AwaitTask
|
||||||
})
|
})
|
||||||
@ -229,13 +233,17 @@ let handleConsume (ctx : IDiscordContext) itemId = PlayerInteractions.executePla
|
|||||||
match player.Inventory |> Inventory.getFoods with
|
match player.Inventory |> Inventory.getFoods with
|
||||||
| [] -> do! Messaging.sendFollowUpMessage ctx "You do not have any items to consume"
|
| [] -> do! Messaging.sendFollowUpMessage ctx "You do not have any items to consume"
|
||||||
| items ->
|
| items ->
|
||||||
let embeds = getItemEmbeds true items
|
let items' = items |> List.map (fun i -> { Item = i ; Stock = 1 ; LimitStock = false ; Available = true })
|
||||||
|
let embeds = getItemEmbeds true items'
|
||||||
let builder = DiscordFollowupMessageBuilder().AddEmbeds(embeds).AsEphemeral(true)
|
let builder = DiscordFollowupMessageBuilder().AddEmbeds(embeds).AsEphemeral(true)
|
||||||
do! ctx.FollowUp builder |> Async.AwaitTask
|
do! ctx.FollowUp builder |> Async.AwaitTask
|
||||||
})
|
})
|
||||||
|
|
||||||
let showJpegsEmbed (ctx : IDiscordContext) = PlayerInteractions.executePlayerAction ctx (fun player -> async {
|
let showJpegsEmbed (ctx : IDiscordContext) = PlayerInteractions.executePlayerAction ctx (fun player -> async {
|
||||||
let jpegs = player.Inventory |> Inventory.getItemsByType ItemType.Jpeg
|
let jpegs =
|
||||||
|
player.Inventory
|
||||||
|
|> Inventory.getItemsByType ItemType.Jpeg
|
||||||
|
|> List.map (fun i -> { Item = i ; Stock = 1 ; LimitStock = false ; Available = true })
|
||||||
let embeds = getItemEmbeds true jpegs
|
let embeds = getItemEmbeds true jpegs
|
||||||
let builder = DiscordFollowupMessageBuilder().AddEmbeds(embeds).AsEphemeral(true)
|
let builder = DiscordFollowupMessageBuilder().AddEmbeds(embeds).AsEphemeral(true)
|
||||||
do! ctx.FollowUp builder |> Async.AwaitTask
|
do! ctx.FollowUp builder |> Async.AwaitTask
|
||||||
|
Loading…
x
Reference in New Issue
Block a user