discord-bot-game/Bot/Trainer.fs

159 lines
7.6 KiB
Forth
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Degenz.Trainer
open DSharpPlus
open System.Threading.Tasks
open DSharpPlus.Entities
open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Degenz.Types
open Degenz.Messaging
let defaultHack = Armory.battleItems |> Array.find (fun i -> i.Id = int HackId.Virus)
let defaultShield = Armory.battleItems |> Array.find (fun i -> i.Id = int ShieldId.Encryption)
let sendInitialEmbed (client : DiscordClient) =
async {
let! channel = client.GetChannelAsync(GuildEnvironment.channelTraining) |> Async.AwaitTask
let builder = DiscordMessageBuilder()
let embed = DiscordEmbedBuilder()
embed.ImageUrl <- "https://s10.gifyu.com/images/MasterTraining_Degenz.gif"
builder.AddEmbed embed |> ignore
builder.Content <- "Welcome Degen… To the Hacker Training Program.\n"
+ "Here you will learn how to defend yourself, and hack other Degenz to steal their 💰$GBT.\n"
+ "Are you ready?"
let button = DiscordButtonComponent(ButtonStyle.Success, $"Trainer-1", $"LFG") :> DiscordComponent
builder.AddComponents [| button |] |> ignore
do! channel.SendMessageAsync(builder)
|> Async.AwaitTask
|> Async.Ignore
} |> Async.RunSynchronously
let handleTrainerStep1 (event : ComponentInteractionCreateEventArgs) =
Game.executePlayerEvent event (fun player -> async {
let shieldMessage , weaponName =
if Player.shields player |> Array.isEmpty
then $"You do not have any Shields in your arsenal, take this {defaultShield.Name}, you can use it for now.\n\n" , defaultShield.Name
else
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
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"
+ shieldMessage
+ "To enable it, you need to run the `/shield` slash command.\n\n"
+ $"Type the `/shield` command now, then select - `{weaponName}`\n")
})
let defend (ctx : InteractionContext) =
Game.executePlayerInteraction ctx (fun player -> async {
let playerWithShields =
match Player.shields player with
| [||] -> { player with Arsenal = [| defaultShield |] }
| _ -> player
let embed = Embeds.pickDefense "Trainer-2" playerWithShields
do! ctx.FollowUpAsync(embed)
|> Async.AwaitTask
|> Async.Ignore
})
let handleDefenseMsg = {
ButtonId = "Trainer-3"
ButtonText = "Got it"
Message = "🎉 Congratulations\n\n"
+ "You successfully defended my hack!\n\n"
+ "Because I tried hacking you when you had your defense up, you stole money from me...\n"
+ "Defenses only protect you for a LIMITED TIME, so remember to keep at least 1 defense up at all times, or risk getting hacked!"
}
let handleDefense (event : ComponentInteractionCreateEventArgs) =
Game.executePlayerEvent event (fun player -> async {
let sendMessage' = sendFollowUpMessage event
let shield = Player.shields player |> 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.\n\nI'll try to **hack** you now"
do! Async.Sleep 4000
do! sendMessage' $"❌ HACKING FAILED!\n\n{player.Name} defended the hack from <@{GuildEnvironment.botHackerBattle}>, and stole 💰$GBT {Game.ShieldPrize} from them!"
do! Async.Sleep 3000
do! sendFollowUpMessageWithButton event handleDefenseMsg
})
let handleTrainerStep3 (event : ComponentInteractionCreateEventArgs) =
Game.executePlayerEvent event (fun player -> async {
let hackMessage , weaponName =
if Player.hacks player |> Array.isEmpty
then $"You do not have any Hacks in your arsenal, take this `{defaultHack.Name}`, you can use it for now.\n\n" , defaultHack.Name
else
let name = Player.hacks player |> Array.tryHead |> Option.defaultValue defaultHack |> fun w -> w.Name
$"Looks like you have `{name}` in your arsenal...\n\n" , name
do! sendFollowUpMessage event
("Now lets **HACK!** 💻\n\n"
+ "I want you to **HACK ME**, and try to steal my 💰$GBT...\n\n"
+ hackMessage
+ "To deploy it, you need to run the `/hack` slash command.\n"
+ $"Type the `/hack` command now, then choose me - <@{GuildEnvironment.botHackerBattle}> as your target, and select `{weaponName}`")
})
let attack (ctx : InteractionContext) (target : DiscordUser) =
Game.executePlayerInteraction ctx (fun player -> async {
let isRightTarget = target.Id = GuildEnvironment.botHackerBattle
match isRightTarget with
| true ->
let playerWithAttacks =
match player.Arsenal with
| [||] -> { player with Arsenal = [| defaultHack |] }
| _ -> player
let embed = Embeds.pickHack "Trainer-4" playerWithAttacks player
do! ctx.FollowUpAsync(embed)
|> Async.AwaitTask
|> Async.Ignore
| false ->
let builder = DiscordFollowupMessageBuilder()
builder.Content <- "You picked the wrong target, you dufus. Try again, this time pick me!"
builder.IsEphemeral <- true
do! ctx.FollowUpAsync(builder)
|> Async.AwaitTask
|> Async.Ignore
})
let handleAttack (event : ComponentInteractionCreateEventArgs) =
Game.executePlayerEvent event (fun player -> async {
let sendMessage' = sendFollowUpMessage event
do! Async.Sleep 1000
let hack = Player.hacks player |> Array.tryHead |> Option.defaultValue defaultHack
let embed = Embeds.responseSuccessfulHack hack
do! event.Interaction.CreateFollowupMessageAsync(embed) |> Async.AwaitTask |> Async.Ignore
do! Async.Sleep 3000
do! sendMessage'
("🎉 **Congratulations**\n\n"
+ "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! sendFollowUpMessage event
("Your training is **complete!**\n\n"
+ "But, youre going to need more **HACKS & SHIELDS** 🛡 to survive in **Beautopia©...**\n"
+ $"You can purchase them from <@{GuildEnvironment.botArmory}> anytime you want...\n\n"
+ $"Go to the <#{GuildEnvironment.channelArmory}> **NOW** and type the `/buy-shield` slash command! 😱")
})
let handleButtonEvent (event : ComponentInteractionCreateEventArgs) =
async {
let split = event.Id.Split("-")
match int split.[1] with
| 1 -> do! handleTrainerStep1 event |> Async.AwaitTask
| 2 -> do! handleDefense event |> Async.AwaitTask
| 3 -> do! handleTrainerStep3 event |> Async.AwaitTask
| 4 -> do! handleAttack event |> Async.AwaitTask
| _ -> do! sendFollowUpMessage event "No action found"
}