Basic stats

This commit is contained in:
Joseph Ferano 2022-04-25 17:17:04 +07:00
parent 0d2bfebb2d
commit 8baa8d8f60
3 changed files with 48 additions and 3 deletions

View File

@ -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 }

View File

@ -131,6 +131,11 @@ type AccessoryItem = {
Item : Item
}
type MeleeWeapon = {
BreakChance : float
Item : Item
}
type ItemDetails =
| Hack of HackItem
| Shield of ShieldItem

View File

@ -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)
[<SlashCommand("stats", "Check your stats")>]
member this.Stats (ctx : InteractionContext) =
showStats (DiscordInteractionContext ctx)