Assign Trainee role and alert player if they're in the wrong channel
This commit is contained in:
parent
7ebba3f61a
commit
3b5852bcfb
@ -51,7 +51,8 @@ let pickDefense actionId player =
|
||||
|
||||
let pickHack actionId attacker defender =
|
||||
let buttons =
|
||||
Messaging.constructButtons actionId $"{defender.DiscordId}-{defender.Name}" (Player.hacks attacker)
|
||||
let hacks = Player.hacks attacker
|
||||
Messaging.constructButtons actionId $"{defender.DiscordId}-{defender.Name}" hacks
|
||||
|> Seq.cast<DiscordComponent>
|
||||
|
||||
let embed =
|
||||
|
@ -17,6 +17,7 @@ let tokenStore = getVar "TOKEN_STORE"
|
||||
let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE"
|
||||
let channelTraining = getId "CHANNEL_TRAINING"
|
||||
let channelArmory = getId "CHANNEL_ARMORY"
|
||||
let channelBattle = getId "CHANNEL_BATTLE"
|
||||
let botHackerBattle = getId "BOT_HACKER_BATTLE"
|
||||
let botArmory = getId "BOT_ARMORY"
|
||||
let roleTrainee = getId "ROLE_TRAINEE"
|
||||
|
@ -109,7 +109,7 @@ let failedHack (event : ComponentInteractionCreateEventArgs) attacker defender h
|
||||
|> Async.Ignore
|
||||
}
|
||||
|
||||
let attack (ctx : InteractionContext) (target : DiscordUser) =
|
||||
let attack (target : DiscordUser) (ctx : InteractionContext) =
|
||||
Game.executePlayerInteraction ctx (fun attacker -> async {
|
||||
let! defender = DbService.tryFindPlayer target.Id
|
||||
match defender with
|
||||
@ -232,19 +232,33 @@ let handleButtonEvent (_ : DiscordClient) (event : ComponentInteractionCreateEve
|
||||
type HackerGame() =
|
||||
inherit ApplicationCommandModule ()
|
||||
|
||||
let enforceChannels (ctx : InteractionContext) (trainerFn : InteractionContext -> Task) (battleFn : InteractionContext -> Task) =
|
||||
match ctx.Channel.Id with
|
||||
| id when id = GuildEnvironment.channelTraining ->
|
||||
let hasTraineeRole = Seq.exists (fun (r : DiscordRole) -> r.Id = GuildEnvironment.roleTrainee) ctx.Member.Roles
|
||||
if hasTraineeRole then
|
||||
trainerFn ctx
|
||||
else
|
||||
task {
|
||||
let msg = $"You're currently not in training, either go to <#{GuildEnvironment.channelBattle}> to hack for real, "
|
||||
+ "or restart training by clicking on the Pinned embed's button up top."
|
||||
do! Messaging.sendSimpleResponse ctx msg
|
||||
}
|
||||
| id when id = GuildEnvironment.channelBattle ->
|
||||
battleFn ctx
|
||||
| _ ->
|
||||
task {
|
||||
let msg = $"You must go to <#{GuildEnvironment.channelBattle}> channel to hack or shield up for real"
|
||||
do! Messaging.sendSimpleResponse ctx msg
|
||||
}
|
||||
|
||||
[<SlashCommand("hack", "Send a hack attack to another player")>]
|
||||
member this.AttackCommand (ctx : InteractionContext, [<Option("target", "The player you want to hack")>] target : DiscordUser) =
|
||||
if ctx.Channel.Id = GuildEnvironment.channelTraining then
|
||||
Trainer.attack ctx target
|
||||
else
|
||||
attack ctx target
|
||||
enforceChannels ctx (Trainer.attack target) (attack target)
|
||||
|
||||
[<SlashCommand("shield", "Create a passive shield that will protect you for a certain time")>]
|
||||
member this.ShieldCommand (ctx : InteractionContext) =
|
||||
if ctx.Channel.Id = GuildEnvironment.channelTraining then
|
||||
Trainer.defend ctx
|
||||
else
|
||||
defend ctx
|
||||
enforceChannels ctx Trainer.defend defend
|
||||
|
||||
// [<SlashCommand("test-autocomplete", "Create a passive defense that will last 24 hours")>]
|
||||
member this.TestAutoComplete (ctx : InteractionContext) =
|
||||
|
@ -37,6 +37,11 @@ let handleTrainerStep1 (event : ComponentInteractionCreateEventArgs) =
|
||||
let name = Player.shields player |> Array.tryHead |> Option.defaultValue defaultShield |> fun w -> w.Name
|
||||
$"Looks like you have `{name}` in your arsenal… 👀\n\n" , name
|
||||
|
||||
let membr = event.User :?> DiscordMember
|
||||
let role = event.Guild.GetRole(GuildEnvironment.roleTrainee)
|
||||
do! membr.GrantRoleAsync(role)
|
||||
|> Async.AwaitTask
|
||||
|
||||
do! sendFollowUpMessage event
|
||||
("Beautopia© is a dangerous place...\n"
|
||||
+ "Quick, put up a SHIELD 🛡 before another Degen hacks you, and steals your 💰$GBT.\n\n"
|
||||
@ -99,13 +104,13 @@ let handleTrainerStep3 (event : ComponentInteractionCreateEventArgs) =
|
||||
+ $"Type the `/hack` command now, then choose me - <@{GuildEnvironment.botHackerBattle}> as your target, and select `{weaponName}`")
|
||||
})
|
||||
|
||||
let attack (ctx : InteractionContext) (target : DiscordUser) =
|
||||
let attack (target : DiscordUser) (ctx : InteractionContext) =
|
||||
Game.executePlayerInteraction ctx (fun player -> async {
|
||||
let isRightTarget = target.Id = GuildEnvironment.botHackerBattle
|
||||
match isRightTarget with
|
||||
| true ->
|
||||
let playerWithAttacks =
|
||||
match player.Arsenal with
|
||||
match Player.hacks player with
|
||||
| [||] -> { player with Arsenal = [| defaultHack |] }
|
||||
| _ -> player
|
||||
let embed = Embeds.pickHack "Trainer-4" playerWithAttacks player
|
||||
@ -137,7 +142,14 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) =
|
||||
+ "You successfully **HACKED** me, and are now an **Elite Haxor!**\n\n"
|
||||
+ "When you **HACK** other Degenz, you **STEAL** their 💰$GBT.\n"
|
||||
+ "But remember, hacks take time to recover, so use them wisely.")
|
||||
do! Async.Sleep 7000
|
||||
|
||||
do! Async.Sleep 5000
|
||||
|
||||
let membr = event.User :?> DiscordMember
|
||||
let role = event.Guild.GetRole(GuildEnvironment.roleTrainee)
|
||||
do! membr.RevokeRoleAsync(role)
|
||||
|> Async.AwaitTask
|
||||
|
||||
do! sendFollowUpMessage event
|
||||
("Your training is **complete!**\n\n"
|
||||
+ "But, you’re going to need more **HACKS & SHIELDS** 🛡 to survive in **Beautopia©...**\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user