diff --git a/module/actor.js b/module/actor.js index ce985271..66a9dedb 100644 --- a/module/actor.js +++ b/module/actor.js @@ -2315,15 +2315,17 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _rollArt(artData, selected, oeuvre, callBackResult = r => this._resultArt(r)) { const actorData = Misc.data(this); - mergeObject(artData, { - oeuvre: oeuvre, - art: oeuvre.type, - competence: Misc.data(this.getCompetence(oeuvre.data.competence ?? artData.art)), - diffLibre: - (oeuvre.data.niveau ?? 0), - diffConditions: 0, - use: { libre: false, conditions: true }, - selectedCarac: duplicate(actorData.data.carac[selected]) - }); + mergeObject(artData, + { + oeuvre: oeuvre, + art: oeuvre.type, + competence: duplicate(Misc.data(this.getCompetence(oeuvre.data.competence ?? artData.art))), + diffLibre: - (oeuvre.data.niveau ?? 0), + diffConditions: 0, + use: { libre: false, conditions: true }, + selectedCarac: duplicate(actorData.data.carac[selected]) + }, + { overwrite: false }); artData.competence.data.defaut_carac = selected; if (!artData.forceCarac) { artData.forceCarac = {}; @@ -2366,13 +2368,13 @@ export class RdDActor extends Actor { const actorData = Misc.data(this); const artData = { art: 'danse', verbe: 'Danser', forceCarac: {} }; const oeuvre = duplicate(this.getItemOfType(id, artData.art)); - const selectedCarac = this._getCaracDanse(oeuvre); if (oeuvre.data.agilite) { artData.forceCarac['agilite'] = duplicate(actorData.data.carac.agilite); } if (oeuvre.data.apparence) { artData.forceCarac['apparence'] = duplicate(actorData.data.carac.apparence); } + const selectedCarac = this._getCaracDanse(oeuvre); await this._rollArt(artData, selectedCarac, oeuvre); } @@ -2434,12 +2436,21 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async rollJeu(id) { + const actorData = Misc.data(this); + const oeuvre = Misc.data(this.getJeu(id)); + + const listCarac = oeuvre.data.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'))), + forceCarac: {} }; - const oeuvre = duplicate(this.getJeu(id)); - await this._rollArt(artData, oeuvre.data?.caraccomp.toLowerCase() ?? 'chance', oeuvre); + listCarac.forEach(c => artData.forceCarac[c] = actorData.data.carac[c]); + artData.competence.data.niveauReel = artData.competence.data.niveau; + artData.competence.data.niveau = Math.max(artData.competence.data.niveau, oeuvre.data.base); + await this._rollArt(artData, carac, oeuvre); } async rollOeuvre(id) { @@ -2597,9 +2608,8 @@ export class RdDActor extends Actor { let xpComp = 0; if (competence) { xpComp = xp - xpCarac; - competence = duplicate(competence); - competence.data.xp = Misc.toInt(competence.data.xp) + xpComp; - await this.updateEmbeddedDocuments('Item', [competence]); + let update = { _id: competence.id, 'data.xp': Misc.toInt(competence.data.xp) + xpComp }; + await this.updateEmbeddedDocuments('Item', [update]); } else { xpCarac = Math.max(xpCarac, 1); } @@ -3202,24 +3212,33 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async effectuerTacheAlchimie(recetteId, alchimieName, alchimieData) { - let recette = this.getItemOfType(recetteId, 'recettealchimique'); + async effectuerTacheAlchimie(recetteId, tacheAlchimie, texteTache) { + let recetteData = Misc.data(this.getItemOfType(recetteId, 'recettealchimique')); const actorData = Misc.data(this); - if (recette) { - let competence = Misc.data(this.getCompetence("alchimie")); - let diffAlchimie = RdDAlchimie.getDifficulte(alchimieData); + if (recetteData) { + if (tacheAlchimie != "couleur" && tacheAlchimie != "consistance") { + ui.notifications.warn(`L'étape alchimique ${tacheAlchimie} - ${texteTache} est inconnue`); + return; + } + + 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: recette, - competence: competence, - diffLibre: diffAlchimie // Per default at startup - } - if (alchimieName == "couleur") { - rollData.selectedCarac = actorData.data.carac.vue, - rollData.alchimieTexte = `Couleurs ${alchimieData} (${diffAlchimie}) (Malus de -4 si vous ne possédez pas de Cristal Alchimique)`; - } else { - rollData.selectedCarac = actorData.data.carac.dexterite, - rollData.alchimieTexte = `Consistances ${alchimieData} (${diffAlchimie})`; + recette: recetteData, + carac: { [caracTache]: actorData.data.carac[caracTache] }, + selectedCarac: actorData.data.carac[caracTache], + competence: alchimieData, + diffLibre: RdDAlchimie.getDifficulte(texteTache), + diffConditions: sansCristal ? -4 : 0, + alchimie: { + tache: Misc.upperFirst(tacheAlchimie), + texte: texteTache, + sansCristal: sansCristal + } } + rollData.competence.data.defaut_carac = caracTache; const dialog = await RdDRoll.create(this, rollData, { @@ -3239,6 +3258,10 @@ export class RdDActor extends Actor { } } + isCristalAlchimique(it) { + return it.type == 'objet' && Grammar.toLowerCaseNoAccent(it.name) == 'cristal alchimique' && it.data.quantite > 0; + } + /* -------------------------------------------- */ _alchimieResult(rollData) { RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-alchimie.html'); diff --git a/module/item.js b/module/item.js index 8c78388c..5259d4b5 100644 --- a/module/item.js +++ b/module/item.js @@ -33,6 +33,12 @@ export class RdDItem extends Item { isEquipement() { return RdDItem.getTypeObjetsEquipement().includes(Misc.data(this).type); } + + isCristalAlchimique() { + const itemData = Misc.data(this); + return itemData.type == 'objet' && Grammar.toLowerCaseNoAccent(itemData.name) == 'cristal alchimique' && itemData.data.quantite > 0; + } + getEnc() { const itemData = Misc.data(this); diff --git a/module/rdd-alchimie.js b/module/rdd-alchimie.js index 4fac68ac..58611457 100644 --- a/module/rdd-alchimie.js +++ b/module/rdd-alchimie.js @@ -53,4 +53,13 @@ export class RdDAlchimie { } return Math.min(0, -composantes); } + + static getCaracTache(tache) { + switch (tache) { + case "consistance": return 'dexterite'; + case "couleur": return 'vue'; + } + return 'intellect'; + } + } diff --git a/module/rdd-roll.js b/module/rdd-roll.js index 2ee9d7d9..943d4697 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -285,7 +285,7 @@ export class RdDRoll extends Dialog { HtmlUtility._showControlWhen($("#ajust-astrologique"), RdDResolutionTable.isAjustementAstrologique(rollData)); // Mise à jour valeurs - $("#compdialogTitle").text(this._getTitle(rollData)); + $(".dialog-roll-title").text(this._getTitle(rollData)); $('#coupsNonMortels').prop('checked', rollData.coupsNonMortels); $(".dmg-arme-actor").text(dmgText); $('.table-ajustement').remove(); @@ -299,7 +299,7 @@ export class RdDRoll extends Dialog { /* -------------------------------------------- */ async buildAjustements(rollData) { - const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/dialog-roll-ajustements.html`, rollData); + const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/partial-roll-ajustements.html`, rollData); return html; } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index bb5ed094..5d690f0c 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -147,7 +147,6 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/niveau-ethylisme.html', 'systems/foundryvtt-reve-de-dragon/templates/casetmr-specific-list.html', // Dialogs - 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-ajustements.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-resolution.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', @@ -155,10 +154,16 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-encaisser.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-meditation.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', - 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-surenc.html', - 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-enctotal.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-alchimie.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', + // Partials + 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-ajustements.html', + 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffLibre.html', + 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffCondition.html', + 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-surenc.html', + 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-enctotal.html', + 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-moral.html', + 'systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html', // Calendrier 'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html', 'systems/foundryvtt-reve-de-dragon/templates/calendar-editor-template.html', diff --git a/styles/simple.css b/styles/simple.css index e5e83279..254dd5b0 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -528,6 +528,12 @@ section.sheet-body:after { text-align: left; width: 50px; } +.select-carac { + display: inline-block; + text-align: left; + width: 100%; + max-width: 90%; +} #vie-plus, #vie-moins, #endurance-plus, #endurance-moins, #fatigue-plus, #fatigue-moins, #ptreve-actuel-plus, #ptreve-actuel-moins, .monnaie-plus, .monnaie-moins { display: inline-block; diff --git a/templates/dialog-competence.html b/templates/dialog-competence.html index 5d7cebbf..46d45fec 100644 --- a/templates/dialog-competence.html +++ b/templates/dialog-competence.html @@ -1,17 +1,12 @@