This commit is contained in:
@@ -14,6 +14,12 @@ import { DonjonEtCieUtility } from "./donjon-et-cie-utility.mjs";
|
||||
import { DonjonEtCieRollDialog } from "./applications/donjon-et-cie-roll-dialog.mjs";
|
||||
|
||||
export class DonjonEtCieActor extends Actor {
|
||||
static defaultPnjAttack = {
|
||||
nom: "Attaque",
|
||||
degats: "1d6",
|
||||
notes: ""
|
||||
};
|
||||
|
||||
prepareDerivedData() {
|
||||
super.prepareDerivedData();
|
||||
|
||||
@@ -163,6 +169,45 @@ export class DonjonEtCieActor extends Actor {
|
||||
if (item?.type === "entrainement") return item.resetUsageDie();
|
||||
}
|
||||
|
||||
getPnjAttacks() {
|
||||
if (this.type !== "pnj") return [];
|
||||
|
||||
const attacks = Array.isArray(this.system.attaques) ? this.system.attaques : [];
|
||||
if (attacks.length) return attacks.map((attack, index) => ({
|
||||
index,
|
||||
nom: attack.nom || `Attaque ${index + 1}`,
|
||||
degats: attack.degats || "",
|
||||
notes: attack.notes || ""
|
||||
}));
|
||||
|
||||
const legacy = this.system.attaque;
|
||||
if (legacy) {
|
||||
return [{
|
||||
index: 0,
|
||||
nom: legacy.nom || "Attaque",
|
||||
degats: legacy.degats || "",
|
||||
notes: legacy.notes || ""
|
||||
}];
|
||||
}
|
||||
|
||||
return [{ index: 0, ...foundry.utils.deepClone(this.constructor.defaultPnjAttack) }];
|
||||
}
|
||||
|
||||
async createPnjAttack() {
|
||||
if (this.type !== "pnj") return null;
|
||||
const attaques = this.getPnjAttacks().map(({ nom, degats, notes }) => ({ nom, degats, notes }));
|
||||
attaques.push(foundry.utils.deepClone(this.constructor.defaultPnjAttack));
|
||||
return this.update({ "system.attaques": attaques });
|
||||
}
|
||||
|
||||
async deletePnjAttack(index) {
|
||||
if (this.type !== "pnj") return null;
|
||||
const attaques = this.getPnjAttacks().map(({ nom, degats, notes }) => ({ nom, degats, notes }));
|
||||
attaques.splice(Number(index), 1);
|
||||
if (!attaques.length) attaques.push(foundry.utils.deepClone(this.constructor.defaultPnjAttack));
|
||||
return this.update({ "system.attaques": attaques });
|
||||
}
|
||||
|
||||
#createPnjResourceProxy({ label, deltaPath, protectionPath = null }) {
|
||||
const delta = Number(foundry.utils.getProperty(this, deltaPath) ?? 0);
|
||||
const protection = protectionPath ? Number(foundry.utils.getProperty(this, protectionPath) ?? 0) : 0;
|
||||
@@ -203,9 +248,10 @@ export class DonjonEtCieActor extends Actor {
|
||||
}));
|
||||
}
|
||||
|
||||
async rollPnjAttackDamage() {
|
||||
const attackName = this.system.attaque?.nom || "Attaque";
|
||||
const attackDamage = this.system.attaque?.degats || "";
|
||||
async rollPnjAttackDamage(index = 0) {
|
||||
const attack = this.getPnjAttacks()[Number(index)] ?? null;
|
||||
const attackName = attack?.nom || "Attaque";
|
||||
const attackDamage = attack?.degats || "";
|
||||
if (!attackDamage) return null;
|
||||
|
||||
return DonjonEtCieRollDialog.createDamage(this, {
|
||||
@@ -213,7 +259,7 @@ export class DonjonEtCieActor extends Actor {
|
||||
type: "attaque",
|
||||
system: {
|
||||
degats: attackDamage,
|
||||
portee: this.system.attaque?.notes || ""
|
||||
portee: attack?.notes || ""
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user