From 5ef3243c4142743ebd6a12221244bb7fe28d7a8b Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sun, 16 Jan 2022 16:21:45 +0700 Subject: [PATCH] Read store items from json file --- GameConfig/HackerGame.json | 4 +++ GameConfig/Items.json | 62 +++++++++++++++++++++++++++++++++++ HackerBattle/Commands.fs | 2 +- PlayerInteractions/Program.fs | 3 +- Shared/Shared.fs | 14 ++++++-- Store/Program.fs | 15 ++++++--- Store/Store.fsproj | 4 +++ 7 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 GameConfig/HackerGame.json create mode 100644 GameConfig/Items.json diff --git a/GameConfig/HackerGame.json b/GameConfig/HackerGame.json new file mode 100644 index 0000000..0269f89 --- /dev/null +++ b/GameConfig/HackerGame.json @@ -0,0 +1,4 @@ +{ + "AttackerPrize" : 1.337, + "AttackerPenalty" : 0.345 +} \ No newline at end of file diff --git a/GameConfig/Items.json b/GameConfig/Items.json new file mode 100644 index 0000000..17cb719 --- /dev/null +++ b/GameConfig/Items.json @@ -0,0 +1,62 @@ +[ + { + "Name" : "Virus", + "ItemType" : { "Case" : "Weapon" }, + "Cost" : 5.0 + }, + { + "Name" : "Ransom", + "ItemType" : { "Case" : "Weapon" }, + "Cost" : 10.0 + }, + { + "Name" : "Worm", + "ItemType" : { "Case" : "Weapon" }, + "Cost" : 5.0 + }, + { + "Name" : "DDos", + "ItemType" : { "Case" : "Weapon" }, + "Cost" : 10.0 + }, + { + "Name" : "Crack", + "ItemType" : { "Case" : "Weapon" }, + "Cost" : 5.0 + }, + { + "Name" : "Injection", + "ItemType" : { "Case" : "Weapon" }, + "Cost" : 10.0 + }, + { + "Name" : "Firewall", + "ItemType" : { "Case" : "Shield" }, + "Cost" : 5.0 + }, + { + "Name" : "PortScan", + "ItemType" : { "Case" : "Shield" }, + "Cost" : 10.0 + }, + { + "Name" : "Encryption", + "ItemType" : { "Case" : "Shield" }, + "Cost" : 5.0 + }, + { + "Name" : "Hardening", + "ItemType" : { "Case" : "Shield" }, + "Cost" : 10.0 + }, + { + "Name" : "Cypher", + "ItemType" : { "Case" : "Shield" }, + "Cost" : 5.0 + }, + { + "Name" : "Sanitation", + "ItemType" : { "Case" : "Shield" }, + "Cost" : 10.0 + } +] diff --git a/HackerBattle/Commands.fs b/HackerBattle/Commands.fs index 61f5c6b..ab6d2be 100644 --- a/HackerBattle/Commands.fs +++ b/HackerBattle/Commands.fs @@ -131,7 +131,7 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) = |> Async.Ignore | true -> let builder = DiscordInteractionResponseBuilder() - let prize = 0.0623f + let prize = 0.223f builder.IsEphemeral <- true builder.Content <- $"Hack failed! {split.[3]} was able to mount a successful defense! You lost {prize} GoodBoyTokenz!" do! event.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, builder) diff --git a/PlayerInteractions/Program.fs b/PlayerInteractions/Program.fs index 57393d4..d34bbd4 100644 --- a/PlayerInteractions/Program.fs +++ b/PlayerInteractions/Program.fs @@ -27,7 +27,7 @@ module Commands = Shields = shields Attacks = [||] Defenses = [||] - Bank = 0f } + Bank = 15f } let addHackerRole (ctx : InteractionContext) = async { @@ -49,6 +49,7 @@ module Commands = } if newPlayer then + // TODO: Add a better registration message that shows which weapon and how much currency they start with do! ctx.CreateResponseAsync("You are now an elite haxxor", true) |> Async.AwaitTask else diff --git a/Shared/Shared.fs b/Shared/Shared.fs index 2f3a5be..3314d11 100644 --- a/Shared/Shared.fs +++ b/Shared/Shared.fs @@ -30,6 +30,17 @@ type Shield = | 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 @@ -68,9 +79,6 @@ type Player = Bank: 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 createSimpleResponseAsync msg (ctx: InteractionContext) = async { let builder = DiscordInteractionResponseBuilder() diff --git a/Store/Program.fs b/Store/Program.fs index 1aff4a7..557ae5c 100644 --- a/Store/Program.fs +++ b/Store/Program.fs @@ -4,9 +4,9 @@ open DSharpPlus.Entities open DSharpPlus open DSharpPlus.EventArgs open DSharpPlus.SlashCommands -open DegenzGame open DegenzGame.Shared open Emzi0767.Utilities +open Newtonsoft.Json module Commands = let constructItemButtons playerInfo (items : 'a array) = @@ -16,10 +16,15 @@ module Commands = let viewStore (ctx : InteractionContext) = async { let builder = DiscordInteractionResponseBuilder() - let hacks = weaponInventory |> Array.map (fun w -> $"{w} - 5 GBT") |> String.concat "\n" - builder.AddEmbed (constructEmbed $"Hacks:\n{hacks}") |> ignore - let shields = shieldInventory |> Array.map (fun w -> $"{w} - 5 GBT") |> String.concat "\n" - builder.AddEmbed (constructEmbed $"Shields:\n{shields}") |> ignore + + try + let file = System.IO.File.ReadAllText("Items.json") + JsonConvert.DeserializeObject(file) + |> Array.groupBy (fun (i : Item) -> i.ItemType) + |> Array.iter (fun ( itemType , items ) -> + let itemList = items |> Array.map (fun i -> $"{i.Name} - {i.Cost} GBT") |> String.concat "\n" + builder.AddEmbed (constructEmbed $"{itemType}:\n{itemList}") |> ignore) + with _ -> builder.Content <- "System error preparing inventory for viewing" builder.AsEphemeral true |> ignore diff --git a/Store/Store.fsproj b/Store/Store.fsproj index 565f091..f5f12f6 100644 --- a/Store/Store.fsproj +++ b/Store/Store.fsproj @@ -12,6 +12,10 @@ + + Items.json + PreserveNewest +