From abf80771312e80fd16922d1e2327ba5ba723c537 Mon Sep 17 00:00:00 2001 From: Byroks Date: Tue, 16 Jan 2024 08:29:14 +0100 Subject: [PATCH] #33 Wrong wealth calculation (#34) Changes: + add function to adjust item value depending on currency Co-authored-by: Simon Gustavs Reviewed-on: https://git.byroks.de/MidgardVTT-Entwicklung/foundry-vtt-system-midgard5/pulls/34 Reviewed-by: oskaloq --- source/module/actors/M5Character.ts | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/source/module/actors/M5Character.ts b/source/module/actors/M5Character.ts index 3a23ab5..c2b4958 100644 --- a/source/module/actors/M5Character.ts +++ b/source/module/actors/M5Character.ts @@ -147,7 +147,7 @@ export class M5Character extends Actor { ret.stats.drinkingFW = Math.floor(ret.attributes.ko.value / 10); ret.stats.hoardMin = M5Character.levelThreshold.at(ret.level - 1) / 2; ret.stats.hoardNext = M5Character.levelThreshold.at(ret.level) / 2; - ret.stats.wealth = data.info.gold + data.info.silver / 10 + data.info.copper / 100; + ret.stats.wealth = parseFloat((data.info.gold + data.info.silver / 10 + data.info.copper / 100).toPrecision(3)); ret.stats.hoard = 0; if (!skip?.mods) { @@ -178,7 +178,7 @@ export class M5Character extends Actor { label += "*"; } if (item.system.valuable) { - ret.stats.wealth += item.system.value || 0; + ret.stats.wealth += this.calculateValue(item.system.value, item.system.currency); } if (item.system.hoarded) { ret.stats.hoard += item.system.value || 0; @@ -305,7 +305,7 @@ export class M5Character extends Actor { ")"; } if (item.system.valuable) { - ret.stats.wealth += item.system.value || 0; + ret.stats.wealth += this.calculateValue(item.system.value, item.system.currency); } if (item.system.hoarded) { ret.stats.hoard += item.system.value || 0; @@ -334,7 +334,7 @@ export class M5Character extends Actor { label += "*(" + (item.system.stats.defenseBonus < 0 ? "" : "+") + item.system.stats.defenseBonus + ")"; } if (item.system.valuable) { - ret.stats.wealth += item.system.value || 0; + ret.stats.wealth += this.calculateValue(item.system.value, item.system.currency); } if (item.system.hoarded) { ret.stats.hoard += item.system.value || 0; @@ -363,7 +363,7 @@ export class M5Character extends Actor { label += "*"; } if (item.system.valuable) { - ret.stats.wealth += item.system.value || 0; + ret.stats.wealth += this.calculateValue(item.system.value, item.system.currency); } if (item.system.hoarded) { ret.stats.hoard += item.system.value || 0; @@ -518,6 +518,19 @@ export class M5Character extends Actor { return (this as any).getEmbeddedDocument("Item", itemId); } + private calculateValue(value: number, currency: string): number { + switch (currency) { + case "gold": + return value; + case "silver": + return parseFloat((value / 10).toPrecision(3)); + case "copper": + return parseFloat((value / 100).toPrecision(3)); + default: + return 0; + } + } + private modResult(value: number): M5ModResult { return { value: value,