Co-authored-by: LeFrique <lefrique@live.de> Reviewed-on: #52
This commit was merged in pull request #52.
This commit is contained in:
+314
-157
@@ -1,5 +1,5 @@
|
||||
import { M5Item } from "../items/M5Item";
|
||||
import { M5Attribute, M5CharacterCalculatedData, M5ItemMod, M5ItemType, M5ModOperation, M5ModResult, M5RollData, M5Skill, M5SkillCalculated, M5SkillLearned, M5SkillType } from "../M5Base";
|
||||
import { M5Attribute, M5CharacterCalculatedData, M5ItemMod, M5ItemType, M5ModOperation, M5ModResult, M5ModType, M5RollData, M5Skill, M5SkillCalculated, M5SkillLearned, M5SkillType } from "../M5Base";
|
||||
import M5ModAggregate from "./M5ModAggregate";
|
||||
export class M5Character extends Actor {
|
||||
// constructor(
|
||||
@@ -23,18 +23,64 @@ export class M5Character extends Actor {
|
||||
return -2;
|
||||
}
|
||||
|
||||
static loadValue(attribute: M5Attribute) {
|
||||
const value = this.attributeMinMax(attribute);
|
||||
if (value > 99) return 35;
|
||||
if (value > 95) return 30;
|
||||
if (value > 80) return 25;
|
||||
if (value > 60) return 20;
|
||||
if (value > 30) return 15;
|
||||
if (value > 10) return 10;
|
||||
if (value > 0) return 5;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static heavyLoadValue(attribute: M5Attribute) {
|
||||
const value = this.attributeMinMax(attribute);
|
||||
if (value > 99) return 50;
|
||||
if (value > 95) return 45;
|
||||
if (value > 80) return 40;
|
||||
if (value > 60) return 35;
|
||||
if (value > 30) return 30;
|
||||
if (value > 10) return 25;
|
||||
if (value > 0) return 20;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static maxLoadValue(attribute: M5Attribute) {
|
||||
const value = this.attributeMinMax(attribute);
|
||||
if (value > 99) return 90;
|
||||
if (value > 95) return 80;
|
||||
if (value > 80) return 75;
|
||||
if (value > 60) return 70;
|
||||
if (value > 30) return 60;
|
||||
if (value > 10) return 50;
|
||||
if (value > 0) return 40;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static thrustLoadValue(attribute: M5Attribute) {
|
||||
const value = this.attributeMinMax(attribute);
|
||||
if (value > 99) return 200;
|
||||
if (value > 95) return 170;
|
||||
if (value > 80) return 150;
|
||||
if (value > 60) return 140;
|
||||
if (value > 30) return 120;
|
||||
if (value > 10) return 70;
|
||||
if (value > 0) return 50;
|
||||
return 0;
|
||||
}
|
||||
|
||||
derivedData(
|
||||
skip: {
|
||||
mods?: boolean;
|
||||
skills?: boolean;
|
||||
weapons?: boolean;
|
||||
defensiveWeapons?: boolean;
|
||||
armor?: boolean;
|
||||
items?: boolean;
|
||||
containers?: boolean;
|
||||
spells?: boolean;
|
||||
effects?: boolean;
|
||||
containers?: boolean;
|
||||
kampfkuenste?: boolean;
|
||||
encumbrance?: boolean;
|
||||
} = {}
|
||||
): M5CharacterCalculatedData {
|
||||
let ret: M5CharacterCalculatedData = {
|
||||
@@ -72,6 +118,11 @@ export class M5Character extends Actor {
|
||||
drinking: { value: 0, mods: [] },
|
||||
drinkingFW: 0,
|
||||
hoard: 0,
|
||||
encumbrance: 0,
|
||||
load: 0,
|
||||
heavyLoad: 0,
|
||||
thrustLoad: 0,
|
||||
loadMax: 0,
|
||||
},
|
||||
skillMods: {},
|
||||
skills: {
|
||||
@@ -149,6 +200,11 @@ export class M5Character extends Actor {
|
||||
ret.stats.hoardNext = M5Character.levelThreshold.at(ret.level) / 2;
|
||||
ret.stats.wealth = parseFloat((data.info.gold + data.info.silver / 10 + data.info.copper / 100).toPrecision(3));
|
||||
ret.stats.hoard = 0;
|
||||
ret.stats.load = M5Character.loadValue(data.attributes.st);
|
||||
ret.stats.heavyLoad = M5Character.heavyLoadValue(data.attributes.st);
|
||||
ret.stats.loadMax = M5Character.maxLoadValue(data.attributes.st);
|
||||
ret.stats.thrustLoad = M5Character.thrustLoadValue(data.attributes.st);
|
||||
ret.stats.encumbrance = 0;
|
||||
|
||||
if (!skip?.mods) {
|
||||
const aggregate = new M5ModAggregate(data, ret);
|
||||
@@ -167,51 +223,6 @@ export class M5Character extends Actor {
|
||||
ret.skillMods = aggregate.calculate();
|
||||
}
|
||||
|
||||
if (!skip?.items) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "item")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
let label = item.name;
|
||||
if (item.system.magic) {
|
||||
label += "*";
|
||||
}
|
||||
if (item.system.valuable) {
|
||||
ret.stats.wealth += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
|
||||
let icon = item.img;
|
||||
let rollable = false;
|
||||
|
||||
for (let key in item.system.rolls.formulas) {
|
||||
rollable = item.system.rolls.formulas[key]?.enabled;
|
||||
if (rollable) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret.gear.items[item.id] = {
|
||||
label: label,
|
||||
icon: icon,
|
||||
magic: item.system.magic,
|
||||
calc: item.system.calc,
|
||||
equipped: item.system?.equipped,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
weight: item.system.weight || 0,
|
||||
containerId: item.system.containerId || "",
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
quantity: item.system.quantity || 0,
|
||||
rollExist: rollable,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (!skip?.containers) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "container")
|
||||
@@ -222,6 +233,7 @@ export class M5Character extends Actor {
|
||||
if (item.system.magic) {
|
||||
label += "*";
|
||||
}
|
||||
|
||||
let icon = item.img;
|
||||
let rollable = false;
|
||||
|
||||
@@ -249,6 +261,243 @@ export class M5Character extends Actor {
|
||||
}
|
||||
|
||||
if (!skip?.items) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "item")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
let label = item.name;
|
||||
if (item.system.magic) {
|
||||
label += "*";
|
||||
}
|
||||
if (item.system.valuable) {
|
||||
ret.stats.wealth += parseFloat(this.calculateValue(item.system.value * item.system.quantity, item.system.currency).toPrecision(3));
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += parseFloat(this.calculateValue(item.system.value * item.system.quantity, item.system.currency).toPrecision(3));
|
||||
}
|
||||
|
||||
if (!!item.system.containerId) {
|
||||
ret.gear.containers[item.system.containerId].weight += parseFloat((item.system.weight * item.system.quantity).toPrecision(4));
|
||||
if (ret.gear.containers[item.system.containerId].equipped) {
|
||||
ret.stats.encumbrance += (item.system.weight * item.system.quantity);
|
||||
}
|
||||
} else if (item.system.equipped) {
|
||||
ret.stats.encumbrance += (item.system.weight * item.system.quantity);
|
||||
}
|
||||
|
||||
let icon = item.img;
|
||||
let rollable = false;
|
||||
|
||||
// console.log(item.system.rolls.formulas.map((p) => p.enabled));
|
||||
for (let key in item.system.rolls.formulas) {
|
||||
rollable = item.system.rolls.formulas[key]?.enabled;
|
||||
if (rollable) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ret.gear.items[item.id] = {
|
||||
label: label,
|
||||
icon: icon,
|
||||
magic: item.system.magic,
|
||||
calc: item.system.calc,
|
||||
equipped: item.system?.equipped,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
weight: item.system.weight || 0,
|
||||
containerId: item.system.containerId || "",
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
quantity: item.system.quantity || 0,
|
||||
rollExist: rollable,
|
||||
};
|
||||
});
|
||||
|
||||
context.items
|
||||
?.filter((item) => item.type === "weapon")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
let label = item.name;
|
||||
if (item.system.magic) {
|
||||
label +=
|
||||
"*(" +
|
||||
(item.system.stats.attackBonus < 0 ? "" : "+") +
|
||||
item.system.stats.attackBonus +
|
||||
"/" +
|
||||
(item.system.stats.damageBonus < 0 ? "" : "+") +
|
||||
item.system.stats.damageBonus +
|
||||
")";
|
||||
}
|
||||
if (item.system.valuable) {
|
||||
ret.stats.wealth += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (!!item.system.containerId) {
|
||||
ret.gear.containers[item.system.containerId].weight += item.system.weight;
|
||||
if (ret.gear.containers[item.system.containerId].equipped) {
|
||||
ret.stats.encumbrance += item.system.weight;
|
||||
}
|
||||
} else if (item.system.equipped) {
|
||||
ret.stats.encumbrance += item.system.weight || 0;
|
||||
}
|
||||
|
||||
ret.gear.weapons[item.id] = {
|
||||
label: label,
|
||||
skillId: item.system.skillId,
|
||||
magic: item.system.magic,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
calc: item.system.calc,
|
||||
special: item.system.special,
|
||||
damageBase: item.system.damageBase,
|
||||
equipped: item.system?.equipped,
|
||||
weight: item.system.weight || 0,
|
||||
containerId: item.system.containerId || "",
|
||||
};
|
||||
});
|
||||
|
||||
context.items
|
||||
?.filter((item) => item.type === "defensiveWeapon")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
let label = item.name;
|
||||
if (item.system.magic) {
|
||||
label += "*(" + (item.system.stats.defenseBonus < 0 ? "" : "+") + item.system.stats.defenseBonus + ")";
|
||||
}
|
||||
if (item.system.valuable) {
|
||||
ret.stats.wealth += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (!!item.system.containerId) {
|
||||
ret.gear.containers[item.system.containerId].weight += item.system.weight;
|
||||
if (ret.gear.containers[item.system.containerId].equipped) {
|
||||
ret.stats.encumbrance += item.system.weight;
|
||||
}
|
||||
} else if (item.system.equipped) {
|
||||
ret.stats.encumbrance += item.system.weight || 0;
|
||||
}
|
||||
|
||||
ret.gear.defensiveWeapons[item.id] = {
|
||||
label: label,
|
||||
skillId: item.system.skillId,
|
||||
magic: item.system.magic,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
defenseBonus: item.system.stats.defenseBonus,
|
||||
calc: item.system.calc,
|
||||
equipped: item.system?.equipped,
|
||||
weight: item.system.weight || 0,
|
||||
containerId: item.system.containerId || "",
|
||||
};
|
||||
});
|
||||
|
||||
context.items
|
||||
?.filter((item) => item.type === "armor")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
let label = item.name;
|
||||
if (item.system.magic) {
|
||||
label += "*";
|
||||
}
|
||||
if (item.system.valuable) {
|
||||
ret.stats.wealth += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (!!item.system.containerId) {
|
||||
ret.gear.containers[item.system.containerId].weight += item.system.weight;
|
||||
if (ret.gear.containers[item.system.containerId].equipped) {
|
||||
ret.stats.encumbrance += item.system.weight;
|
||||
}
|
||||
} else if (item.system.equipped) {
|
||||
ret.stats.encumbrance += 0;
|
||||
} else {
|
||||
ret.stats.encumbrance += item.system.weight || 0;
|
||||
}
|
||||
|
||||
ret.gear.armor[item.id] = {
|
||||
label: label,
|
||||
magic: item.system.magic,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
lpProtection: item.system.lpProtection,
|
||||
calc: item.system.calc,
|
||||
equipped: item.system?.equipped,
|
||||
weight: item.system.weight || 0,
|
||||
containerId: item.system.containerId || "",
|
||||
};
|
||||
});
|
||||
|
||||
if (!skip?.encumbrance) {
|
||||
const item = context.items.filter((x) => x.name === "Belastung");
|
||||
if (ret.stats.encumbrance > ret.stats.heavyLoad) {
|
||||
if (item.length === 0) {
|
||||
this.createEffect("Belastung", [{ id: "movement", operation: M5ModOperation.DIVISION, type: M5ModType.STAT, value: 2 }]);
|
||||
} else if (item.length === 1) {
|
||||
item[0].update({
|
||||
data: {
|
||||
equipped: true,
|
||||
},
|
||||
});
|
||||
} else if (item.length === 2) {
|
||||
item[1]?.delete();
|
||||
}
|
||||
} else if (ret.stats.encumbrance <= ret.stats.heavyLoad) {
|
||||
if (item.length === 1) {
|
||||
item[0].update({
|
||||
data: {
|
||||
equipped: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip?.encumbrance) {
|
||||
const item = context.items.filter((x) => x.name === "Höchstlast");
|
||||
if (ret.stats.encumbrance > ret.stats.loadMax) {
|
||||
if (item.length === 0) {
|
||||
let messageContent = `Höchstlast wurde überschritten: 1 AP Schaden durch Belastung alle 10 Minuten abziehen!`;
|
||||
let chatData = {
|
||||
speaker: ChatMessage.getSpeaker({actor: Actor.name}),
|
||||
content: messageContent,
|
||||
};
|
||||
ChatMessage.create(chatData, {});
|
||||
ui.notifications.warn(messageContent);
|
||||
this.createEffect("Höchstlast", [{ id: "ap", operation: M5ModOperation.SUBTRACT, type: M5ModType.STAT, value: 1 }]);
|
||||
} else if (item.length === 2) {
|
||||
item[1]?.delete();
|
||||
} else if (item.length === 1) {
|
||||
item[0].update({
|
||||
data: {
|
||||
equipped: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
} else if (ret.stats.encumbrance < ret.stats.loadMax) {
|
||||
if (item.length === 1) {
|
||||
item[0]?.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip?.effects) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "effect")
|
||||
.forEach((item) => {
|
||||
@@ -285,112 +534,6 @@ export class M5Character extends Actor {
|
||||
});
|
||||
}
|
||||
|
||||
if (!skip?.weapons) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "weapon")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
let label = item.name;
|
||||
if (item.system.magic) {
|
||||
label +=
|
||||
"*(" +
|
||||
(item.system.stats.attackBonus < 0 ? "" : "+") +
|
||||
item.system.stats.attackBonus +
|
||||
"/" +
|
||||
(item.system.stats.damageBonus < 0 ? "" : "+") +
|
||||
item.system.stats.damageBonus +
|
||||
")";
|
||||
}
|
||||
if (item.system.valuable) {
|
||||
ret.stats.wealth += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
|
||||
ret.gear.weapons[item.id] = {
|
||||
label: label,
|
||||
skillId: item.system.skillId,
|
||||
magic: item.system.magic,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
calc: item.system.calc,
|
||||
special: item.system.special,
|
||||
damageBase: item.system.damageBase,
|
||||
equipped: item.system?.equipped,
|
||||
containerId: item.system.containerId || "",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (!skip?.defensiveWeapons) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "defensiveWeapon")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
let label = item.name;
|
||||
if (item.system.magic) {
|
||||
label += "*(" + (item.system.stats.defenseBonus < 0 ? "" : "+") + item.system.stats.defenseBonus + ")";
|
||||
}
|
||||
if (item.system.valuable) {
|
||||
ret.stats.wealth += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
|
||||
ret.gear.defensiveWeapons[item.id] = {
|
||||
label: label,
|
||||
skillId: item.system.skillId,
|
||||
magic: item.system.magic,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
defenseBonus: item.system.stats.defenseBonus,
|
||||
calc: item.system.calc,
|
||||
equipped: item.system?.equipped,
|
||||
containerId: item.system.containerId || "",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (!skip?.armor) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "armor")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
let label = item.name;
|
||||
if (item.system.magic) {
|
||||
label += "*";
|
||||
}
|
||||
if (item.system.valuable) {
|
||||
ret.stats.wealth += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += this.calculateValue(item.system.value * item.system.quantity, item.system.currency);
|
||||
}
|
||||
|
||||
ret.gear.armor[item.id] = {
|
||||
label: label,
|
||||
magic: item.system.magic,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
lpProtection: item.system.lpProtection,
|
||||
calc: item.system.calc,
|
||||
equipped: item.system?.equipped,
|
||||
containerId: item.system.containerId || "",
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (!skip?.spells) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "spell")
|
||||
@@ -511,7 +654,7 @@ export class M5Character extends Actor {
|
||||
return data?.attributes[name];
|
||||
}
|
||||
|
||||
createSkill(skillName: string): Promise<M5Item> {
|
||||
async createSkill(skillName: string): Promise<M5Item> {
|
||||
const itemData = {
|
||||
name: skillName,
|
||||
type: "skill",
|
||||
@@ -536,6 +679,20 @@ export class M5Character extends Actor {
|
||||
});
|
||||
}
|
||||
|
||||
async createEffect(itemName: string, mods: M5ItemMod[]): Promise<M5Item> {
|
||||
const itemData = {
|
||||
name: itemName,
|
||||
type: "effect",
|
||||
|
||||
system: { mods: mods, equipped: true },
|
||||
};
|
||||
|
||||
return (this as any).createEmbeddedDocuments("Item", [itemData]).then((docs) => {
|
||||
const item = docs[0];
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
||||
getItem(itemId: string): any {
|
||||
if (!(this as any).items) return null;
|
||||
return (this as any).getEmbeddedDocument("Item", itemId);
|
||||
|
||||
Reference in New Issue
Block a user