Small improvements to the hack/shield embeds. Delete active shield after selling

This commit is contained in:
Joseph Ferano 2022-02-07 23:01:53 +07:00
parent 0e3909d4f2
commit 2603833fc6
4 changed files with 22 additions and 15 deletions

View File

@ -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<DiscordComponent>
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<DiscordComponent>
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()

View File

@ -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 }
})

View File

@ -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() =
}
[<SlashCommand("arsenal", "Get the Hacks and Shields you own, and which ones are active")>]
member this.Arsenal (ctx : InteractionContext) = enforceChannel ctx arsenal
member this.Arsenal (ctx : InteractionContext) = arsenal ctx
[<SlashCommand("buy-hack", "Purchase a hack attack you can use to earn GoodBoyTokenz")>]
member _.BuyHack (ctx : InteractionContext) = enforceChannel ctx (buy ItemType.Hack)

View File

@ -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()