Stop player from hacking themself, don't check for trainer role, clean up
This commit is contained in:
parent
5f4bb71245
commit
d1cf329521
@ -18,6 +18,12 @@ let getTimeTillCooldownFinishes (timespan : TimeSpan) timestamp =
|
||||
else
|
||||
$"{timeRemaining.Seconds} seconds"
|
||||
|
||||
|
||||
let checkIfPlayerIsAttackingThemselves defender attacker =
|
||||
match attacker.DiscordId = defender.DiscordId with
|
||||
| true -> Error "You think you're clever? You can't hack yourself, pal."
|
||||
| false -> Ok attacker
|
||||
|
||||
let checkForExistingHack defenderId attacker =
|
||||
let updatedAttacks =
|
||||
attacker.Attacks
|
||||
@ -81,13 +87,8 @@ let successfulHack (event : ComponentInteractionCreateEventArgs) attacker defend
|
||||
|
||||
do! updateCombatants attacker defender hack prize
|
||||
|
||||
let embed = DiscordEmbedBuilder()
|
||||
embed.ImageUrl <- Embeds.getHackGif hack
|
||||
let builder = DiscordInteractionResponseBuilder()
|
||||
builder.IsEphemeral <- true
|
||||
builder.AddEmbed embed |> ignore
|
||||
builder.Content <- $"Successfully hacked {defender.Name} using {hack}! You just won {prize} GoodBoyTokenz!"
|
||||
do! event.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|
||||
let embed = Embeds.responseSuccessfulHack defender.Name hack prize
|
||||
do! event.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, embed)
|
||||
|> Async.AwaitTask
|
||||
|
||||
let builder = Embeds.eventSuccessfulHack event defender.DiscordId prize
|
||||
@ -125,6 +126,7 @@ let attack (ctx : InteractionContext) (target : DiscordUser) =
|
||||
let hackAttempt =
|
||||
checkForExistingHack defender.DiscordId attacker
|
||||
|> Result.bind checkIfInventoryIsEmpty
|
||||
|> Result.bind (checkIfPlayerIsAttackingThemselves defender)
|
||||
match hackAttempt with
|
||||
| Ok _ ->
|
||||
let embed = Embeds.pickHack "Attack" attacker defender
|
||||
@ -150,7 +152,6 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) =
|
||||
let! resultPlayer = DbService.tryFindPlayer event.User.Id
|
||||
let! resultTarget = DbService.tryFindPlayer targetId
|
||||
|
||||
// TODO: Do not let player hack themselves
|
||||
match resultPlayer , resultTarget , true , resultId with
|
||||
| Some attacker , Some defender , true , true ->
|
||||
do! checkForExistingHack defender.DiscordId attacker
|
||||
@ -207,13 +208,8 @@ let handleDefense (event : ComponentInteractionCreateEventArgs) =
|
||||
|
||||
match alreadyUsedShield , updatedDefenses.Length < 2 with
|
||||
| false , true ->
|
||||
let builder = DiscordInteractionResponseBuilder()
|
||||
let embed = DiscordEmbedBuilder()
|
||||
embed.ImageUrl <- Embeds.getShieldGif shield
|
||||
builder.IsEphemeral <- true
|
||||
builder.AddEmbed embed |> ignore
|
||||
builder.Content <- $"Mounted a {shield} defense for 6 hours"
|
||||
do! event.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|
||||
let embed = Embeds.responseCreatedShield shield
|
||||
do! event.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, embed)
|
||||
|> Async.AwaitTask
|
||||
let defense = { DefenseType = shield ; Timestamp = DateTime.UtcNow }
|
||||
do! DbService.updatePlayer <| { player with Defenses = Array.append [| defense |] player.Defenses }
|
||||
@ -274,16 +270,14 @@ type HackerGame() =
|
||||
|
||||
[<SlashCommand("hack", "Send a hack attack to another player")>]
|
||||
member this.AttackCommand (ctx : InteractionContext, [<Option("target", "The player you want to hack")>] target : DiscordUser) =
|
||||
let hasTraineeRole = Seq.exists (fun (r : DiscordRole) -> r.Id = GuildEnvironment.roleTrainee) ctx.Member.Roles
|
||||
if ctx.Channel.Id = GuildEnvironment.channelTraining && hasTraineeRole then
|
||||
if ctx.Channel.Id = GuildEnvironment.channelTraining then
|
||||
Trainer.attack ctx target
|
||||
else
|
||||
attack ctx target
|
||||
|
||||
[<SlashCommand("defend", "Create a passive defense that will last 24 hours")>]
|
||||
member this.DefendCommand (ctx : InteractionContext) =
|
||||
let hasTraineeRole = Seq.exists (fun (r : DiscordRole) -> r.Id = GuildEnvironment.roleTrainee) ctx.Member.Roles
|
||||
if ctx.Channel.Id = GuildEnvironment.channelTraining && hasTraineeRole then
|
||||
if ctx.Channel.Id = GuildEnvironment.channelTraining then
|
||||
Trainer.defend ctx
|
||||
else
|
||||
defend ctx
|
||||
|
@ -52,7 +52,6 @@ module Commands =
|
||||
}
|
||||
|
||||
if newPlayer then
|
||||
// TODO: Add a better registration message that shows which weapon and how much currency they start with
|
||||
do! ctx.CreateResponseAsync("You are now an elite haxxor", true)
|
||||
|> Async.AwaitTask
|
||||
else
|
||||
|
@ -7,6 +7,9 @@ open DSharpPlus.EventArgs
|
||||
open DSharpPlus.SlashCommands
|
||||
open Degenz.Shared
|
||||
|
||||
let defaultHack = Hack.Virus
|
||||
let defaultShield = Shield.Firewall
|
||||
|
||||
let sendInitialEmbed (client : DiscordClient) =
|
||||
async {
|
||||
let! channel = client.GetChannelAsync(GuildEnvironment.channelTraining) |> Async.AwaitTask
|
||||
@ -47,7 +50,7 @@ let handleTrainerStep2 (event : ComponentInteractionCreateEventArgs) =
|
||||
let! result = DbService.tryFindPlayer event.User.Id
|
||||
match result with
|
||||
| Some player ->
|
||||
let weaponName = player.Shields |> Array.tryHead |> Option.defaultValue Shield.Firewall
|
||||
let weaponName = player.Shields |> Array.tryHead |> Option.defaultValue defaultShield
|
||||
do! Message.sendInteractionEvent event
|
||||
($"First things first, let's get your system protected. Let's enable a shield to protect you from potential hackers. "
|
||||
+ $"You currently have {weaponName} in your arsenal. To enable it and protect your system, you can use the `/defend` slash command to choose a shield."
|
||||
@ -63,7 +66,7 @@ let defend (ctx : InteractionContext) =
|
||||
| Some player ->
|
||||
let playerWithShields =
|
||||
match player.Shields with
|
||||
| [||] -> { player with Shields = [| Shield.Firewall |] }
|
||||
| [||] -> { player with Shields = [| defaultShield |] }
|
||||
| _ -> player
|
||||
let embed = Embeds.pickDefense "Trainer-3" playerWithShields
|
||||
|
||||
@ -89,8 +92,10 @@ let handleDefense (event : ComponentInteractionCreateEventArgs) =
|
||||
match result with
|
||||
| Some player ->
|
||||
let prize = 0.223f
|
||||
do! sendMessage' $"{event.User.Username} has protected their system!"
|
||||
do! Async.Sleep 3000
|
||||
let shield = player.Shields |> Array.tryHead |> Option.defaultValue defaultShield
|
||||
let embed = Embeds.responseCreatedShieldTrainer shield
|
||||
do! event.Interaction.CreateFollowupMessageAsync(embed) |> Async.AwaitTask |> Async.Ignore
|
||||
do! Async.Sleep 2000
|
||||
do! sendMessage' "Ok, good, let me make sure that worked. I'll try to hack you now"
|
||||
do! Async.Sleep 4000
|
||||
do! sendMessage' $"Hacking attempt failed! {player.Name} defended hack from Degenz-Trainer and took {prize} from them! "
|
||||
@ -107,8 +112,7 @@ let handleTrainerStep4 (event : ComponentInteractionCreateEventArgs) =
|
||||
let! result = DbService.tryFindPlayer event.User.Id
|
||||
match result with
|
||||
| Some player ->
|
||||
// TODO: There's a potential bug here where if the player sold their weapons, they'll get stuck
|
||||
let weaponName = player.Weapons |> Array.tryHead |> Option.defaultValue Hack.Virus
|
||||
let weaponName = player.Weapons |> Array.tryHead |> Option.defaultValue defaultHack
|
||||
do! Message.sendInteractionEvent event
|
||||
($"Next why don't you try hacking me. You currently have {weaponName} equipped. To hack me and get some money, "
|
||||
+ $" you can use the '/hack' slash command and select a user to hack, then choose the hack attack you wish to use."
|
||||
@ -156,11 +160,13 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) =
|
||||
| Some player ->
|
||||
let prize = 2
|
||||
do! Async.Sleep 1000
|
||||
do! sendMessage' $"{player.Name} successfully hacked Degenz-Trainer for a total of {prize} GoodBoyTokenz"
|
||||
let hack = player.Weapons |> Array.tryHead |> Option.defaultValue defaultHack
|
||||
let embed = Embeds.responseSuccessfulHackTrainer $"<@{GuildEnvironment.botHackerBattle}>" hack prize
|
||||
do! event.Interaction.CreateFollowupMessageAsync(embed) |> Async.AwaitTask |> Async.Ignore
|
||||
do! Async.Sleep 3000
|
||||
do! sendMessage' ("Look at that, you are now officially an elite haxor! By successfully hacking other people you can earn GoodBoyTokenz. "
|
||||
+ "Hacks take time to recover so check back in later once you've used all your hacks.")
|
||||
do! Async.Sleep 6000
|
||||
do! Async.Sleep 7000
|
||||
let msg = ("I think we're done. You are going to need more hacks and shields if you want to survive in this crazy world. "
|
||||
+ "Remember to go check out the store and purchase whatever you need to add to your arsenal."
|
||||
+ "\n\nAlright you degenerate, off you go!")
|
||||
|
Loading…
x
Reference in New Issue
Block a user