module DegenzGame.Shared open System open DSharpPlus open DSharpPlus.Entities open DSharpPlus.SlashCommands type ItemType = | Weapon = 0 | Shield = 1 type ActionClass = | Network | Exploit | Penetration type Weapon = | Virus = 0 | Ransom = 1 | Worm = 2 | DDos = 3 | Crack = 4 | Injection = 5 type Shield = | Firewall = 0 | PortScan = 1 | Encryption = 2 | Hardening = 4 | Sanitation = 5 | Cypher = 3 [] type Item = { Name : string ItemType : ItemType Cost : single } let weaponInventory = [| Weapon.Virus ; Weapon.Ransom ; Weapon.DDos ; Weapon.Worm ; Weapon.Crack ; Weapon.Injection |] let shieldInventory = [| Shield.Firewall ; Shield.PortScan ; Shield.Encryption ; Shield.Cypher ; Shield.Hardening ; Shield.Sanitation |] let getClass = function | 0 | 1 -> Network | 2 | 3 -> Exploit | 4 | _ -> Penetration type HackResult = | Strong | Weak [] type DiscordPlayer = { Id: uint64; Name: string } [] type Attack = { HackType: Weapon Target: DiscordPlayer Timestamp: DateTime } [] type Defense = { DefenseType: Shield Timestamp: DateTime } [] type Player = { DiscordId: uint64 Name: string Weapons: Weapon array Shields: Shield array Attacks: Attack array Defenses: Defense array Bank: single } let createSimpleResponseAsync msg (ctx: InteractionContext) = async { let builder = DiscordInteractionResponseBuilder() builder.Content <- msg builder.AsEphemeral true |> ignore do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder) |> Async.AwaitTask } let notYetAHackerMsg = createSimpleResponseAsync "You are not currently a hacker, first use the /redpill command to become one" let hackDescription = "" let statusFormat player = $"Hack Inventory: {player.Weapons} Shield Inventory: {player.Shields} Active Hacks: {player.Attacks |> Array.toList} Active Defenses: {player.Defenses |> Array.toList} Bank: {player.Bank}" let constructButtons (actionType: string) (playerInfo: string) (weapons: 'a array) = weapons |> Seq.map (fun hack -> DiscordButtonComponent(ButtonStyle.Primary, $"{actionType}-{hack}-{playerInfo}", $"{hack}")) let removeExpiredActions timespan (timestamp: 'a -> DateTime) actions = actions |> Array.filter (fun act -> DateTime.UtcNow - (timestamp act) < timespan) let constructEmbed message = let builder = DiscordEmbedBuilder() builder.Color <- Optional(DiscordColor.PhthaloGreen) builder.Description <- message let author = DiscordEmbedBuilder.EmbedAuthor() author.Name <- "Degenz Hacker Game" author.Url <- "https://twitter.com/degenzgame" author.IconUrl <- "https://pbs.twimg.com/profile_images/1473192843359309825/cqjm0VQ4_400x400.jpg" builder.Author <- author builder.Build() let calculateDamage (hack: int) (shield: int) = let hackClass = getClass hack let protectionClass = getClass shield match hackClass, protectionClass with | h, p when h = p -> Weak | _ -> Strong