From 451ee677d24329b8bf4b51d73e05979091d00943 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sun, 12 Jun 2022 08:17:59 +0200 Subject: [PATCH] Big WIP... --- module/actor-creature-sheet.js | 4 +- module/actor-entite-sheet.js | 19 +- module/actor-sheet.js | 80 +-- module/actor-vehicule-sheet.js | 11 +- module/actor.js | 497 +++++++++--------- module/chat-utility.js | 27 +- module/dialog-create-signedraconique.js | 40 +- module/grammar.js | 4 + module/item-arme.js | 68 ++- module/item-competence.js | 42 +- module/item-competencecreature.js | 6 +- module/item-meditation.js | 2 +- module/item-monnaie.js | 6 +- module/item-sheet.js | 21 +- module/item-signedraconique-sheet.js | 25 +- module/item-signedraconique.js | 33 +- module/item-sort.js | 2 +- module/item.js | 71 ++- module/misc.js | 30 +- module/rdd-combat.js | 115 ++-- module/rdd-herbes.js | 4 +- module/rdd-main.js | 5 +- module/rdd-possession.js | 127 +++-- module/rdd-roll.js | 58 +- module/rdd-sheet-utility.js | 4 +- module/rdd-utility.js | 103 ++-- module/rolldata-ajustements.js | 14 +- module/tmr-utility.js | 23 +- module/tmr/effets-draconiques.js | 26 +- module/tmr/pixi-tmr.js | 2 +- templates/actor-creature-sheet.html | 11 +- templates/actor-entite-sheet.html | 8 +- templates/actor-sheet-competence-partial.html | 10 +- templates/actor-sheet-editor-notes-mj.html | 2 +- templates/actor-sheet.html | 257 ++++----- templates/actor-vehicule-sheet.html | 6 +- templates/chat-resultat-possession.html | 7 + templates/competence-carac-defaut.html | 1 + templates/dialog-create-signedraconique.html | 22 +- templates/dialog-roll-chant.html | 2 +- templates/dialog-roll-competence.html | 4 +- templates/dialog-roll-danse.html | 2 +- templates/dialog-roll-jeu.html | 4 +- templates/dialog-roll-maitrise-tmr.html | 2 +- templates/dialog-roll-meditation.html | 16 +- templates/dialog-roll-musique.html | 4 +- templates/dialog-roll-recettecuisine.html | 4 +- templates/dialog-roll-reve-de-dragon.html | 2 +- templates/dialog-roll-signedraconique.html | 3 +- templates/hud-actor-attaque.html | 4 +- templates/hud-actor-init.html | 2 +- templates/item-possession-sheet.html | 29 + templates/item-tache-sheet.html | 22 +- templates/partial-description-sort.html | 12 +- templates/partial-item-description.html | 4 +- templates/post-item.html | 2 +- 56 files changed, 990 insertions(+), 921 deletions(-) create mode 100644 templates/item-possession-sheet.html diff --git a/module/actor-creature-sheet.js b/module/actor-creature-sheet.js index 215731aa..dac64737 100644 --- a/module/actor-creature-sheet.js +++ b/module/actor-creature-sheet.js @@ -27,8 +27,8 @@ export class RdDActorCreatureSheet extends RdDActorSheet { /* -------------------------------------------- */ async getData() { - let formData = await super.getData(); - console.log("Creature : ", formData); + let formData = await super.getData() + //console.log("Creature : ", formData, formData.system) formData.calc = { caracTotal: RdDCarac.computeTotal(formData.data.carac), resumeBlessures: this.actor.computeResumeBlessure(formData.data.blessures), diff --git a/module/actor-entite-sheet.js b/module/actor-entite-sheet.js index 920c4ac5..26905d35 100644 --- a/module/actor-entite-sheet.js +++ b/module/actor-entite-sheet.js @@ -22,33 +22,26 @@ export class RdDActorEntiteSheet extends ActorSheet { }); } - /* -------------------------------------------- */ - _checkNull(items) { - if (items && items.length) { - return items; - } - return []; - } /* -------------------------------------------- */ async getData() { const objectData = Misc.data(this.object); let formData = { title: this.title, - id: this.object.id, - type: this.object.type, - img: this.object.img, - name: this.object.name, + id: objectData.id, + type: objectData.type, + img: objectData.img, + name: objectData.name, // actor: this.object, editable: this.isEditable, cssClass: this.isEditable ? "editable" : "locked", - data: foundry.utils.deepClone(Misc.templateData(this.object)), + data: foundry.utils.deepClone(this.actor.system), effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)), // items: items, limited: this.object.limited, options: this.options, owner: this.document.isOwner, - itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i))), + itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i.system))), }; formData.options.isGM = game.user.isGM; diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 4e6842d5..6b05672b 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -36,10 +36,9 @@ export class RdDActorSheet extends ActorSheet { /* -------------------------------------------- */ async getData() { - const objectData = Misc.data(this.object) - - //this.actor.checkMonnaiePresence(this.actor.data.items); // Always check - + const objectData = this.object.system + + console.log("New actor", objectData) let formData = { title: this.title, id: this.object.id, @@ -48,17 +47,16 @@ export class RdDActorSheet extends ActorSheet { name: this.object.name, editable: this.isEditable, cssClass: this.isEditable ? "editable" : "locked", - data: foundry.utils.deepClone(this.object.system), + data: foundry.utils.deepClone(this.actor.system), effects: this.object.effects.map(e => foundry.utils.deepClone(e.data)), limited: this.object.limited, options: this.options, owner: this.document.isOwner, itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i))), - }; - console.log("ACTOR DATA:", formData) - + } + console.log("BUILD",formData.itemsByType, this.object.items ) RdDUtility.filterItemsPerTypeForSheet(formData) - + formData.options.isGM = game.user.isGM; if (formData.type == 'creature') return formData; // Shortcut @@ -79,12 +77,11 @@ export class RdDActorSheet extends ActorSheet { }; formData.competences.forEach(item => { - console.log('Comp', item) - item.isVisible = this.options.cherchercompetence + item.system.visible = this.options.cherchercompetence ? RdDItemCompetence.nomContientTexte(item, this.options.cherchercompetence) : (!this.options.showCompNiveauBase || !RdDItemCompetence.isNiveauBase(item)); - RdDItemCompetence.levelUp(item, formData.data.compteurs.experience.value) - }) + RdDItemCompetence.levelUp(item, formData.data.compteurs.experience.value); + }); Object.values(formData.data.carac).forEach(c => { RdDCarac.levelUp(c); @@ -92,11 +89,11 @@ export class RdDActorSheet extends ActorSheet { // toujours avoir une liste d'armes (pour mettre esquive et corps à corps) - formData.combat = duplicate(formData.armes ?? []) - RdDItemArme.computeNiveauArmes(formData.combat, formData.competences) - /* TODO TODO RdDItemArme.ajoutCorpsACorps(formData.combat, formData.competences, formData.data.carac)*/ + formData.combat = duplicate(formData.armes ?? []); + RdDItemArme.computeNiveauArmes(formData.combat, formData.competences); + RdDItemArme.ajoutCorpsACorps(formData.combat, formData.competences, formData.data.carac); formData.esquives = this.actor.getCompetences("Esquive").map(i => foundry.utils.deepClone(i.system)) - formData.combat = RdDCombatManager.finalizeArmeList(formData.combat, formData.competences, formData.data.carac) + formData.combat = RdDCombatManager.finalizeArmeList(formData.combat, formData.competences, formData.data.carac); this.armesList = formData.combat; @@ -169,13 +166,14 @@ 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) + console.log("ITEM :", item) item.sheet.render(true) - }); + }) html.find('.display-label a').click(async event => { const item = RdDSheetUtility.getItem(event, this.actor); item.sheet.render(true); @@ -197,7 +195,7 @@ export class RdDActorSheet extends ActorSheet { }); html.find('.item-action').click(async event => { - const item = RdDSheetUtility.getItem(event, this.actor); + const item = RdDSheetUtility.getItem(event, this.actor) this.actor.actionItem(item); }); html.find('.subacteur-delete').click(async event => { @@ -207,8 +205,11 @@ export class RdDActorSheet extends ActorSheet { html.find('.encaisser-direct').click(async event => { this.actor.encaisser(); - }); - + }) + html.find('.sheet-possession-attack').click(async event => { + const poss = RdDSheetUtility.getItem(event, this.actor) + this.actor.conjurerPossession(poss) + }) html.find('.remise-a-neuf').click(async event => { if (game.user.isGM) { this.actor.remiseANeuf(); @@ -254,7 +255,7 @@ export class RdDActorSheet extends ActorSheet { // Equip Inventory Item html.find('.item-equip').click(async event => { - this.actor.equiperObjet(RdDSheetUtility.getItemId(event)) + this.actor.equiperObjet(RdDSheetUtility.getItemId(event)); }); // Roll Carac @@ -326,8 +327,8 @@ export class RdDActorSheet extends ActorSheet { // Roll Weapon1 html.find('.arme-label a').click(async event => { - let arme = this._getEventArmeCombat(event) - this.actor.rollArme(duplicate(arme)) + let arme = this._getEventArmeCombat(event); + this.actor.rollArme(duplicate(arme)); }); // Initiative pour l'arme html.find('.arme-initiative a').click(async event => { @@ -387,9 +388,9 @@ export class RdDActorSheet extends ActorSheet { this.actor.updateCarac(caracName, parseInt(event.target.value)); }); html.find('.carac-xp').change(async event => { - let caracName = event.currentTarget.name.replace(".xp", "").replace("system.carac.", "") - //console.log("Value changed :", event, caracName) - this.actor.updateCaracXP(caracName, parseInt(event.target.value)) + let caracName = event.currentTarget.name.replace(".xp", "").replace("data.carac.", ""); + //console.log("Value changed :", event, caracName); + this.actor.updateCaracXP(caracName, parseInt(event.target.value)); }); // On competence change html.find('.competence-value').change(async event => { @@ -513,17 +514,15 @@ export class RdDActorSheet extends ActorSheet { }); } - /* -------------------------------------------- */ _getEventArmeCombat(event) { - const li = $(event.currentTarget)?.parents(".item") - let armeName = li.data("arme-name") - let compName = li.data('competence-name') - console.log("Searching for", armeName, compName) - const arme = this.armesList.find(a => a.name == armeName && a.system.competence == compName) + const li = $(event.currentTarget)?.parents(".item"); + let armeName = li.data("arme-name"); + let compName = li.data('competence-name'); + const arme = this.armesList.find(a => a.name == armeName && a.data.competence == compName); if (!arme) { - return { name: armeName, data: { competence: compName } } + return { name: armeName, data: { competence: compName } }; } - return arme + return arme; } /* -------------------------------------------- */ @@ -552,9 +551,10 @@ export class RdDActorSheet extends ActorSheet { } async _onSplitItem(item, split) { - if (split >= 1 && split < item.system.quantite) { - await item.diminuerQuantite(split) - item.system.quantite = split; + if (split >= 1 && split < Misc.data(item).data.quantite) { + await item.diminuerQuantite(split); + const itemData = duplicate(Misc.data(item)); + itemData.data.quantite = split; await this.actor.createEmbeddedDocuments('Item', [itemData]) } } diff --git a/module/actor-vehicule-sheet.js b/module/actor-vehicule-sheet.js index 1d39f106..e6cf1fbc 100644 --- a/module/actor-vehicule-sheet.js +++ b/module/actor-vehicule-sheet.js @@ -25,14 +25,6 @@ export class RdDActorVehiculeSheet extends ActorSheet { }); } - /* -------------------------------------------- */ - _checkNull(items) { - if (items && items.length) { - return items; - } - return []; - } - /* -------------------------------------------- */ async getData() { const objectData = Misc.data(this.object); @@ -68,6 +60,9 @@ export class RdDActorVehiculeSheet extends ActorSheet { return formData; } + async computeMalusArmure() { + // pas de malus armure + } /* -------------------------------------------- */ async _onDropItem(event, dragData) { const destItemId = $(event.target)?.closest('.item').attr('data-item-id'); diff --git a/module/actor.js b/module/actor.js index 1927ffaf..ce4bea75 100644 --- a/module/actor.js +++ b/module/actor.js @@ -115,18 +115,17 @@ export class RdDActor extends Actor { return actor; } - const competences = await RdDUtility.loadCompendium(RdDItemCompetence.actorCompendium(actorData.type)); - actorData.items = competences.map(i => i.toObject()); + const competences = await RdDUtility.loadCompendium(RdDItemCompetence.actorCompendium(actorData.type)) + actorData.items = competences.map(i => i.toObject()) if (isPersonnage) { actorData.items = actorData.items.concat(Monnaie.monnaiesData()); } - return super.create(actorData, options); + return super.create(actorData, options) } /* -------------------------------------------- */ prepareData() { super.prepareData(); - const actorData = this.system // Dynamic computing fields this.encTotal = 0; @@ -141,9 +140,9 @@ export class RdDActor extends Actor { // Make separate methods for each Actor type (character, npc, etc.) to keep // things organized. - if (actorData.type === 'personnage') this._prepareCharacterData(actorData); - if (actorData.type === 'creature') this._prepareCreatureData(actorData); - if (actorData.type === 'vehicule') this._prepareVehiculeData(actorData); + if (this.type === 'personnage') this._prepareCharacterData(this) + if (this.type === 'creature') this._prepareCreatureData(this) + if (this.type === 'vehicule') this._prepareVehiculeData(this) } /* -------------------------------------------- */ @@ -173,7 +172,7 @@ export class RdDActor extends Actor { */ async _prepareCharacterData(actorData) { // Initialize empty items - RdDCarac.computeCarac(actorData.data); + RdDCarac.computeCarac(actorData.system) this.computeIsHautRevant(); await this.cleanupConteneurs(); await this.computeEncombrementTotalEtMalusArmure(); @@ -186,8 +185,8 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async cleanupConteneurs() { let updates = this.listItemsData('conteneur') - .filter(c => c.data.contenu.filter(id => this.getObjet(id) == undefined).length > 0) - .map(c => { return { _id: c._id, 'data.contenu': c.data.contenu.filter(id => this.getObjet(id) != undefined) } }); + .filter(c => c.system.contenu.filter(id => this.getObjet(id) == undefined).length > 0) + .map(c => { return { _id: c._id, 'data.contenu': c.system.contenu.filter(id => this.getObjet(id) != undefined) } }); if (updates.length > 0) { await this.updateEmbeddedDocuments("Item", updates) } @@ -213,12 +212,12 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ isHautRevant() { - return this.isPersonnage() && this.system.attributs.hautrevant.value != "" + return this.isPersonnage() && this.attributs.hautrevant.value != "" } /* -------------------------------------------- */ getFatigueActuelle() { if (ReglesOptionelles.isUsing("appliquer-fatigue") && this.isPersonnage()) { - return Misc.toInt(this.system.sante.fatigue?.value); + return this.system.sante.fatigue?.value; } return 0; } @@ -231,7 +230,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ getReveActuel() { - return Misc.toInt(this.system.reve?.reve?.value ?? this.system.carac.reve.value); + return Misc.toInt(this.system.reve?.reve?.value ?? this.carac.reve.value); } /* -------------------------------------------- */ getChanceActuel() { @@ -276,13 +275,12 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getEtatGeneral(options = { ethylisme: false }) { - const tplData = this.system - let etatGeneral = Misc.toInt(tplData.compteurs.etat?.value); + let etatGeneral = Misc.toInt(this.system.compteurs.etat?.value) if (options.ethylisme) { // Pour les jets d'Ethylisme, on ignore le degré d'éthylisme (p.162) - etatGeneral -= Math.min(0, tplData.compteurs.ethylisme.value); + etatGeneral -= Math.min(0, this.system.compteurs.ethylisme.value) } - return etatGeneral; + return etatGeneral } /* -------------------------------------------- */ getActivePoisons() { @@ -291,7 +289,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getMalusArmure() { - return Misc.toInt(this.system.attributs?.malusarmure?.value); + return Misc.toInt(this.system.attributs?.malusarmure?.value) } /* -------------------------------------------- */ @@ -301,16 +299,16 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getPrixTotalEquipement() { - return Math.floor(this.system.prixTotalEquipement ?? 0); + return Math.floor(this.system.prixTotalEquipement ?? 0) } /* -------------------------------------------- */ getCompetence(idOrName, options = {}) { - return RdDItemCompetence.findCompetence(this.items, idOrName, options); + return RdDItemCompetence.findCompetence(this.items, idOrName, options) } getCompetences(name) { - return RdDItemCompetence.findCompetences(this.items, name); + return RdDItemCompetence.findCompetences(this.items, name) } /* -------------------------------------------- */ @@ -322,10 +320,10 @@ export class RdDActor extends Actor { return this.filterItemsData(it => it.type == type); } filterItemsData(filter) { - return this.items.map(it => it).filter(filter) + return this.items.map( it => it).filter(filter) } filterItems(filter) { - return this.items.filter(it => filter(Misc.data(it))) + return this.items.filter(it => filter(it)) } getItemOfType(idOrName, type) { @@ -369,13 +367,12 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getBestDraconic() { const list = this.getDraconicList() - console.log("Draco", list) return duplicate(list[0]) } getDraconicOrZero() { - const list = this.getDraconicList().filter(it => Misc.data(it).data.niveau >= 0); + const list = this.getDraconicList().filter(it => it.system.niveau >= 0); if (list.length == 0) { - return { name: "Aucun", data: { niveau: 0 } }; + return { name: "Aucun", system: { niveau: 0 } }; } return duplicate(list[0]); } @@ -386,11 +383,11 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async verifierPotionsEnchantees() { - let potionsEnchantees = this.filterItemsData(it => it.type == 'potion' && it.data.categorie.toLowerCase().includes('enchant')); + let potionsEnchantees = this.filterItemsData(it => it.type == 'potion' && it.system.categorie.toLowerCase().includes('enchant')); for (let potion of potionsEnchantees) { - if (!potion.data.prpermanent) { + if (!potion.system.prpermanent) { console.log(potion); - let newPr = (potion.data.pr > 0) ? potion.data.pr - 1 : 0; + let newPr = (potion.system.pr > 0) ? potion.system.pr - 1 : 0; let update = { _id: potion._id, 'data.pr': newPr }; const updated = await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity @@ -471,7 +468,7 @@ export class RdDActor extends Actor { content: "" }; - const blessures = duplicate(this.system.blessures); + const blessures = duplicate(this.system.blessures) await this._recupererBlessures(message, "legere", blessures.legeres.liste.filter(b => b.active), []); await this._recupererBlessures(message, "grave", blessures.graves.liste.filter(b => b.active), blessures.legeres.liste); await this._recupererBlessures(message, "critique", blessures.critiques.liste.filter(b => b.active), blessures.graves.liste); @@ -556,7 +553,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _recupererVie(message) { - const tData = this.system + const tData = Misc.templateData(this); let blessures = [].concat(tData.blessures.legeres.liste).concat(tData.blessures.graves.liste).concat(tData.blessures.critiques.liste); let nbBlessures = blessures.filter(b => b.active); let vieManquante = tData.sante.vie.max - tData.sante.vie.value; @@ -583,7 +580,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _jetRecuperationConstitution(bonusSoins, message = undefined) { - const tData = this.system + const tData = Misc.templateData(this); let difficulte = Misc.toInt(bonusSoins) + Math.min(0, tData.sante.vie.value - tData.sante.vie.max); let rolled = await RdDResolutionTable.roll(tData.carac.constitution.value, difficulte); if (message) { @@ -671,7 +668,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _recupererEthylisme(message) { - let ethylisme = duplicate(this.system.compteurs.ethylisme); + let ethylisme = duplicate(Misc.templateData(this).compteurs.ethylisme); ethylisme.nb_doses = 0; ethylisme.jet_moral = false; if (ethylisme.value < 1) { @@ -685,7 +682,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async recupereEndurance(message) { - const manquant = this._computeEnduranceMax() - this.system.sante.endurance.value; + const manquant = this._computeEnduranceMax() - Misc.templateData(this).sante.endurance.value; if (manquant > 0) { await this.santeIncDec("endurance", manquant); message.content += "Vous récuperez " + manquant + " points d'endurance. "; @@ -695,7 +692,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async recupererFatigue(message) { if (ReglesOptionelles.isUsing("appliquer-fatigue")) { - let fatigue = this.system.sante.fatigue.value; + let fatigue = Misc.templateData(this).sante.fatigue.value; const fatigueMin = this._computeFatigueMin(); if (fatigue <= fatigueMin) { return; @@ -710,7 +707,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ _calculRecuperationSegment(actuel) { - const segments = RdDUtility.getSegmentsFatigue(this.system.sante.endurance.max); + const segments = RdDUtility.getSegmentsFatigue(Misc.templateData(this).sante.endurance.max); let cumul = 0; let i; for (i = 0; i < 11; i++) { @@ -730,7 +727,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async recuperationReve(message) { - const seuil = this.system.reve.seuil.value; + const seuil = Misc.templateData(this).reve.seuil.value; const reveActuel = this.getReveActuel(); if (reveActuel < seuil) { let deRecuperation = await RdDDice.rollTotal("1dr"); @@ -751,7 +748,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async retourSeuilDeReve(message) { - const seuil = this.system.reve.seuil.value; + const seuil = Misc.templateData(this).reve.seuil.value; const reveActuel = this.getReveActuel(); if (reveActuel > seuil) { message.content += `
Votre rêve redescend vers son seuil naturel (${seuil}, nouveau rêve actuel ${(reveActuel - 1)})`; @@ -760,7 +757,7 @@ export class RdDActor extends Actor { } async retourSust(message) { - const tplData = this.system + const tplData = Misc.templateData(this); const sustNeeded = tplData.attributs.sust.value; const sustConsomme = tplData.compteurs.sust.value; const eauConsomme = tplData.compteurs.eau.value; @@ -837,7 +834,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async sortMisEnReserve(rollData, sort) { - let reserve = duplicate(this.system.reve.reserve.list); + let reserve = duplicate(Misc.templateData(this).reve.reserve.list); reserve.push({ coord: rollData.tmr.coord, sort: sort, draconic: duplicate(rollData.competence) }); await this.update({ "data.reve.reserve.list": reserve }); this.currentTMR.updateTokens(); @@ -845,25 +842,23 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async updateCarac(caracName, caracValue) { - console.log("Carac change", caracName) if (caracName == "force") { if (Number(caracValue) > this.getTaille() + 4) { ui.notifications.warn("Votre FORCE doit être au maximum de TAILLE+4"); return; } } - const tplData = this.system if (caracName == "reve") { - if (caracValue > Misc.toInt(tplData.reve.seuil.value)) { + if (caracValue > Misc.toInt(this.system.reve.seuil.value)) { this.setPointsDeSeuil(caracValue); } } if (caracName == "chance") { - if (caracValue > Misc.toInt(tplData.compteurs.chance.value)) { + if (caracValue > Misc.toInt(this.system.compteurs.chance.value)) { this.setPointsDeChance(caracValue); } } - await this.update({ [`data.carac.${caracName}.value`]: caracValue }); + await this.update({ [`system.carac.${caracName}.value`]: caracValue }); } /* -------------------------------------------- */ @@ -881,7 +876,7 @@ export class RdDActor extends Actor { if (caracName == 'Taille') { return; } - let carac = RdDActor._findCaracByName(this.system.carac, caracName); + let carac = RdDActor._findCaracByName(Misc.templateData(this).carac, caracName); if (carac) { carac = duplicate(carac); let xp = Number(carac.xp); @@ -952,11 +947,11 @@ export class RdDActor extends Actor { if (competence) { const update = { _id: competence.id } if (fieldName == "niveau") - update['system.niveau'] = compValue; + update['data.niveau'] = compValue; else if (fieldName == "dommages") - update['system.dommages'] = compValue; + update['data.dommages'] = compValue; else - update['system.carac_value'] = compValue; + update['data.carac_value'] = compValue; await this.updateEmbeddedDocuments('Item', [update]); // updates one EmbeddedEntity } } @@ -1032,7 +1027,7 @@ export class RdDActor extends Actor { async updateExperienceLog(modeXP, valeurXP, raisonXP = 'Inconnue') { let d = new Date(); console.log(modeXP, valeurXP, raisonXP); - let expLog = duplicate(this.system.experiencelog); + let expLog = duplicate((Misc.templateData(this)).experiencelog); expLog.push({ mode: Misc.upperFirst(modeXP), valeur: valeurXP, raison: Misc.upperFirst(raisonXP), daterdd: game.system.rdd.calendrier.getDateFromIndex(), datereel: `${d.getDate()}/${d.getMonth() + 1}/${d.getFullYear()}` @@ -1049,7 +1044,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async addCompteurValue(fieldName, fieldValue, raison = 'Inconnue') { - let oldValue = this.system.compteurs[fieldName].value; + let oldValue = (Misc.templateData(this)).compteurs[fieldName].value; await this.update({ [`data.compteurs.${fieldName}.value`]: Number(oldValue) + Number(fieldValue) }); await this.addStressExperienceLog(fieldName, fieldValue, raison); } @@ -1083,7 +1078,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ _isConteneurContenu(item, conteneur) { if (item?.isConteneur()) { // Si c'est un conteneur, il faut vérifier qu'on ne le déplace pas vers un sous-conteneur lui appartenant - for (let id of item.system.contenu) { + for (let id of Misc.templateData(item).contenu) { let subObjet = this.getObjet(id); if (subObjet?.id == conteneur.id) { return true; // Loop detected ! @@ -1101,7 +1096,7 @@ export class RdDActor extends Actor { if (!objet) { return 0; } - const tplData = this.system + const tplData = Misc.templateData(objet); if (objet.type != 'conteneur') { return Number(tplData.encombrement) * Number(tplData.quantite); } @@ -1114,7 +1109,7 @@ export class RdDActor extends Actor { buildSubConteneurObjetList(conteneurId, deleteList) { let conteneur = this.getObjet(conteneurId); if (conteneur?.type == 'conteneur') { // Si c'est un conteneur - for (let subId of conteneur.system.contenu) { + for (let subId of Misc.templateData(conteneur).contenu) { let subObj = this.getObjet(subId); if (subObj) { if (subObj.type == 'conteneur') { @@ -1268,7 +1263,7 @@ export class RdDActor extends Actor { let newItemId = itemMap[item.id]; // Get newItem console.log('New conteneur filling!', newConteneur, newItemId, item); - let contenu = duplicate(newConteneur.system.contenu); + let contenu = duplicate(Misc.templateData(newConteneur).contenu); contenu.push(newItemId); await this.updateEmbeddedDocuments('Item', [{ _id: newConteneurId, 'data.contenu': contenu }]); } @@ -1303,6 +1298,7 @@ export class RdDActor extends Actor { return this.computeMalusSurEncombrement() <0 ? "Sur-Encombrement!" : ""; } + /* -------------------------------------------- */ getEncombrementMax() { switch (this.type){ case 'vehicule': @@ -1310,7 +1306,7 @@ export class RdDActor extends Actor { case 'entite': return 0; default: - return this.system.attributs.encombrement.value; + return this.system.attributs.encombrement.value } } @@ -1345,15 +1341,14 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async computeMalusArmure() { - let arm = this.filterItemsData(it => it.type == 'armure' && it.system.equipe) const newMalusArmure = this.filterItemsData(it => it.type == 'armure' && it.system.equipe) .map(it => it.system.malus ?? 0) - .reduce(Misc.sum(), 0) + .reduce(Misc.sum(), 0); // Mise à jour éventuelle du malus armure if (this.system.attributs?.malusarmure?.value != newMalusArmure) { - await this.updateAttributeValue("malusarmure", newMalusArmure) + await this.updateAttributeValue("malusarmure", newMalusArmure); } - return newMalusArmure + return newMalusArmure; } /* -------------------------------------------- */ @@ -1367,7 +1362,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ computeResumeBlessure(blessures = undefined) { - blessures = blessures ?? this.system.blessures + blessures = blessures ?? Misc.templateData(this).blessures; let nbLegeres = this.countBlessures(blessures.legeres.liste); let nbGraves = this.countBlessures(blessures.graves.liste); let nbCritiques = this.countBlessures(blessures.critiques.liste); @@ -1396,43 +1391,43 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ computeEtatGeneral() { - const tplData = this.system - // Pas d'état général pour les entités forçage à 0 - if (this.data.type == 'entite') { - tplData.compteurs.etat.value = 0; - return; + if (this.type == 'entite') { + this.compteurs.etat.value = 0; + return } // Pour les autres - let state = Math.min(tplData.sante.vie.value - tplData.sante.vie.max, 0); - if (ReglesOptionelles.isUsing("appliquer-fatigue") && tplData.sante.fatigue) { - state += RdDUtility.currentFatigueMalus(tplData.sante.fatigue.value, tplData.sante.endurance.max); + let sante = this.system.sante + let compteurs = this.system.compteurs + let state = Math.min(sante.vie.value - sante.vie.max, 0); + if (ReglesOptionelles.isUsing("appliquer-fatigue") && sante.fatigue) { + state += RdDUtility.currentFatigueMalus(sante.fatigue.value, sante.endurance.max); } // Ajout de l'éthylisme - state += Math.min(0, (tplData.compteurs.ethylisme?.value ?? 0)); + state += Math.min(0, (compteurs.ethylisme?.value ?? 0)); - tplData.compteurs.etat.value = state; - if (tplData.compteurs?.surenc) { - tplData.compteurs.surenc.value = this.computeMalusSurEncombrement(); + compteurs.etat.value = state; + if (compteurs?.surenc) { + compteurs.surenc.value = this.computeMalusSurEncombrement(); } } /* -------------------------------------------- */ async ajouterRefoulement(value = 1) { - let refoulement = this.system.reve.refoulement.value + value - let total = await RdDDice.rollTotal("1d20") + let refoulement = Misc.templateData(this).reve.refoulement.value + value; + let total = await RdDDice.rollTotal("1d20"); if (total <= refoulement) { refoulement = 0; await this.ajouterSouffle({ chat: true }); } - await this.update({ "data.reve.refoulement.value": refoulement }) + await this.update({ "data.reve.refoulement.value": refoulement }); return refoulement == 0 ? "souffle" : "none"; } /* -------------------------------------------- */ async ajouterSouffle(options = { chat: false }) { - let souffle = Misc.data(await RdDRollTables.getSouffle()) - souffle._id = undefined;//TBC + let souffle = Misc.data(await RdDRollTables.getSouffle()); + souffle._id = undefined; //TBC await this.createEmbeddedDocuments('Item', [souffle]); if (options.chat) { ChatMessage.create({ @@ -1445,15 +1440,15 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async ajouterQueue(options = { chat: false }) { - let queue - if (this.system.reve.reve.thanatosused) { - queue = Misc.data(await RdDRollTables.getOmbre()) - await this.update({ "data.reve.reve.thanatosused": false }) + let queue; + if (Misc.data(this).data.reve.reve.thanatosused) { + queue = Misc.data(await RdDRollTables.getOmbre()); + await this.update({ "data.reve.reve.thanatosused": false }); } else { - queue = Misc.data(await RdDRollTables.getQueue()) + queue = Misc.data(await RdDRollTables.getQueue()); } - await this.createEmbeddedDocuments('Item', [queue]) + await this.createEmbeddedDocuments('Item', [queue]); if (options.chat) { ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), @@ -1471,7 +1466,7 @@ export class RdDActor extends Actor { await this.update({ 'data.reve.tmrpos.cache': false }); } isTMRCache() { - return this.system.reve.tmrpos.cache + return this.system.reve.tmrpos.cache; } /* -------------------------------------------- */ async cacheTMRetMessage() { @@ -1479,8 +1474,8 @@ export class RdDActor extends Actor { await this.cacheTMR(); game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_tmr_move", data: { - actorId: this.data._id, - tmrPos: this.data.data.reve.tmrpos + actorId: this._id, + tmrPos: this.system.data.reve.tmrpos } }); } @@ -1490,7 +1485,7 @@ export class RdDActor extends Actor { await this.montreTMR(); game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_tmr_move", data: { - actorId: this.id, + actorId: this._id, tmrPos: this.system.reve.tmrpos } }); @@ -1513,12 +1508,12 @@ export class RdDActor extends Actor { buildTMRInnaccessible() { const tmrInnaccessibles = this.filterItemsData(it => Draconique.isCaseTMR(it) && EffetsDraconiques.isInnaccessible(it)); - return tmrInnaccessibles.map(it => it.system.coord); + return tmrInnaccessibles.map(it => it.data.coord); } /* -------------------------------------------- */ getTMRRencontres() { - return this.system.reve.rencontre.list; + return Misc.templateData(this).reve.rencontre.list; } /* -------------------------------------------- */ @@ -1548,19 +1543,19 @@ export class RdDActor extends Actor { if (i != rencontreKey) newList.push(list[i]); } - await this.update({ "data.reve.rencontre.list": newList }); + await this.update({ "system.reve.rencontre.list": newList }); } /* -------------------------------------------- */ async updateCoordTMR(coord) { //console.log("UPDATE TMR", coord); - await this.update({ "data.reve.tmrpos.coord": coord }); + await this.update({ "system.reve.tmrpos.coord": coord }); } /* -------------------------------------------- */ async reveActuelIncDec(value) { let reve = Math.max(this.system.reve.reve.value + value, 0); - await this.update({ "data.reve.reve.value": reve }); + await this.update({ "system.reve.reve.value": reve }); } /* -------------------------------------------- */ @@ -1574,12 +1569,12 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async setPointsDeSeuil(seuil) { - await this.update({ "data.reve.seuil.value": seuil }) + await this.update({ "system.reve.seuil.value": seuil }); } /* -------------------------------------------- */ async setPointsDeChance(chance) { - await this.updateCompteurValue("chance", chance) + await this.updateCompteurValue("chance", chance); } /* -------------------------------------------- */ @@ -1626,12 +1621,12 @@ export class RdDActor extends Actor { if (this.isEntiteCauchemar()) { return 0; } - return RdDCarac.calculSConst(this.system.carac.constitution.value); + return RdDCarac.calculSConst(this.system.carac.constitution.value) } async ajoutXpConstitution(xp) { - await this.update({ "data.carac.constitution.xp": Misc.toInt(this.system.carac.constitution.xp) + xp }); + await this.update({ "system.carac.constitution.xp": Misc.toInt(this.system.carac.constitution.xp) + xp }); } /* -------------------------------------------- */ @@ -1724,7 +1719,7 @@ export class RdDActor extends Actor { if (name == 'fatigue' && !ReglesOptionelles.isUsing("appliquer-fatigue")) { return; } - const sante = duplicate(this.system.sante); + const sante = duplicate(this.system.sante) let compteur = sante[name]; if (!compteur) { return; @@ -1767,7 +1762,7 @@ export class RdDActor extends Actor { if (ReglesOptionelles.isUsing("appliquer-fatigue") && sante.fatigue && fatigue > 0) { sante.fatigue.value = Math.max(sante.fatigue.value + fatigue, this._computeFatigueMin()); } - await this.update({ "data.sante": sante }); + await this.update({ "system.sante": sante }) if (this.isDead()) { await this.setStatusEffect("EFFECT.StatusComma", true); } @@ -1894,7 +1889,7 @@ export class RdDActor extends Actor { vie: this.system.sante.vie.max, forceAlcool: 0, etat: this.getEtatGeneral({ ethylisme: true }), - diffNbDoses: -Number(this.system.data.compteurs.ethylisme.nb_doses || 0), + diffNbDoses: -Number(this.system.compteurs.ethylisme.nb_doses || 0), finalLevel: 0, diffConditions: 0, ajustementsForce: CONFIG.RDD.difficultesLibres, @@ -1906,7 +1901,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async actionItem(item, onActionItem = async ()=>{}) { if (!item.getActionPrincipale()) return; - switch (Misc.data(item).type) { + switch (item.type) { case 'nourritureboisson': return await this.actionNourritureboisson(item, onActionItem); case 'potion': return await this.consommerPotion(item, onActionItem); case 'livre': return await this.actionLire(item); @@ -1934,7 +1929,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async consommer(item, choix) { - switch (Misc.data(item).type) { + switch (item.type) { case 'nourritureboisson': return await this.consommerNourritureboisson(item, choix); case 'potion': @@ -1944,11 +1939,10 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async consommerNourritureboisson(item, choix = { doses: 1, seForcer: false, supprimerSiZero: false }) { - const itemData = Misc.data(item); if (itemData.type != 'nourritureboisson') { return; } - if (choix.doses > itemData.data.quantite) { + if (choix.doses > itemData.system.quantite) { ui.notifications.warn(`Il n'y a pas assez de ${itemData.name} pour manger ${choix.doses}`) return; } @@ -1964,7 +1958,7 @@ export class RdDActor extends Actor { async _apprecierCuisine(itemData, seForcer) { const surmonteExotisme = await this._surmonterExotisme(itemData, seForcer); if (surmonteExotisme) { - await this.apprecier('gout', 'cuisine', itemData.data.qualite, itemData.data.boisson ? "apprécie la boisson" : "apprécie le plat"); + await this.apprecier('gout', 'cuisine', itemData.system.qualite, itemData.system.boisson ? "apprécie la boisson" : "apprécie le plat"); } else if (seForcer) { await this.jetDeMoral('malheureux'); @@ -1977,7 +1971,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _surmonterExotisme(itemData) { - const exotisme = Math.min(itemData.data.exotisme, itemData.data.qualite, 0); + const exotisme = Math.min(itemData.system.exotisme, itemData.system.qualite, 0); if (exotisme < 0) { const rolled = await this.rollCaracCompetence('volonte', 'cuisine', exotisme, { title: `tente de surmonter l'exotisme de ${itemData.name}` }); return rolled.isSuccess; @@ -1995,7 +1989,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async manger(item, doses, options = { diminuerQuantite: true }) { - const sust = this.system.sust; + const sust = item.system.sust if (sust > 0) { await this.updateCompteurValue('sust', Misc.keepDecimals(this.system.compteurs.sust.value + sust * doses, 1)); } @@ -2024,15 +2018,15 @@ export class RdDActor extends Actor { const etat = this.getEtatGeneral({ ethylisme: true }); const nbDoses = Number(this.system.compteurs.ethylisme.nb_doses || 0); const ethylismeData = { - alias: actorData.name, - actor: actorData, + alias: this.name, + actor: this, vie: this.system.sante.vie.max, alcool: Misc.data(alcool), jetVie: { forceAlcool: forceAlcool, nbDoses: nbDoses, selectedCarac: this.system.sante.vie, - carac: actorData.data.carac, + carac: this.system.carac, caracValue: this.system.sante.vie.max, finalLevel: etat + forceAlcool - nbDoses }, @@ -2079,7 +2073,7 @@ export class RdDActor extends Actor { ethylismeData.nomEthylisme = RdDUtility.getNomEthylisme(ethylisme.value); ethylismeData.doses = ethylisme.nb_doses; - await this.update({ 'data.compteurs.ethylisme': ethylisme }); + await this.update({ 'system.compteurs.ethylisme': ethylisme }); await RdDResolutionTable.displayRollData(ethylismeData, this, 'chat-resultat-ethylisme.html'); } @@ -2128,7 +2122,7 @@ export class RdDActor extends Actor { compteurs.experience.value += stressRollData.xp; compteurs.dissolution.value = dissolution - perteDissolution; compteurs.exaltation.value = 0; - await this.update({ "data.compteurs": compteurs }); + await this.update({ "system.compteurs": compteurs }); this.updateExperienceLog('XP', stressRollData.xp, "Transformation du stress"); } @@ -2179,7 +2173,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async checkCaracXP(caracName, display = true) { - let carac = RdDActor._findCaracByName(this.system.carac, caracName); + let carac = RdDActor._findCaracByName(Misc.templateData(this).carac, caracName); if (carac && carac.xp > 0) { const niveauSuivant = Number(carac.value) + 1; let xpNeeded = RdDCarac.getCaracNextXp(niveauSuivant); @@ -2206,24 +2200,24 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async checkCompetenceXP(compName, newXP, display = true) { - let compData = this.getCompetence(compName) + let compData = Misc.data(this.getCompetence(compName)); if (compData && newXP && newXP == compData.data.xp) { // Si édition, mais sans changement XP - return + return; } - newXP = (newXP) ? newXP : compData.system.xp + newXP = (newXP) ? newXP : compData.data.xp; if (compData && newXP > 0) { - let xpNeeded = RdDItemCompetence.getCompetenceNextXp(compData.system.niveau + 1); + let xpNeeded = RdDItemCompetence.getCompetenceNextXp(compData.data.niveau + 1); if (newXP >= xpNeeded) { - let newCompData = duplicate(compData) - newCompData.system.niveau += 1; - newCompData.system.xp = newXP; + let newCompData = duplicate(compData); + newCompData.data.niveau += 1; + newCompData.data.xp = newXP; let checkXp = { alias: this.name, competence: newCompData.name, - niveau: newCompData.system.niveau, - xp: newCompData.system.xp, - archetype: newCompData.system.niveau_archetype, - archetypeWarning: newCompData.system.niveau > compData.system.niveau_archetype + niveau: newCompData.data.niveau, + xp: newCompData.data.xp, + archetype: newCompData.data.niveau_archetype, + archetypeWarning: newCompData.data.niveau > compData.data.niveau_archetype } if (display) { ChatMessage.create({ @@ -2330,7 +2324,8 @@ export class RdDActor extends Actor { if (this.currentTMR) this.currentTMR.minimize(); // Hide let draconicList = this.computeDraconicAndSortIndex(sortList); - const reve = duplicate(this.system.carac.reve); + const actorData = Misc.data(this); + const reve = duplicate(actorData.data.carac.reve); let rollData = { carac: { 'reve': reve }, forceCarac: { 'reve': reve }, @@ -2395,8 +2390,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async checkSoufflePeage(tmr) { - let peage = this.items.find(item => EffetsDraconiques.isPeage(item)); - if (peage && (tmr.type == 'pont' || tmr.type == 'cite')) { + if ((tmr.type == 'pont' || tmr.type == 'cite') && EffetsDraconiques.isPeage(actor)) { await this.reveActuelIncDec(-1); ChatMessage.create({ content: "Vous êtes sous le coup d'un Péage : l'entrée sur cette case vous a coûté 1 Point de Rêve (déduit automatiquement).", @@ -2417,7 +2411,7 @@ export class RdDActor extends Actor { if (rollData.competence.name.includes('Thanatos')) { // Si Thanatos await this.update({ "data.reve.reve.thanatosused": true }); } - let reveActuel = this.system.reve.reve.value; + let reveActuel = Misc.templateData(this).reve.reve.value; if (rolled.isSuccess) { // Réussite du sort ! if (rolled.isPart) { rollData.depenseReve = Math.max(Math.floor(rollData.depenseReve / 2), 1); @@ -2528,22 +2522,22 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async rollCompetence(idOrName) { - let comp = this.getCompetence(idOrName) - let rollData = { competence: comp } + let rollData = { competence: Misc.data(this.getCompetence(idOrName)) } - //console.log("COMP CREATURE", name, rollData, name); if (rollData.competence.type == 'competencecreature') { - if (rollData.competence.system.iscombat) { - const arme = RdDItemCompetenceCreature.toArme(rollData.competence); - RdDCombat.createUsingTarget(this).attaque(rollData.competence, arme); - return; + if (rollData.competence.data.iscombat) { + if (rollData.competence.data.ispossession) { + RdDPossession.managePossession(this, rollData.competence) + } else { + const arme = RdDItemCompetenceCreature.toArme(rollData.competence) + RdDCombat.createUsingTarget(this)?.attaque(competence, arme) + } + return } - //console.log("COMP CREATURE2"); // Fake competence pour créature - RdDItemCompetenceCreature.setRollDataCreature(rollData); - } - else { - rollData.carac = this.system.carac; + RdDItemCompetenceCreature.setRollDataCreature(rollData) + } else { + rollData.carac = this.system.carac } console.log("rollCompetence !!!", rollData); @@ -2555,8 +2549,14 @@ export class RdDActor extends Actor { this.createCallbackAppelAuMoral(), { action: r => this._competenceResult(r) } ] - }) - dialog.render(true) + }); + dialog.render(true); + } + + /* -------------------------------------------- */ + conjurerPossession(possession) { + let draconic = this.getBestDraconic() + RdDPossession.managePossession(this, draconic, possession) } /* -------------------------------------------- */ @@ -2592,19 +2592,20 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async rollTache(id) { - const tacheData = this.getTache(id) - const compData = this.getCompetence(tacheData.system.competence) - compData.system.defaut_carac = tacheData.system.carac // Patch ! + const actorData = Misc.data(this); + const tacheData = Misc.data(this.getTache(id)) + const compData = Misc.data(this.getCompetence(tacheData.data.competence)) + compData.data.defaut_carac = tacheData.data.carac; // Patch ! let rollData = { competence: compData, tache: tacheData, - diffLibre: tacheData.system.difficulte, + diffLibre: tacheData.data.difficulte, diffConditions: 0, use: { libre: false, conditions: true }, carac: {} }; - rollData.carac[tacheData.system.carac] = duplicate(this.system.carac[tacheData.system.carac]); // Single carac + rollData.carac[tacheData.data.carac] = duplicate(actorData.data.carac[tacheData.data.carac]); // Single carac console.log("rollTache !!!", rollData); @@ -2617,29 +2618,29 @@ export class RdDActor extends Actor { { action: r => this._tacheResult(r) } ] }); - dialog.render(true) + dialog.render(true); } /* -------------------------------------------- */ async _tacheResult(rollData) { // Mise à jour de la tache - rollData.appliquerFatigue = ReglesOptionelles.isUsing("appliquer-fatigue") - rollData.tache = duplicate(rollData.tache) - rollData.tache.system.points_de_tache_courant += rollData.rolled.ptTache + rollData.appliquerFatigue = ReglesOptionelles.isUsing("appliquer-fatigue"); + rollData.tache = duplicate(rollData.tache); + rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache; if (rollData.rolled.isETotal) { - rollData.tache.system.difficulte-- + rollData.tache.data.difficulte--; } if (rollData.rolled.isSuccess) { - rollData.tache.system.nb_jet_succes++ + rollData.tache.data.nb_jet_succes++; } else { - rollData.tache.system.nb_jet_echec++ + rollData.tache.data.nb_jet_echec++; } - rollData.tache.system.tentatives = rollData.tache.system.nb_jet_succes + rollData.tache.system.nb_jet_echec + rollData.tache.data.tentatives = rollData.tache.data.nb_jet_succes + rollData.tache.data.nb_jet_echec; - this.updateEmbeddedDocuments('Item', [rollData.tache]) - this.santeIncDec("fatigue", rollData.tache.system.fatigue) + this.updateEmbeddedDocuments('Item', [rollData.tache]); + this.santeIncDec("fatigue", rollData.tache.data.fatigue); - await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-tache.html') + await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-tache.html'); } /* -------------------------------------------- */ @@ -2648,19 +2649,18 @@ export class RdDActor extends Actor { { oeuvre: oeuvre, art: oeuvre.type, - competence: duplicate( this.getCompetence(artData.compName ?? oeuvre.system.competence ?? artData.art)), + competence: duplicate(this.getCompetence(artData.compName ?? oeuvre.system.competence ?? artData.art)), diffLibre: - (oeuvre.system.niveau ?? 0), diffConditions: 0, use: { libre: false, conditions: true }, selectedCarac: duplicate(this.system.carac[selected]) }, { overwrite: false }); - artData.competence.system.defaut_carac = selected + artData.competence.system.defaut_carac = selected; if (!artData.forceCarac) { artData.forceCarac = {}; artData.forceCarac[selected] = duplicate(this.system.carac[selected]); } - console.log("rollArt !!!", artData); const dialog = await RdDRoll.create(this, artData, @@ -2713,20 +2713,20 @@ export class RdDActor extends Actor { _getCaracDanse(oeuvre) { if (oeuvre.system.agilite) { return "agilite"; } else if (oeuvre.system.apparence) { return "apparence"; } - const compData = Misc.data(this.getCompetence(oeuvre.system.competence)); - return compData.data.defaut_carac; + const compData = this.getCompetence(oeuvre.data.competence); + return compData.system.defaut_carac; } /* -------------------------------------------- */ async rollMusique(id) { const artData = { art: 'musique', verbe: 'Jouer' }; - const oeuvre = Misc.data(this.getItemOfType(id, artData.art)); + const oeuvre = this.getItemOfType(id, artData.art); await this._rollArt(artData, "ouie", oeuvre); } /* -------------------------------------------- */ async rollRecetteCuisine(id) { - const oeuvre = Misc.data(this.getRecetteCuisine(id)); + const oeuvre = this.getRecetteCuisine(id); const artData = { verbe: 'Cuisiner', compName: 'cuisine', @@ -2767,14 +2767,14 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async rollJeu(id) { - const oeuvre = Misc.data(this.getJeu(id)); + const oeuvre = this.getJeu(id); const listCarac = oeuvre.system.caraccomp.toLowerCase().split(/[.,:\/-]/).map(it => it.trim()); const carac = listCarac.length > 0 ? listCarac[0] : 'chance' const artData = { art: 'jeu', verbe: 'Jeu', use: { libre: true, conditions: true, }, - competence: duplicate(Misc.data(this.getCompetence('jeu'))), + competence: duplicate(this.getCompetence('jeu')), forceCarac: {} }; listCarac.forEach(c => artData.forceCarac[c] = this.system.carac[c]); @@ -2784,15 +2784,15 @@ export class RdDActor extends Actor { } async rollOeuvre(id) { - const artData = { art: 'oeuvre', verbe: 'Interpréter' }; - const oeuvre = duplicate(this.getItemOfType(id, artData.art)); - await this._rollArt(artData, oeuvre.system.default_carac, oeuvre); + const artData = { art: 'oeuvre', verbe: 'Interpréter' } + const oeuvre = duplicate(this.getItemOfType(id, artData.art)) + await this._rollArt(artData, oeuvre.system.default_carac, oeuvre) } /* -------------------------------------------- */ async rollMeditation(id) { - const meditation = duplicate(Misc.data(this.getMeditation(id))); - const competence = duplicate(Misc.data(this.getCompetence(meditation.system.competence))); + const meditation = duplicate(this.getMeditation(id)); + const competence = duplicate(this.getCompetence(meditation.system.competence)); competence.system.defaut_carac = "intellect"; // Meditation = toujours avec intellect let meditationData = { competence: competence, @@ -2821,27 +2821,26 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async _meditationResult(meditationData) { + async _meditationResult(meditationRoll) { this.santeIncDec("fatigue", 2); - const signeData = RdDItemSigneDraconique.prepareSigneDraconiqueMeditation(meditationData.meditation, meditationData.rolled) - if (signeData) { - await this.createEmbeddedDocuments("Item", [signeData]); + if (meditationRoll.rolled.isSuccess) { + await this.createEmbeddedDocuments("Item", [RdDItemSigneDraconique.prepareSigneDraconiqueMeditation(meditationRoll.meditation, meditationRoll.rolled)]); } - await RdDResolutionTable.displayRollData(meditationData, this.name, 'chat-resultat-meditation.html'); + await RdDResolutionTable.displayRollData(meditationRoll, this.name, 'chat-resultat-meditation.html'); } /* -------------------------------------------- */ - _meditationEPart(meditationData) { - this.updateEmbeddedDocuments('Item', [{ _id: meditationData._id, 'data.malus': meditationData.meditation.data.malus - 1 }]); + _meditationEPart(meditationRoll) { + this.updateEmbeddedDocuments('Item', [{ _id: meditationRoll.meditation._id, 'data.malus': meditationRoll.meditation.data.malus - 1 }]); } /* -------------------------------------------- */ _getSignesDraconiques(coord) { const type = TMRUtility.getTMRType(coord); - return this.listItemsData("signedraconique").filter(it => it.system.typesTMR.includes(type)); + return this.listItemsData("signedraconique").filter(it => it.data.typesTMR.includes(type)); } /* -------------------------------------------- */ @@ -2864,7 +2863,7 @@ export class RdDActor extends Actor { let draconicList = this.getDraconicList() .map(draconic => duplicate(Misc.data(draconic))) - .map(draconic => { draconic.data.defaut_carac = "intellect"; return draconic; }); + .map(draconic => { draconic.system.defaut_carac = "intellect"; return draconic; }); const intellect = this.system.carac.intellect; let rollData = { @@ -2875,7 +2874,7 @@ export class RdDActor extends Actor { signe: signes[0], signes: signes, tmr: TMRUtility.getTMR(coord), - diffLibre: Misc.data(signes[0]).data.difficulte, + diffLibre: signes[0].system.difficulte, } const dialog = await RdDRoll.create(this, rollData, @@ -2905,7 +2904,7 @@ export class RdDActor extends Actor { } rollData.xpSort = RdDItemSigneDraconique.getXpSortSigneDraconique(rollData.rolled.code, rollData.signe); if (rollData.xpSort > 0) { - await this.updateEmbeddedDocuments("Item", [{ _id: compData._id, 'data.xp_sort': Misc.toInt(compData.data.xp_sort) + rollData.xpSort }]); + await this.updateEmbeddedDocuments("Item", [{ _id: compData._id, 'data.xp_sort': Misc.toInt(compData.system.xp_sort) + rollData.xpSort }]); await this.updateExperienceLog("XP Sort", rollData.xpSort, "Signe draconique en " + rollData.competence.name); } await this.deleteEmbeddedDocuments("Item", [rollData.signe._id]); @@ -2969,8 +2968,7 @@ export class RdDActor extends Actor { if (this.isCreature()) { return 0; } - const actorData = Misc.data(this); - return actorData.data.heure; + return this.system.heure; } /* -------------------------------------------- */ @@ -2979,7 +2977,7 @@ export class RdDActor extends Actor { return 0; } // selon l'heure de naissance... - return game.system.rdd.calendrier.getAjustementAstrologique(this.system.heure, this.name); + return game.system.rdd.calendrier.getAjustementAstrologique(this.system.heure, this.name) } /* -------------------------------------------- */ checkDesirLancinant() { @@ -3025,7 +3023,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _xpCompetence(xpData) { if (xpData.competence) { - const newXp = Misc.toInt(xpData.competence.data.xp) + xpData.xpCompetence; + const newXp = Misc.toInt(xpData.competence.system.xp) + xpData.xpCompetence; let update = { _id: xpData.competence._id, 'data.xp': newXp }; await this.updateEmbeddedDocuments('Item', [update]); xpData.checkComp = await this.checkCompetenceXP(xpData.competence.name, undefined, false); @@ -3059,7 +3057,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async ajouteNombreAstral(data) { // Gestion expérience (si existante) - data.competence = Misc.data(this.getCompetence("astrologie")); + data.competence = this.getCompetence("astrologie") data.selectedCarac = this.system.carac["vue"]; this.appliquerAjoutExperience(data, false); @@ -3187,16 +3185,15 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ rollArme(arme) { - let itemData = arme.system && arme.system || arme.data - let competence = this.getCompetence( itemData.competence ) + let competence = Misc.data(this.getCompetence(arme.system.competence)); if (arme || (competence.type == 'competencecreature' && competence.system.iscombat)) { if (competence.system.ispossession) { - RdDPossession.managePosession(this, competence) + RdDPossession.managePossession(this, competence); } else { - RdDCombat.createUsingTarget(this)?.attaque(competence, arme) + RdDCombat.createUsingTarget(this)?.attaque(competence, arme); } } else { - this.rollCompetence(competence.name) + this.rollCompetence(competence.name); } } @@ -3228,15 +3225,16 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async equiperObjet(itemID) { - let item = this.getEmbeddedDocument('Item', itemID) - if (item.system) { - const isEquipe = !item.system.equipe + let item = this.getEmbeddedDocument('Item', itemID); + let itemData = Misc.data(item); + if (itemData?.data) { + const isEquipe = !itemData.data.equipe; let update = { _id: item.id, "data.equipe": isEquipe }; await this.updateEmbeddedDocuments('Item', [update]); this.computeEncombrementTotalEtMalusArmure(); // Mise à jour encombrement this.computePrixTotalEquipement(); // Mis à jour du prix total de l'équipement if (isEquipe) - this.verifierForceMin(item) + this.verifierForceMin(itemData); } } @@ -3258,11 +3256,11 @@ export class RdDActor extends Actor { protection = Math.max(protection - penetration, 0); protection += this.getProtectionNaturelle(); // Gestion des cas particuliers sur la fenêtre d'encaissement - if (attackerRoll.dmg.encaisserSpecial && attackerRoll.dmg.encaisserSpecial == "noarmure") { + if (attackerRoll.dmg.encaisserSpecial == "noarmure") { protection = 0; } - if (attackerRoll.dmg.encaisserSpecial && attackerRoll.dmg.encaisserSpecial == "chute" && Number(protection) > 2) { - protection = 2; + if (attackerRoll.dmg.encaisserSpecial == "chute") { + protection = Math.min(protection, 2); } console.log("Final protect", protection, attackerRoll); return protection; @@ -3270,20 +3268,25 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ _deteriorerArmure(item, dmg) { - if (!ReglesOptionelles.isUsing('deteriorationArmure')) { + let itemData = duplicate(Misc.data(item)); + if (!ReglesOptionelles.isUsing('deteriorationArmure') || itemData.data.protection == '0') { return; } - let itemData = duplicate(Misc.data(item)); itemData.data.deterioration = (itemData.data.deterioration ?? 0) + dmg; if (itemData.data.deterioration >= 10) { - itemData.data.deterioration = 0; - let res = /\d+/.exec(itemData.data.protection); - if (!res) { - itemData.data.protection = "1d" + itemData.data.protection; + itemData.data.deterioration -= 10; + let res = /(\d+)?d(\d+)(\-\d+)?/.exec(itemData.data.protection); + if (res) { + let malus = Misc.toInt(res[3]) - 1; + let armure = Misc.toInt(res[2]); + if (armure+malus <= 0){ + itemData.data.protection = 0; + } else { + itemData.data.protection = '' + (res[1]??'1') + 'd' + armure + malus; + } } - else if (res = /(\d+d\d+)(\-\d+)?/.exec(itemData.data.protection)) { - let malus = Misc.toInt(res[2]) - 1; - itemData.data.protection = res[1] + malus; + else if (/\d+/.exec(itemData.data.protection)) { + itemData.data.protection = "1d" + itemData.data.protection; } else { ui.notifications.warn(`La valeur d'armure de votre ${item.name} est incorrecte`); @@ -3308,7 +3311,7 @@ export class RdDActor extends Actor { console.log("encaisserDommages", rollData) - let santeOrig = duplicate(this.system.sante); + let santeOrig = duplicate(Misc.templateData(this).sante); let encaissement = await this.jetEncaissement(rollData); this.ajouterBlessure(encaissement); // Will upate the result table @@ -3319,10 +3322,11 @@ export class RdDActor extends Actor { this.computeEtatGeneral(); + const actorData = Misc.data(this); mergeObject(encaissement, { alias: this.name, hasPlayerOwner: this.hasPlayerOwner, - resteEndurance: this.system.sante.endurance.value, + resteEndurance: actorData.data.sante.endurance.value, sonne: perteEndurance.sonne, jetEndurance: perteEndurance.jetEndurance, endurance: santeOrig.endurance.value - perteEndurance.newValue, @@ -3406,11 +3410,12 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ ajouterBlessure(encaissement) { + const actorData = Misc.data(this); if (actorData.type == 'entite') return; // Une entité n'a pas de blessures if (encaissement.legeres + encaissement.graves + encaissement.critiques == 0) return; - const endActuelle = Number(this.system.sante.endurance.value); - let blessures = duplicate(this.system.blessures); + const endActuelle = Number(actorData.data.sante.endurance.value); + let blessures = duplicate(actorData.data.blessures); let count = encaissement.legeres; // Manage blessures @@ -3519,7 +3524,7 @@ export class RdDActor extends Actor { || entite.isEntiteCauchemarAccordee(this)) { return true; } - const tplData = this.system; + const tplData = Misc.templateData(this); let rolled = await RdDResolutionTable.roll(this.getReveActuel(), - Number(Misc.templateData(entite).carac.niveau.value)); const rollData = { alias: this.name, @@ -3541,7 +3546,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ isEntiteCauchemar() { - return this.data.type == 'entite'; + return this.type == 'entite'; } /* -------------------------------------------- */ @@ -3557,7 +3562,7 @@ export class RdDActor extends Actor { ui.notifications.error("Impossible de s'accorder à " + this.name + ": ce n'est pas une entite de cauchemer/rêve"); return; } - let resonnance = duplicate(this.system.sante.resonnance); + let resonnance = duplicate(Misc.templateData(this).sante.resonnance); if (resonnance.actors.find(it => it == attaquant._id)) { // déjà accordé return; @@ -3569,10 +3574,10 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getFortune() { - let monnaies = Monnaie.filtrerMonnaies(this.items); + let monnaies = Monnaie.filtrerMonnaies(this.data.items); if (monnaies.length < 4) { ui.notifications.error("Problème de monnaies manquantes, impossible de payer correctement!") - return 0; + throw "Problème de monnaies manquantes, impossible de payer correctement!"; } return monnaies.map(m => Misc.templateData(m)) .map(tpl => tpl.valeur_deniers * Number(tpl.quantite)) @@ -3581,7 +3586,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async optimizeArgent(fortuneTotale) { - let monnaies = Monnaie.filtrerMonnaies(this.items); + let monnaies = Monnaie.filtrerMonnaies(this.data.items); let parValeur = Misc.classifyFirst(monnaies, it => Misc.templateData(it).valeur_deniers); let nouvelleFortune = { 1000: Math.floor(fortuneTotale / 1000), // or @@ -3726,7 +3731,7 @@ export class RdDActor extends Actor { vendeur.ajouterDeniers(coutDeniers); let resteQuantite = (itemVendu.data.quantite ?? 1) - achat.quantiteTotal; if (resteQuantite == 0) { - vendeur.deleteEmbeddedDocuments("Item", [itemId]); + vendeur.deleteEmbeddedDocuments("Item", [itemId]) } else { vendeur.updateEmbeddedDocuments("Item", [{ _id: itemId, 'data.quantite': resteQuantite }]); @@ -3774,22 +3779,22 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async effectuerTacheAlchimie(recetteId, tacheAlchimie, texteTache) { - let recetteData = Misc.data(this.getItemOfType(recetteId, 'recettealchimique')) - const actorData = this.system + let recetteData = Misc.data(this.getItemOfType(recetteId, 'recettealchimique')); + const actorData = Misc.data(this); if (recetteData) { if (tacheAlchimie != "couleur" && tacheAlchimie != "consistance") { ui.notifications.warn(`L'étape alchimique ${tacheAlchimie} - ${texteTache} est inconnue`); return; } - const sansCristal = tacheAlchimie == "couleur" && this.items.filter(it => it.isCristalAlchimique()).length == 0; + const sansCristal = tacheAlchimie == "couleur" && this.data.items.filter(it => it.isCristalAlchimique()).length == 0; const caracTache = RdDAlchimie.getCaracTache(tacheAlchimie); const alchimieData = Misc.data(this.getCompetence("alchimie")); let rollData = { recette: recetteData, - carac: { [caracTache]: actorData.carac[caracTache] }, - selectedCarac: actorData.carac[caracTache], + carac: { [caracTache]: actorData.data.carac[caracTache] }, + selectedCarac: actorData.data.carac[caracTache], competence: alchimieData, diffLibre: RdDAlchimie.getDifficulte(texteTache), diffConditions: sansCristal ? -4 : 0, @@ -3853,27 +3858,26 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ static _vehicleData(vehicle) { - const vehicleData = Misc.data(vehicle); return { id: vehicle.id, - name: vehicleData.name, - img: vehicleData.img, - categorie: vehicleData.data.categorie, - structure: vehicleData.data.structure, + name: vehicle.name, + img: vehicle.img, + categorie: vehicle.system.categorie, + structure: vehicle.system.structure, }; } /* -------------------------------------------- */ static _buildActorData(it) { - return { id: it.id, name: it.data.name, img: it.data.img }; + return { id: it.id, name: it.name, img: it.img }; } /* -------------------------------------------- */ async pushSubacteur(actor, dataArray, dataPath, dataName) { - let alreadyPresent = dataArray.find(attached => attached.id == actor.data._id); + let alreadyPresent = dataArray.find(attached => attached.id == actor._id); if (!alreadyPresent) { let newArray = duplicate(dataArray); - newArray.push({ id: actor.data._id }); + newArray.push({ id: actor._id }); await this.update({ [dataPath]: newArray }); } else { ui.notifications.warn(dataName + " est déja attaché à ce Personnage."); @@ -3885,13 +3889,12 @@ export class RdDActor extends Actor { let subActor = game.actors.get(subActorId); //console.log("Ajout acteur : ", actor, this); if (subActor && !subActor.owner) { - const actorData = Misc.data(this); if (subActor.data.type == 'vehicule') { - this.pushSubacteur(subActor, actorData.data.subacteurs.vehicules, 'data.subacteurs.vehicules', 'Ce Véhicule'); + this.pushSubacteur(subActor, this.system.subacteurs.vehicules, 'data.subacteurs.vehicules', 'Ce Véhicule'); } else if (subActor.data.type == 'creature') { - this.pushSubacteur(subActor, actorData.data.subacteurs.montures, 'data.subacteurs.montures', 'Cette Monture'); + this.pushSubacteur(subActor, this.system.subacteurs.montures, 'data.subacteurs.montures', 'Cette Monture'); } else if (subActor.data.type == 'personnage') { - this.pushSubacteur(subActor, actorData.data.subacteurs.suivants, 'data.subacteurs.suivants', 'Ce Suivant'); + this.pushSubacteur(subActor, this.system.subacteurs.suivants, 'data.subacteurs.suivants', 'Ce Suivant'); } } else { ui.notifications.warn("Vous n'avez pas les droits sur l'acteur que vous attachez.") @@ -3900,10 +3903,9 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async removeSubacteur(actorId) { - const actorData = Misc.data(this); - let newVehicules = actorData.data.subacteurs.vehicules.filter(function (obj, index, arr) { return obj.id != actorId }); - let newSuivants = actorData.data.subacteurs.suivants.filter(function (obj, index, arr) { return obj.id != actorId }); - let newMontures = actorData.data.subacteurs.montures.filter(function (obj, index, arr) { return obj.id != actorId }); + let newVehicules = this.system.subacteurs.vehicules.filter(function (obj, index, arr) { return obj.id != actorId }); + let newSuivants = this.system.subacteurs.suivants.filter(function (obj, index, arr) { return obj.id != actorId }); + let newMontures = this.system.subacteurs.montures.filter(function (obj, index, arr) { return obj.id != actorId }); await this.update({ 'data.subacteurs.vehicules': newVehicules }); await this.update({ 'data.subacteurs.suivants': newSuivants }); await this.update({ 'data.subacteurs.montures': newMontures }); @@ -3912,7 +3914,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async buildPotionGuerisonList(pointsGuerison) { let pointsGuerisonInitial = pointsGuerison; - let myData = this.system; + let myData = Misc.templateData(this); const blessures = duplicate(myData.blessures); let guerisonData = { list: [], pointsConsommes: 0 } @@ -4085,9 +4087,9 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async onUpdateActor(update, options, actorId) { - const updatedEndurance = update?.data?.sante?.endurance; + const updatedEndurance = update?.system?.sante?.endurance if (updatedEndurance && options.diff) { - await this.setStatusEffect("EFFECT.StatusUnconscious", updatedEndurance.value == 0); + await this.setStatusEffect("EFFECT.StatusUnconscious", updatedEndurance.value == 0) } } @@ -4116,7 +4118,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async setStatusEffect(label, status, updates = {}) { - if (this.isEntiteCauchemar() || this.data.type == 'vehicule') { + if (this.isEntiteCauchemar() || this.type == 'vehicule') { return; } console.log("setStatusEffect", label, status, updates) @@ -4147,9 +4149,8 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async onPreUpdateItem(item, change, options, id) { - const itemData = Misc.data(item); - if (itemData.type == 'competence' && itemData.data.defaut_carac && itemData.data.xp) { - await this.checkCompetenceXP(itemData.name, itemData.data.xp); + if (item.type == 'competence' && item.system.defaut_carac && item.system.xp) { + await this.checkCompetenceXP(item.name, item.system.xp); } } diff --git a/module/chat-utility.js b/module/chat-utility.js index d2062edf..e4a12af9 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -32,7 +32,6 @@ export class ChatUtility { } } - /* -------------------------------------------- */ static onNotifyUser(data) { if (game.user.id == data.userId) { switch (data.level) { @@ -47,15 +46,28 @@ export class ChatUtility { static onRemoveMessages(data) { if (Misc.isUniqueConnectedGM()) { if (data.part) { - const toDelete = game.messages.filter(it => it.content.includes(data.part)) - toDelete.forEach(it => it.delete()) + const toDelete = game.messages.filter(it => it.data.content.includes(data.part)); + toDelete.forEach(it => it.delete()); } if (data.messageId) { - game.messages.get(data.messageId)?.delete() + game.messages.get(data.messageId)?.delete(); + } + } + } + + static onRemoveMessages(data) { + if (Misc.isUniqueConnectedGM()) { + if (data.part) { + const toDelete = game.messages.filter(it => it.content.includes(data.part)); + toDelete.forEach(it => it.delete()); + } + if (data.messageId) { + game.messages.get(data.messageId)?.delete(); } } } /* -------------------------------------------- */ + static removeMessages(data) { if (Misc.isUniqueConnectedGM()) { ChatUtility.onRemoveMessages(data); @@ -78,7 +90,7 @@ export class ChatUtility { /* -------------------------------------------- */ static async createChatWithRollMode(name, chatOptions) { - return await ChatUtility.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions) + return await ChatUtility.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions); } /* -------------------------------------------- */ @@ -129,7 +141,7 @@ export class ChatUtility { /* -------------------------------------------- */ static getUsers(filter) { - return Misc.getUsers().filter(filter).map(user => user.id) + return Misc.getUsers().filter(filter).map(user => user.data._id); } /* -------------------------------------------- */ @@ -150,20 +162,17 @@ export class ChatUtility { } } - /* -------------------------------------------- */ static async setMessageData(chatMessage, key, data) { if (data) { await chatMessage.setFlag(SYSTEM_RDD, key, JSON.stringify(data)); } } - /* -------------------------------------------- */ static getMessageData(chatMessage, key) { const json = chatMessage.getFlag(SYSTEM_RDD, key); return json ? JSON.parse(json) : undefined; } - /* -------------------------------------------- */ static getChatMessage(event) { const chatMessageId = $(event.currentTarget).closest('.chat-message').attr('data-message-id'); return game.messages.get(chatMessageId); diff --git a/module/dialog-create-signedraconique.js b/module/dialog-create-signedraconique.js index c6203a69..57d17d3a 100644 --- a/module/dialog-create-signedraconique.js +++ b/module/dialog-create-signedraconique.js @@ -10,7 +10,7 @@ export class DialogCreateSigneDraconique extends Dialog { const signe = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true}); let dialogData = { signe: signe, - tmrs: TMRUtility.listSelectedTMR(signe.system.typesTMR ?? []), + tmrs: TMRUtility.listSelectedTMR(signe.data.typesTMR ?? []), actors: game.actors.filter(actor => actor.isHautRevant()).map(actor => { let actorData = duplicate(Misc.data(actor)); actorData.selected = actor.hasPlayerOwner; @@ -51,26 +51,26 @@ export class DialogCreateSigneDraconique extends Dialog { whisper: ChatUtility.getWhisperRecipientsAndGMs(Misc.data(actor).name), content: await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/chat-signe-draconique-actor.html", { signe: signe, - alias: actor.name + alias: Misc.data(actor).name }) }); } validerSigne() { this.dialogData.signe.name = $("[name='signe.name']").val(); - this.dialogData.signe.system.valeur.norm = $("[name='signe.data.valeur.norm']").val(); - this.dialogData.signe.system.valeur.sign = $("[name='signe.data.valeur.sign']").val(); - this.dialogData.signe.system.valeur.part = $("[name='signe.data.valeur.part']").val(); - this.dialogData.signe.system.difficulte = $("[name='signe.data.difficulte']").val(); - this.dialogData.signe.system.ephemere = $("[name='signe.data.ephemere']").prop("checked"); - this.dialogData.signe.system.duree = $("[name='signe.data.duree']").val(); - this.dialogData.signe.system.typesTMR = $(".select-tmr").val(); + this.dialogData.signe.data.valeur.norm = $("[name='signe.data.valeur.norm']").val(); + this.dialogData.signe.data.valeur.sign = $("[name='signe.data.valeur.sign']").val(); + this.dialogData.signe.data.valeur.part = $("[name='signe.data.valeur.part']").val(); + this.dialogData.signe.data.difficulte = $("[name='signe.data.difficulte']").val(); + this.dialogData.signe.data.ephemere = $("[name='signe.data.ephemere']").prop("checked"); + this.dialogData.signe.data.duree = $("[name='signe.data.duree']").val(); + this.dialogData.signe.data.typesTMR = $(".select-tmr").val(); } /* -------------------------------------------- */ activateListeners(html) { super.activateListeners(html); - this.setEphemere(this.dialogData.signe.system.ephemere); + this.setEphemere(this.dialogData.signe.data.ephemere); html.find(".signe-aleatoire").click(event => this.setSigneAleatoire()); html.find("[name='signe.data.ephemere']").change((event) => this.setEphemere(event.currentTarget.checked)); html.find(".select-actor").change((event) => this.onSelectActor(event)); @@ -81,14 +81,14 @@ export class DialogCreateSigneDraconique extends Dialog { const newSigne = await RdDItemSigneDraconique.randomSigneDraconique({ephemere: true}); $("[name='signe.name']").val(newSigne.name); - $("[name='signe.data.valeur.norm']").val(newSigne.system.valeur.norm); - $("[name='signe.data.valeur.sign']").val(newSigne.system.valeur.sign); - $("[name='signe.data.valeur.part']").val(newSigne.system.valeur.part); - $("[name='signe.data.difficulte']").val(newSigne.system.difficulte); - $("[name='signe.data.duree']").val(newSigne.system.duree); - $("[name='signe.data.ephemere']").prop("checked", newSigne.system.ephemere); - $(".select-tmr").val(newSigne.system.typesTMR); - this.setEphemere(newSigne.system.ephemere); + $("[name='signe.data.valeur.norm']").val(newSigne.data.valeur.norm); + $("[name='signe.data.valeur.sign']").val(newSigne.data.valeur.sign); + $("[name='signe.data.valeur.part']").val(newSigne.data.valeur.part); + $("[name='signe.data.difficulte']").val(newSigne.data.difficulte); + $("[name='signe.data.duree']").val(newSigne.data.duree); + $("[name='signe.data.ephemere']").prop("checked", newSigne.data.ephemere); + $(".select-tmr").val(newSigne.data.typesTMR); + this.setEphemere(newSigne.data.ephemere); } async setEphemere(ephemere) { @@ -111,8 +111,8 @@ export class DialogCreateSigneDraconique extends Dialog { onValeurXpSort(event) { const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0; const xp = Number(event.currentTarget.value); - const oldValeur = this.dialogData.signe.system.valeur; - this.dialogData.signe.system.valeur = RdDItemSigneDraconique.calculValeursXpSort(codeReussite, xp, oldValeur); + const oldValeur = this.dialogData.signe.data.valeur; + this.dialogData.signe.data.valeur = RdDItemSigneDraconique.calculValeursXpSort(codeReussite, xp, oldValeur); } } \ No newline at end of file diff --git a/module/grammar.js b/module/grammar.js index 6bb642b4..a8bd17a6 100644 --- a/module/grammar.js +++ b/module/grammar.js @@ -19,6 +19,10 @@ export class Grammar { return word.match(/^[aeiouy]/i) } + + static includesLowerCaseNoAccent(value, content) { + return Grammar.toLowerCaseNoAccent(value).includes(Grammar.toLowerCaseNoAccent(content)); + } /* -------------------------------------------- */ static toLowerCaseNoAccent(words) { return words?.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "") ?? words; diff --git a/module/item-arme.js b/module/item-arme.js index 8e1e4806..929f112b 100644 --- a/module/item-arme.js +++ b/module/item-arme.js @@ -20,8 +20,7 @@ const nomCategorieParade = { export class RdDItemArme extends Item { static isArme(itemData) { - console.log("ARM", itemData) - //itemData = Misc.data(itemData) + itemData = Misc.data(itemData); return (itemData.type == 'competencecreature' && itemData.system.iscombat) || itemData.type == 'arme'; } @@ -36,14 +35,12 @@ export class RdDItemArme extends Item { return RdDItemArme.mainsNues(); } - /* -------------------------------------------- */ static computeNiveauArmes(armes, competences) { for (const arme of armes) { - arme.system.niveau = RdDItemArme.niveauCompetenceArme(arme, competences) + arme.system.niveau = RdDItemArme.niveauCompetenceArme(arme, competences); } } - /* -------------------------------------------- */ static niveauCompetenceArme(arme, competences) { const compArme = competences.find(it => it.name == arme.system.competence); return compArme?.system.niveau ?? -8; @@ -51,7 +48,7 @@ export class RdDItemArme extends Item { /* -------------------------------------------- */ static getNomCategorieParade(arme) { - const categorie = arme?.data ? RdDItemArme.getCategorieParade(arme) : arme; + const categorie = arme?.system ? RdDItemArme.getCategorieParade(arme) : arme; return nomCategorieParade[categorie]; } @@ -69,21 +66,20 @@ export class RdDItemArme extends Item { /* -------------------------------------------- */ static getCategorieParade(armeData) { - armeData = Misc.data(armeData); - if (armeData.data.categorie_parade) { - return armeData.data.categorie_parade; + if (armeData.system.categorie_parade) { + return armeData.system.categorie_parade; } // pour compatibilité avec des personnages existants - if (armeData.type == 'competencecreature' || armeData.data.categorie == 'creature') { - return armeData.data.categorie_parade || (armeData.data.isparade ? 'armes-naturelles' : ''); + if (armeData.type == 'competencecreature' || armeData.system.categorie == 'creature') { + return armeData.system.categorie_parade || (armeData.system.isparade ? 'armes-naturelles' : ''); } if (!armeData.type.match(/arme|competencecreature/)) { return ''; } - if (armeData.data.competence == undefined) { + if (armeData.system.competence == undefined) { return 'competencecreature'; } - let compname = armeData.data.competence.toLowerCase(); + let compname = armeData.system.competence.toLowerCase(); if (compname.match(/^(dague de jet|javelot|fouet|arc|arbalête|fronde|hache de jet|fléau)$/)) return ''; if (compname.match('hache')) return 'haches'; @@ -140,22 +136,21 @@ export class RdDItemArme extends Item { /* -------------------------------------------- */ static armeUneOuDeuxMains(armeData, aUneMain) { - armeData = Misc.data(armeData); - if (armeData && !armeData.data.cac) { - armeData.data.unemain = armeData.data.unemain || !armeData.data.deuxmains; - const uneOuDeuxMains = armeData.data.unemain && armeData.data.deuxmains; - const containsSlash = !Number.isInteger(armeData.data.dommages) && armeData.data.dommages.includes("/"); + if (armeData && !armeData.system.cac) { + armeData.system.unemain = armeData.system.unemain || !armeData.system.deuxmains; + const uneOuDeuxMains = armeData.system.unemain && armeData.system.deuxmains; + const containsSlash = !Number.isInteger(armeData.system.dommages) && armeData.system.dommages.includes("/"); if (containsSlash) { // Sanity check armeData = duplicate(armeData); - const tableauDegats = armeData.data.dommages.split("/"); + const tableauDegats = armeData.system.dommages.split("/"); if (aUneMain) - armeData.data.dommagesReels = Number(tableauDegats[0]); + armeData.system.dommagesReels = Number(tableauDegats[0]); else // 2 mains - armeData.data.dommagesReels = Number(tableauDegats[1]); + armeData.system.dommagesReels = Number(tableauDegats[1]); } else { - armeData.data.dommagesReels = Number(armeData.data.dommages); + armeData.system.dommagesReels = Number(armeData.system.dommages); } if (uneOuDeuxMains != containsSlash) { @@ -166,14 +161,13 @@ export class RdDItemArme extends Item { } static isArmeUtilisable(itemData) { - itemData = Misc.data(itemData); - return itemData.type == 'arme' && itemData.data.equipe && (itemData.data.resistance > 0 || itemData.data.portee_courte > 0); + return itemData.type == 'arme' && itemData.system.equipe && (itemData.system.resistance > 0 || itemData.system.portee_courte > 0); } static ajoutCorpsACorps(armes, competences, carac) { - let corpsACorps = competences.find(it => it.name == 'Corps à corps') ?? { data: { niveau: -6 } } - let init = RdDCombatManager.calculInitiative(corpsACorps.system.niveau, carac['melee'].value) - armes.push(RdDItemArme.mainsNues({ niveau: corpsACorps.system.niveau, initiative: init })) + let corpsACorps = competences.find(it => it.name == 'Corps à corps') ?? { system: { niveau: -6 } }; + let init = RdDCombatManager.calculInitiative(corpsACorps.system.niveau, carac['melee'].value); + armes.push(RdDItemArme.mainsNues({ niveau: corpsACorps.system.niveau, initiative: init })); //armes.push(RdDItemArme.empoignade({ niveau: corpsACorps.data.niveau, initiative: init })); } @@ -197,19 +191,19 @@ export class RdDItemArme extends Item { } static mainsNues(actorData) { - const mainsNues = RdDItemArme.corpsACorps(actorData); - mainsNues.name = 'Mains nues'; - mainsNues.system.cac = 'pugilat'; - mainsNues.system.baseInit = 4; + const mainsNues = RdDItemArme.corpsACorps(actorData) + mainsNues.name = 'Mains nues' + mainsNues.system.cac = 'pugilat' + mainsNues.system.baseInit = 4 return mainsNues; } static empoignade(actorData) { - const empoignade = RdDItemArme.corpsACorps(actorData); - empoignade.name = 'Empoignade'; - empoignade.system.cac = 'empoignade'; - empoignade.system.baseInit = 3; - empoignade.system.mortalite = 'empoignade'; - return empoignade; + const empoignade = RdDItemArme.corpsACorps(actorData) + empoignade.name = 'Empoignade' + empoignade.system.cac = 'empoignade' + empoignade.system.baseInit = 3 + empoignade.system.mortalite = 'empoignade' + return empoignade } } diff --git a/module/item-competence.js b/module/item-competence.js index 02ae799c..1b8a0405 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -109,7 +109,7 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static isMalusEncombrementTotal(competence) { - return competence?.name.toLowerCase().match(/(natation|acrobatie)/) + return competence.name.toLowerCase().match(/(natation|acrobatie)/); } /* -------------------------------------------- */ @@ -133,12 +133,11 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static computeXP(competence) { - console.log("Competence", competence) - const factor = competence.name.includes('Thanatos') ? 2 : 1 // Thanatos compte double ! - const xpNiveau = RdDItemCompetence.computeDeltaXP(competence.system.base, competence.system.niveau ?? competence.system.base) - const xp = competence.system.xp ?? 0 - const xpSort = competence.system.xp_sort ?? 0 - return factor * (xpNiveau + xp) + xpSort + const factor = competence.name.includes('Thanatos') ? 2 : 1; // Thanatos compte double ! + const xpNiveau = RdDItemCompetence.computeDeltaXP(competence.system.base, competence.system.niveau ?? competence.system.base); + const xp = competence.system.xp ?? 0; + const xpSort = competence.system.xp_sort ?? 0; + return factor * (xpNiveau + xp) + xpSort; } /* -------------------------------------------- */ @@ -162,11 +161,10 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static computeCompetenceXPCost(competence) { - const compData = Misc.data(competence); - let xp = RdDItemCompetence.getDeltaXp(compData.data.base, compData.data.niveau ?? compData.data.base); - xp += compData.data.xp ?? 0; + let xp = RdDItemCompetence.getDeltaXp(competence.system.base, competence.system.niveau ?? competence.system.base); + xp += competence.system.xp ?? 0; if (compData.name.includes('Thanatos')) xp *= 2; /// Thanatos compte double ! - xp += compData.data.xp_sort ?? 0; + xp += competence.system.xp_sort ?? 0; return xp; } @@ -177,8 +175,8 @@ export class RdDItemCompetence extends Item { let list = troncList.map(name => RdDItemCompetence.findCompetence(competences, name)) .sort(Misc.descending(c => Misc.templateData(c).niveau)); // tri du plus haut au plus bas list.splice(0, 1); // ignorer la plus élevée - list.map(c => Misc.templateData(c)).forEach(tplData => { - economie += RdDItemCompetence.getDeltaXp(tplData.base, Math.min(tplData.niveau, 0)); + list.map(c => c).forEach(c => { + economie += RdDItemCompetence.getDeltaXp(c.system.base, Math.min(c.system.niveau, 0)) }); } return economie; @@ -186,13 +184,13 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static levelUp(itemData, stressTransforme) { - itemData.data.xpNext = RdDItemCompetence.getCompetenceNextXp(itemData.data.niveau); - const xpManquant = itemData.data.xpNext - itemData.data.xp; - itemData.data.isLevelUp = xpManquant <= 0; - itemData.data.isStressLevelUp = (xpManquant > 0 && stressTransforme >= xpManquant && itemData.data.niveau < itemData.data.niveau_archetype); - itemData.data.stressXpMax = 0; - if (xpManquant > 0 && stressTransforme > 0 && itemData.data.niveau < itemData.data.niveau_archetype) { - itemData.data.stressXpMax = Math.min(xpManquant , stressTransforme); + itemData.system.xpNext = RdDItemCompetence.getCompetenceNextXp(itemData.system.niveau); + const xpManquant = itemData.system.xpNext - itemData.system.xp; + itemData.system.isLevelUp = xpManquant <= 0; + itemData.system.isStressLevelUp = (xpManquant > 0 && stressTransforme >= xpManquant && itemData.system.niveau < itemData.system.niveau_archetype); + itemData.system.stressXpMax = 0; + if (xpManquant > 0 && stressTransforme > 0 && itemData.system.niveau < itemData.system.niveau_archetype) { + itemData.system.stressXpMax = Math.min(xpManquant , stressTransforme); } } @@ -207,7 +205,7 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static isNiveauBase(itemData) { - return Number(itemData.data.niveau) == RdDItemCompetence.getNiveauBase(itemData.data.categorie); + return Number(itemData.system.niveau) == RdDItemCompetence.getNiveauBase(itemData.system.categorie); } /* -------------------------------------------- */ @@ -257,7 +255,7 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static computeResumeArchetype(competences) { const archetype = RdDItemCompetence.getLimitesArchetypes(); - competences.map(it => Math.max(0, Misc.templateData(it).niveau_archetype)) + competences.map(it => Math.max(0, it.system.niveau_archetype)) .forEach(niveau => { archetype[niveau] = archetype[niveau] ?? { "niveau": niveau, "nombreMax": 0, "nombre": 0 }; archetype[niveau].nombre = (archetype[niveau]?.nombre ?? 0) + 1; diff --git a/module/item-competencecreature.js b/module/item-competencecreature.js index 5a2bde73..760b7f1e 100644 --- a/module/item-competencecreature.js +++ b/module/item-competencecreature.js @@ -7,9 +7,9 @@ export class RdDItemCompetenceCreature extends Item { static setRollDataCreature(rollData) { rollData.competence = Misc.data(rollData.competence); rollData.carac = { "carac_creature": { label: rollData.competence.name, value: rollData.competence.data.carac_value } }; - rollData.competence.data.defaut_carac = "carac_creature"; - rollData.competence.data.categorie = "creature"; - rollData.selectedCarac = rollData.carac.carac_creature; + rollData.competence.data.defaut_carac = "carac_creature" + rollData.competence.data.categorie = "creature" + rollData.selectedCarac = rollData.carac.carac_creature if (rollData.competence.data.iscombat) { rollData.arme = RdDItemCompetenceCreature.toArme(rollData.competence); } diff --git a/module/item-meditation.js b/module/item-meditation.js index 7ba0b076..fb77f098 100644 --- a/module/item-meditation.js +++ b/module/item-meditation.js @@ -3,7 +3,7 @@ export class RdDItemMeditation { static calculDifficulte(rollData) { if (rollData.meditation) { // Malus permanent éventuel - let diff = -rollData.meditation.data.malus ?? 0; + let diff = rollData.meditation.data.malus ?? 0; if (!rollData.conditionMeditation.isHeure) diff -= 2; if (!rollData.conditionMeditation.isVeture) diff -= 2; if (!rollData.conditionMeditation.isComportement) diff -= 2; diff --git a/module/item-monnaie.js b/module/item-monnaie.js index 5a1b9646..99a4ab4c 100644 --- a/module/item-monnaie.js +++ b/module/item-monnaie.js @@ -26,7 +26,7 @@ const monnaiesData = [ export class Monnaie { static isSystemMonnaie(item) { - let present = monnaiesData.find(monnaie => monnaie.system.valeur_deniers == item.system?.valeur_deniers); + let present = monnaiesData.find(monnaie => monnaie.system.valeur_deniers == item?.system?.valeur_deniers); return present; } @@ -40,8 +40,8 @@ export class Monnaie { static monnaiesManquantes(items) { const valeurs = Monnaie.filtrerMonnaies(items) - .map(it => Misc.templateData(it).valeur_deniers); - const manquantes = monnaiesData.filter(monnaie => !valeurs.find(v => v != monnaie.system.valeur_deniers)); + .map(it => it.system.valeur_deniers); + const manquantes = monnaiesData.filter(monnaie => !valeurs.find(v => v != monnaie.system?.valeur_deniers)) //const manquantes = monnaiesData.filter(monnaie => !valeurs.find(v => v != Misc.templateData(monnaie).valeur_deniers) ); //console.log("Valeurs : ", valeurs, manquantes); return []; //manquantes; diff --git a/module/item-sheet.js b/module/item-sheet.js index eaabf15e..5ce5b8b2 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -32,7 +32,7 @@ export class RdDItemSheet extends ItemSheet { let buttons = super._getHeaderButtons(); // Add "Post to chat" button // We previously restricted this to GM and editable items only. If you ever find this comment because it broke something: eh, sorry! - if ("cout" in Misc.templateData(this.object) && this.object.isVideOuNonConteneur()) { + if ("cout" in this.object.system && this.object.isVideOuNonConteneur()) { buttons.unshift({ class: "vendre", icon: "fas fa-comments-dollar", @@ -60,14 +60,13 @@ export class RdDItemSheet extends ItemSheet { /* -------------------------------------------- */ async getData() { - const objectData = this.object; let formData = { id: this.object.id, - title: objectData.name, - type: objectData.type, - img: objectData.img, - name: objectData.name, - data: objectData.system, + title: this.object.name, + type: this.object.type, + img: this.object.img, + name: this.object.name, + data: this.object.system, isGM: game.user.isGM, actorId: this.actor?.id, owner: this.document.isOwner, @@ -77,7 +76,7 @@ export class RdDItemSheet extends ItemSheet { } if (this.actor) { formData.isOwned = true; - if (objectData.type == 'conteneur') { + if (this.object.type == 'conteneur') { this.prepareConteneurData(formData); } } @@ -85,7 +84,8 @@ export class RdDItemSheet extends ItemSheet { 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.competences = await RdDUtility.loadCompendium('foundryvtt-reve-de-dragon.competences'); + formData.caracList["reve-actuel"] = duplicate(game.system.model.Actor.personnage.reve.reve) + 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)); @@ -113,6 +113,7 @@ export class RdDItemSheet extends ItemSheet { return formData; } + /* -------------------------------------------- */ prepareConteneurData(formData) { formData.itemsByType = Misc.classify(this.actor.items.map(i => foundry.utils.deepClone(i.data))); RdDUtility.filterEquipementParType(formData); @@ -228,7 +229,7 @@ export class RdDItemSheet extends ItemSheet { /* -------------------------------------------- */ get template() { let type = this.object.type - return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html` + return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html`; } /* -------------------------------------------- */ diff --git a/module/item-signedraconique-sheet.js b/module/item-signedraconique-sheet.js index 594d2222..f2217fdd 100644 --- a/module/item-signedraconique-sheet.js +++ b/module/item-signedraconique-sheet.js @@ -40,21 +40,18 @@ export class RdDSigneDraconiqueItemSheet extends ItemSheet { /* -------------------------------------------- */ async getData() { - let formData = { - name: this.object.name, - img: this.object.img, - title: this.object.name, + const formData = duplicate(Misc.data(this.object)); + mergeObject(formData, { + title: formData.name, isGM: game.user.isGM, owner: this.document.isOwner, - data: this.object.system, isOwned: this.actor ? true : false, actorId: this.actor?.id, editable: this.isEditable, cssClass: this.isEditable ? "editable" : "locked", - } - formData.tmrs = TMRUtility.listSelectedTMR(this.object.system.typesTMR ?? []) - console.log("SIG", formData) - return formData + }); + formData.tmrs = TMRUtility.listSelectedTMR(formData.data.typesTMR ?? []); + return formData; } /* -------------------------------------------- */ @@ -75,17 +72,17 @@ export class RdDSigneDraconiqueItemSheet extends ItemSheet { } async onSelectTmr(event) { - event.preventDefault() - const selectedTMR = $(".select-tmr").val() - this.object.update({ 'data.typesTMR': selectedTMR }) + event.preventDefault(); + const selectedTMR = $(".select-tmr").val(); + this.object.update({ 'data.typesTMR': selectedTMR }); } async onValeurXpSort(event) { const codeReussite = event.currentTarget.attributes['data-typereussite']?.value ?? 0; const xp = Number(event.currentTarget.value); - const oldValeur = this.object.system.valeur + const oldValeur = Misc.templateData(this.object).valeur; const newValeur = RdDItemSigneDraconique.calculValeursXpSort(codeReussite, xp, oldValeur); - await this.object.update({ 'data.valeur': newValeur }) + await this.object.update({ 'data.valeur': newValeur }); } /* -------------------------------------------- */ diff --git a/module/item-signedraconique.js b/module/item-signedraconique.js index 6e6e75c0..b540a9aa 100644 --- a/module/item-signedraconique.js +++ b/module/item-signedraconique.js @@ -13,25 +13,24 @@ const tableSignesIndicatifs = [ ] +const DIFFICULTE_LECTURE_SIGNE_MANQUE = +11; + export class RdDItemSigneDraconique { static prepareSigneDraconiqueMeditation(meditation, rolled) { - if (rolled.isSuccess != undefined) { - meditation = Misc.data(meditation); - return { - name: "de la " + meditation.name, - type: "signedraconique", - img: meditation.img, - data: { - typesTMR: [TMRUtility.typeTmrName(meditation.data.tmr)], - difficulte: RdDItemSigneDraconique.getDiffSigneMeditation(rolled.code), - ephemere: true, - duree: "1 round", - valeur: { "norm": 3, "sign": 5, "part": 10 } - } - }; - } - return undefined; + meditation = Misc.data(meditation); + return { + name: "de la " + meditation.name, + type: "signedraconique", + img: meditation.img, + data: { + typesTMR: [TMRUtility.typeTmrName(meditation.data.tmr)], + difficulte: rolled.isSuccess ? RdDItemSigneDraconique.getDiffSigneMeditation(rolled.code) : DIFFICULTE_LECTURE_SIGNE_MANQUE, + ephemere: true, + duree: "1 round", + valeur: rolled.isSuccess ? { "norm": 3, "sign": 5, "part": 10 } : { "norm": 0, "sign": 0, "part": 0 } + } + }; } static getDiffSigneMeditation(code) { @@ -44,7 +43,7 @@ export class RdDItemSigneDraconique { } static getXpSortSigneDraconique(code, signe) { - return Misc.data(signe).data.valeur[code] ?? 0; + return Misc.toInt(Misc.data(signe).data.valeur[code] ?? 0); } static calculValeursXpSort(qualite, valeur, avant) { diff --git a/module/item-sort.js b/module/item-sort.js index eeeaf634..9b9af594 100644 --- a/module/item-sort.js +++ b/module/item-sort.js @@ -18,7 +18,7 @@ export class RdDItemSort extends Item { /* -------------------------------------------- */ static setCoutReveReel(sort){ if (sort) { - sort.data.ptreve_reel = this.isCoutVariable(sort) ? 1 : sort.data.ptreve; + sort.system.ptreve_reel = this.isCoutVariable(sort) ? 1 : sort.system.ptreve; } } diff --git a/module/item.js b/module/item.js index b472c314..c8c55488 100644 --- a/module/item.js +++ b/module/item.js @@ -3,8 +3,8 @@ import { Grammar } from "./grammar.js"; import { Misc } from "./misc.js"; import { RdDUtility } from "./rdd-utility.js"; -const typesObjetsEquipement = ["objet", "arme", "armure", "gemme", "conteneur", "herbe", "ingredient", "livre", "potion", "munition", "nourritureboisson", "monnaie"]; -const typesObjetsOeuvres = ["oeuvre", "recettecuisine", "musique", "chant", "danse", "jeu"]; +const typesObjetsEquipement = ["objet", "arme", "armure", "gemme", "conteneur", "herbe", "ingredient", "livre", "potion", "munition", "nourritureboisson", "monnaie"] +const typesObjetsOeuvres = ["oeuvre", "recettecuisine", "musique", "chant", "danse", "jeu"] const encBrin = 0.00005;// un brin = 1 décigramme = 1/10g = 1/10000kg = 1/20000 enc export const defaultItemImg = { @@ -34,7 +34,8 @@ export const defaultItemImg = { oeuvre: "systems/foundryvtt-reve-de-dragon/icons/competence_comedie.webp", nourritureboisson: "systems/foundryvtt-reve-de-dragon/icons/objets/provision_crue.webp", signedraconique: "systems/foundryvtt-reve-de-dragon/icons/tmr/signe_draconique.webp", - gemme: "systems/foundryvtt-reve-de-dragon/icons/gemmes/almaze.webp" + gemme: "systems/foundryvtt-reve-de-dragon/icons/gemmes/almaze.webp", + possession: "systems/foundryvtt-reve-de-dragon/icons/entites/possession2.webp" } /* -------------------------------------------- */ @@ -48,11 +49,11 @@ export class RdDItem extends Item { } static getTypeObjetsEquipement() { - return typesObjetsEquipement; + return typesObjetsEquipement } static getTypesOeuvres() { - return typesObjetsOeuvres; + return typesObjetsOeuvres } isCompetence() { @@ -82,7 +83,7 @@ export class RdDItem extends Item { return this.type == 'herbe' && (this.system.categorie == 'Soin' || this.system.categorie == 'Repos'); } isPotion() { - return this.type == 'potion'; + return Misc.data(this).type == 'potion'; } isEquipement() { @@ -94,20 +95,18 @@ export class RdDItem extends Item { } isMagique() { - return this.system.magique; + return this.system.magique } getEncTotal() { - const itemData = this.system - return Number(itemData.encombrement ?? 0) * Number(itemData.quantite ?? 1); + return Number(this.system.encombrement ?? 0) * Number(this.system.quantite ?? 1) } getEnc() { - const itemData = this.system - switch (itemData.type) { + switch (this.type) { case 'herbe': return encBrin; } - return itemData.encombrement ?? 0 + return this.system.encombrement ?? 0; } prepareDerivedData() { @@ -118,50 +117,47 @@ export class RdDItem extends Item { if (this.isPotion()) { this.prepareDataPotion() } - this.system.actionPrincipale = this.getActionPrincipale({ warnIfNot: false }); + this.actionPrincipale = this.getActionPrincipale({ warnIfNot: false }); } } prepareDataPotion() { - const tplData = Misc.templateData(this); - const categorie = Grammar.toLowerCaseNoAccent(tplData.categorie); - tplData.magique = categorie.includes('enchante'); - if (tplData.magique) { + const categorie = Grammar.toLowerCaseNoAccent(this.system.categorie); + this.system.magique = categorie.includes('enchante'); + if (this.system.magique) { if (categorie.includes('soin') || categorie.includes('repos')) { - tplData.puissance = tplData.herbebonus * tplData.pr; + this.system.puissance = this.system.herbebonus * this.system.pr; } } } _calculsEquipement() { - const tplData = this.system - const quantite = this.isConteneur() ? 1 : (tplData.quantite ?? 0); + const quantite = this.isConteneur() ? 1 : (this.system.quantite ?? 0); const enc = this.getEnc(); if (enc != undefined) { - tplData.encTotal = Math.max(enc, 0) * quantite; + this.system.encTotal = Math.max(enc, 0) * quantite; } - if (tplData.cout != undefined) { - tplData.prixTotal = Math.max(tplData.cout, 0) * quantite; + if (this.cout != undefined) { + this.system.prixTotal = Math.max(this.cout, 0) * quantite; } } getActionPrincipale(options = { warnIfNot: true }) { - const itemData = this.system - if (!this.isConteneur() && (itemData.quantite ?? 0) <= 0) { + if (!this.isConteneur() && (this.system.quantite ?? 0) <= 0) { if (options.warnIfNot) { - ui.notifications.warn(`Vous n'avez plus de ${itemData.name}.`); + ui.notifications.warn(`Vous n'avez plus de ${this.name}.`); } return undefined; } - switch (itemData.type) { - case 'nourritureboisson': return itemData.boisson ? 'Boire' : 'Manger'; + switch (this.type) { + case 'nourritureboisson': return this.boisson ? 'Boire' : 'Manger'; case 'potion': return 'Boire'; case 'livre': return 'Lire'; case 'conteneur': return 'Ouvrir'; } if (this.isHerbeAPotion()) { return 'Décoction'; } if (options.warnIfNot) { - ui.notifications.warn(`Impossible d'utiliser un ${itemData.name}, aucune action associée définie.`); + ui.notifications.warn(`Impossible d'utiliser un ${this.name}, aucune action associée définie.`); } return undefined; @@ -173,18 +169,17 @@ export class RdDItem extends Item { } async quantiteIncDec(nombre, options = { diminuerQuantite: true, supprimerSiZero: false }) { - const itemData = this.system - const quantite = Number(itemData.quantite ?? -1); + const quantite = Number(this.system.quantite ?? -1); if (quantite >= 0) { const reste = Math.max(quantite + Number(nombre), 0); if (reste == 0) { if (options.supprimerSiZero) { - ui.notifications.notify(`${itemData.name} supprimé de votre équipement`); + ui.notifications.notify(`${this.name} supprimé de votre équipement`); await this.delete(); } else { - ui.notifications.notify(`Il ne vous reste plus de ${itemData.name}, vous pouvez le supprimer de votre équipement, ou trouver un moyen de vous en procurer.`); + ui.notifications.notify(`Il ne vous reste plus de ${this.name}, vous pouvez le supprimer de votre équipement, ou trouver un moyen de vous en procurer.`); await this.update({ "data.quantite": 0 }); } } @@ -197,10 +192,10 @@ export class RdDItem extends Item { /* -------------------------------------------- */ // détermine si deux équipements sont similaires: de même type, et avec les même champs hormis la quantité isEquipementSimilaire(other) { - const itemData = this.system - const otherData = other.data - const tplData = Misc.templateData(this); - const otherTplData = Misc.templateData(other); + const itemData = Misc.data(this) + const otherData = Misc.data(other) + const tplData = Misc.templateData(this) + const otherTplData = Misc.templateData(other) if (!this.isEquipement()) return false; if (itemData.type != otherData.type) return false; if (itemData.name != otherData.name) return false; @@ -246,7 +241,7 @@ export class RdDItem extends Item { /* -------------------------------------------- */ getProprietes() { - return this[`_${this.type}ChatData`](); + return this[`_${Misc.data(this).type}ChatData`](); } /* -------------------------------------------- */ diff --git a/module/misc.js b/module/misc.js index 4a14ba9c..c2a2aefe 100644 --- a/module/misc.js +++ b/module/misc.js @@ -69,9 +69,9 @@ export class Misc { } static classify(items, classifier = it => it.type) { - let itemsBy = {}; - Misc.classifyInto(itemsBy, items, classifier); - return itemsBy; + let itemsBy = {} + Misc.classifyInto(itemsBy, items, classifier) + return itemsBy } static classifyFirst(items, classifier) { @@ -87,13 +87,13 @@ export class Misc { static classifyInto(itemsBy, items, classifier = it => it.type) { for (const item of items) { - const classification = classifier(item); + const classification = classifier(item) let list = itemsBy[classification]; if (!list) { - list = []; - itemsBy[classification] = list; + list = [] + itemsBy[classification] = list } - list.push(item); + list.push(item) } } @@ -105,21 +105,21 @@ 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 - } - return it + /*if (it instanceof Actor || it instanceof Item || it instanceof Combatant) { + return it.data; + }*/ + return it; } static templateData(it) { - return it.system ?? {} - //return Misc.data(it)?.system ?? {} + return Misc.data(it)?.data ?? {} } static getEntityTypeLabel(entity) { - const documentName = entity?.documentName; - const type = entity?.data.type; + const documentName = entity?.documentName + const type = entity?.type if (documentName === 'Actor' || documentName === 'Item') { const label = CONFIG[documentName]?.typeLabels?.[type] ?? type; return game.i18n.has(label) ? game.i18n.localize(label) : t; diff --git a/module/rdd-combat.js b/module/rdd-combat.js index ecbc11f2..fd958570 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -77,7 +77,7 @@ export class RdDCombatManager extends Combat { /************************************************************************************/ async rollInitiative(ids, formula = undefined, messageOptions = {}) { - console.log(`${game.data.system.title} | Combat.rollInitiative()`, ids, formula, messageOptions); + console.log(`${game.data.system.data.title} | Combat.rollInitiative()`, ids, formula, messageOptions); // Structure input data ids = typeof ids === "string" ? [ids] : ids; const currentId = this.combatant._id; @@ -89,23 +89,23 @@ export class RdDCombatManager extends Combat { let rollFormula = formula; // Init per default if (!rollFormula) { let armeCombat, competence; - if (combatant.actor.type == 'creature' || combatant.actor.type == 'entite') { - for (const competenceItemData of combatant.actor.items) { - if (competenceItemData.system.iscombat) { - competence = duplicate(competenceItemData) + if (combatant.actor.data.type == 'creature' || combatant.actor.data.type == 'entite') { + for (const competenceItemData of combatant.actor.data.items) { + if (competenceItemData.data.data.iscombat) { + competence = duplicate(competenceItemData); } } - rollFormula = "2+( (" + RdDCombatManager.calculInitiative(competence.system.niveau, competence.system.carac_value) + ")/100)"; + rollFormula = "2+( (" + RdDCombatManager.calculInitiative(competence.data.niveau, competence.data.carac_value) + ")/100)"; } else { - for (const itemData of combatant.actor.items) { - if (itemData.type == "arme" && itemData.system.equipe) { - armeCombat = duplicate(itemData) + for (const itemData of combatant.actor.data.items) { + if (itemData.type == "arme" && itemData.data.equipe) { + armeCombat = duplicate(itemData); } } - let compName = (armeCombat == undefined) ? "Corps à corps" : armeCombat.system.competence; - competence = RdDItemCompetence.findCompetence(combatant.actor.items, compName); - let bonusEcaille = (armeCombat && armeCombat.system.magique) ? armeCombat.system.ecaille_efficacite : 0; - rollFormula = "2+( (" + RdDCombatManager.calculInitiative(competence.system.niveau, combatant.actor.system.carac[competence.system.defaut_carac].value, bonusEcaille) + ")/100)"; + let compName = (armeCombat == undefined) ? "Corps à corps" : armeCombat.data.competence; + competence = RdDItemCompetence.findCompetence(combatant.actor.data.items, compName); + let bonusEcaille = (armeCombat && armeCombat.data.magique) ? armeCombat.data.ecaille_efficacite : 0; + rollFormula = "2+( (" + RdDCombatManager.calculInitiative(competence.data.niveau, Misc.data(combatant.actor).data.carac[competence.data.defaut_carac].value, bonusEcaille) + ")/100)"; } } //console.log("Combatat", c); @@ -153,40 +153,39 @@ 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 = [] - console.log("ARMES", armes) - for (const arme of armes) { - let armeData = duplicate(arme) - if (armeData.system.equipe) { - let compData = competences.map(c => c).find(c => c.name == armeData.system.competence) + let armesEquipe = []; + for (const arme of armes) { + let armeData = duplicate(arme.system) + if (armeData.equipe) { + let compData = competences.find(c => c.name.toLowerCase() == armeData.competence.toLowerCase()) + console.log("ARME", arme, compData, armeData.competence, competences) armesEquipe.push(armeData) - armeData.system.dommagesReels = Number(armeData.system.dommages) - console.log("ARME", armeData, compData) - armeData.system.niveau = compData.system.niveau - armeData.system.initiative = RdDCombatManager.calculInitiative(compData.system.niveau, carac[compData.system.defaut_carac].value); + armeData.dommagesReels = Number(armeData.dommages) + armeData.niveau = compData.system.niveau + armeData.initiative = RdDCombatManager.calculInitiative(compData.system.niveau, carac[compData.system.defaut_carac].value); // Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence - if (armeData.system.unemain && !armeData.system.deuxmains) { - armeData.system.mainInfo = "(1m)"; - } else if (!armeData.system.unemain && armeData.system.deuxmains) { - armeData.system.mainInfo = "(2m)"; - } else if (armeData.system.unemain && armeData.system.deuxmains) { - armeData.system.mainInfo = "(1m)"; + if (armeData.unemain && !armeData.deuxmains) { + armeData.mainInfo = "(1m)"; + } else if (!armeData.unemain && armeData.deuxmains) { + armeData.mainInfo = "(2m)"; + } else if (armeData.unemain && armeData.deuxmains) { + armeData.mainInfo = "(1m)"; - const comp2m = armeData.system.competence.replace(" 1 main", " 2 mains"); // Replace ! - const comp = Misc.data(competences.find(c => c.name == comp2m)); + const comp2m = armeData.competence.replace(" 1 main", " 2 mains"); // Replace ! + const comp = competences.find(c => c.name == comp2m) - const arme2main = duplicate(armeData); - arme2main.system.mainInfo = "(2m)"; - arme2main.system.niveau = comp.system.niveau; - arme2main.system.competence = comp2m; - arme2main.system.initiative = RdDCombatManager.calculInitiative(arme2main.system.niveau, carac[comp.system.defaut_carac].value); + const arme2main = duplicate(armeData) + arme2main.mainInfo = "(2m)"; + arme2main.niveau = comp.data.niveau; + arme2main.competence = comp2m; + arme2main.initiative = RdDCombatManager.calculInitiative(arme2main.niveau, carac[comp.system.defaut_carac].value) armesEquipe.push(arme2main); - const containsSlash = armeData.system.dommages.includes("/"); + const containsSlash = armeData.dommages.includes("/"); if (containsSlash) { - const tableauDegats = armeData.system.dommages.split("/"); - armeData.system.dommagesReels = Number(tableauDegats[0]); - arme2main.system.dommagesReels = Number(tableauDegats[1]); + const tableauDegats = armeData.dommages.split("/"); + armeData.dommagesReels = Number(tableauDegats[0]); + arme2main.dommagesReels = Number(tableauDegats[1]); } else{ ui.notifications.info("Les dommages de l'arme à 1/2 mains " + armeData.name + " ne sont pas corrects (ie sous la forme X/Y)"); @@ -194,7 +193,7 @@ export class RdDCombatManager extends Combat { } } } - return armesEquipe.sort(Misc.ascending(armeData => armeData.name + (armeData.system.mainInfo ?? ''))); + return armesEquipe.sort(Misc.ascending(armeData => armeData.name + (armeData.mainInfo ?? ''))) } /* -------------------------------------------- */ @@ -204,7 +203,7 @@ export class RdDCombatManager extends Combat { return []; } const actorData = Misc.data(combatant.actor); - let items = combatant.actor.data.items; + let items = combatant.actor.items let actions = [] if (combatant.actor.isCreature()) { actions = actions.concat(items.filter(it => RdDItemCompetenceCreature.isCompetenceAttaque(it)) @@ -215,7 +214,7 @@ export class RdDCombatManager extends Combat { //.concat(RdDItemArme.empoignade()) .concat(RdDItemArme.mainsNues()); - let competences = items.filter(it => it.type == 'competence'); + let competences = items.filter(it => it.type == 'competence') actions = actions.concat(RdDCombatManager.finalizeArmeList(armes, competences, actorData.data.carac)); if (actorData.data.attributs.hautrevant.value) { @@ -467,15 +466,15 @@ export class RdDCombat { } /* -------------------------------------------- */ - static onMsgEncaisser(data) { - let defender = canvas.tokens.get(data.defenderTokenId).actor; + static onMsgEncaisser(msg) { + let defender = canvas.tokens.get(msg.defenderTokenId).actor; if (Misc.isOwnerPlayerOrUniqueConnectedGM()) { - let attackerRoll = data.attackerRoll; - let attacker = data.attackerId ? game.actors.get(data.attackerId) : null; + let attackerRoll = msg.attackerRoll; + let attacker = msg.attackerId ? game.actors.get(msg.attackerId) : null; defender.encaisserDommages(attackerRoll, attacker); - RdDCombat._deleteDefense(attackerRoll.passeArme); - RdDCombat._deleteAttaque(data.attackerId); + const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId); + rddCombat?.removeChatMessageActionsPasseArme(attackerRoll.passeArme); } } @@ -484,11 +483,8 @@ export class RdDCombat { let defenderToken = canvas.tokens.get(msg.defenderTokenId); if (defenderToken && Misc.isUniqueConnectedGM()) { const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId); - if (rddCombat) { - const defenderRoll = msg.defenderRoll; - rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme); - rddCombat._chatMessageDefense(msg.paramChatDefense, msg.defenderRoll); - } + rddCombat?.removeChatMessageActionsPasseArme(msg.defenderRoll.passeArme); + rddCombat?._chatMessageDefense(msg.paramChatDefense, msg.defenderRoll); } } @@ -668,7 +664,6 @@ 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, @@ -678,7 +673,7 @@ export class RdDCombat { competence: competence }) }); - return + return; } let rollData = this._prepareAttaque(competence, arme); @@ -705,7 +700,7 @@ export class RdDCombat { { condition: RdDCombat.isEchecTotal, action: r => this._onAttaqueEchecTotal(r) }, ] }); - dialog.render(true) + dialog.render(true); } /* -------------------------------------------- */ @@ -1008,8 +1003,7 @@ export class RdDCombat { await this.computeRecul(defenderRoll); await this.computeDeteriorationArme(defenderRoll); await RdDResolutionTable.displayRollData(defenderRoll, this.defender, 'chat-resultat-parade.html'); - - RdDCombat._deleteDefense(defenderRoll.passeArme); + this.removeChatMessageActionsPasseArme(defenderRoll.passeArme); } /* -------------------------------------------- */ @@ -1080,7 +1074,7 @@ export class RdDCombat { async _onEsquiveNormale(defenderRoll) { console.log("RdDCombat._onEsquiveNormal >>>", defenderRoll); await RdDResolutionTable.displayRollData(defenderRoll, this.defender, 'chat-resultat-esquive.html'); - RdDCombat._deleteDefense(defenderRoll.passeArme); + this.removeChatMessageActionsPasseArme(defenderRoll.passeArme); } /* -------------------------------------------- */ @@ -1220,7 +1214,6 @@ export class RdDCombat { } }); } - RdDCombat._deleteDefense(attackerRoll.passeArme); this.removeChatMessageActionsPasseArme(attackerRoll.passeArme); } diff --git a/module/rdd-herbes.js b/module/rdd-herbes.js index fa67527e..4736f90b 100644 --- a/module/rdd-herbes.js +++ b/module/rdd-herbes.js @@ -8,11 +8,11 @@ export class RdDHerbes extends Item { /* -------------------------------------------- */ static isHerbeSoin( botaniqueItem ) { - return Misc.templateData(botaniqueItem).categorie == 'Soin'; + return botaniqueItem.categorie == 'Soin'; } /* -------------------------------------------- */ static isHerbeRepos( botaniqueItem ) { - return Misc.templateData(botaniqueItem).categorie == 'Repos'; + return botaniqueItem.categorie == 'Repos'; } /* -------------------------------------------- */ diff --git a/module/rdd-main.js b/module/rdd-main.js index f89c0535..199972cc 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -183,7 +183,7 @@ Hooks.once("init", async function () { Items.registerSheet(SYSTEM_RDD, RdDItemSheet, { types: ["arme", "armure", "objet", "arme", "armure", "conteneur", "competence", "sort", "herbe", "ingredient", "livre", "potion", "munition", "rencontresTMR", "queue", "ombre", "souffle", "tete", "competencecreature", "tarot", "monnaie", "nombreastral", "tache", "meditation", "casetmr", "recettealchimique", "gemme", - "musique", "chant", "danse", "jeu", "recettecuisine", "maladie", "poison", "oeuvre", "nourritureboisson"], makeDefault: true + "musique", "chant", "danse", "jeu", "recettecuisine", "maladie", "poison", "oeuvre", "nourritureboisson", "possession"], makeDefault: true }); CONFIG.Combat.documentClass = RdDCombatManager; @@ -225,7 +225,6 @@ function registerUsageCount( registerKey ) { name: "Unique world key", scope: "world", config: false, - value: "EMPTY", type: String }); @@ -269,7 +268,7 @@ Hooks.once("ready", async function () { } if (Misc.isUniqueConnectedGM()) { messageDeBienvenue(); - registerUsageCount( SYSTEM_RDD ) + registerUsageCount( SYSTEM_RDD ); } }); diff --git a/module/rdd-possession.js b/module/rdd-possession.js index 4b9e0f36..44a02423 100644 --- a/module/rdd-possession.js +++ b/module/rdd-possession.js @@ -1,11 +1,7 @@ /* -------------------------------------------- */ -import { Misc } from "./misc.js"; -import { RdDDice } from "./rdd-dice.js"; -import { RdDUtility } from "./rdd-utility.js"; import { RdDCombat } from "./rdd-combat.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDRoll } from "./rdd-roll.js"; -import { RdDRollTables } from "./rdd-rolltables.js"; import { RdDItemCompetenceCreature } from "./item-competencecreature.js"; /* -------------------------------------------- */ @@ -18,7 +14,7 @@ Donc la compétence Possession ne peut être démarrée que par le MJ. export class RdDPossession { /* -------------------------------------------- */ - static init() { + static init() { } /* -------------------------------------------- */ @@ -32,52 +28,83 @@ export class RdDPossession { /* -------------------------------------------- */ static updateEtatPossession( possession ) { - possession.ptsConjuration = 0; - possession.ptsPossession = 0; + possession.ptsConjuration = 0 + possession.ptsPossession = 0 + console.log("Possession", possession) if ( possession.data.compteur > 0) { - possession.ptsPossession = possession.data.compteur; + possession.ptsPossession = possession.data.compteur } if ( possession.data.compteur < 0) { - possession.ptsConjuration = Math.abs(possession.data.compteur); + possession.ptsConjuration = Math.abs(possession.data.compteur) } + possession.isPosseder = false + possession.isConjurer = false if (possession.ptsPossession >= 2 ) { - // Possede + possession.isPosseder = true } - if (possession.ptsConjuration <= -2 ) { - // Libere + if (possession.ptsConjuration >= 2 ) { + possession.isConjurer = true } - console.log("Poss", possession); } /* -------------------------------------------- */ static async resultConjuration( rollData) { - console.log("RollData!!!", rollData); - if ( !rollData.rolled.isSuccess ) { - rollData.possession.data.compteur++; + let actor = game.actors.get(rollData.possession.data.possedeid) + if ( !rollData.rolled.isSuccess ) { + if( rollData.isECNIDefender) { + rollData.possession.data.compteur-- + } else { + rollData.possession.data.compteur++ + } + let update = { _id: rollData.possession._id, "data.compteur": rollData.possession.data.compteur } + await actor.updateEmbeddedDocuments('Item', [update]) + } + + this.updateEtatPossession(rollData.possession) + await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-possession.html') + if ( rollData.possession.isPosseder || rollData.possession.isConjurer) { + actor.deleteEmbeddedDocuments("Item", [rollData.possession._id]) } - this.updateEtatPossession(rollData.possession); - await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-possession.html'); } /* -------------------------------------------- */ - static async onDefensePossession( actorId, possessionId) { - let actor = game.actors.get(actorId); - console.log("onDefensePossession", actor, possessionId); - let possession = duplicate(actor.items.find( item => item.type =='possession' && item.data.data.possessionid == possessionId)); - let attacker = game.actors.get(possession.data.possesseurid); + static async onDefensePossession( attackerId, defenderId, possessionId) { + let attacker = game.actors.get(attackerId) + let defender = game.actors.get(defenderId) + + let possession = attacker.items.find( item => item.type =='possession' && item.data.data.possessionid == possessionId) + if ( !possession ) { + possession = defender.items.find( item => item.type =='possession' && item.data.data.possessionid == possessionId) + if ( !possession) { + ui.notifications.warn("Une erreur s'est produite : Aucune possession trouvée !!") + return + } + } + possession = duplicate(possession) // Update for draconic roll let rollData = { possession: possession } - rollData.actor = actor; - rollData.competence = duplicate(actor.getDraconicOrZero()); - rollData.competence.data.defaut_carac = 'reve-actuel'; - rollData.forceCarac = { 'reve-actuel': { label: "Rêve Actuel", value: actor.getReveActuel() } } - rollData.mode = "conjuration"; - rollData.possesseur = attacker.name; + rollData.actor = defender + if ( defender.type == "personnage") { + rollData.competence = duplicate(defender.getDraconicOrZero()) + rollData.competence.data.defaut_carac = 'reve-actuel' + rollData.forceCarac = { 'reve-actuel': { label: "Rêve Actuel", value: defender.getReveActuel() } } + rollData.selectedCarac = defender.data.data.carac.reve + rollData.isECNIDefender = false + } else { + rollData.competence = duplicate(defender.getCompetence("Possession")) + rollData.competence.data.defaut_carac = "reve" + rollData.forceCarac = { 'reve': { label: "Rêve", value: defender.data.data.carac.reve.value } } + rollData.selectedCarac = defender.data.data.carac.reve + rollData.isECNIDefender = true + //RdDItemCompetenceCreature.setRollDataCreature( rollData ) + } + rollData.mode = "conjuration" + rollData.possesseur = attacker.name - const dialog = await RdDRoll.create(actor, rollData, + const dialog = await RdDRoll.create(defender, rollData, { html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-defense-possession.html', options: { height: 400 } @@ -90,21 +117,21 @@ export class RdDPossession { ] } ); - dialog.render(true); + dialog.render(true) } /* -------------------------------------------- */ static async _onRollPossession( rollData, isSuccess ) { - let possession = rollData.possession; - possession.isSuccess = isSuccess; - this.updateEtatPossession( possession); + let possession = rollData.possession + possession.isSuccess = isSuccess + this.updateEtatPossession( possession) await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-possession.html'); } /* -------------------------------------------- */ - static async managePosession(attacker, competence ) { + static async managePossession(attacker, competence, possession=undefined) { - const target = RdDCombat.getTarget(); + const target = RdDCombat.getTarget() if (target == undefined) { ui.notifications.warn((game.user.targets?.size ?? 0) > 1 ? "Vous devez choisir une seule cible à posséder!" @@ -112,13 +139,16 @@ export class RdDPossession { return; } - const defender = target.actor; - let possession = this.searchPossessionFromEntite( attacker, defender); + const defender = target.actor if ( !possession) { - possession = this.createPossession(attacker, defender); + possession = this.searchPossessionFromEntite( attacker, defender) + if ( !possession) { + possession = await this.createPossession(attacker, defender) + } } + possession = duplicate(possession) - this.updateEtatPossession(possession); + this.updateEtatPossession(possession) let rollData = { competence: competence, possession: possession, @@ -129,9 +159,8 @@ export class RdDPossession { mode: "possession" }; if ( attacker.isCreature()) { - RdDItemCompetenceCreature.setRollDataCreature(rollData); + RdDItemCompetenceCreature.setRollDataCreature(rollData) } - console.log("Creation de possession2", attacker, rollData); const dialog = await RdDRoll.create( attacker, rollData, { @@ -145,19 +174,19 @@ export class RdDPossession { { condition: r => (r.rolled.isEchec), action: async r => await this._onRollPossession(r, false) }, ] }); - dialog.render(true); + dialog.render(true) } /* -------------------------------------------- */ static async createPossession( attacker, defender ) { - let posessionData = { - name: "Possession en cours", type: 'possession', + let possessionData = { + name: "Possession en cours de " + attacker.name, type: 'possession', img: "systems/foundryvtt-reve-de-dragon/icons/entites/possession2.webp", - data: { description: "", possede: false, possessionid: randomID(16), possesseurid: attacker.data._id, possedeid: defender.data._id, date: 0 } + data: { description: "", typepossession: attacker.name, possede: false, possessionid: randomID(16), possesseurid: attacker.data._id, possedeid: defender.data._id, date: 0, compteur: 0 } } - await attacker.createEmbeddedDocuments('Item', [posessionData]) - let poss = await defender.createEmbeddedDocuments('Item', [posessionData]) - return duplicate(poss[0]); + // Creates only the possession on the personnage side + let poss = await defender.createEmbeddedDocuments('Item', [possessionData]) + return duplicate(poss[0]) } } \ No newline at end of file diff --git a/module/rdd-roll.js b/module/rdd-roll.js index 4ed55155..3bc8d238 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -38,18 +38,19 @@ export class RdDRoll extends Dialog { /* -------------------------------------------- */ static _setDefaultOptions(actor, rollData) { + const actorData = actor.system let defaultRollData = { alias: actor.name, ajustementsConditions: CONFIG.RDD.ajustementsConditions, difficultesLibres: CONFIG.RDD.difficultesLibres, etat: actor.getEtatGeneral(), moral: actor.getMoralTotal(), /* La valeur du moral pour les jets de volonté */ - carac: actor.system.carac, + carac: actorData.carac, finalLevel: 0, diffConditions: 0, diffLibre: rollData.competence?.system.default_diffLibre ?? 0, malusArmureValue: actor.getMalusArmure(), - surencMalusFlag: actor.isPersonnage() ? (actor.system.compteurs.surenc.value < 0) : false, + surencMalusFlag: actor.isPersonnage() ? (actorData.compteurs.surenc.value < 0) : false, surencMalusValue: actor.computeMalusSurEncombrement(), useMalusSurenc: false, useMoral: false, /* Est-ce que le joueur demande d'utiliser le moral ? Utile si le joueur change plusieurs fois de carac associée. */ @@ -63,7 +64,11 @@ export class RdDRoll extends Dialog { canClose: true, isGM: game.user.isGM, forceDiceResult: -1 - }; + } + // Mini patch :Ajout du rêve actuel + if ( actorData.type == "personnage") { + defaultRollData.carac["reve-actuel"] = actorData.reve.reve + } mergeObject(rollData, defaultRollData, { recursive: true, overwrite: false }); if (rollData.forceCarac) { @@ -73,7 +78,6 @@ export class RdDRoll extends Dialog { RollDataAjustements.calcul(rollData, actor); } - /* -------------------------------------------- */ static getDiviseurSignificative(rollData) { let facteurSign = 1; @@ -166,12 +170,12 @@ export class RdDRoll extends Dialog { if (rollData.competence) { 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.system.listIndex); // Uniquement a la selection du sort, pour permettre de changer } RdDItemSort.setCoutReveReel(rollData.selectedSort); $("#diffLibre").val(Misc.toInt(rollData.diffLibre)); @@ -267,47 +271,47 @@ export class RdDRoll extends Dialog { async setSelectedSort(sort) { this.rollData.selectedSort = sort; // Update the selectedCarac - this.rollData.competence = RdDItemCompetence.getVoieDraconic(this.rollData.draconicList, sort.data.draconic); + this.rollData.competence = RdDItemCompetence.getVoieDraconic(this.rollData.draconicList, sort.system.draconic); this.rollData.bonus = RdDItemSort.getCaseBonus(sort, this.rollData.tmr.coord); this.rollData.diffLibre = RdDItemSort.getDifficulte(sort, -7); RdDItemSort.setCoutReveReel(sort); const htmlSortDescription = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html", { sort: sort }); - $(".sort-ou-rituel").text(sort.data.isrituel ? "rituel" : "sort"); + $(".sort-ou-rituel").text(sort.system.isrituel ? "rituel" : "sort"); $(".bonus-case").text(`${this.rollData.bonus}%`); $(".details-sort").remove(); $(".description-sort").append(htmlSortDescription); - $(".roll-draconic").val(sort.data.listIndex); - $(".div-sort-difficulte-fixe").text(Misc.toSignedString(sort.data.difficulte)); - $(".div-sort-ptreve-fixe").text(sort.data.ptreve); + $(".roll-draconic").val(sort.system.listIndex); + $(".div-sort-difficulte-fixe").text(Misc.toSignedString(sort.system.difficulte)); + $(".div-sort-ptreve-fixe").text(sort.system.ptreve); const diffVariable = RdDItemSort.isDifficulteVariable(sort); const coutVariable = RdDItemSort.isCoutVariable(sort); - HtmlUtility._showControlWhen($(".div-sort-non-rituel"), !sort.data.isrituel); + HtmlUtility._showControlWhen($(".div-sort-non-rituel"), !sort.system.isrituel); HtmlUtility._showControlWhen($(".div-sort-difficulte-var"), diffVariable); HtmlUtility._showControlWhen($(".div-sort-difficulte-fixe"), !diffVariable); HtmlUtility._showControlWhen($(".div-sort-ptreve-var"), coutVariable); 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)); } /* -------------------------------------------- */ async updateRollResult() { let rollData = this.rollData; - rollData.dmg = rollData.attackerRoll?.dmg ?? RdDBonus.dmg(rollData, this.actor.getBonusDegat()); - rollData.caracValue = parseInt(rollData.selectedCarac.value); + rollData.dmg = rollData.attackerRoll?.dmg ?? RdDBonus.dmg(rollData, this.actor.getBonusDegat()) + rollData.caracValue = parseInt(rollData.selectedCarac.value) rollData.mortalite = rollData.attackerRoll?.dmg.mortalite ?? rollData.dmg.mortalite ?? 'mortel'; rollData.coupsNonMortels = (rollData.attackerRoll?.dmg.mortalite ?? rollData.dmg.mortalite) == 'non-mortel'; 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); @@ -339,7 +343,7 @@ export class RdDRoll extends Dialog { /* -------------------------------------------- */ _computeFinalLevel(rollData) { - return RollDataAjustements.sum(rollData.ajustements) + return RollDataAjustements.sum(rollData.ajustements); } /* -------------------------------------------- */ _computeDiffCompetence(rollData) { @@ -375,13 +379,13 @@ 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.system.niveau) diff --git a/module/rdd-sheet-utility.js b/module/rdd-sheet-utility.js index fa114829..22555a7f 100644 --- a/module/rdd-sheet-utility.js +++ b/module/rdd-sheet-utility.js @@ -4,7 +4,7 @@ import { Misc } from "./misc.js"; export class RdDSheetUtility { static getItem(event, actor) { - return actor.items.get(RdDSheetUtility.getItemId(event)); + return actor.items.get(RdDSheetUtility.getItemId(event)) } static getItemId(event) { @@ -21,7 +21,7 @@ export class RdDSheetUtility { } static prepareItemDropParameters(destItemId, actorId, dragData, objetVersConteneur) { - const itemId = dragData.id || dragData._id + const itemId = dragData.id || dragData.data._id return { destId: destItemId, targetActorId: actorId, diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 1831720c..8309d9f8 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -147,6 +147,7 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/item-meditation-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-nourritureboisson-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-signedraconique-sheet.html', + 'systems/foundryvtt-reve-de-dragon/templates/item-possession-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/competence-carac-defaut.html', 'systems/foundryvtt-reve-de-dragon/templates/competence-base.html', 'systems/foundryvtt-reve-de-dragon/templates/enum-aspect-tarot.html', @@ -325,8 +326,8 @@ export class RdDUtility { } /* -------------------------------------------- */ - static checkNull(items) { - if (items && items.length) { + static arrayOrEmpty(items) { + if (items?.length) { return items; } return []; @@ -359,44 +360,44 @@ export class RdDUtility { RdDUtility.filterEquipementParType(formData); - formData.sorts = this.checkNull(formData.itemsByType['sort']); - formData.signesdraconiques = this.checkNull(formData.itemsByType['signedraconique']); - formData.queues = this.checkNull(formData.itemsByType['queue']); - formData.souffles = this.checkNull(formData.itemsByType['souffle']); - formData.ombres = this.checkNull(formData.itemsByType['ombre']); - formData.tetes = this.checkNull(formData.itemsByType['tete']); - formData.taches = this.checkNull(formData.itemsByType['tache']); - formData.meditations = this.checkNull(formData.itemsByType['meditation']); - formData.chants = this.checkNull(formData.itemsByType['chant']); - formData.danses = this.checkNull(formData.itemsByType['danse']); - formData.musiques = this.checkNull(formData.itemsByType['musique']); - formData.oeuvres = this.checkNull(formData.itemsByType['oeuvre']); - formData.jeux = this.checkNull(formData.itemsByType['jeu']); + formData.sorts = this.arrayOrEmpty(formData.itemsByType['sort']); + formData.signesdraconiques = this.arrayOrEmpty(formData.itemsByType['signedraconique']); + formData.queues = this.arrayOrEmpty(formData.itemsByType['queue']); + formData.souffles = this.arrayOrEmpty(formData.itemsByType['souffle']); + formData.ombres = this.arrayOrEmpty(formData.itemsByType['ombre']); + formData.tetes = this.arrayOrEmpty(formData.itemsByType['tete']); + formData.taches = this.arrayOrEmpty(formData.itemsByType['tache']); + formData.meditations = this.arrayOrEmpty(formData.itemsByType['meditation']); + formData.chants = this.arrayOrEmpty(formData.itemsByType['chant']); + formData.danses = this.arrayOrEmpty(formData.itemsByType['danse']); + formData.musiques = this.arrayOrEmpty(formData.itemsByType['musique']); + formData.oeuvres = this.arrayOrEmpty(formData.itemsByType['oeuvre']); + formData.jeux = this.arrayOrEmpty(formData.itemsByType['jeu']); - formData.recettescuisine = this.checkNull(formData.itemsByType['recettecuisine']); - formData.recettesAlchimiques = this.checkNull(formData.itemsByType['recettealchimique']); - formData.maladies = this.checkNull(formData.itemsByType['maladie']); - formData.poisons = this.checkNull(formData.itemsByType['poison']); - formData.possessions = this.checkNull(formData.itemsByType['possession']); + formData.recettescuisine = this.arrayOrEmpty(formData.itemsByType['recettecuisine']); + formData.recettesAlchimiques = this.arrayOrEmpty(formData.itemsByType['recettealchimique']); + formData.maladies = this.arrayOrEmpty(formData.itemsByType['maladie']); + formData.poisons = this.arrayOrEmpty(formData.itemsByType['poison']); + formData.possessions = this.arrayOrEmpty(formData.itemsByType['possession']); formData.maladiesPoisons = formData.maladies.concat(formData.poisons); formData.competences = (formData.itemsByType.competence ?? []).concat(formData.itemsByType.competencecreature ?? []); } static filterEquipementParType(formData) { - formData.conteneurs = this.checkNull(formData.itemsByType['conteneur']); + formData.conteneurs = this.arrayOrEmpty(formData.itemsByType['conteneur']); - formData.materiel = this.checkNull(formData.itemsByType['objet']); - formData.armes = this.checkNull(formData.itemsByType['arme']); - formData.armures = this.checkNull(formData.itemsByType['armure']); - formData.munitions = this.checkNull(formData.itemsByType['munition']); - formData.livres = this.checkNull(formData.itemsByType['livre']); - formData.potions = this.checkNull(formData.itemsByType['potion']); - formData.ingredients = this.checkNull(formData.itemsByType['ingredient']); - formData.herbes = this.checkNull(formData.itemsByType['herbe']); - formData.monnaie = this.checkNull(formData.itemsByType['monnaie']); + formData.materiel = this.arrayOrEmpty(formData.itemsByType['objet']); + formData.armes = this.arrayOrEmpty(formData.itemsByType['arme']); + formData.armures = this.arrayOrEmpty(formData.itemsByType['armure']); + formData.munitions = this.arrayOrEmpty(formData.itemsByType['munition']); + formData.livres = this.arrayOrEmpty(formData.itemsByType['livre']); + formData.potions = this.arrayOrEmpty(formData.itemsByType['potion']); + formData.ingredients = this.arrayOrEmpty(formData.itemsByType['ingredient']); + formData.herbes = this.arrayOrEmpty(formData.itemsByType['herbe']); + formData.monnaie = this.arrayOrEmpty(formData.itemsByType['monnaie']); formData.monnaie.sort(Monnaie.triValeurDenier()); - formData.nourritureboissons = this.checkNull(formData.itemsByType['nourritureboisson']); - formData.gemmes = this.checkNull(formData.itemsByType['gemme']); + formData.nourritureboissons = this.arrayOrEmpty(formData.itemsByType['nourritureboisson']); + formData.gemmes = this.arrayOrEmpty(formData.itemsByType['gemme']); formData.objets = formData.conteneurs .concat(formData.materiel) @@ -414,40 +415,40 @@ export class RdDUtility { /* -------------------------------------------- */ static buildArbreDeConteneurs(conteneurs, objets) { - let objetVersConteneur = {} + let objetVersConteneur = {}; // Attribution des objets aux conteneurs for (let conteneur of conteneurs) { - conteneur.subItems = [] + conteneur.subItems = []; for (let id of conteneur.system.contenu ?? []) { - let objet = objets.find(objet => (id == objet._id)) + let objet = objets.find(objet => (id == objet._id)); if (objet) { objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template - objetVersConteneur[id] = conteneur._id - conteneur.subItems.push(objet) + objetVersConteneur[id] = conteneur._id; + conteneur.subItems.push(objet); } } } for (let conteneur of conteneurs) { - conteneur.system.encTotal = RdDUtility.calculEncContenu(conteneur, objets) + conteneur.system.encTotal = RdDUtility.calculEncContenu(conteneur, objets); } - return objetVersConteneur + return objetVersConteneur; } /* -------------------------------------------- */ static calculEncContenu(conteneur, objets) { const contenuDatas = (conteneur.system.contenu ?? []).filter(id => id != undefined) - .map(id => objets.find(it => (id == it._id)) ) - .filter(it => it) - let enc = Number(conteneur.system.encombrement ?? 0) * Number(conteneur.system.quantite ?? 1) - for (let subContenu of contenuDatas) { - if (subContenu.type == 'conteneur') { - enc += RdDUtility.calculEncContenu(subContenu, objets) + .map(id => Misc.data(objets.find(it => (id == it._id)))) + .filter(it => it); + let enc = Number(conteneur.system.encombrement ?? 0) * Number(conteneur.system.quantite ?? 1); + for (let itemData of contenuDatas) { + if (itemData.type == 'conteneur') { + enc += RdDUtility.calculEncContenu(itemData, objets); } else { - enc += Number(subContenu.system.encombrement ?? 0) * Number(subContenu.system.quantite ?? 1) + enc += Number(itemData.system.encombrement ?? 0) * Number(itemData.system.quantite ?? 1) } } - return enc; + return enc } /* -------------------------------------------- */ @@ -472,6 +473,7 @@ export class RdDUtility { return str; } + /* -------------------------------------------- */ static buildContenu(objet, niveau, afficherContenu) { if (!niveau) niveau = 1; objet.niveau = niveau; @@ -691,9 +693,10 @@ export class RdDUtility { // gestion bouton tchat Acheter html.on("click", '.defense-possession', event => { - let actorId = event.currentTarget.attributes['data-defenderId'].value; - let possessionId = event.currentTarget.attributes['data-possessionId'].value; - RdDPossession.onDefensePossession(actorId, possessionId); + let attackerId = event.currentTarget.attributes['data-attackerId'].value + let defenderId = event.currentTarget.attributes['data-defenderId'].value + let possessionId = event.currentTarget.attributes['data-possessionId'].value + RdDPossession.onDefensePossession(attackerId, defenderId, possessionId) }); // gestion bouton tchat Acheter diff --git a/module/rolldata-ajustements.js b/module/rolldata-ajustements.js index 6263eb05..783d9424 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) => rollData.competence, - getLabel: (rollData, actor) => rollData.competence?.name, - getValue: (rollData, actor) => rollData.competence?.system.niveau, + isUsed: (rollData, actor) => Misc.data(rollData.competence), + getLabel: (rollData, actor) => Misc.data(rollData.competence)?.name, + getValue: (rollData, actor) => Misc.data(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 ?? rollData.competence?.system.default_diffLibre ?? 0 + : rollData.diffLibre ?? Misc.data(rollData.competence)?.data.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) => 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, + isVisible: (rollData, actor) => Misc.data(rollData.arme)?.system.magique && Number(Misc.data(rollData.arme)?.system.ecaille_efficacite) > 0, + isUsed: (rollData, actor) => Misc.data(rollData.arme)?.system.magique && Number(Misc.data(rollData.arme)?.system.ecaille_efficacite) > 0, getLabel: (rollData, actor) => "Ecaille d'Efficacité: ", - getValue: (rollData, actor) => Math.max(Number(rollData.arme?.data.ecaille_efficacite), 0), + getValue: (rollData, actor) => Math.max(Number(Misc.data(rollData.arme)?.system.ecaille_efficacite), 0), }, finesse: { isUsed: (rollData, actor) => RdDBonus.isDefenseAttaqueFinesse(rollData), diff --git a/module/tmr-utility.js b/module/tmr-utility.js index cebf8e83..81829b71 100644 --- a/module/tmr-utility.js +++ b/module/tmr-utility.js @@ -2,7 +2,6 @@ import { TMRRencontres } from "./tmr-rencontres.js"; import { Misc } from "./misc.js"; import { Grammar } from "./grammar.js"; import { RdDDice } from "./rdd-dice.js"; -import { tmrConstants } from "./tmr-constants.js"; /* -------------------------------------------- */ const TMRMapping = { @@ -12,7 +11,7 @@ const TMRMapping = { D1: { type: "fleuve", label: "Fleuve de l'Oubli" }, E1: { type: "monts", label: "Monts de Kanaï" }, F1: { type: "cite", label: "Cité Glauque" }, - G1: { type: "desolation", label: "Désolation de Demain" }, + G1: { type: "desolation", label: "Désolation de Jamais" }, H1: { type: "lac", label: "Lac d’Anticalme" }, I1: { type: "plaines", label: "Plaines Grises" }, J1: { type: "monts", label: "Monts Fainéants" }, @@ -70,7 +69,7 @@ const TMRMapping = { F5: { type: "cite", label: "Cité de Panople" }, G5: { type: "pont", label: "Pont d’Ik" }, H5: { type: "desert", label: "Désert de Krane" }, - I5: { type: "desolation", label: "Désolation de Demain" }, + I5: { type: "desolation", label: "Désolation de Toujours" }, J5: { type: "marais", label: "Marais de Jab" }, K5: { type: "fleuve", label: "Fleuve de l'Oubli" }, L5: { type: "collines", label: "Collines Suaves" }, @@ -86,9 +85,9 @@ const TMRMapping = { H6: { type: "monts", label: "Monts Gurdes" }, I6: { type: "necropole", label: "Nécropole de Xotar" }, J6: { type: "lac", label: "Lac d’Iaupe" }, - K6: { type: "desolation", label: "Désolation de Demain" }, + K6: { type: "desolation", label: "Désolation de Poor" }, L6: { type: "foret", label: "Forêt Gueuse" }, - M6: { type: "desolation", label: "Désolation de Demain" }, + M6: { type: "desolation", label: "Désolation de Presque" }, A7: { type: "plaines", label: "Plaines de l’Arc" }, B7: { type: "marais", label: "Marais Bluants" }, @@ -124,7 +123,7 @@ const TMRMapping = { D9: { type: "pont", label: "Pont d’Orx" }, E9: { type: "fleuve", label: "Fleuve de l'Oubli" }, F9: { type: "plaines", label: "Plaines de Foe" }, - G9: { type: "desolation", label: "Désolation de Demain" }, + G9: { type: "desolation", label: "Désolation de Sel" }, H9: { type: "collines", label: "Collines de Noirseul" }, I9: { type: "fleuve", label: "Fleuve de l'Oubli" }, J9: { type: "marais", label: "Marais Gronchants" }, @@ -146,10 +145,10 @@ const TMRMapping = { L10: { type: "desert", label: "Désert de Nicrop" }, M10: { type: "foret", label: "Forêt de Jajou" }, - A11: { type: "desolation", label: "Désolation de Demain" }, + A11: { type: "desolation", label: "Désolation d’Hier" }, B11: { type: "cite", label: "Cité de Brilz" }, C11: { type: "pont", label: "Pont de Roï" }, - D11: { type: "desolation", label: "Désolation de Demain" }, + D11: { type: "desolation", label: "Désolation de Partout" }, E11: { type: "lac", label: "Lac de Glinster" }, F11: { type: "cite", label: "Cité de Noape" }, G11: { type: "fleuve", label: "Fleuve de l'Oubli" }, @@ -170,7 +169,7 @@ const TMRMapping = { H12: { type: "collines", label: "Collines de Tooth" }, I12: { type: "gouffre", label: "Gouffre Abimeux" }, J12: { type: "cite", label: "Cité Folle" }, - K12: { type: "desolation", label: "Désolation de Demain" }, + K12: { type: "desolation", label: "Désolation d’Amour" }, L12: { type: "plaines", label: "Plaines Venteuses" }, M12: { type: "collines", label: "Collines Révulsantes" }, @@ -181,7 +180,7 @@ const TMRMapping = { E13: { type: "plaines", label: "Plaines de Xnez" }, F13: { type: "foret", label: "Forêt des Cris" }, G13: { type: "plaines", label: "Plaines Calcaires" }, - H13: { type: "desolation", label: "Désolation de Demain" }, + H13: { type: "desolation", label: "Désolation de Rien" }, I13: { type: "monts", label: "Monts Bigleux" }, J13: { type: "gouffre", label: "Gouffre de Gromph" }, K13: { type: "foret", label: "Forêt de Kluth" }, @@ -200,8 +199,8 @@ const TMRMapping = { J14: { type: "desert", label: "Désert de Sank" }, K14: { type: "necropole", label: "Nécropole d’Antinéar" }, L14: { type: "plaines", label: "Plaines de Jislith" }, - M14: { type: "desolation", label: "Désolation de Demain" }, - + M14: { type: "desolation", label: "Désolation d’Après" }, + A15: { type: "cite", label: "Cité de Mielh" }, C15: { type: "plaines", label: "Plaines de Toué" }, E15: { type: "foret", label: "Forêt des Furies" }, diff --git a/module/tmr/effets-draconiques.js b/module/tmr/effets-draconiques.js index 7236b40c..4d6463f6 100644 --- a/module/tmr/effets-draconiques.js +++ b/module/tmr/effets-draconiques.js @@ -16,7 +16,7 @@ import { Conquete } from "./conquete.js"; import { Pelerinage } from "./pelerinage.js"; import { Periple } from "./periple.js"; import { UrgenceDraconique } from "./urgence-draconique.js"; -import { Misc } from "../misc.js"; +import { Grammar } from "../grammar.js"; export class EffetsDraconiques { @@ -111,36 +111,42 @@ export class EffetsDraconiques { ); } + static filterItems(actor, filter, name) { + return actor.data.items.filter(filter) + .filter(it => Grammar.includesLowerCaseNoAccent(it.name, name)); + } + static isDonDoubleReve(actor) { - return actor.data.items.find(it => Draconique.isTeteDragon(it) && it.name == 'Don de double-rêve'); + return EffetsDraconiques.filterItems(actor, Draconique.isTeteDragon, 'Don de double-rêve').length>0; } static isConnaissanceFleuve(actor) { - return actor.data.items.find(it => Draconique.isTeteDragon(it) && it.name.toLowerCase().includes('connaissance du fleuve')); + return EffetsDraconiques.filterItems(actor, Draconique.isTeteDragon, 'connaissance du fleuve').length>0; } static isReserveEnSecurite(actor) { - return actor.data.items.find(it => Draconique.isTeteDragon(it) && it.name.toLowerCase().includes(' en sécurité')); + return EffetsDraconiques.filterItems(actor, Draconique.isTeteDragon, 'réserve en sécurité').length>0; } static isDeplacementAccelere(actor) { - return actor.data.items.find(it => Draconique.isTeteDragon(it) && it.name.toLowerCase().includes(' déplacement accéléré')); + return EffetsDraconiques.filterItems(actor, Draconique.isTeteDragon, ' déplacement accéléré').length>0; } static isDoubleResistanceFleuve(actor) { - return actor.data.items.find(it => Draconique.isSouffleDragon(it) && it.name.toLowerCase().includes('résistance du fleuve')); + return EffetsDraconiques.filterItems(actor, Draconique.isSouffleDragon, 'résistance du fleuve').length>0; } static countInertieDraconique(actor) { - return actor.data.items.filter(it => Draconique.isQueueDragon(it) && it.name.toLowerCase().includes('inertie draconique')).length; + return EffetsDraconiques.filterItems(actor, Draconique.isQueueDragon, 'inertie draconique').length; } static countMonteeLaborieuse(actor) { - return actor.data.items.filter(it => Draconique.isQueueSouffle(it) && it.name.toLowerCase().includes('montée laborieuse')).length; + return EffetsDraconiques.filterItems(actor, Draconique.isQueueSouffle, 'montée laborieuse').length; } static mauvaiseRencontre(actor) { - return actor.data.items.find(it => Draconique.isQueueSouffle(it) && it.name.toLowerCase().includes('mauvaise rencontre')); + const mauvaisesRencontres = EffetsDraconiques.filterItems(actor, Draconique.isQueueSouffle, 'mauvaise rencontre'); + return mauvaisesRencontres.length>0 ? mauvaisesRencontres[0] : undefined; } static isPontImpraticable(actor) { @@ -152,7 +158,7 @@ export class EffetsDraconiques { } static isPeage(actor) { - return actor.data.items.find(it => Draconique.isSouffleDragon(it) && it.name.toLowerCase().includes('péage')); + return EffetsDraconiques.filterItems(actor, Draconique.isSouffleDragon, 'péage').length > 0; } diff --git a/module/tmr/pixi-tmr.js b/module/tmr/pixi-tmr.js index 368e0e00..a5f6cbbe 100644 --- a/module/tmr/pixi-tmr.js +++ b/module/tmr/pixi-tmr.js @@ -25,7 +25,7 @@ export class PixiTMR { for (const [name, img] of Object.entries(PixiTMR.textures)) { loader = loader.add(name, img); } - loader.onLoad.add((error, resaon) => { console.log("ERROR", error, resaon) }); + loader.onLoad.add((error, reason) => { console.log("ERROR", error, reason) }); loader.load( (loader, resources) => { onLoad(loader, resources); for (let onAnimate of this.callbacksOnAnimate) { diff --git a/templates/actor-creature-sheet.html b/templates/actor-creature-sheet.html index ae2249fc..1ab46cbb 100644 --- a/templates/actor-creature-sheet.html +++ b/templates/actor-creature-sheet.html @@ -55,7 +55,6 @@ {{/each}}
  • Total Caractéristiques - {{log 'data-actor-creature' this}} {{calc.caracTotal}}
  • @@ -103,11 +102,11 @@ {{comp.name}} + value="{{comp.data.carac_value}}" data-dtype="number" /> + value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" /> + value="{{numberFormat comp.data.dommages decimals=0 sign=true}}" data-dtype="number" />
    @@ -166,9 +165,9 @@
    -
    +

    Description

    - {{editor content=data.description target="data.description" button=true owner=owner editable=editable}} + {{editor data.description target="system.description" button=true owner=owner editable=true}}
    {{>"systems/foundryvtt-reve-de-dragon/templates/actor-sheet-editor-notes-mj.html"}} diff --git a/templates/actor-entite-sheet.html b/templates/actor-entite-sheet.html index 04aa7108..b9d1f1be 100644 --- a/templates/actor-entite-sheet.html +++ b/templates/actor-entite-sheet.html @@ -99,11 +99,11 @@ {{comp.name}} + value="{{comp.data.carac_value}}" data-dtype="number" /> + value="{{numberFormat comp.data.niveau decimals=0 sign=true}}" data-dtype="number" /> + value="{{numberFormat comp.data.dommages decimals=0 sign=true}}" data-dtype="number" />
    @@ -133,7 +133,7 @@ {{!-- Biography Tab --}}
    - {{editor content=data.description target="data.description" button=true owner=owner editable=editable}} + {{editor data.description target="system.description" button=true owner=owner editable=true}}
    {{>"systems/foundryvtt-reve-de-dragon/templates/actor-sheet-editor-notes-mj.html"}}
    diff --git a/templates/actor-sheet-competence-partial.html b/templates/actor-sheet-competence-partial.html index 4cd32545..5080290e 100644 --- a/templates/actor-sheet-competence-partial.html +++ b/templates/actor-sheet-competence-partial.html @@ -1,11 +1,11 @@ -{{#if isVisible}} -
  • +{{#if visible}} +
  • {{name}} - {{#if data.isLevelUp}} + {{#if system.isLevelUp}} Vous pouvez dépenser {{system.xpNext}} points d'Experience pour augmenter de 1 votre compétence {{name}} @@ -32,8 +32,8 @@
    {{#if system.stressXpMax}} - + title="Dépenser {{system.stressXpMax}} points de stress {{#if system.isStressLevelUp}} pour augmenter d'un niveau {{/if}}"> + {{else}} diff --git a/templates/actor-sheet-editor-notes-mj.html b/templates/actor-sheet-editor-notes-mj.html index c37d5b91..11858afe 100644 --- a/templates/actor-sheet-editor-notes-mj.html +++ b/templates/actor-sheet-editor-notes-mj.html @@ -1,6 +1,6 @@ {{#if options.isGM}}

    Notes du MJ :

    - {{editor content=data.notesmj target="data.notesmj" button=true owner=owner editable=editable}} + {{editor system.notesmj target="system.notesmj" button=true owner=owner editable=editable}}
    {{/if}} diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index ca143ec7..e848e5bc 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -286,7 +286,7 @@
  • {{#each combat as |arme key|}}
  • + data-arme-name="{{arme.name}}" data-competence-name="{{arme.data.competence}}" > {{#if arme.img}} @@ -295,10 +295,10 @@ {{arme.name}} - {{arme.system.initiative}} - {{arme.system.competence}} - {{numberFormat arme.system.niveau decimals=0 sign=true}} - {{numberFormat arme.system.dommagesReels decimals=0 sign=true}} + {{arme.data.initiative}} + {{arme.data.competence}} + {{numberFormat arme.data.niveau decimals=0 sign=true}} + {{numberFormat arme.data.dommagesReels decimals=0 sign=true}}
  • {{/each}} {{#each esquives as |esq key|}} @@ -307,12 +307,11 @@ {{esq.name}} - {{log esq}} - {{numberFormat esq.system.niveau decimals=0 sign=true}} + {{numberFormat esq.data.niveau decimals=0 sign=true}} {{/each}} @@ -334,7 +333,7 @@ {{#each maladiesPoisons as |maladie key|}}
  • - {{#if (or @root.options.isGM maladie.system.identifie)}} + {{#if (or @root.options.isGM maladie.data.identifie)}} {{maladie.name}} {{else}} Inconnue @@ -342,8 +341,8 @@ {{maladie.type}} - {{#if (or @root.options.isGM maladie.system.remedesconnus)}} - {{maladie.system.remedes}} + {{#if (or @root.options.isGM maladie.data.remedesconnus)}} + {{maladie.data.remedes}} {{else}} Remèdes Inconnus {{/if}} @@ -366,7 +365,7 @@ {{#each possessions as |possession key|}}
  • - {{possession.name}} + {{possession.name}} (Conjurer) {{possession.system.type}}
    @@ -408,7 +407,7 @@ {{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-oeuvre-partial.html" oeuvre=danse typeOeuvre="Danse" classOeuvre="danse-label"}} {{/each}} {{#each oeuvres as |oeuvre id|}} - {{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-oeuvre-partial.html" oeuvre=oeuvre typeOeuvre=oeuvre.data.competence classOeuvre="oeuvre-label"}} + {{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-oeuvre-partial.html" oeuvre=oeuvre typeOeuvre=oeuvre.system.competence classOeuvre="oeuvre-label"}} {{/each}} {{#each recettescuisine as |recette id|}} {{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-oeuvre-partial.html" oeuvre=recette typeOeuvre="Recette de cuisine" classOeuvre="recettecuisine-label"}} @@ -509,65 +508,8 @@

    - {{#if data.attributs.hautrevant.value}} - {{#if options.isGM}} -

    Signes draconiques

    -
      - {{#each signesdraconiques as |signe key|}} -
    • - {{signe.name}} - {{signe.system.difficulte}} -
      - -
      -
    • - {{/each}} -
    - {{/if}} -

    Sorts:

    -
      - {{#each sorts as |sort key|}} -
    • - {{sort.name}} - {{sort.system.draconic}} / {{sort.system.difficulte}} -
      - -
      -
    • - {{/each}} -
    - -

    Sorts en Réserve:

    -
      - {{#each hautreve.sortsReserve as |reserve key|}} -
    • - - {{reserve.sort.name}} - r{{reserve.sort.data.ptreve_reel}} - {{reserve.coord}} - {{caseTmr-label reserve.coord}} -
      - -
      -
    • - {{/each}} -
    - -

    Méditations:

    - -
    - {{/if}} {{!-- Queues, Souffles, Tetes, Ombre --}} + {{#if queues.length}}

    Queues:

      {{#each queues as |queue key|}} @@ -579,28 +521,8 @@ {{/each}}
    -

    Souffles:

    -
      - {{#each souffles as |souffle key|}} -
    • - {{souffle.name}} -
      - -
      -
    • - {{/each}} -
    -

    Tetes:

    -
      - {{#each tetes as |tete key|}} -
    • - {{tete.name}} -
      - -
      -
    • - {{/each}} -
    + {{/if}} + {{#if ombres.length}}

    Ombres de Thanatos:

      {{#each ombres as |ombre key|}} @@ -612,35 +534,128 @@ {{/each}}
    + {{/if}} + {{#if souffles.length}} +

    Souffles:

    +
      + {{#each souffles as |souffle key|}} +
    • + {{souffle.name}} +
      + +
      +
    • + {{/each}} +
    + {{/if}} + {{#if tetes.length}} +

    Tetes:

    +
      + {{#each tetes as |tete key|}} +
    • + {{tete.name}} +
      + +
      +
    • + {{/each}} +
    + {{/if}} {{#if data.attributs.hautrevant.value}} + {{#if (and options.isGM signesdraconiques.length)}} +

    Signes draconiques

    +
      + {{#each signesdraconiques as |signe key|}} +
    • + {{signe.name}} + {{signe.data.difficulte}} +
      + +
      +
    • + {{/each}} +
    + {{/if}} + + {{#if hautreve.rencontres.length}} +

    Rencontres présentes:

    +
      + {{#each hautreve.rencontres as |rencontre key|}} +
    • + {{rencontre.name}} r{{rencontre.force}} + {{rencontre.coord}} - {{caseTmr-label rencontre.coord}} + {{#if rencontre.date}} + {{upperFirst rencontre.heure}}, le {{rencontre.date}} + {{/if}} +
      + +
      +
    • + {{/each}} +
    + {{/if}} + {{#if hautreve.sortsReserve.length}} +

    Sorts en Réserve:

    +
      + {{#each hautreve.sortsReserve as |reserve key|}} +
    • + + {{reserve.sort.name}} r{{reserve.sort.data.ptreve_reel}} + {{reserve.coord}} - {{caseTmr-label reserve.coord}} +
      + +
      +
    • + {{/each}} +
    + {{/if}} + +
    + +

    Sorts:

    + + +

    Méditations:

    +
    -

    Rencontres présentes:

    -
      - {{#each hautreve.rencontres as |rencontre key|}} -
    • - {{rencontre.name}} - {{rencontre.coord}} - {{caseTmr-label rencontre.coord}} - {{#if rencontre.date}} - Le {{rencontre.date}} à {{rencontre.heure}} - {{/if}} -
      - -
      -
    • - {{/each}} -
    -
    -

    Cases Spéciales:

    -
      - {{#each hautreve.casesTmr as |casetmr key|}} -
    • - {{casetmr.name}} -
      - -
      -
    • - {{/each}} -
    + {{#if hautreve.casesTmr}} +

    Cases Spéciales:

    +
      + {{#each hautreve.casesTmr as |casetmr key|}} +
    • + {{casetmr.name}} + {{casetmr.data.coord}} - {{caseTmr-label casetmr.data.coord}} +
      + +
      +
    • + {{/each}} +
    + {{/if}}

    {{/if}}
  • @@ -780,11 +795,11 @@

    Biographie :

    - {{editor content=data.biographie target="data.biographie" button=true owner=owner editable=editable}} + {{editor data.biographie target="system.biographie" button=true owner=owner editable=editable}}

    Notes :

    - {{editor content=data.notes target="data.notes" button=true owner=owner editable=editable}} + {{editor data.notes target="system.notes" button=true owner=owner editable=editable}}

    Journal d'Experience

    diff --git a/templates/actor-vehicule-sheet.html b/templates/actor-vehicule-sheet.html index aa7aff63..1e645e71 100644 --- a/templates/actor-vehicule-sheet.html +++ b/templates/actor-vehicule-sheet.html @@ -92,10 +92,10 @@
  • {{item.name}} - {{item.system.quantite}} - {{numberFormat item.system.encTotal decimals=2}} + {{item.data.quantite}} + {{numberFormat item.data.encTotal decimals=2}} diff --git a/templates/chat-resultat-possession.html b/templates/chat-resultat-possession.html index 9b0c6d7c..025ba08a 100644 --- a/templates/chat-resultat-possession.html +++ b/templates/chat-resultat-possession.html @@ -30,4 +30,11 @@ {{/if}}
    Points de Possession: {{possession.ptsPossession}}
    Points de Conjuration: {{possession.ptsConjuration}} + + {{#if possession.isPosseder}} +
    Vous êtes été possédé par {{possession.data.typepossession}} ! La possession en cours a été supprimée. + {{/if}} + {{#if possession.isConjurer}} +
    Vous avez conjuré {{possession.data.typepossession}} ! La possession en cours a été supprimée. + {{/if}}
  • diff --git a/templates/competence-carac-defaut.html b/templates/competence-carac-defaut.html index c7c4d740..3c68c3fc 100644 --- a/templates/competence-carac-defaut.html +++ b/templates/competence-carac-defaut.html @@ -15,3 +15,4 @@ + diff --git a/templates/dialog-create-signedraconique.html b/templates/dialog-create-signedraconique.html index 53cf9bf4..44a7e941 100644 --- a/templates/dialog-create-signedraconique.html +++ b/templates/dialog-create-signedraconique.html @@ -8,33 +8,33 @@
    - - + +
    - + Sign. - + Part. - +
    - + - +
    diff --git a/templates/dialog-roll-chant.html b/templates/dialog-roll-chant.html index d67de505..8f72f568 100644 --- a/templates/dialog-roll-chant.html +++ b/templates/dialog-roll-chant.html @@ -6,7 +6,7 @@ {{competence.name}}
    - +
    {{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html" oeuvre.data}}
    diff --git a/templates/dialog-roll-competence.html b/templates/dialog-roll-competence.html index 0e33f2a9..86d26d22 100644 --- a/templates/dialog-roll-competence.html +++ b/templates/dialog-roll-competence.html @@ -43,9 +43,9 @@ {{#if arme}} {{#unless attackerRoll}}
    - {{#if (eq arme.system.mortalite 'non-mortel')}} + {{#if (eq arme.data.mortalite 'non-mortel')}} - {{else if (eq arme.system.mortalite 'empoignade')}} + {{else if (eq arme.data.mortalite 'empoignade')}} {{else}} diff --git a/templates/dialog-roll-danse.html b/templates/dialog-roll-danse.html index f5884fd7..65d3376e 100644 --- a/templates/dialog-roll-danse.html +++ b/templates/dialog-roll-danse.html @@ -6,7 +6,7 @@ {{competence.name}}
    {{>"systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html"}} - +
    {{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html" oeuvre.data}}
    diff --git a/templates/dialog-roll-jeu.html b/templates/dialog-roll-jeu.html index af7356f2..049a1512 100644 --- a/templates/dialog-roll-jeu.html +++ b/templates/dialog-roll-jeu.html @@ -7,8 +7,8 @@
    {{>"systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html"}} - - + +
    diff --git a/templates/dialog-roll-maitrise-tmr.html b/templates/dialog-roll-maitrise-tmr.html index 5b0517c9..7408b24d 100644 --- a/templates/dialog-roll-maitrise-tmr.html +++ b/templates/dialog-roll-maitrise-tmr.html @@ -5,7 +5,7 @@ {{competence.name}}
    - +
    diff --git a/templates/dialog-roll-meditation.html b/templates/dialog-roll-meditation.html index f6ef1df4..718ae819 100644 --- a/templates/dialog-roll-meditation.html +++ b/templates/dialog-roll-meditation.html @@ -4,14 +4,14 @@
    {{competence.name}}
    - +
    - - + +
    + {{numberFormat carac.intellect.value decimals=0 sign=false}} / {{numberFormat competence.data.niveau decimals=0 sign=true}}
    @@ -19,19 +19,19 @@
    - +
    - +
    - +
    - +

    diff --git a/templates/dialog-roll-musique.html b/templates/dialog-roll-musique.html index f435998b..b93161f1 100644 --- a/templates/dialog-roll-musique.html +++ b/templates/dialog-roll-musique.html @@ -6,9 +6,9 @@ {{competence.name}}
    - +
    - {{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html" oeuvre.system}} + {{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html" oeuvre.data}}
    {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffFixe.html"}} diff --git a/templates/dialog-roll-recettecuisine.html b/templates/dialog-roll-recettecuisine.html index 5a03c1ab..394ff935 100644 --- a/templates/dialog-roll-recettecuisine.html +++ b/templates/dialog-roll-recettecuisine.html @@ -9,10 +9,10 @@
    - +
    - +
    diff --git a/templates/dialog-roll-reve-de-dragon.html b/templates/dialog-roll-reve-de-dragon.html index 308c6fdf..5e93afda 100644 --- a/templates/dialog-roll-reve-de-dragon.html +++ b/templates/dialog-roll-reve-de-dragon.html @@ -5,7 +5,7 @@ {{competence.name}}
    - +
    diff --git a/templates/dialog-roll-signedraconique.html b/templates/dialog-roll-signedraconique.html index 0bff6729..051341ec 100644 --- a/templates/dialog-roll-signedraconique.html +++ b/templates/dialog-roll-signedraconique.html @@ -1,4 +1,3 @@ -{{log 'lecture signe draconique' this}}

    Lire le signe draconique {{#select draconic}} {{#each draconicList as |draconic key|}} - {{/each}} {{/select}} diff --git a/templates/hud-actor-attaque.html b/templates/hud-actor-attaque.html index ece3180a..50c2f82b 100644 --- a/templates/hud-actor-attaque.html +++ b/templates/hud-actor-attaque.html @@ -2,9 +2,9 @@
    {{#each armes as |arme key|}} - {{#unless arme.system.initOnly}} + {{#unless arme.data.initOnly}}
    - +
    {{/unless}} {{/each}} diff --git a/templates/hud-actor-init.html b/templates/hud-actor-init.html index 35f265dc..48ea33ae 100644 --- a/templates/hud-actor-init.html +++ b/templates/hud-actor-init.html @@ -3,7 +3,7 @@
    {{#each armes as |arme key|}}
    - +
    {{/each}} {{#each commandes as |commande key|}} diff --git a/templates/item-possession-sheet.html b/templates/item-possession-sheet.html new file mode 100644 index 00000000..011a1e0f --- /dev/null +++ b/templates/item-possession-sheet.html @@ -0,0 +1,29 @@ + +
    + +
    +

    +
    +
    + + {{!-- Sheet Body --}} +
    +
    + + +
    +
    + + +
    +
    + + +
    + + + {{>"systems/foundryvtt-reve-de-dragon/templates/partial-item-description.html"}} + +
    + + diff --git a/templates/item-tache-sheet.html b/templates/item-tache-sheet.html index 805ba0be..fac2fe3d 100644 --- a/templates/item-tache-sheet.html +++ b/templates/item-tache-sheet.html @@ -11,7 +11,7 @@
    - {{#select data.competence}} + {{#select system.competence}} {{#each competences as |competence key|}} {{/each}} @@ -30,24 +30,24 @@
    - +
    - +
    - +
    {{#if isGM}}
    - +
    - +
    {{else}}
    @@ -55,22 +55,22 @@ {{#if data.cacher_points_de_tache}} {{else}} - + {{/if}}
    {{/if}}
    - +
    - +
    - +
    {{>"systems/foundryvtt-reve-de-dragon/templates/partial-item-description.html"}} diff --git a/templates/partial-description-sort.html b/templates/partial-description-sort.html index 841eeb6b..1174e0c7 100644 --- a/templates/partial-description-sort.html +++ b/templates/partial-description-sort.html @@ -1,10 +1,10 @@
    - {{#if sort.system.cible}}{{/if}} - {{#if sort.system.JR}}{{/if}} - {{#if sort.system.portee}}{{/if}} - {{#if sort.system.duree}}{{/if}} - {{#if sort.system.coutseuil}}{{/if}} + {{#if sort.data.cible}}{{/if}} + {{#if sort.data.JR}}{{/if}} + {{#if sort.data.portee}}{{/if}} + {{#if sort.data.duree}}{{/if}} + {{#if sort.data.coutseuil}}{{/if}}
    - {{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html" sort.system}} + {{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html" sort.data}}
    \ No newline at end of file diff --git a/templates/partial-item-description.html b/templates/partial-item-description.html index 0a39a6db..8e77ad41 100644 --- a/templates/partial-item-description.html +++ b/templates/partial-item-description.html @@ -1,14 +1,14 @@
    - {{editor content=system.description target="system.description" button=true owner=owner editable=editable}} + {{editor data.description target="system.description" button=true owner=owner editable=editable}}
    {{#if isGM}}
    - {{editor content=system.descriptionmj target="system.descriptionmj" button=true owner=owner editable=editable}} + {{editor data.descriptionmj target="system.descriptionmj" button=true owner=owner editable=editable}}
    {{/if}} \ No newline at end of file diff --git a/templates/post-item.html b/templates/post-item.html index 380dcdcc..57ef44aa 100644 --- a/templates/post-item.html +++ b/templates/post-item.html @@ -4,7 +4,7 @@ {{/if}} -

    {{{system.description}}}

    +

    {{{data.description}}}

    {{#each properties as |property p|}} {{{property}}}