diff --git a/Bot/Embeds.fs b/Bot/Embeds.fs index e31b83b..d328512 100644 --- a/Bot/Embeds.fs +++ b/Bot/Embeds.fs @@ -20,32 +20,36 @@ let getShieldGif = function | ShieldId.Cypher -> "https://s10.gifyu.com/images/Cypher-Smaller.jpg" | _ -> shieldGif +let constructButtons (actionType: string) (playerInfo: string) (items: BattleItem array) = + items + |> Array.map (fun item -> DiscordButtonComponent(Game.getClassButtonColor item.Class, $"{actionType}-{item.Id}-{playerInfo}", $"{item.Name}")) + let pickDefense actionId player = let buttons = - Messaging.constructButtons actionId (string player.DiscordId) (Player.shields player) + constructButtons actionId (string player.DiscordId) (Player.shields player) |> Seq.cast let embed = DiscordEmbedBuilder() - .WithColor(DiscordColor.Blurple) + .WithTitle("Shields") .WithDescription("Pick a shield to protect yourself from hacks") .WithImageUrl(shieldGif) DiscordFollowupMessageBuilder() .AddComponents(buttons) .AddEmbed(embed) - .AsEphemeral true + .AsEphemeral(true) let pickHack actionId attacker defender = let buttons = let hacks = Player.hacks attacker - Messaging.constructButtons actionId $"{defender.DiscordId}-{defender.Name}" hacks + constructButtons actionId $"{defender.DiscordId}-{defender.Name}" hacks |> Seq.cast let embed = DiscordEmbedBuilder() - .WithColor(DiscordColor.Blurple) - .WithDescription("Pick the hack that you want to use") + .WithTitle("Hacks") + .WithDescription($"Pick the hack that you want to use against {defender.Name}") .WithImageUrl(hackGif) DiscordFollowupMessageBuilder() diff --git a/Bot/HackerBattle.fs b/Bot/HackerBattle.fs index ca10e45..6481517 100644 --- a/Bot/HackerBattle.fs +++ b/Bot/HackerBattle.fs @@ -188,12 +188,12 @@ let handleDefense (event : ComponentInteractionCreateEventArgs) = | _ , false -> let timestamp = updatedDefenses |> Array.rev |> Array.head |> fun a -> a.Timestamp // This should be the next expiring timestamp let cooldown = getTimeTillCooldownFinishes (TimeSpan.FromMinutes(int shield.Cooldown)) timestamp - do! sendFollowUpMessage event $"You are only allowed two shields at a time. Wait {cooldown} minutes to add another shield" + do! sendFollowUpMessage event $"You are only allowed two shields at a time. Wait {cooldown} to add another shield" do! DbService.updatePlayer <| { player with Actions = updatedDefenses } | true , _ -> let timestamp = updatedDefenses |> Array.find (fun d -> d.ActionId = int shieldId) |> fun a -> a.Timestamp let cooldown = getTimeTillCooldownFinishes (TimeSpan.FromMinutes(int shield.Cooldown)) timestamp - do! sendFollowUpMessage event $"{shieldId} shield is already in use. Wait {cooldown} minutes to use this shield again" + do! sendFollowUpMessage event $"{shield.Name} shield is already in use. Wait {cooldown} to use this shield again" do! DbService.updatePlayer <| { player with Actions = updatedDefenses } }) diff --git a/Bot/Store.fs b/Bot/Store.fs index 6332bde..c82544f 100644 --- a/Bot/Store.fs +++ b/Bot/Store.fs @@ -67,7 +67,6 @@ let buy itemType (ctx : InteractionContext) = |> Async.Ignore }) -// TODO: Remove active shield when selling let sell itemType (ctx : InteractionContext) = Game.executePlayerInteraction ctx (fun player -> async { match checkHasItemsInArsenal itemType player with @@ -101,7 +100,15 @@ let handleSell (event : ComponentInteractionCreateEventArgs) itemId = do! player |> checkSoldItemAlready item |> handleResultWithResponseFromEvent event (fun player -> async { - let updatedPlayer = { player with Bank = player.Bank + item.Cost ; Arsenal = player.Arsenal |> Array.filter (fun w -> w.Id <> itemId) } + let updatedPlayer = { + player with + Bank = player.Bank + item.Cost + Arsenal = player.Arsenal |> Array.filter (fun i -> i.Id <> itemId) + Actions = + if item.Type = ItemType.Shield + then player.Actions |> Array.filter (fun a -> a.ActionId <> itemId) + else player.Actions + } do! DbService.updatePlayer updatedPlayer do! sendFollowUpMessage event $"Sold {item.Type} {item.Name} for {item.Cost}! Current Balance: {updatedPlayer.Bank}" }) @@ -135,7 +142,7 @@ type Store() = } [] - member this.Arsenal (ctx : InteractionContext) = enforceChannel ctx arsenal + member this.Arsenal (ctx : InteractionContext) = arsenal ctx [] member _.BuyHack (ctx : InteractionContext) = enforceChannel ctx (buy ItemType.Hack) diff --git a/Shared/Shared.fs b/Shared/Shared.fs index f6febd4..719e089 100644 --- a/Shared/Shared.fs +++ b/Shared/Shared.fs @@ -122,10 +122,6 @@ module Messaging = $"{item.Name} active for {cooldown}") |> String.concat "\n" - let constructButtons (actionType: string) (playerInfo: string) (weapons: BattleItem array) = - weapons - |> Array.map (fun w -> DiscordButtonComponent(ButtonStyle.Success, $"{actionType}-{w.Id}-{playerInfo}", $"{w.Name}")) - let sendSimpleResponse (ctx: InteractionContext) msg = async { let builder = DiscordInteractionResponseBuilder()