Fix issues where people don't have money and improve hack/shield embeds

This commit is contained in:
Joseph Ferano 2022-02-26 13:27:34 +07:00
parent 658c57f97b
commit ad17e139c6
4 changed files with 29 additions and 10 deletions

View File

@ -36,6 +36,7 @@ let getShieldGif = function
let constructButtons (actionId: string) (buttonInfo : string) (player: PlayerData) itemType ignoreCooldown = let constructButtons (actionId: string) (buttonInfo : string) (player: PlayerData) itemType ignoreCooldown =
player player
|> Player.getItems itemType |> Player.getItems itemType
|> Array.sortBy (fun i -> i.Power)
|> Array.map (fun item -> |> Array.map (fun item ->
let action = let action =
player.Events player.Events
@ -58,13 +59,17 @@ let pickDefense actionId player isTrainer =
let embed = let embed =
DiscordEmbedBuilder() DiscordEmbedBuilder()
.WithTitle("Shields") .WithTitle("Shield Defense")
.WithDescription("Pick a shield to protect yourself from hacks") .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() DiscordFollowupMessageBuilder()
.AddComponents(buttons) .AddComponents(buttons)
.AddEmbed(embed) .AddEmbeds([ DiscordEmbedBuilder().WithImageUrl(shieldGif).Build() ; embed.Build() ])
.AsEphemeral(true) .AsEphemeral(true)
let pickHack actionId attacker defender isTrainer = let pickHack actionId attacker defender isTrainer =
@ -72,13 +77,16 @@ let pickHack actionId attacker defender isTrainer =
let embed = let embed =
DiscordEmbedBuilder() DiscordEmbedBuilder()
.WithTitle("Hacks") .WithTitle("Hack Attack")
.WithDescription($"Pick the hack that you want to use against {defender.Name}") .WithDescription($"{defender.Name} has **{defender.Bank} $GBT** we can take from them. Pick the hack you want to use.")
.WithImageUrl(hackGif)
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() DiscordFollowupMessageBuilder()
.AddComponents(buttons) .AddComponents(buttons)
.AddEmbed(embed.Build()) .AddEmbeds([ DiscordEmbedBuilder().WithImageUrl(hackGif).Build() ; embed.Build() ])
.AsEphemeral true .AsEphemeral true
let responseSuccessfulHack earnedMoney (targetId : uint64) amountTaken (hack : Item) = let responseSuccessfulHack earnedMoney (targetId : uint64) amountTaken (hack : Item) =

View File

@ -21,8 +21,8 @@ module Game =
let getGoodAgainst = function let getGoodAgainst = function
| 0 -> ( ShieldId.Firewall , HackId.Virus ) | 0 -> ( ShieldId.Firewall , HackId.Virus )
| 1 -> ( ShieldId.Cypher , HackId.RemoteAccess ) | 1 -> ( ShieldId.Encryption , HackId.RemoteAccess )
| _ -> ( ShieldId.Encryption , HackId.Worm ) | _ -> ( ShieldId.Cypher , HackId.Worm )
let executePlayerAction (ctx : IDiscordContext) (dispatch : PlayerData -> Async<unit>) = let executePlayerAction (ctx : IDiscordContext) (dispatch : PlayerData -> Async<unit>) =
async { async {

View File

@ -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" Error $"You are only allowed three shields at a time. Wait {cooldown} to add another shield"
| false -> Ok updatedPlayer | false -> Ok updatedPlayer
let checkTargetHasFunds target player =
match target.Bank = 0<GBT> with
| true -> Error $"Looks like the poor bastard has no $GBT... pick a different victim."
| false -> Ok player
let calculateDamage (hack : Item) (shield : Item) = let calculateDamage (hack : Item) (shield : Item) =
if hack.Class = shield.Class if hack.Class = shield.Class
then Weak then Weak

View File

@ -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}." Error $"{defender.Name} was robbed recently so they won't be going out for at least another {hours}."
| None -> Ok attacker | None -> Ok attacker
let checkTargetHasFunds target player =
match target.Bank = 0<GBT> with
| true -> Error $"Looks like the poor bastard has no $GBT... pick a different victim."
| false -> Ok player
let checkThiefCooldown attacker = let checkThiefCooldown attacker =
attacker attacker
|> Player.removeExpiredActions |> Player.removeExpiredActions
@ -212,6 +217,7 @@ let handleSteal (ctx : IDiscordContext) =
|> Player.removeExpiredActions |> Player.removeExpiredActions
// |> checkVictimStealingCooldown defender // |> checkVictimStealingCooldown defender
|> checkThiefCooldown |> checkThiefCooldown
>>= checkTargetHasFunds defender
|> handleResultWithResponse ctx (handleYes defender ) |> handleResultWithResponse ctx (handleYes defender )
}) })
else else