From 8baa8d8f60614be3c8f14025f9fa24561318f653 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 25 Apr 2022 17:17:04 +0700 Subject: [PATCH] Basic stats --- Bot/GameHelpers.fs | 20 +++++++++++++++++--- Bot/GameTypes.fs | 5 +++++ Bot/Games/Store.fs | 26 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Bot/GameHelpers.fs b/Bot/GameHelpers.fs index ca6e930..cccf390 100644 --- a/Bot/GameHelpers.fs +++ b/Bot/GameHelpers.fs @@ -88,15 +88,29 @@ module PlayerStats = let Luck = { Id = StatId.Luck ; BaseDecayRate = 4.17 ; BaseRange = Range.normalized } let Charisma = { Id = StatId.Charisma ; BaseDecayRate = 4.17 ; BaseRange = Range.normalized } - let stats = [ Strength ; Focus ; Luck ; Charisma ] + 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.sumBy (fun item -> match item with | Accessory a -> a.FloorBoost | _ -> 0) - let max = items |> List.sumBy (fun item -> match item with | Accessory a -> a.CeilBoost | _ -> 0) + let min = + items + |> List.filter (fun item -> match item with | Accessory a -> a.TargetStat = statId | _ -> false) + |> List.sumBy (fun item -> match item with | Accessory a -> a.FloorBoost | _ -> 0) + let max = + items + |> List.filter (fun item -> match item with | Accessory a -> a.TargetStat = statId | _ -> false) + |> List.sumBy (fun item -> match item with | Accessory a -> a.CeilBoost | _ -> 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/GameTypes.fs b/Bot/GameTypes.fs index 5f85b57..faece8d 100644 --- a/Bot/GameTypes.fs +++ b/Bot/GameTypes.fs @@ -131,6 +131,11 @@ type AccessoryItem = { Item : Item } +type MeleeWeapon = { + BreakChance : float + Item : Item +} + type ItemDetails = | Hack of HackItem | Shield of ShieldItem diff --git a/Bot/Games/Store.fs b/Bot/Games/Store.fs index 0b0887e..b0e97dd 100644 --- a/Bot/Games/Store.fs +++ b/Bot/Games/Store.fs @@ -232,6 +232,28 @@ let showInventoryEmbed (ctx : IDiscordContext) = PlayerInteractions.executePlaye do! ctx.FollowUp builder |> Async.AwaitTask }) +let showStats (ctx : IDiscordContext) = PlayerInteractions.executePlayerAction ctx (fun player -> async { + let embed = DiscordEmbedBuilder() + PlayerStats.stats + |> List.iter (fun statConfig -> + let playerStat = PlayerStats.getPlayerStat statConfig player +// let diffSymbol lhs rhs = if lhs < rhs then "-" elif lhs = rhs then "" else "+" + let min = + match statConfig.BaseRange.Min = playerStat.ModRange.Min with + | true -> $"{statConfig.BaseRange.Min}" + | false -> $"{statConfig.BaseRange.Min} (+{playerStat.ModRange.Min}) " + let max = + match statConfig.BaseRange.Max = playerStat.ModRange.Max with + | true -> $"{statConfig.BaseRange.Max}" + | false -> $"{statConfig.BaseRange.Max} (+{playerStat.ModRange.Max}) " + let field = $"{min} |---------------| {max}" + embed.AddField(string statConfig.Id , field) |> ignore) + let builder = + DiscordFollowupMessageBuilder() + .AddEmbed(embed) + .AsEphemeral(true) + do! ctx.FollowUp builder |> Async.AwaitTask +}) type Store() = inherit ApplicationCommandModule () @@ -283,3 +305,7 @@ type Store() = member this.Inventory (ctx : InteractionContext) = showInventoryEmbed (DiscordInteractionContext ctx) + [] + member this.Stats (ctx : InteractionContext) = + showStats (DiscordInteractionContext ctx) +