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

View File

@@ -106,8 +106,17 @@ export class HawkmoonUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static updatePauseLogo(html) { static updatePauseLogo(html) {
let logoPause = "systems/fvtt-hawkmoon-cyd/assets/logos/" + game.settings.get("fvtt-hawkmoon-cyd", "hawkmoon-pause-logo") + ".webp" const validLogos = ["hawkmoon_logo", "logo_pause_resistance", "logo_pause_hawkmoon_stone", "logo_pause_hawkmoon_violet", "logo_pause_hawkmoon_beige", "logo_pause_hawkmoon_rouge"];
console.log("Hawkmoon | Updating pause logo to:", logoPause) let logoName = game.settings.get("fvtt-hawkmoon-cyd", "hawkmoon-pause-logo");
// Validation du nom du logo
if (!validLogos.includes(logoName)) {
console.error("Hawkmoon | Invalid logo name:", logoName);
return;
}
let logoPause = "systems/fvtt-hawkmoon-cyd/assets/logos/" + logoName + ".webp";
console.log("Hawkmoon | Updating pause logo to:", logoPause);
// Supprimer l'ancien style s'il existe // Supprimer l'ancien style s'il existe
let oldStyle = document.getElementById('hawkmoon-pause-logo-override') let oldStyle = document.getElementById('hawkmoon-pause-logo-override')
@@ -138,13 +147,6 @@ export class HawkmoonUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static createDirectOptionList(min, max) {
let options = {};
for (let i = min; i <= max; i++) {
options[`${i}`] = `${i}`;
}
return options;
}
static createArrayOptionList(min, max) { static createArrayOptionList(min, max) {
let options = []; let options = [];
for (let i = min; i <= max; i++) { for (let i = min; i <= max; i++) {
@@ -161,8 +163,19 @@ export class HawkmoonUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async loadCompendium(compendium, filter = item => true) { static async loadCompendium(compendium, filter = item => true) {
let compendiumData = await HawkmoonUtility.loadCompendiumData(compendium); const pack = game.packs.get(compendium);
if (!pack) {
console.warn(`Hawkmoon | Compendium not found: ${compendium}`);
return [];
}
try {
const compendiumData = await pack.getDocuments();
return compendiumData.filter(filter); return compendiumData.filter(filter);
} catch (error) {
console.error(`Hawkmoon | Error loading compendium ${compendium}:`, error);
return [];
}
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@@ -366,6 +379,12 @@ export class HawkmoonUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static computeResult(rollData) { static computeResult(rollData) {
// Validation des données de roll
if (!rollData.roll?.terms?.[0]?.results?.[0]?.result) {
console.error("Hawkmoon | Invalid roll data:", rollData);
return;
}
rollData.diceResult = rollData.roll.terms[0].results[0].result rollData.diceResult = rollData.roll.terms[0].results[0].result
if (rollData.mainDice.includes("d20")) { if (rollData.mainDice.includes("d20")) {
let diceValue = rollData.roll.terms[0].results[0].result let diceValue = rollData.roll.terms[0].results[0].result
@@ -379,7 +398,6 @@ export class HawkmoonUtility {
} }
} }
//console.log("Result : ", rollData
this.computeResultQuality(rollData) this.computeResultQuality(rollData)
} }