From ad17e139c628a11f21f00f3e082e34fb750a7e8d Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sat, 26 Feb 2022 13:27:34 +0700 Subject: [PATCH] Fix issues where people don't have money and improve hack/shield embeds --- Bot/Embeds.fs | 22 +++++++++++++++------- Bot/Game.fs | 4 ++-- Bot/HackerBattle.fs | 5 +++++ Bot/Thief.fs | 8 +++++++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Bot/Embeds.fs b/Bot/Embeds.fs index 118fa0b..66df061 100644 --- a/Bot/Embeds.fs +++ b/Bot/Embeds.fs @@ -36,6 +36,7 @@ let getShieldGif = function let constructButtons (actionId: string) (buttonInfo : string) (player: PlayerData) itemType ignoreCooldown = player |> Player.getItems itemType + |> Array.sortBy (fun i -> i.Power) |> Array.map (fun item -> let action = player.Events @@ -58,13 +59,17 @@ let pickDefense actionId player isTrainer = let embed = DiscordEmbedBuilder() - .WithTitle("Shields") + .WithTitle("Shield Defense") .WithDescription("Pick a shield to protect yourself from hacks") - .WithImageUrl(shieldGif) + + for s in Player.getShields player |> Array.sortBy (fun i -> i.Power) do + let hours = TimeSpan.FromMinutes(int s.Cooldown).TotalHours + let against = Game.getGoodAgainst(s.Class) |> snd + embed.AddField(s.Name, $"Active {hours} hours\nDefeats {against}", true) |> ignore DiscordFollowupMessageBuilder() .AddComponents(buttons) - .AddEmbed(embed) + .AddEmbeds([ DiscordEmbedBuilder().WithImageUrl(shieldGif).Build() ; embed.Build() ]) .AsEphemeral(true) let pickHack actionId attacker defender isTrainer = @@ -72,13 +77,16 @@ let pickHack actionId attacker defender isTrainer = let embed = DiscordEmbedBuilder() - .WithTitle("Hacks") - .WithDescription($"Pick the hack that you want to use against {defender.Name}") - .WithImageUrl(hackGif) + .WithTitle("Hack Attack") + .WithDescription($"{defender.Name} has **{defender.Bank} $GBT** we can take from them. Pick the hack you want to use.") + + for h in Player.getHacks attacker |> Array.sortBy (fun i -> i.Power) do + let amount = if h.Power > int defender.Bank then int defender.Bank else h.Power + embed.AddField(h.Name, $"Extract {amount}", true) |> ignore DiscordFollowupMessageBuilder() .AddComponents(buttons) - .AddEmbed(embed.Build()) + .AddEmbeds([ DiscordEmbedBuilder().WithImageUrl(hackGif).Build() ; embed.Build() ]) .AsEphemeral true let responseSuccessfulHack earnedMoney (targetId : uint64) amountTaken (hack : Item) = diff --git a/Bot/Game.fs b/Bot/Game.fs index cb98b0e..9ccd028 100644 --- a/Bot/Game.fs +++ b/Bot/Game.fs @@ -21,8 +21,8 @@ module Game = let getGoodAgainst = function | 0 -> ( ShieldId.Firewall , HackId.Virus ) - | 1 -> ( ShieldId.Cypher , HackId.RemoteAccess ) - | _ -> ( ShieldId.Encryption , HackId.Worm ) + | 1 -> ( ShieldId.Encryption , HackId.RemoteAccess ) + | _ -> ( ShieldId.Cypher , HackId.Worm ) let executePlayerAction (ctx : IDiscordContext) (dispatch : PlayerData -> Async) = async { diff --git a/Bot/HackerBattle.fs b/Bot/HackerBattle.fs index 28d9835..2d47d45 100644 --- a/Bot/HackerBattle.fs +++ b/Bot/HackerBattle.fs @@ -62,6 +62,11 @@ let checkPlayerHasShieldSlotsAvailable (shield : Item) player = Error $"You are only allowed three shields at a time. Wait {cooldown} to add another shield" | false -> Ok updatedPlayer +let checkTargetHasFunds target player = + match target.Bank = 0 with + | true -> Error $"Looks like the poor bastard has no $GBT... pick a different victim." + | false -> Ok player + let calculateDamage (hack : Item) (shield : Item) = if hack.Class = shield.Class then Weak diff --git a/Bot/Thief.fs b/Bot/Thief.fs index 76a2a84..128f6ef 100644 --- a/Bot/Thief.fs +++ b/Bot/Thief.fs @@ -80,6 +80,11 @@ let checkVictimStealingCooldown defender attacker = Error $"{defender.Name} was robbed recently so they won't be going out for at least another {hours}." | None -> Ok attacker +let checkTargetHasFunds target player = + match target.Bank = 0 with + | true -> Error $"Looks like the poor bastard has no $GBT... pick a different victim." + | false -> Ok player + let checkThiefCooldown attacker = attacker |> Player.removeExpiredActions @@ -211,7 +216,8 @@ let handleSteal (ctx : IDiscordContext) = do! attacker |> Player.removeExpiredActions // |> checkVictimStealingCooldown defender - |> checkThiefCooldown + |> checkThiefCooldown + >>= checkTargetHasFunds defender |> handleResultWithResponse ctx (handleYes defender ) }) else