86 lines
2.8 KiB
Forth
86 lines
2.8 KiB
Forth
module DegenzGame.Functions
|
|
|
|
open System
|
|
open DSharpPlus
|
|
open DSharpPlus.Entities
|
|
open DSharpPlus.SlashCommands
|
|
open DegenzGame.Types
|
|
open MongoDB.Bson
|
|
|
|
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 newPlayer nickname (membr : uint64) =
|
|
let h1 = [| Weapon.Virus ; Weapon.Ransom |]
|
|
let h2 = [| Weapon.DDos ; Weapon.Worm |]
|
|
let h3 = [| Weapon.Crack ; Weapon.Injection |]
|
|
let d1 = [| Shield.Firewall ; Shield.PortScan |]
|
|
let d2 = [| Shield.Encryption ; Shield.Cypher |]
|
|
let d3 = [| Shield.Hardening ; Shield.Sanitation |]
|
|
|
|
let rand = System.Random(System.Guid.NewGuid().GetHashCode())
|
|
let getRandom (actions : 'a array) = actions.[rand.Next(0,2)]
|
|
|
|
let weapons = [| getRandom h1 ; getRandom h2 ; getRandom h3 |]
|
|
let shields = [| getRandom d1 ; getRandom d2 ; getRandom d3 |]
|
|
|
|
{ Id = BsonObjectId(ObjectId.GenerateNewId())
|
|
DiscordId = membr
|
|
Name = nickname
|
|
Weapons = weapons
|
|
Shields = shields
|
|
Attacks = [||]
|
|
Defenses = [||]
|
|
Bank = 0f }
|
|
|
|
let constructButtons (actionType : string) (playerInfo : string) (weapons : 'a array) =
|
|
weapons
|
|
|> Seq.map (fun hack ->
|
|
DiscordButtonComponent(
|
|
ButtonStyle.Primary,
|
|
$"{actionType}-{hack}-{playerInfo}",
|
|
$"{hack}"))
|
|
|
|
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 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
|
|
|