Minor fixes and enhancements

This commit is contained in:
2026-04-02 09:29:27 +02:00
parent 81c1848e87
commit 0cb764f1f3
2 changed files with 84 additions and 53 deletions

View File

@@ -148,26 +148,32 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
getSkills() {
let comp = []
for (let item of this.items) {
item = foundry.utils.duplicate(item)
if (item.type == "competence") {
item.system.attribut1total = item.system.niveau + (this.system.attributs[item.system.attribut1]?.value || 0)
item.system.attribut2total = item.system.niveau + (this.system.attributs[item.system.attribut2]?.value || 0)
item.system.attribut3total = item.system.niveau + (this.system.attributs[item.system.attribut3]?.value || 0)
if (item.system.niveau == 0) {
item.system.attribut1total -= 3
item.system.attribut2total -= 3
item.system.attribut3total -= 3
// Utiliser filter et map pour éviter les duplications inutiles
const comp = this.items
.filter(item => item.type === "competence")
.map(item => {
const itemCopy = foundry.utils.duplicate(item);
const attrs = this.system.attributs;
itemCopy.system.attribut1total = itemCopy.system.niveau + (attrs[itemCopy.system.attribut1]?.value || 0);
itemCopy.system.attribut2total = itemCopy.system.niveau + (attrs[itemCopy.system.attribut2]?.value || 0);
itemCopy.system.attribut3total = itemCopy.system.niveau + (attrs[itemCopy.system.attribut3]?.value || 0);
if (itemCopy.system.niveau === 0) {
itemCopy.system.attribut1total -= 3;
itemCopy.system.attribut2total -= 3;
itemCopy.system.attribut3total -= 3;
}
item.system.attribut1label = this.system.attributs[item.system.attribut1]?.label || ""
item.system.attribut2label = this.system.attributs[item.system.attribut2]?.label || ""
item.system.attribut3label = this.system.attributs[item.system.attribut3]?.label || ""
comp.push(item)
}
}
HawkmoonUtility.sortArrayObjectsByName(comp)
return comp
itemCopy.system.attribut1label = attrs[itemCopy.system.attribut1]?.label || "";
itemCopy.system.attribut2label = attrs[itemCopy.system.attribut2]?.label || "";
itemCopy.system.attribut3label = attrs[itemCopy.system.attribut3]?.label || "";
return itemCopy;
});
HawkmoonUtility.sortArrayObjectsByName(comp);
return comp;
}
/* ----------------------- --------------------- */
@@ -745,41 +751,48 @@ export class HawkmoonActor extends Actor {
/* -------------------------------------------- */
async rollArmeDegats(armeId, targetVigueur = undefined, rollDataInput = undefined) {
let arme = this.items.get(armeId)
if (!arme.system.equipped) {
ui.notifications.warn("Cette arme doit être équipée pour pouvoir infliger des dégâts !")
return
const arme = this.items.get(armeId);
if (!arme) {
ui.notifications.warn("Arme non trouvée !");
return;
}
if (arme.type == "arme") {
arme = this.prepareArme(arme)
if (!arme.system?.equipped) {
ui.notifications.warn("Cette arme doit être équipée pour pouvoir infliger des dégâts !");
return;
}
console.log("DEGATS", arme, targetVigueur, rollDataInput)
let roll
let bonus = 0
let bonus2 = 0
const preparedArme = arme.type === "arme" ? this.prepareArme(arme) : arme;
console.log("DEGATS", preparedArme, targetVigueur, rollDataInput);
let roll;
let bonus = 0;
let bonus2 = 0;
if (rollDataInput?.applyCoupDevastateur) {
bonus2 = Math.floor(this.system.attributs.pui.value / 2)
let talent = this.items.find(item => item.type == "talent" && item.name.toLowerCase() == "coup dévastateur")
this.updateEmbeddedDocuments('Item', [{ _id: talent.id, 'system.used': true }])
bonus2 = Math.floor(this.system.attributs.pui.value / 2);
const talent = this.items.find(item => item.type === "talent" && item.name.toLowerCase() === "coup dévastateur");
if (talent) {
await this.updateEmbeddedDocuments('Item', [{ _id: talent.id, 'system.used': true }]);
}
}
if (rollDataInput?.isHeroique) {
if (rollDataInput?.attaqueCharge) {
bonus = 5
bonus = 5;
}
if (rollDataInput?.chargeCavalerie) {
bonus = 6
bonus = 6;
}
roll = await new Roll("2d10rr10+" + arme.system.totalDegats + "+" + bonus + "+" + bonus2).roll()
roll = await new Roll("2d10rr10+" + preparedArme.system.totalDegats + "+" + bonus + "+" + bonus2).roll();
} else {
if (rollDataInput?.attaqueCharge) {
bonus = 3
bonus = 3;
}
if (rollDataInput?.chargeCavalerie) {
bonus = 4
bonus = 4;
}
roll = await new Roll("1d10+" + arme.system.totalDegats + "+" + bonus + "+" + bonus2).roll()
roll = await new Roll("1d10+" + preparedArme.system.totalDegats + "+" + bonus + "+" + bonus2).roll();
}
await HawkmoonUtility.showDiceSoNice(roll, game.settings.get("core", "rollMode"));
let nbEtatPerdus = 0
@@ -788,17 +801,17 @@ export class HawkmoonActor extends Actor {
}
//console.log(roll)
let rollData = {
arme: arme,
arme: preparedArme,
finalResult: roll.total,
formula: roll.formula,
alias: this.name,
actorImg: this.img,
actorId: this.id,
defenderTokenId: rollDataInput?.defenderTokenId,
actionImg: arme.img,
actionImg: preparedArme.img,
targetVigueur: targetVigueur,
nbEtatPerdus: nbEtatPerdus
}
};
HawkmoonUtility.createChatWithRollMode(rollData.alias, {
content: await foundry.applications.handlebars.renderTemplate(`systems/fvtt-hawkmoon-cyd/templates/chat-degats-result.hbs`, rollData)
})