Read store items from json file

This commit is contained in:
Joseph Ferano 2022-01-16 16:21:45 +07:00
parent f92e253dac
commit 5ef3243c41
7 changed files with 94 additions and 10 deletions

View File

@ -0,0 +1,4 @@
{
"AttackerPrize" : 1.337,
"AttackerPenalty" : 0.345
}

62
GameConfig/Items.json Normal file
View File

@ -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
}
]

View File

@ -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)

View File

@ -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

View File

@ -30,6 +30,17 @@ type Shield =
| Sanitation = 5
| Cypher = 3
[<CLIMutable>]
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()

View File

@ -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<Item array>(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

View File

@ -12,6 +12,10 @@
<Content Include=".dockerignore" />
<Content Include="Dockerfile" />
<Content Include="paket.references" />
<Content Include="..\GameConfig\Items.json">
<Link>Items.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DbService\DbService.fsproj" />