diff --git a/Bot/DbService.fs b/Bot/DbService.fs index c82327d..baa7c76 100644 --- a/Bot/DbService.fs +++ b/Bot/DbService.fs @@ -93,14 +93,19 @@ let getStoreItems (channelId : uint64) = |> Sql.connect |> Sql.parameters [ "cid", Sql.string (string channelId) ] |> 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 FROM store_item JOIN store st on store_item.store_id = st.id JOIN item i on store_item.item_id = i.id 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 let getWeapons () = diff --git a/Bot/GameTypes.fs b/Bot/GameTypes.fs index 8b8e73b..2bf556d 100644 --- a/Bot/GameTypes.fs +++ b/Bot/GameTypes.fs @@ -139,6 +139,13 @@ type Item = { Attributes : ItemAttribute list } +type StoreItem = { + Stock : int + LimitStock : bool + Available : bool + Item : Item +} + type HackItem = { Id : int Name : string diff --git a/Bot/Games/Store.fs b/Bot/Games/Store.fs index 1516be9..f531ed1 100644 --- a/Bot/Games/Store.fs +++ b/Bot/Games/Store.fs @@ -10,20 +10,22 @@ open Degenz open Degenz.Messaging open Degenz.PlayerInteractions -let getItemEmbeds owned (items : Inventory) = +let getItemEmbeds owned (items : StoreItem list) = items - |> List.countBy (fun item -> item.Id) - |> List.map (fun (id,count) -> items |> List.find (fun i -> i.Id = id) , count ) + |> List.countBy (fun item -> item.Item.Id) + |> List.map (fun (id,count) -> items |> List.find (fun i -> i.Item.Id = id) , count ) |> List.map (fun (item,count) -> let embed = DiscordEmbedBuilder() - item.Attributes + if not owned && item.LimitStock then + embed.AddField("Stock", $"{item.Stock}", true) |> ignore + item.Item.Attributes |> List.iter (function | Buyable price -> embed.AddField("Price 💰", (if price = 0 then "Free" else $"{price} $GBT"), true) |> ignore | 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 | 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 timeStr = if ts.Hours = 0 then $"{ts.Minutes} mins" else $"{ts.Hours} hours" embed.AddField($"{title} |", timeStr, true) |> ignore @@ -47,23 +49,23 @@ let getItemEmbeds owned (items : Inventory) = embed.AddField($"Effect - Amount ", $"{fx}", true) |> ignore | _ -> ()) embed - .WithColor(WeaponClass.getClassEmbedColor item) - .WithTitle($"{item.Name}") + .WithColor(WeaponClass.getClassEmbedColor item.Item) + .WithTitle($"{item.Item.Name}") |> ignore - match Embeds.getItemIcon item.Id with + match Embeds.getItemIcon item.Item.Id with | 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()) |> Seq.ofList -let getBuyItemsEmbed (playerInventory : Inventory) (storeInventory : Inventory) = +let getBuyItemsEmbed (playerInventory : Inventory) (storeInventory : StoreItem list) = let embeds = getItemEmbeds false storeInventory let buttons = storeInventory |> List.map (fun item -> - if playerInventory |> List.exists (fun i -> i.Id = item.Id) - then DiscordButtonComponent(WeaponClass.getClassButtonColor item, $"Buy-{item.Id}", $"Own {item.Name}", true) - else DiscordButtonComponent(WeaponClass.getClassButtonColor item, $"Buy-{item.Id}", $"Buy {item.Name}") + if playerInventory |> List.exists (fun i -> i.Id = item.Item.Id) + then DiscordButtonComponent(WeaponClass.getClassButtonColor item.Item, $"Buy-{item.Item.Id}", $"Own {item.Item.Name}", true) + else DiscordButtonComponent(WeaponClass.getClassButtonColor item.Item, $"Buy-{item.Item.Id}", $"Buy {item.Item.Name}") :> DiscordComponent) let builder = @@ -174,7 +176,8 @@ let purchaseItemEmbed (item : Item) = let handleBuyItem (ctx : IDiscordContext) itemId = executePlayerAction ctx (fun player -> async { 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 |> checkHasSufficientFunds item >>= checkDoesntExceedStackCap item @@ -218,8 +221,9 @@ let handleSell (ctx : IDiscordContext) itemId = let consume (ctx : IDiscordContext) = PlayerInteractions.executePlayerAction ctx (fun player -> async { match player.Inventory |> Inventory.getFoods with | [] -> do! Messaging.sendFollowUpMessage ctx "You do not have any items to consume" - | items -> - let embeds = getItemEmbeds true items + | 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) do! ctx.FollowUp builder |> Async.AwaitTask }) @@ -229,13 +233,17 @@ let handleConsume (ctx : IDiscordContext) itemId = PlayerInteractions.executePla match player.Inventory |> Inventory.getFoods with | [] -> do! Messaging.sendFollowUpMessage ctx "You do not have any items to consume" | 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) do! ctx.FollowUp builder |> Async.AwaitTask }) 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 builder = DiscordFollowupMessageBuilder().AddEmbeds(embeds).AsEphemeral(true) do! ctx.FollowUp builder |> Async.AwaitTask