discord-bot-game/Bot/Embeds.fs
2022-06-02 23:25:03 +07:00

152 lines
6.4 KiB
Forth

module Degenz.Embeds
open System
open Degenz
open Degenz.Messaging
open DSharpPlus.Entities
let hackGif = "https://s10.gifyu.com/images/Hacker-Degenz-V20ce8eb832734aa62-min.gif"
let shieldGif = "https://s10.gifyu.com/images/Defense-Degenz-V2-min.gif"
let constructButtons (actionId: string) (buttonInfo : string) (player: PlayerData) (items : Inventory) ignoreCooldown =
items
|> List.map (fun item ->
let action =
player.Events
|> List.tryFind (fun event ->
match event.Type with
| Hacking h -> h.HackId = item.Id && h.IsInstigator
| Shielding id -> id = item.Id
| _ -> false)
let btnColor = WeaponClass.getClassButtonColor item
match action , ignoreCooldown with
| None , _ | Some _ , true ->
DiscordButtonComponent(btnColor, $"{actionId}-{item.Id}-{buttonInfo}-{player.Name}", $"{item.Name}")
| Some event , false ->
let time = Messaging.getShortTimeText (TimeSpan.FromMinutes(int event.Cooldown)) event.Timestamp
DiscordButtonComponent(btnColor, $"{actionId}-{item.Id}", $"{item.Name} ({time} left)", true))
|> Seq.cast<DiscordComponent>
let pickDefense actionId player isTrainer =
let shieldItems =
player.Inventory
|> Inventory.getItemsByType ItemType.Shield
|> List.sortBy (fun item -> item.Id)
let buttons = constructButtons actionId (string player.DiscordId) player shieldItems isTrainer
let embed =
DiscordEmbedBuilder()
.WithTitle("Shield Defense")
.WithDescription("Pick a shield to protect yourself from hacks")
for shield in Inventory.getShields player.Inventory do
let hours = TimeSpan.FromMinutes(int shield.Cooldown).TotalHours |> int
let against = WeaponClass.getGoodAgainst shield.Class |> snd
embed.AddField(shield.Name, $"Active {hours} hours\nDefeats {against}", true) |> ignore
DiscordFollowupMessageBuilder()
.AddComponents(buttons)
.AddEmbeds([ DiscordEmbedBuilder().WithImageUrl(shieldGif).Build() ; embed.Build() ])
.AsEphemeral(true)
let pickHack actionId attacker defender bonus isTrainer =
let hackItems =
attacker.Inventory
|> Inventory.getItemsByType ItemType.Hack
|> List.sortBy (fun item -> item.Id)
let buttons = constructButtons actionId $"{defender.DiscordId}-{defender.Name}" attacker hackItems isTrainer
let ( outcomeMsg , bonusMsg ) =
if attacker.Stats.Strength.Amount > defender.Stats.Strength.Amount then
"\nYou're stronger so you'll steal more!!!\n" , $"\n**__Potential Bonus:__**\n`{bonus} 💰$GBT`"
else
"\nYou're not stronger than them, you need to eat more!" , ""
let stealMsg =
if not isTrainer
then $"""
**{defender.Name}** has `{defender.Bank} $GBT` we can take from them.
**__Your Strength:__**
`💪 {attacker.Stats.Strength.Amount}`
**__Their Strength:__**
`💪 {defender.Stats.Strength.Amount}`
{outcomeMsg}{bonusMsg}"""
else ""
let embed =
DiscordEmbedBuilder()
.WithTitle("Hack Attack")
.WithDescription($"{stealMsg}\n\nPick the hack you want to use.")
if not isTrainer then
for hack in Inventory.getHacks attacker.Inventory do
let amount = if hack.Power > int defender.Bank then int defender.Bank else hack.Power
embed.AddField(hack.Name, $"Cooldown: {hack.Cooldown} mins\nSteal Total: `{amount + bonus} $GBT`", true) |> ignore
DiscordFollowupMessageBuilder()
.AddComponents(buttons)
.AddEmbeds([ DiscordEmbedBuilder().WithImageUrl(hackGif).Build() ; embed.Build() ])
.AsEphemeral true
let responseSuccessfulHack (hacker : PlayerData) (target : PlayerData) totalTaken bonus (hack : HackItem) =
let earnedMoney = totalTaken > 0<GBT>
let msg = $"You successfully hacked <@{target.DiscordId}> using {hack.Name}!\n\n"
+ (if earnedMoney then $"**__Total Stolen__**: {totalTaken} 💰$GBT\n" else "")
let bonusMsg =
if bonus > 0<GBT>
then $"Because your strength is `💪 {hacker.Stats.Strength.Amount}` and your target's strength is `💪 {target.Stats.Strength.Amount}` You stole an extra `{bonus}` 💰$GBT"
else ""
let embed =
DiscordEmbedBuilder()
.WithImageUrl(hack.ImageUrl)
.WithTitle("✅ Hack Successful!")
.WithDescription($"{msg}\n{bonusMsg}")
embed.AddField("New $GBT Balance", $"`💰` {hacker.Bank} `💰` {hacker.Bank + totalTaken} `(+{totalTaken} $GBT)`") |> ignore
DiscordFollowupMessageBuilder()
.AddEmbed(embed.Build())
.AsEphemeral(true)
let responseCreatedShield (shield : ShieldItem) =
let embed = DiscordEmbedBuilder().WithImageUrl(shield.ImageUrl)
embed.Title <- "Mounted Shield"
embed.Description <- $"Mounted {shield.Name} shield for {TimeSpan.FromMinutes(int shield.Cooldown).TotalHours} hours"
DiscordFollowupMessageBuilder()
.AddEmbed(embed)
.AsEphemeral(true)
let eventSuccessfulHack (ctx : IDiscordContext) target prize =
DiscordMessageBuilder()
.WithContent($"{ctx.GetDiscordMember().Username} successfully hacked <@{target.DiscordId}> and took {prize} GoodBoyTokenz")
let getArsenalEmbed (player : PlayerData) =
DiscordFollowupMessageBuilder()
.AsEphemeral(true)
.AddEmbed(
DiscordEmbedBuilder()
.AddField( "Arsenal", Arsenal.statusFormat player ))
let getAchievementEmbed rewards description achievement =
let embed = DiscordEmbedBuilder()
GuildEnvironment.botClientHacker
|> Option.iter (fun bot ->
embed.Author <- DiscordEmbedBuilder.EmbedAuthor()
embed.Author.Name <- bot.CurrentUser.Username
embed.Author.IconUrl <- bot.CurrentUser.AvatarUrl)
DiscordFollowupMessageBuilder()
.AddEmbed(
embed.WithTitle("Achievement Unlocked!")
.WithDescription(description)
.WithColor(DiscordColor.Gold)
// .AddField("Achievement", $"🏆 {achievement}")
.AddField("Achievement", $"{achievement}", true)
.AddField("Gifts", rewards |> String.concat "\n", true)
// TODO: Once we add another achievement, fix this
.WithImageUrl("https://s10.gifyu.com/images/MasterTraining_Degenz.gif"))
.AsEphemeral(true)