121 lines
2.9 KiB
Forth

module DegenzGame.Shared
open System
open DSharpPlus
open DSharpPlus.Entities
open DSharpPlus.SlashCommands
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
let getClass = function
| 0 | 1 -> Network
| 2 | 3 -> Exploit
| 4 | _ -> Penetration
type HackResult =
| Strong
| Weak
[<CLIMutable>]
type DiscordPlayer = {
Id : uint64
Name : string
}
[<CLIMutable>]
type Attack = {
HackType : Weapon
Target : DiscordPlayer
Timestamp : DateTime
}
[<CLIMutable>]
type Defense = {
DefenseType : Shield
Timestamp : DateTime
}
[<CLIMutable>]
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 ->
if DateTime.UtcNow - (timestamp act) < timespan
then true
else false)
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