Reshape stat types

This commit is contained in:
Joseph Ferano 2022-02-27 23:37:47 +07:00
parent 45fab5ca82
commit 53f60bcf86
4 changed files with 25 additions and 25 deletions

View File

@ -17,7 +17,7 @@ let mapBack user : PlayerData =
Name = user.Name
Inventory = user.Inventory |> List.choose (fun id -> Armory.weapons |> List.tryFind (fun item -> item.Id = id))
Events = [||]
Stats = [ { Id = StatId.Strength ; Amount = user.Strength ; LastRead = DateTime.UtcNow} ]
Stats = { Stats.empty with Strength = { Id = StatId.Strength ; ModMinMax = Range(0, 100) ; Amount = user.Strength; LastRead = DateTime.UtcNow } }
Bank = user.Bank
}
@ -90,7 +90,7 @@ let updatePlayer connStr (player : PlayerData) =
|> Sql.parameters [
"did", Sql.string (string player.DiscordId)
"gbt", Sql.int (int player.Bank)
"str", Sql.int (player |> Player.getStat StatId.Strength |> int)
"str", Sql.int (player.Stats.Strength.Amount |> int)
"inv", Sql.intArray (player.Inventory |> Array.ofList |> Array.map (fun item -> item.Id))
]
|> Sql.query """

View File

@ -67,7 +67,6 @@ module Inventory =
inventory |> getShieldItems |> List.tryFind (fun item -> item.Id = id)
module WeaponClass =
// TODO: Find a different place to put this
let SameTargetAttackCooldown = System.TimeSpan.FromHours(1)
let getClassButtonColor item =
@ -107,25 +106,20 @@ module Player =
let modifyBank (player : PlayerData) amount = { player with Bank = max (player.Bank + amount) 0<GBT> }
let getStat statId player =
player.Stats
|> List.tryFind (fun stat -> statId = stat.Id)
|> Option.map (fun stat -> stat.Amount)
|> Option.defaultValue 0
module PlayerStats =
let Strength = { Id = StatId.Strength ; BaseDecayRate = 5.0f ; BaseMinMax = Range(0, 100) }
let Focus = { Id = StatId.Focus ; BaseDecayRate = 5.0f ; BaseMinMax = Range(0, 100) }
let Luck = { Id = StatId.Luck ; BaseDecayRate = 5.0f ; BaseMinMax = Range(0, 100) }
let Charisma = { Id = StatId.Charisma ; BaseDecayRate = 5.0f ; BaseMinMax = Range(0, 100) }
// 4.17f would go from 100 to 0 in roughly 24 hours
let Strength = { Id = StatId.Strength ; BaseDecayRate = 4.17 ; BaseMinMax = Range(0, 100) }
let Focus = { Id = StatId.Focus ; BaseDecayRate = 4.17 ; BaseMinMax = Range(0, 100) }
let Luck = { Id = StatId.Luck ; BaseDecayRate = 4.17 ; BaseMinMax = Range(0, 100) }
let Charisma = { Id = StatId.Charisma ; BaseDecayRate = 4.17 ; BaseMinMax = Range(0, 100) }
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 totalDecay = float hoursElapsed * statConfig.BaseDecayRate
{ stat with Amount = max stat.ModMinMax.Start.Value (stat.Amount - int totalDecay) ; LastRead = DateTime.UtcNow }
let statConsumableMap =
[ ( StatId.Strength , 12 )

View File

@ -2,6 +2,7 @@
module Degenz.Types
open System
open Degenz
[<Measure>]
type mins
@ -25,7 +26,7 @@ type StatId =
type StatConfig = {
Id : StatId
BaseDecayRate : single
BaseDecayRate : float
BaseMinMax : Range
}
@ -35,6 +36,15 @@ type PlayerStat = {
ModMinMax : Range
LastRead : DateTime
}
with static member empty = { Id = StatId.Strength ; Amount = 0 ; ModMinMax = Range(0, 100) ; LastRead = DateTime.UtcNow}
type Stats = {
Strength : PlayerStat
Focus : PlayerStat
Luck : PlayerStat
Charisma : PlayerStat
}
with static member empty = { Strength = PlayerStat.empty ; Focus = PlayerStat.empty ; Luck = PlayerStat.empty ; Charisma = PlayerStat.empty }
type HackResult =
| Strong
@ -111,7 +121,7 @@ and PlayerData = {
Name : string
Inventory : Inventory
Events : PlayerEvent array
Stats : PlayerStat list
Stats : Stats
Bank : int<GBT>
}
// Achievements : string array
@ -122,7 +132,7 @@ with member this.basicPlayer = { Id = this.DiscordId ; Name = this.Name }
Name = "None"
Inventory = []
Events = [||]
Stats = []
Stats = Stats.empty
// Achievements = [||]
// XP = 0
Bank = 0<GBT> }

View File

@ -128,9 +128,7 @@ let steal target amount (ctx : IDiscordContext) =
>>= checkPrizeRequestZero amount
|> handleResultWithResponse ctx (fun _ -> async {
let cappedPrize , winPercentage , wasCapped =
// calculateWinPercentage amount (int victim.Bank) thief.Stats.Strength victim.Stats.Strength
// TODO: Readd stats
calculateWinPercentage amount (int victim.Bank) 0 0
calculateWinPercentage amount (int victim.Bank) thief.Stats.Strength.Amount victim.Stats.Strength.Amount
let chance = int (winPercentage * 100.0)
let buttons =
@ -140,8 +138,7 @@ let steal target amount (ctx : IDiscordContext) =
let cappedMsg = if wasCapped then $"They only have {cappedPrize} $GBT though... " else ""
let strengthMsg =
// TODO: Readd stats
match 0 - 0 with
match thief.Stats.Strength.Amount - victim.Stats.Strength.Amount with
| diff when diff < -50 -> "much stronger"
| diff when diff < 0 -> "stronger"
| diff when diff < 50 -> "weaker"
@ -164,8 +161,7 @@ let handleSteal (ctx : IDiscordContext) =
let targetId = uint64 tokens.[2]
let targetName = tokens.[3]
let amount = int tokens.[4]
// TODO: Readd stats
let prize , winPercentage , _ = calculateWinPercentage amount (int victim.Bank) 0 0
let prize , winPercentage , _ = calculateWinPercentage amount (int victim.Bank) thief.Stats.Strength.Amount victim.Stats.Strength.Amount
let prize = int prize * 1<GBT>
let rand = Random(Guid.NewGuid().GetHashCode())