diff --git a/Bot/Bot.fsproj b/Bot/Bot.fsproj index f13dcd5..25120a6 100644 --- a/Bot/Bot.fsproj +++ b/Bot/Bot.fsproj @@ -12,8 +12,8 @@ - + diff --git a/Bot/DbService.fs b/Bot/DbService.fs index 3ed06e0..4d307a7 100644 --- a/Bot/DbService.fs +++ b/Bot/DbService.fs @@ -37,6 +37,7 @@ let readItem (reader : RowReader) = Item.Attributes = [ reader.intOrNone "buy_price" |> Option.map (fun a -> Buyable (a * 1)) reader.intOrNone "sell_price" |> Option.map (fun a -> Sellable (a * 1)) + reader.intOrNone "rate_limit" |> Option.map (fun a -> RateLimitable (a * 1)) reader.intOrNone "expiration" |> Option.map (fun a -> Expireable (a * 1)) reader.floatOrNone "drop_chance" |> Option.map (float >> Droppable) reader.intOrNone "attack_power" |> Option.map Attackable @@ -124,8 +125,8 @@ let getWeapons () = connStr |> Sql.connect |> Sql.query """ - SELECT i.id,i.name,description,icon_url,image_url,category,buy_price,sell_price,rate_limit,expiration,drop_chance,can_trade,can_consume, - attack_power,defense_power,class_name,max_stack,mods + SELECT id,name,description,icon_url,image_url,category,buy_price,sell_price,rate_limit,expiration, + drop_chance,can_trade,can_consume,attack_power,defense_power,class_name,max_stack,mods FROM item WHERE category = 'Hack' OR category = 'Shield' """ |> Sql.executeAsync readItem diff --git a/Bot/GameHelpers.fs b/Bot/GameHelpers.fs index 2b1ca81..dbc1fe8 100644 --- a/Bot/GameHelpers.fs +++ b/Bot/GameHelpers.fs @@ -1,6 +1,7 @@ namespace Degenz open System +open System.Threading open DSharpPlus open DSharpPlus.Entities open Degenz @@ -19,7 +20,7 @@ module Inventory = let getHackItem item = match item.Type , item.Attributes with - | ItemType.Hack , CanBuy buyPrice & CanSell _ & CanAttack power & CanExpire cooldown & CanClass ``class``-> + | ItemType.Hack , CanBuy buyPrice & CanSell _ & CanAttack power & CanRateLimit cooldown & CanClass ``class``-> Some { Id = item.Id Name = item.Name Price = buyPrice @@ -32,7 +33,7 @@ module Inventory = let getShieldItem item = match item.Type , item.Attributes with - | ItemType.Shield , CanBuy buyPrice & CanSell _ & CanDefend resistance & CanExpire cooldown & CanClass ``class`` -> + | ItemType.Shield , CanBuy buyPrice & CanSell _ & CanDefend resistance & CanRateLimit cooldown & CanClass ``class`` -> Some { Id = item.Id Name = item.Name Price = buyPrice @@ -64,9 +65,9 @@ module WeaponClass = let getClassButtonColor item = match item.Attributes with - | CanClass "0" -> ButtonStyle.Danger - | CanClass "1" -> ButtonStyle.Primary - | CanClass "2" -> ButtonStyle.Success + | CanClass "NETWORK" -> ButtonStyle.Danger + | CanClass "EXPLOIT" -> ButtonStyle.Primary + | CanClass "PENETRATION" -> ButtonStyle.Success | _ -> ButtonStyle.Primary let getClassEmbedColor item = @@ -100,43 +101,10 @@ module Player = let modifyBank (player : PlayerData) amount = { player with Bank = max (player.Bank + amount) 0 } -module PlayerStats = - // 2.09f would go from 100 to 0 in roughly 48 hours - let Strength = { Id = StatId.Strength ; BaseDecayRate = 2.09 ; BaseRange = Range.normalized } - let Focus = { Id = StatId.Focus ; BaseDecayRate = 2.09 ; BaseRange = Range.normalized } - let Luck = { Id = StatId.Luck ; BaseDecayRate = 2.09 ; BaseRange = Range.normalized } - let Charisma = { Id = StatId.Charisma ; BaseDecayRate = 2.09 ; BaseRange = Range.normalized } - - let stats = [ Strength ; Focus ; Charisma ; Luck ] - - let getPlayerStat (statConfig : StatConfig) player = - match statConfig.Id with - | StatId.Strength -> player.Stats.Strength - | StatId.Focus -> player.Stats.Focus - | StatId.Charisma -> player.Stats.Charisma - | StatId.Luck -> player.Stats.Luck - | _ -> player.Stats.Luck - - let calculateActiveStat statId amount items = - let statConfig = stats |> List.find (fun s -> s.Id = statId) -// let hoursElapsed = (DateTime.UtcNow - lastRead).Hours -// let totalDecay = float hoursElapsed * statConfig.BaseDecayRate - let modMinMax = - let min = - items - |> List.choose (fun i -> match i.Attributes with CanModify fx -> Some fx | _ -> None) - |> List.concat - |> List.sumBy (fun fx -> match fx.Effect with | Min x -> x | _ -> 0) - let max = - items - |> List.choose (fun i -> match i.Attributes with CanModify fx -> Some fx | _ -> None) - |> List.concat - |> List.sumBy (fun fx -> match fx.Effect with | Max x -> x | _ -> 0) - Range.create (statConfig.BaseRange.Min + min) (statConfig.BaseRange.Max + max) - let amountAfterDecay = modMinMax |> Range.constrain amount - { Id = statId ; Amount = amountAfterDecay ; ModRange = modMinMax ; LastRead = DateTime.UtcNow } module Arsenal = + let weapons = DbService.getWeapons () |> Async.RunSynchronously + let battleItemFormat (items : Inventory) = match items with | [] -> "None" @@ -165,5 +133,5 @@ module Arsenal = let hacks = Player.getHackEvents p $"**Hacks:** {Inventory.getItemsByType ItemType.Hack p.Inventory |> battleItemFormat}\n **Shields:** {Inventory.getItemsByType ItemType.Shield p.Inventory |> battleItemFormat}\n - **Hack Attacks:**\n{hacks |> List.take (min hacks.Length 10) |> actionFormat p.Inventory}\n - **Active Shields:**\n{Player.getShieldEvents p |> actionFormat p.Inventory}" + **Hack Attacks:**\n{hacks |> List.take (min hacks.Length 10) |> actionFormat weapons}\n + **Active Shields:**\n{Player.getShieldEvents p |> actionFormat weapons}" diff --git a/Bot/GameTypes.fs b/Bot/GameTypes.fs index b39097f..9d03522 100644 --- a/Bot/GameTypes.fs +++ b/Bot/GameTypes.fs @@ -190,3 +190,38 @@ with member this.toDiscordPlayer = { Id = this.DiscordId ; Name = this.Name } Bank = 0 Active = false } +module PlayerStats = + // 2.09f would go from 100 to 0 in roughly 48 hours + let Strength = { Id = StatId.Strength ; BaseDecayRate = 2.09 ; BaseRange = Range.normalized } + let Focus = { Id = StatId.Focus ; BaseDecayRate = 2.09 ; BaseRange = Range.normalized } + let Luck = { Id = StatId.Luck ; BaseDecayRate = 2.09 ; BaseRange = Range.normalized } + let Charisma = { Id = StatId.Charisma ; BaseDecayRate = 2.09 ; BaseRange = Range.normalized } + + let stats = [ Strength ; Focus ; Charisma ; Luck ] + + let getPlayerStat (statConfig : StatConfig) player = + match statConfig.Id with + | StatId.Strength -> player.Stats.Strength + | StatId.Focus -> player.Stats.Focus + | StatId.Charisma -> player.Stats.Charisma + | StatId.Luck -> player.Stats.Luck + | _ -> player.Stats.Luck + + let calculateActiveStat statId amount items = + let statConfig = stats |> List.find (fun s -> s.Id = statId) +// let hoursElapsed = (DateTime.UtcNow - lastRead).Hours +// let totalDecay = float hoursElapsed * statConfig.BaseDecayRate + let modMinMax = + let min = + items + |> List.choose (fun i -> match i.Attributes with CanModify fx -> Some fx | _ -> None) + |> List.concat + |> List.sumBy (fun fx -> match fx.Effect with | Min x -> x | _ -> 0) + let max = + items + |> List.choose (fun i -> match i.Attributes with CanModify fx -> Some fx | _ -> None) + |> List.concat + |> List.sumBy (fun fx -> match fx.Effect with | Max x -> x | _ -> 0) + Range.create (statConfig.BaseRange.Min + min) (statConfig.BaseRange.Max + max) + let amountAfterDecay = modMinMax |> Range.constrain amount + { Id = statId ; Amount = amountAfterDecay ; ModRange = modMinMax ; LastRead = DateTime.UtcNow } diff --git a/Bot/Games/HackerBattle.fs b/Bot/Games/HackerBattle.fs index 30783ad..14b3b17 100644 --- a/Bot/Games/HackerBattle.fs +++ b/Bot/Games/HackerBattle.fs @@ -83,7 +83,7 @@ let runHackerBattle defender (hack : HackItem) = |> List.exists (fun event -> match event.Type with | Shielding id -> - let item = Inventory.findItemById id Trainer.weapons + let item = Inventory.findItemById id Arsenal.weapons match item.Attributes with | CanClass c -> hack.Class = c | _ -> false @@ -166,7 +166,7 @@ let handleAttack (ctx : IDiscordContext) = let tokens = ctx.GetInteractionId().Split("-") let hackId = tokens.[1] // TODO: This sucks - let item = Trainer.weapons |> Inventory.findItemById hackId + let item = Arsenal.weapons |> Inventory.findItemById hackId let hackItem = (Inventory.getHackItem item).Value let resultId , targetId = UInt64.TryParse tokens.[2] let! resultTarget = DbService.tryFindPlayer targetId @@ -207,7 +207,7 @@ let handleDefense (ctx : IDiscordContext) = executePlayerAction ctx (fun player -> async { let tokens = ctx.GetInteractionId().Split("-") let shieldId = tokens.[1] - let item = Trainer.weapons |> Inventory.findItemById shieldId + let item = Arsenal.weapons |> Inventory.findItemById shieldId let shieldItem = (Inventory.getShieldItem item).Value do! player diff --git a/Bot/Games/Store.fs b/Bot/Games/Store.fs index 0ffabea..6a2362d 100644 --- a/Bot/Games/Store.fs +++ b/Bot/Games/Store.fs @@ -336,8 +336,8 @@ let sendArmoryEmbed (ctx : IDiscordContext) = embed.Color <- DiscordColor.Black embed.Description <- "Buy Shields to protect yourself or buy Hacks to extract $GBT from others" builder.AddEmbed embed |> ignore - let btn1 = DiscordButtonComponent(ButtonStyle.Success, $"ShowHacks-0", $"Hacks") :> DiscordComponent - let btn2 = DiscordButtonComponent(ButtonStyle.Success, $"ShowShields-0", $"Shields") :> DiscordComponent + let btn1 = DiscordButtonComponent(ButtonStyle.Success, $"ShowHacks-0-ARMORY", $"Hacks") :> DiscordComponent + let btn2 = DiscordButtonComponent(ButtonStyle.Success, $"ShowShields-0-ARMORY", $"Shields") :> DiscordComponent builder.AddComponents [| btn1 ; btn2 |] |> ignore do! GuildEnvironment.botClientStore.Value.SendMessageAsync(channel, builder) diff --git a/Bot/Games/Trainer.fs b/Bot/Games/Trainer.fs index 0b54166..99b4d56 100644 --- a/Bot/Games/Trainer.fs +++ b/Bot/Games/Trainer.fs @@ -9,9 +9,8 @@ open Degenz.Messaging let TrainerAchievement = "LEARN_TO_HACKER_BATTLE_QUEST_COMPLETED" let Sensei = { Id = GuildEnvironment.botIdHackerBattle ; Name = "Sensei" } -let weapons = DbService.getWeapons () |> Async.RunSynchronously -let hackItem = weapons |> Inventory.findItemById (string ItemId.VIRUS) -let shieldItem = weapons |> Inventory.findItemById (string ItemId.FIREWALL) +let hackItem = Arsenal.weapons |> Inventory.findItemById (string ItemId.REMOTE) +let shieldItem = Arsenal.weapons |> Inventory.findItemById (string ItemId.FIREWALL) let defaultHack = (Inventory.getHackItem hackItem).Value let defaultShield = (Inventory.getShieldItem shieldItem ).Value let CurrencyGift = 250 @@ -99,7 +98,6 @@ let handleDefense (ctx : IDiscordContext) = let sendMessage' = sendFollowUpMessage ctx let tokens = ctx.GetInteractionId().Split("-") - let shieldId = enum(int tokens.[2]) let playerName = tokens.[4] let embed = Embeds.responseCreatedShield defaultShield do! ctx.FollowUp embed |> Async.AwaitTask @@ -218,7 +216,7 @@ let handleArsenal (ctx : IDiscordContext) = PlayerInteractions.executePlayerActi } do! DbService.updatePlayer updatedPlayer |> Async.Ignore try - do! ShieldEvents () + do! ShieldEvents () @ [ HackEvent () ] |> List.map (DbService.addPlayerEvent player.DiscordId) |> Async.Parallel |> Async.Ignore