#6-lasten-und-belastung
Changes: + berechne belastung + füge effect für belastung hinzu was B halbiert + Container berechnen lasten von gegenständen in ihnen (#16)
This commit is contained in:
+194
-143
@@ -1,5 +1,5 @@
|
||||
import { M5Item } from "../items/M5Item";
|
||||
import { M5Attribute, M5CharacterCalculatedData, M5ItemMod, M5ItemType, M5ModOperation, M5ModResult, M5RollData, M5Skill, M5SkillCalculated, M5SkillLearned } from "../M5Base";
|
||||
import { M5Attribute, M5CharacterCalculatedData, M5ItemMod, M5ItemType, M5ModOperation, M5ModResult, M5ModType, M5RollData, M5Skill, M5SkillCalculated, M5SkillLearned } from "../M5Base";
|
||||
import M5ModAggregate from "./M5ModAggregate";
|
||||
export class M5Character extends Actor {
|
||||
// constructor(
|
||||
@@ -75,14 +75,12 @@ export class M5Character extends Actor {
|
||||
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 = {
|
||||
@@ -182,7 +180,7 @@ export class M5Character extends Actor {
|
||||
ret.stats.damageBonus = this.modResult(Math.floor(ret.attributes.st.value / 20) + Math.floor(ret.attributes.gs.value / 30) - 3);
|
||||
ret.stats.attackBonus = this.modResult(ret.attributes.gs.bonus);
|
||||
ret.stats.defenseBonus = this.modResult(ret.attributes.gw.bonus);
|
||||
ret.stats.movement = this.modResult(data.info.encumbrance > data.info.heavyLoad ? data.movement / 2 : data.movement);
|
||||
ret.stats.movement = this.modResult(data.movement);
|
||||
ret.stats.resistanceMind = this.modResult(
|
||||
(data.info.magicUsing ? 2 : 0) + ret.stats.defense.value + (data.info.race === "Mensch" ? ret.attributes.in.bonus : this.raceBonus(data.info.race))
|
||||
);
|
||||
@@ -242,6 +240,44 @@ export class M5Character extends Actor {
|
||||
ret.skillMods = aggregate.calculate();
|
||||
}
|
||||
|
||||
if (!skip?.containers) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "container")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
let label = item.name;
|
||||
if (item.system.magic) {
|
||||
label += "*";
|
||||
}
|
||||
|
||||
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.containers[item.id] = {
|
||||
label: label,
|
||||
icon: icon,
|
||||
magic: item.system.magic,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
calc: item.system.calc,
|
||||
equipped: item.system?.equipped,
|
||||
weight: item.system.weight || 0,
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
quantity: item.system.quantity || 0,
|
||||
rollExist: rollable,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (!skip?.items) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "item")
|
||||
@@ -258,7 +294,13 @@ export class M5Character extends Actor {
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += item.system.value || 0;
|
||||
}
|
||||
if (item.system.equipped) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -289,11 +331,93 @@ export class M5Character extends Actor {
|
||||
rollExist: rollable,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
if (!skip?.containers) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "container")
|
||||
?.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.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += item.system.value || 0;
|
||||
}
|
||||
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,
|
||||
calc: item.system.calc,
|
||||
special: item.system.special,
|
||||
damageBase: item.system.damageBase,
|
||||
equipped: item.system?.equipped,
|
||||
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.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += item.system.value || 0;
|
||||
}
|
||||
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,
|
||||
defenseBonus: item.system.stats.defenseBonus,
|
||||
calc: item.system.calc,
|
||||
equipped: item.system?.equipped,
|
||||
containerId: item.system.containerId || "",
|
||||
};
|
||||
});
|
||||
|
||||
context.items
|
||||
?.filter((item) => item.type === "armor")
|
||||
.forEach((item) => {
|
||||
item.prepareDerivedData();
|
||||
|
||||
@@ -301,34 +425,61 @@ export class M5Character extends Actor {
|
||||
if (item.system.magic) {
|
||||
label += "*";
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (item.system.valuable) {
|
||||
ret.stats.wealth += this.calculateValue(item.system.value, item.system.currency);
|
||||
}
|
||||
ret.gear.containers[item.id] = {
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += item.system.value || 0;
|
||||
}
|
||||
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,
|
||||
icon: icon,
|
||||
magic: item.system.magic,
|
||||
valuable: item.system?.valuable,
|
||||
hoarded: item.system?.hoarded,
|
||||
value: item.system.value || 0,
|
||||
lpProtection: item.system.lpProtection,
|
||||
calc: item.system.calc,
|
||||
equipped: item.system?.equipped,
|
||||
weight: item.system.weight || 0,
|
||||
value: item.system.value || 0,
|
||||
currency: item.system.currency || "",
|
||||
quantity: item.system.quantity || 0,
|
||||
rollExist: rollable,
|
||||
containerId: item.system.containerId || "",
|
||||
};
|
||||
});
|
||||
|
||||
if (!skip?.encumbrance) {
|
||||
const item = context.items.find((x) => x.name === "Belastung");
|
||||
if (ret.stats.encumbrance > data.info.heavyLoad) {
|
||||
if (!item) {
|
||||
this.createEffect("Belastung", [{ id: "movement", operation: M5ModOperation.DIVISION, type: M5ModType.STAT, value: 2 }]);
|
||||
} else {
|
||||
item.update({
|
||||
data: {
|
||||
equipped: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
} else if (ret.stats.encumbrance <= data.info.heavyLoad) {
|
||||
if (!!item) {
|
||||
item.update({
|
||||
data: {
|
||||
equipped: false,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip?.items) {
|
||||
if (!skip?.effects) {
|
||||
context.items
|
||||
?.filter((item) => item.type === "effect")
|
||||
.forEach((item) => {
|
||||
@@ -365,120 +516,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.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += item.system.value || 0;
|
||||
}
|
||||
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,
|
||||
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.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += item.system.value || 0;
|
||||
}
|
||||
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,
|
||||
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.currency);
|
||||
}
|
||||
if (item.system.hoarded) {
|
||||
ret.stats.hoard += item.system.value || 0;
|
||||
}
|
||||
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,
|
||||
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")
|
||||
@@ -599,7 +636,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",
|
||||
@@ -611,7 +648,7 @@ export class M5Character extends Actor {
|
||||
});
|
||||
}
|
||||
|
||||
createItem(itemName: string, itemType: M5ItemType): Promise<M5Item> {
|
||||
async createItem(itemName: string, itemType: M5ItemType): Promise<M5Item> {
|
||||
const itemData = {
|
||||
name: itemName,
|
||||
type: itemType,
|
||||
@@ -623,6 +660,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