From 45fab5ca82c56d4a69db4ccf079860c2d33881aa Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sun, 27 Feb 2022 23:13:23 +0700 Subject: [PATCH] Stat decay --- Bot/GameHelpers.fs | 9 ++++++++- Bot/GameTypes.fs | 7 ++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Bot/GameHelpers.fs b/Bot/GameHelpers.fs index 1524e73..2cd13ef 100644 --- a/Bot/GameHelpers.fs +++ b/Bot/GameHelpers.fs @@ -119,7 +119,14 @@ module PlayerStats = let Luck = { Id = StatId.Luck ; BaseDecayRate = 5.0f ; BaseMinMax = Range(0, 100) } let Charisma = { Id = StatId.Charisma ; BaseDecayRate = 5.0f ; BaseMinMax = Range(0, 100) } - let stats = [| Strength ; Focus ; Luck ; Charisma |] + let stats = [ Strength ; Focus ; Luck ; Charisma ] + + let calculateStatDecay (stat : PlayerStat) = + let statConfig = stats |> List.find (fun s -> s.Id = stat.Id) + let hoursElapsed = (DateTime.UtcNow - stat.LastRead).Hours + let totalDecay = hoursElapsed * int statConfig.BaseDecayRate + { stat with Amount = max stat.ModMinMax.Start.Value (stat.Amount - totalDecay) ; LastRead = DateTime.UtcNow } + let statConsumableMap = [ ( StatId.Strength , 12 ) ( StatId.Focus , 13 ) diff --git a/Bot/GameTypes.fs b/Bot/GameTypes.fs index 717f42a..4b3e1a2 100644 --- a/Bot/GameTypes.fs +++ b/Bot/GameTypes.fs @@ -23,15 +23,16 @@ type StatId = | Luck = 2 | Charisma = 3 -type Stat = { +type StatConfig = { Id : StatId BaseDecayRate : single BaseMinMax : Range } -type ActiveStat = { +type PlayerStat = { Id : StatId Amount : int + ModMinMax : Range LastRead : DateTime } @@ -110,7 +111,7 @@ and PlayerData = { Name : string Inventory : Inventory Events : PlayerEvent array - Stats : ActiveStat list + Stats : PlayerStat list Bank : int } // Achievements : string array