Fix store bugs
This commit is contained in:
parent
ed68f0b87d
commit
b501dfbb73
@ -2,61 +2,61 @@
|
|||||||
{
|
{
|
||||||
"Name" : "Virus",
|
"Name" : "Virus",
|
||||||
"ItemType" : { "Case" : "Hack" },
|
"ItemType" : { "Case" : "Hack" },
|
||||||
"Cost" : 5.0
|
"Cost" : 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "Ransom",
|
"Name" : "Ransom",
|
||||||
"ItemType" : { "Case" : "Hack" },
|
"ItemType" : { "Case" : "Hack" },
|
||||||
"Cost" : 10.0
|
"Cost" : 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "Worm",
|
"Name" : "Worm",
|
||||||
"ItemType" : { "Case" : "Hack" },
|
"ItemType" : { "Case" : "Hack" },
|
||||||
"Cost" : 5.0
|
"Cost" : 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "DDos",
|
"Name" : "DDos",
|
||||||
"ItemType" : { "Case" : "Hack" },
|
"ItemType" : { "Case" : "Hack" },
|
||||||
"Cost" : 10.0
|
"Cost" : 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "Crack",
|
"Name" : "Crack",
|
||||||
"ItemType" : { "Case" : "Hack" },
|
"ItemType" : { "Case" : "Hack" },
|
||||||
"Cost" : 5.0
|
"Cost" : 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "Injection",
|
"Name" : "Injection",
|
||||||
"ItemType" : { "Case" : "Hack" },
|
"ItemType" : { "Case" : "Hack" },
|
||||||
"Cost" : 10.0
|
"Cost" : 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "Firewall",
|
"Name" : "Firewall",
|
||||||
"ItemType" : { "Case" : "Shield" },
|
"ItemType" : { "Case" : "Shield" },
|
||||||
"Cost" : 5.0
|
"Cost" : 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "PortScan",
|
"Name" : "PortScan",
|
||||||
"ItemType" : { "Case" : "Shield" },
|
"ItemType" : { "Case" : "Shield" },
|
||||||
"Cost" : 10.0
|
"Cost" : 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "Cypher",
|
"Name" : "Cypher",
|
||||||
"ItemType" : { "Case" : "Shield" },
|
"ItemType" : { "Case" : "Shield" },
|
||||||
"Cost" : 5.0
|
"Cost" : 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "Encryption",
|
"Name" : "Encryption",
|
||||||
"ItemType" : { "Case" : "Shield" },
|
"ItemType" : { "Case" : "Shield" },
|
||||||
"Cost" : 10.0
|
"Cost" : 10
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "Sanitation",
|
"Name" : "Sanitation",
|
||||||
"ItemType" : { "Case" : "Shield" },
|
"ItemType" : { "Case" : "Shield" },
|
||||||
"Cost" : 5.0
|
"Cost" : 5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name" : "Hardening",
|
"Name" : "Hardening",
|
||||||
"ItemType" : { "Case" : "Shield" },
|
"ItemType" : { "Case" : "Shield" },
|
||||||
"Cost" : 10.0
|
"Cost" : 10
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
49
Bot/Store.fs
49
Bot/Store.fs
@ -11,11 +11,9 @@ open Degenz.Shared
|
|||||||
open Newtonsoft.Json
|
open Newtonsoft.Json
|
||||||
|
|
||||||
let store =
|
let store =
|
||||||
try
|
|
||||||
let file = System.IO.File.ReadAllText("Items.json")
|
let file = System.IO.File.ReadAllText("Items.json")
|
||||||
JsonConvert.DeserializeObject<Item array>(file)
|
JsonConvert.DeserializeObject<Item array>(file)
|
||||||
|> Array.groupBy (fun (i : Item) -> i.ItemType)
|
|> Array.groupBy (fun (i : Item) -> i.ItemType)
|
||||||
with _ -> [||]
|
|
||||||
|
|
||||||
let viewStore (ctx : InteractionContext) =
|
let viewStore (ctx : InteractionContext) =
|
||||||
async {
|
async {
|
||||||
@ -85,7 +83,7 @@ let constructItemButtons playerInfo itemType (items : 'a array) =
|
|||||||
items
|
items
|
||||||
|> Seq.map (fun item -> DiscordButtonComponent(ButtonStyle.Primary, $"{playerInfo}-{itemType}-{item}", $"{item}"))
|
|> Seq.map (fun item -> DiscordButtonComponent(ButtonStyle.Primary, $"{playerInfo}-{itemType}-{item}", $"{item}"))
|
||||||
|
|
||||||
let sellItem (ctx : InteractionContext) =
|
let sell (ctx : InteractionContext) =
|
||||||
async {
|
async {
|
||||||
let! playerResult = DbService.tryFindPlayer ctx.Member.Id
|
let! playerResult = DbService.tryFindPlayer ctx.Member.Id
|
||||||
match playerResult with
|
match playerResult with
|
||||||
@ -123,6 +121,23 @@ let sellItem (ctx : InteractionContext) =
|
|||||||
} |> Async.StartAsTask
|
} |> Async.StartAsTask
|
||||||
:> Task
|
:> Task
|
||||||
|
|
||||||
|
let updateShields player salePrice updatedShields = { player with Bank = player.Bank + salePrice ; Shields = updatedShields }
|
||||||
|
let updateHacks player salePrice updatedHacks = { player with Bank = player.Bank + salePrice ; Weapons = updatedHacks }
|
||||||
|
|
||||||
|
let sellItem (event : ComponentInteractionCreateEventArgs) updateFn player inventory itemType itemName =
|
||||||
|
async {
|
||||||
|
let item = getItems itemType |> Array.find (fun i -> i.Name = itemName)
|
||||||
|
let salePrice = item.Cost
|
||||||
|
let updatedItems = inventory |> Array.filter (fun i -> string i <> itemName)
|
||||||
|
let updatedPlayer = updateFn player salePrice updatedItems
|
||||||
|
do! DbService.updatePlayer updatedPlayer
|
||||||
|
let builder = DiscordInteractionResponseBuilder()
|
||||||
|
builder.IsEphemeral <- true
|
||||||
|
builder.Content <- $"Sold {itemType.ToString().ToLower()} {itemName} for {salePrice}! Current Balance: {updatedPlayer.Bank}"
|
||||||
|
do! event.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, builder)
|
||||||
|
|> Async.AwaitTask
|
||||||
|
}
|
||||||
|
|
||||||
let handleSellButtonEvents (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
|
let handleSellButtonEvents (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
|
||||||
async {
|
async {
|
||||||
let! playerResult = DbService.tryFindPlayer event.User.Id
|
let! playerResult = DbService.tryFindPlayer event.User.Id
|
||||||
@ -132,28 +147,8 @@ let handleSellButtonEvents (_ : DiscordClient) (event : ComponentInteractionCrea
|
|||||||
let itemType = match split.[0] with "Hack" -> ItemType.Hack | _ -> ItemType.Shield
|
let itemType = match split.[0] with "Hack" -> ItemType.Hack | _ -> ItemType.Shield
|
||||||
let itemName = split.[1]
|
let itemName = split.[1]
|
||||||
match itemType with
|
match itemType with
|
||||||
| ItemType.Hack ->
|
| ItemType.Hack -> do! sellItem event updateHacks player player.Weapons ItemType.Hack itemName
|
||||||
let item = getItems ItemType.Hack |> Array.find (fun w -> w.Name = itemName)
|
| ItemType.Shield -> do! sellItem event updateShields player player.Shields ItemType.Hack itemName
|
||||||
let salePrice = item.Cost / 2
|
|
||||||
let updatedWeapons = player.Weapons |> Array.filter (fun (w : Hack) -> string w <> itemName)
|
|
||||||
let updatedPlayer = { player with Bank = player.Bank + salePrice ; Weapons = updatedWeapons }
|
|
||||||
do! DbService.updatePlayer updatedPlayer
|
|
||||||
let builder = DiscordInteractionResponseBuilder()
|
|
||||||
builder.IsEphemeral <- true
|
|
||||||
builder.Content <- $"Sold hack {itemName} for {salePrice}! Current Balance: {updatedPlayer.Bank}"
|
|
||||||
do! event.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, builder)
|
|
||||||
|> Async.AwaitTask
|
|
||||||
| ItemType.Shield ->
|
|
||||||
let item = getItems ItemType.Shield |> Array.find (fun s -> s.Name = itemName)
|
|
||||||
let salePrice = item.Cost / 2
|
|
||||||
let updatedShields = player.Shields |> Array.filter (fun (s : Shield) -> string s <> itemName)
|
|
||||||
let updatedPlayer = { player with Bank = player.Bank + salePrice ; Shields = updatedShields }
|
|
||||||
do! DbService.updatePlayer updatedPlayer
|
|
||||||
let builder = DiscordInteractionResponseBuilder()
|
|
||||||
builder.IsEphemeral <- true
|
|
||||||
builder.Content <- $"Sold shield {itemName} for {salePrice}! Current Balance: {updatedPlayer.Bank}"
|
|
||||||
do! event.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, builder)
|
|
||||||
|> Async.AwaitTask
|
|
||||||
| None ->
|
| None ->
|
||||||
let builder = DiscordInteractionResponseBuilder()
|
let builder = DiscordInteractionResponseBuilder()
|
||||||
builder.IsEphemeral <- true
|
builder.IsEphemeral <- true
|
||||||
@ -166,7 +161,7 @@ let handleSellButtonEvents (_ : DiscordClient) (event : ComponentInteractionCrea
|
|||||||
type Store() =
|
type Store() =
|
||||||
inherit ApplicationCommandModule ()
|
inherit ApplicationCommandModule ()
|
||||||
|
|
||||||
[<SlashCommand("store", "View items available for purchase")>]
|
[<SlashCommand("view-store", "View items available for purchase")>]
|
||||||
member _.ViewStore (ctx : InteractionContext) = viewStore ctx
|
member _.ViewStore (ctx : InteractionContext) = viewStore ctx
|
||||||
|
|
||||||
[<SlashCommand("buy-hack", "Purchase a hack attack you can use to earn GoodBoyTokenz")>]
|
[<SlashCommand("buy-hack", "Purchase a hack attack you can use to earn GoodBoyTokenz")>]
|
||||||
@ -178,5 +173,5 @@ type Store() =
|
|||||||
buyShield ctx shieldId
|
buyShield ctx shieldId
|
||||||
|
|
||||||
[<SlashCommand("sell", "Sell an item in your inventory for GoodBoyTokenz")>]
|
[<SlashCommand("sell", "Sell an item in your inventory for GoodBoyTokenz")>]
|
||||||
member this.SellItem (ctx : InteractionContext) = sellItem ctx
|
member this.SellItem (ctx : InteractionContext) = sell ctx
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user