#33 Wrong wealth calculation (#34)

Changes:
 + add function to adjust item value depending on currency
Co-authored-by: Simon Gustavs <simon.gustavs@bms-cs.de>
Reviewed-on: #34
Reviewed-by: oskaloq <os_ka_loq@gmx.de>
This commit is contained in:
Byroks 2024-01-16 08:29:14 +01:00
parent b5b75aa2c6
commit abf8077131
1 changed files with 18 additions and 5 deletions

View File

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