diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 5d129fe1..6768f3ad 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -36,16 +36,16 @@ export class RdDActorSheet extends ActorSheet { /* -------------------------------------------- */ async getData() { - const objectData = Misc.data(this.object); + const objectData = Misc.data(this.object) //this.actor.checkMonnaiePresence(this.actor.data.items); // Always check let formData = { title: this.title, - id: objectData.id, - type: objectData.type, - img: objectData.img, - name: objectData.name, + id: this.object.id, + type: this.object.type, + img: this.object.img, + name: this.object.name, editable: this.isEditable, cssClass: this.isEditable ? "editable" : "locked", data: foundry.utils.deepClone(this.object.system), @@ -168,12 +168,12 @@ export class RdDActorSheet extends ActorSheet { if (!this.options.editable) return; html.find('.item-split').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); - RdDSheetUtility.splitItem(item, this.actor); + const item = RdDSheetUtility.getItem(event, this.actor) + RdDSheetUtility.splitItem(item, this.actor) }); html.find('.item-edit').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); - item.sheet.render(true); + const item = RdDSheetUtility.getItem(event, this.actor) + item.sheet.render(true) }); html.find('.display-label a').click(async event => { const item = RdDSheetUtility.getItem(event, this.actor); @@ -549,10 +549,9 @@ export class RdDActorSheet extends ActorSheet { } async _onSplitItem(item, split) { - if (split >= 1 && split < Misc.data(item).data.quantite) { - await item.diminuerQuantite(split); - const itemData = duplicate(Misc.data(item)); - itemData.data.quantite = split; + if (split >= 1 && split < item.system.quantite) { + await item.diminuerQuantite(split) + item.system.quantite = split; await this.actor.createEmbeddedDocuments('Item', [itemData]) } } diff --git a/module/actor.js b/module/actor.js index 6b6f16eb..b886e3b5 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1785,13 +1785,13 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ _computeEnduranceMax() { - let blessures = this.system.data.blessures; - let diffVie = this.system.data.sante.vie.max - this.system.data.sante.vie.value; - let maxEndVie = this.system.data.sante.endurance.max - (diffVie * 2); + let blessures = this.system.blessures; + let diffVie = this.system.sante.vie.max - this.system.sante.vie.value; + let maxEndVie = this.system.sante.endurance.max - (diffVie * 2); let nbGraves = this.countBlessures(blessures.graves.liste); let nbCritiques = this.countBlessures(blessures.critiques.liste); - let maxEndGraves = Math.floor(this.system.data.sante.endurance.max / (2 * nbGraves)); - let maxEndCritiques = nbCritiques > 0 ? 1 : this.system.data.sante.endurance.max; + let maxEndGraves = Math.floor(this.system.sante.endurance.max / (2 * nbGraves)); + let maxEndCritiques = nbCritiques > 0 ? 1 : this.system.sante.endurance.max; return Math.max(0, Math.min(maxEndVie, maxEndGraves, maxEndCritiques)); } @@ -2206,24 +2206,24 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async checkCompetenceXP(compName, newXP, display = true) { - let compData = Misc.data(this.getCompetence(compName)); + let compData = this.getCompetence(compName) if (compData && newXP && newXP == compData.data.xp) { // Si édition, mais sans changement XP - return; + return } - newXP = (newXP) ? newXP : compData.data.xp; + newXP = (newXP) ? newXP : compData.system.xp if (compData && newXP > 0) { - let xpNeeded = RdDItemCompetence.getCompetenceNextXp(compData.data.niveau + 1); + let xpNeeded = RdDItemCompetence.getCompetenceNextXp(compData.system.niveau + 1); if (newXP >= xpNeeded) { - let newCompData = duplicate(compData); - newCompData.data.niveau += 1; - newCompData.data.xp = newXP; + let newCompData = duplicate(compData) + newCompData.system.niveau += 1; + newCompData.system.xp = newXP; let checkXp = { alias: this.name, competence: newCompData.name, - niveau: newCompData.data.niveau, - xp: newCompData.data.xp, - archetype: newCompData.data.niveau_archetype, - archetypeWarning: newCompData.data.niveau > compData.data.niveau_archetype + niveau: newCompData.system.niveau, + xp: newCompData.system.xp, + archetype: newCompData.system.niveau_archetype, + archetypeWarning: newCompData.system.niveau > compData.system.niveau_archetype } if (display) { ChatMessage.create({ @@ -2528,11 +2528,12 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async rollCompetence(idOrName) { - let rollData = { competence: Misc.data(this.getCompetence(idOrName)) } + let comp = this.getCompetence(idOrName) + let rollData = { competence: comp } //console.log("COMP CREATURE", name, rollData, name); if (rollData.competence.type == 'competencecreature') { - if (rollData.competence.data.iscombat) { + if (rollData.competence.system.iscombat) { const arme = RdDItemCompetenceCreature.toArme(rollData.competence); RdDCombat.createUsingTarget(this).attaque(rollData.competence, arme); return; @@ -2554,8 +2555,8 @@ export class RdDActor extends Actor { this.createCallbackAppelAuMoral(), { action: r => this._competenceResult(r) } ] - }); - dialog.render(true); + }) + dialog.render(true) } /* -------------------------------------------- */ @@ -3186,15 +3187,16 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ rollArme(arme) { - let competence = Misc.data(this.getCompetence(arme.system.competence)); + let itemData = arme.system && arme.system || arme.data + let competence = this.getCompetence( itemData.competence ) if (arme || (competence.type == 'competencecreature' && competence.system.iscombat)) { - if (competence.data.ispossession) { - RdDPossession.managePosession(this, competence); + if (competence.system.ispossession) { + RdDPossession.managePosession(this, competence) } else { - RdDCombat.createUsingTarget(this)?.attaque(competence, arme); + RdDCombat.createUsingTarget(this)?.attaque(competence, arme) } } else { - this.rollCompetence(competence.name); + this.rollCompetence(competence.name) } } diff --git a/module/item-arme.js b/module/item-arme.js index b1f1aafa..4ab1bffe 100644 --- a/module/item-arme.js +++ b/module/item-arme.js @@ -37,13 +37,13 @@ export class RdDItemArme extends Item { static computeNiveauArmes(armes, competences) { for (const arme of armes) { - arme.data.niveau = RdDItemArme.niveauCompetenceArme(arme, competences); + arme.system.niveau = RdDItemArme.niveauCompetenceArme(arme, competences) } } static niveauCompetenceArme(arme, competences) { - const compArme = competences.find(it => it.name == arme.data.competence); - return compArme?.data.niveau ?? -8; + const compArme = competences.find(it => it.name == arme.system.competence); + return compArme?.system.niveau ?? -8; } /* -------------------------------------------- */ diff --git a/module/item-competence.js b/module/item-competence.js index 89bdba98..cc9a18cb 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -89,9 +89,9 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static isCompetenceArme(competence) { - switch (Misc.templateData(competence).categorie) { + switch (competence.categorie) { case 'melee': - return Misc.data(competence).name != 'Esquive'; + return competence.name != 'Esquive'; case 'tir': case 'lancer': return true; @@ -101,15 +101,15 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static isArmeUneMain(competence) { - return Misc.data(competence)?.name.toLowerCase().includes("1 main"); + return competence.name.toLowerCase().includes("1 main"); } static isArme2Main(competence) { - return Misc.data(competence)?.name.toLowerCase().includes("2 main"); + return competence.name.toLowerCase().includes("2 main"); } /* -------------------------------------------- */ static isMalusEncombrementTotal(competence) { - return Misc.data(competence)?.name.toLowerCase().match(/(natation|acrobatie)/); + return competence?.name.toLowerCase().match(/(natation|acrobatie)/) } /* -------------------------------------------- */ diff --git a/module/item-sheet.js b/module/item-sheet.js index 2bade3f8..c283d19f 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -60,14 +60,14 @@ export class RdDItemSheet extends ItemSheet { /* -------------------------------------------- */ async getData() { - const objectData = Misc.data(this.object); + const objectData = this.object; let formData = { id: this.object.id, title: objectData.name, type: objectData.type, img: objectData.img, name: objectData.name, - data: objectData.data, + data: objectData.system, isGM: game.user.isGM, actorId: this.actor?.id, owner: this.document.isOwner, @@ -82,14 +82,14 @@ export class RdDItemSheet extends ItemSheet { } } - formData.categorieCompetences = RdDItemCompetence.getCategorieCompetences(); + formData.categorieCompetences = RdDItemCompetence.getCategorieCompetences() if (formData.type == 'tache' || formData.type == 'livre' || formData.type == 'meditation' || formData.type == 'oeuvre') { - formData.caracList = duplicate(game.system.model.Actor.personnage.carac); + formData.caracList = duplicate(game.system.model.Actor.personnage.carac) formData.competences = await RdDUtility.loadCompendium('foundryvtt-reve-de-dragon.competences'); } if (formData.type == 'arme') { formData.competences = await RdDUtility.loadCompendium('foundryvtt-reve-de-dragon.competences', it => RdDItemCompetence.isCompetenceArme(it)); - console.log(formData.competences); + console.log(formData.competences) } if (formData.type == 'recettealchimique') { RdDAlchimie.processManipulation(objectData, this.actor && this.actor.id); diff --git a/module/item.js b/module/item.js index 98f94ffb..845ebdbe 100644 --- a/module/item.js +++ b/module/item.js @@ -56,48 +56,45 @@ export class RdDItem extends Item { } isCompetence() { - return Misc.data(this).type == 'competence'; + return this.type == 'competence'; } isConteneur() { - return Misc.data(this).type == 'conteneur'; + return this.type == 'conteneur'; } isConteneurNonVide() { - return this.isConteneur() && (Misc.templateData(this).contenu?.length ?? 0) > 0; + return this.isConteneur() && (this.system.contenu?.length ?? 0) > 0; } isConteneurVide() { - return this.isConteneur() && (Misc.templateData(this).contenu?.length ?? 0) == 0; + return this.isConteneur() && (this.system.contenu?.length ?? 0) == 0; } isVideOuNonConteneur() { - return !this.isConteneur() || (Misc.templateData(this).contenu?.length ?? 0) == 0; + return !this.isConteneur() || (this.system.contenu?.length ?? 0) == 0; } isAlcool() { - const itemData = Misc.data(this); - return itemData.type == 'nourritureboisson' && itemData.data.boisson && itemData.data.alcoolise; + return this.type == 'nourritureboisson' && this.system.boisson && this.system.alcoolise; } isHerbeAPotion() { - const itemData = Misc.data(this); - return itemData.type == 'herbe' && (itemData.data.categorie == 'Soin' || itemData.data.categorie == 'Repos'); + return this.type == 'herbe' && (this.system.categorie == 'Soin' || this.system.categorie == 'Repos'); } isPotion() { - return Misc.data(this).type == 'potion'; + return this.type == 'potion'; } isEquipement() { - return RdDItem.getTypeObjetsEquipement().includes(Misc.data(this).type); + return RdDItem.getTypeObjetsEquipement().includes(this.type) } isCristalAlchimique() { - const itemData = Misc.data(this); - return itemData.type == 'objet' && Grammar.toLowerCaseNoAccent(itemData.name) == 'cristal alchimique' && itemData.data.quantite > 0; + return this.type == 'objet' && Grammar.toLowerCaseNoAccent(this.name) == 'cristal alchimique' && this.system.quantite > 0; } isMagique() { - return Misc.templateData(this).magique; + return this.system.magique; } getEncTotal() { @@ -121,8 +118,7 @@ export class RdDItem extends Item { if (this.isPotion()) { this.prepareDataPotion() } - const itemData = Misc.data(this); - itemData.data.actionPrincipale = this.getActionPrincipale({ warnIfNot: false }); + this.system.actionPrincipale = this.getActionPrincipale({ warnIfNot: false }); } } diff --git a/module/misc.js b/module/misc.js index 02d296e5..4a14ba9c 100644 --- a/module/misc.js +++ b/module/misc.js @@ -105,7 +105,6 @@ export class Misc { return params.reduce((a, b) => a + separator + b); } - static data(it) { if (it instanceof Actor || it instanceof Item || it instanceof Combatant) { return it.system diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 21ed8a4d..6cdb828e 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -153,7 +153,7 @@ export class RdDCombatManager extends Combat { /** Retourne une liste triée d'armes avec le split arme1 main / arme 2 main */ static finalizeArmeList(armes, competences, carac) { // Gestion des armes 1/2 mains - let armesEquipe = []; + let armesEquipe = [] for (const arme of armes) { let armeData = duplicate(arme) if (armeData.data.equipe) { @@ -667,6 +667,7 @@ export class RdDCombat { if (!await this.accorderEntite('avant-attaque')) { return; } + console.log("ATTACK", competence, arme) if (arme.data.cac == 'empoignade' && this.attacker.isCombatTouche()) { ChatMessage.create({ alias: this.attacker.name, @@ -676,7 +677,7 @@ export class RdDCombat { competence: competence }) }); - return; + return } let rollData = this._prepareAttaque(competence, arme); @@ -703,7 +704,7 @@ export class RdDCombat { { condition: RdDCombat.isEchecTotal, action: r => this._onAttaqueEchecTotal(r) }, ] }); - dialog.render(true); + dialog.render(true) } /* -------------------------------------------- */ diff --git a/module/rdd-roll.js b/module/rdd-roll.js index aae05e03..4ed55155 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -47,7 +47,7 @@ export class RdDRoll extends Dialog { carac: actor.system.carac, finalLevel: 0, diffConditions: 0, - diffLibre: rollData.competence?.data.default_diffLibre ?? 0, + diffLibre: rollData.competence?.system.default_diffLibre ?? 0, malusArmureValue: actor.getMalusArmure(), surencMalusFlag: actor.isPersonnage() ? (actor.system.compteurs.surenc.value < 0) : false, surencMalusValue: actor.computeMalusSurEncombrement(), @@ -73,6 +73,7 @@ export class RdDRoll extends Dialog { RollDataAjustements.calcul(rollData, actor); } + /* -------------------------------------------- */ static getDiviseurSignificative(rollData) { let facteurSign = 1; @@ -163,14 +164,14 @@ export class RdDRoll extends Dialog { console.log(rollData); // Update html, according to data if (rollData.competence) { - const defaut_carac = Misc.templateData(rollData.competence).defaut_carac; + const defaut_carac = rollData.competence.system.defaut_carac // Set the default carac from the competence item - rollData.selectedCarac = rollData.carac[defaut_carac]; - $("#carac").val(defaut_carac); + rollData.selectedCarac = rollData.carac[defaut_carac] + $("#carac").val(defaut_carac) } if (rollData.selectedSort) { - dialog.setSelectedSort(rollData.selectedSort); - $(".draconic").val(rollData.selectedSort.data.listIndex); // Uniquement a la selection du sort, pour permettre de changer + dialog.setSelectedSort(rollData.selectedSort) + $(".draconic").val(rollData.selectedSort.data.listIndex) // Uniquement a la selection du sort, pour permettre de changer } RdDItemSort.setCoutReveReel(rollData.selectedSort); $("#diffLibre").val(Misc.toInt(rollData.diffLibre)); @@ -287,10 +288,10 @@ export class RdDRoll extends Dialog { HtmlUtility._showControlWhen($(".div-sort-ptreve-fixe"), !coutVariable); } - async setSelectedSigneDraconique(signe){ + async setSelectedSigneDraconique(signe) { this.rollData.signe = signe; - this.rollData.diffLibre = Misc.data(signe).data.difficulte, - $(".signe-difficulte").text(Misc.toSignedString(this.rollData.diffLibre)); + this.rollData.diffLibre = Misc.data(signe).data.difficulte, + $(".signe-difficulte").text(Misc.toSignedString(this.rollData.diffLibre)); } /* -------------------------------------------- */ @@ -304,9 +305,9 @@ export class RdDRoll extends Dialog { rollData.use.appelAuMoral = this.actor.isPersonnage() && RdDCarac.isActionPhysique(rollData.selectedCarac); let dmgText = Misc.toSignedString(rollData.dmg.total); - switch (rollData.mortalite){ - case 'non-mortel': dmgText = `(${dmgText}) non-mortel`; break; - case 'empoignade': dmgText = `empoignade`; break; + switch (rollData.mortalite) { + case 'non-mortel': dmgText = `(${dmgText}) non-mortel`; break; + case 'empoignade': dmgText = `empoignade`; break; } RollDataAjustements.calcul(rollData, this.actor); @@ -338,7 +339,7 @@ export class RdDRoll extends Dialog { /* -------------------------------------------- */ _computeFinalLevel(rollData) { - return RollDataAjustements.sum(rollData.ajustements); + return RollDataAjustements.sum(rollData.ajustements) } /* -------------------------------------------- */ _computeDiffCompetence(rollData) { @@ -374,16 +375,16 @@ export class RdDRoll extends Dialog { /* -------------------------------------------- */ _getTitle(rollData) { - const carac = rollData.selectedCarac.label; + const carac = rollData.selectedCarac.label if (!rollData.competence) { - return carac; + return carac } - const compName = rollData.competence.name; + const compName = rollData.competence.name if (rollData.draconicList && rollData.selectedSort) { - return compName + " - " + rollData.selectedSort.name; + return compName + " - " + rollData.selectedSort.name } // If a weapon is there, add it in the title - const niveau = Misc.toSignedString(rollData.competence.data.niveau); + const niveau = Misc.toSignedString(rollData.competence.system.niveau) if (compName == carac) { // cas des créatures return carac + " Niveau " + niveau diff --git a/module/rolldata-ajustements.js b/module/rolldata-ajustements.js index 752b2c84..6263eb05 100644 --- a/module/rolldata-ajustements.js +++ b/module/rolldata-ajustements.js @@ -19,9 +19,9 @@ import { ReglesOptionelles } from "./regles-optionelles.js"; */ export const referenceAjustements = { competence: { - isUsed: (rollData, actor) => Misc.data(rollData.competence), - getLabel: (rollData, actor) => Misc.data(rollData.competence)?.name, - getValue: (rollData, actor) => Misc.data(rollData.competence)?.data?.niveau, + isUsed: (rollData, actor) => rollData.competence, + getLabel: (rollData, actor) => rollData.competence?.name, + getValue: (rollData, actor) => rollData.competence?.system.niveau, }, meditation: { isUsed: (rollData, actor) => rollData.meditation, @@ -33,7 +33,7 @@ export const referenceAjustements = { getLabel: (rollData, actor) => rollData.selectedSort?.name ?? rollData.attackerRoll ? 'Imposée' : 'Libre', getValue: (rollData, actor) => rollData.selectedSort ? RdDItemSort.getDifficulte(rollData.selectedSort, rollData.diffLibre) - : rollData.diffLibre ?? Misc.data(rollData.competence)?.data.default_diffLibre ?? 0 + : rollData.diffLibre ?? rollData.competence?.system.default_diffLibre ?? 0 }, diffConditions: { isUsed: (rollData, actor) => rollData.diffConditions != undefined, @@ -95,10 +95,10 @@ export const referenceAjustements = { getDescr: (rollData, actor) => rollData.diviseurSignificative > 1 ? `Facteur significative ×${Misc.getFractionHtml(rollData.diviseurSignificative)}` : '' }, isEcaille: { - isVisible: (rollData, actor) => Misc.data(rollData.arme)?.data.magique && Number(Misc.data(rollData.arme)?.data.ecaille_efficacite) > 0, - isUsed: (rollData, actor) => Misc.data(rollData.arme)?.data.magique && Number(Misc.data(rollData.arme)?.data.ecaille_efficacite) > 0, + isVisible: (rollData, actor) => rollData.arme?.data.magique && Number(rollData.arme?.data.ecaille_efficacite) > 0, + isUsed: (rollData, actor) => rollData.arme?.data.magique && Number(rollData.arme?.data.ecaille_efficacite) > 0, getLabel: (rollData, actor) => "Ecaille d'Efficacité: ", - getValue: (rollData, actor) => Math.max(Number(Misc.data(rollData.arme)?.data.ecaille_efficacite), 0), + getValue: (rollData, actor) => Math.max(Number(rollData.arme?.data.ecaille_efficacite), 0), }, finesse: { isUsed: (rollData, actor) => RdDBonus.isDefenseAttaqueFinesse(rollData), diff --git a/templates/dialog-roll-competence.html b/templates/dialog-roll-competence.html index 86d26d22..0e33f2a9 100644 --- a/templates/dialog-roll-competence.html +++ b/templates/dialog-roll-competence.html @@ -43,9 +43,9 @@ {{#if arme}} {{#unless attackerRoll}}