diff --git a/module/actor.js b/module/actor.js index 8180fee1..a97b6bfe 100644 --- a/module/actor.js +++ b/module/actor.js @@ -19,6 +19,7 @@ import { RdDItemArme } from "./item-arme.js"; import { RdDAlchimie } from "./rdd-alchimie.js"; import { StatusEffects } from "./status-effects.js"; import { RdDItemCompetenceCreature } from "./item-competencecreature.js"; +import { RdDItemSigneDraconique } from "./item-signedraconique.js"; import { ReglesOptionelles } from "./regles-optionelles.js"; import { TMRRencontres } from "./tmr-rencontres.js"; import { Poetique } from "./poetique.js"; @@ -1691,7 +1692,7 @@ export class RdDActor extends Actor { // enduranceLostRoll.showDice = true; RdDDice.show(enduranceLostRoll); let enduranceLost = enduranceLostRoll.total; - let perteEndurance = await this.santeIncDec("endurance", -enduranceLost, {ethylisme: true}); + let perteEndurance = await this.santeIncDec("endurance", -enduranceLost, { ethylisme: true }); let jetEnduranceView = { ethylismeEtape: 'Endurance', enduranceLost: perteEndurance.perte, @@ -1725,7 +1726,7 @@ export class RdDActor extends Actor { RdDResolutionTable.displayRollData(jetVolonteView, this, 'chat-resultat-ethylisme.html'); } - await this.update({'data.compteurs.ethylisme': ethylisme}); + await this.update({ 'data.compteurs.ethylisme': ethylisme }); } /* -------------------------------------------- */ @@ -2283,7 +2284,7 @@ export class RdDActor extends Actor { RdDResolutionTable.displayRollData(rollData, this) return rollData.rolled; } - + /* -------------------------------------------- */ _appliquerExperienceRollData(rollData) { const callback = this.createCallbackExperience(); @@ -2319,6 +2320,11 @@ export class RdDActor extends Actor { }); dialog.render(true); } + + /* -------------------------------------------- */ + async _competenceResult(rollData) { + RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-competence.html') + } /* -------------------------------------------- */ async creerTacheDepuisLivre(item, options = { renderSheet: true }) { @@ -2544,24 +2550,15 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async rollMeditation(id) { let meditation = Misc.data(this.getMeditation(id)); - let competence = Misc.data(this.getCompetence(meditation.data.competence)); - competence.data.defaut_carac = "intellect"; // Meditation = tjs avec intellect let meditationData = { - competence: competence, - meditation: meditation, - conditionMeditation: { - isHeure: false, - isVeture: false, - isComportement: false, - isPurification: false, - }, + competence: duplicate(Misc.data(this.getCompetence(meditation.data.competence))), + meditation: duplicate(meditation), + conditionMeditation: { isHeure: false, isVeture: false, isComportement: false, isPurification: false }, diffConditions: 0, use: { libre: false, conditions: true, }, - carac: {} + carac: { "intellect": Misc.templateData(this).carac.intellect } }; - meditationData.carac["intellect"] = Misc.templateData(this).carac["intellect"]; - - console.log("rollMeditation !!!", meditationData); + meditationData.competence.data.defaut_carac = "intellect"; // Meditation = tjs avec intellect const dialog = await RdDRoll.create(this, meditationData, { @@ -2584,27 +2581,92 @@ export class RdDActor extends Actor { async _meditationResult(meditationData) { this.santeIncDec("fatigue", 2); - meditationData.diffLecture = -7; - if (meditationData.rolled.isPart) - meditationData.diffLecture = 0; - else if (meditationData.rolled.isSign) - meditationData.diffLecture = -3; + const signeData = RdDItemSigneDraconique.prepareSigneDraconiqueMeditation(meditationData.meditation, meditationData.rolled) + if (signeData) { + await this.createEmbeddedDocuments("Item", [signeData]); + } RdDResolutionTable.displayRollData(meditationData, this.name, 'chat-resultat-meditation.html'); } /* -------------------------------------------- */ _meditationEPart(meditationData) { - meditationData.meditation.data.malus--; - this.updateEmbeddedDocuments('Item', [meditationData.meditation]); + this.updateEmbeddedDocuments('Item', [{ _id: meditation._id, 'data.malus': meditationData.meditation.data.malus - 1 }]); + } + + + /* -------------------------------------------- */ + _getSignesDraconiques(coord) { + const type = TMRUtility.getTMRType(coord); + return this.listItemsData("signedraconique").filter(it => it.data.typesTMR.includes(type)); } /* -------------------------------------------- */ - async _competenceResult(rollData) { - RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-competence.html') + isResonanceSigneDraconique(coord) { + return this._getSignesDraconiques(coord).length > 0; } - async _moralDecrease(rollData) { - RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-competence.html') + + /* -------------------------------------------- */ + async rollLireSigneDraconique(coord) { + if (!this.isHautRevant()) { + ui.notifications.info("Seul un haut rêvant peut lire un signe draconique!"); + return; + } + let signes = this._getSignesDraconiques(coord); + if (signes.length == 0) { + ui.notifications.info(`Aucun signe draconiques en ${coord} !`); + return; + } + if (this.currentTMR) this.currentTMR.minimize(); // Hide + + let draconicList = this.getDraconicList() + .map(draconic => duplicate(Misc.data(draconic))) + .map(draconic => { draconic.data.defaut_carac = "intellect"; return draconic; }); + + const intellect = Misc.templateData(this).carac.intellect; + let rollData = { + carac: { 'intellect': intellect }, + selectedCarac: intellect, + competence: draconicList[0], + draconicList: draconicList, + signe: signes[0], + signes: signes, + tmr: TMRUtility.getTMR(coord), + diffLibre: Misc.data(signes[0]).data.difficulte, + } + + const dialog = await RdDRoll.create(this, rollData, + { + html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-signedraconique.html', + options: { height: 600 }, + close: html => { this.currentTMR.maximize() } // Re-display TMR + }, + { + name: 'lire-signe-draconique', + label: 'Lire le signe draconique', + callbacks: [ + this.createCallbackExperience(), + { action: r => this._rollLireSigneDraconique(r) } + ] + } + ); + dialog.render(true); + } + + /* -------------------------------------------- */ + async _rollLireSigneDraconique(rollData) { + const compData = rollData.competence; + if (!RdDItemCompetence.isDraconic(compData)) { + ui.notifications.error(`La compétence ${compData.name} n'est pas une compétence draconique`); + return; + } + 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.deleteEmbeddedDocuments("Item", [rollData.signe._id]); + RdDResolutionTable.displayRollData(rollData, this.name, 'chat-resultat-lecture-signedraconique.html'); + this.currentTMR.close(); } /* -------------------------------------------- */ @@ -2840,6 +2902,7 @@ export class RdDActor extends Actor { fatigue: RdDUtility.calculFatigueHtml(fatigue, endurance), draconic: this.getDraconicList(), sort: this.getSortList(), + signes: this.listItemsData("signedraconique"), caracReve: actorData.data.carac.reve.value, pointsReve: this.getReveActuel(), isRapide: isRapide diff --git a/module/rdd-roll.js b/module/rdd-roll.js index e305965f..1151eb5f 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -205,6 +205,11 @@ export class RdDRoll extends Dialog { this.updateRollResult(); $("#diffLibre").val(this.rollData.diffLibre); }); + html.find('.roll-signedraconique').change((event) => { + let sortKey = Misc.toInt(event.currentTarget.value); + this.setSelectedSigneDraconique(this.rollData.signes[sortKey]); + this.updateRollResult(); + }); html.find('#ptreve-variable').change((event) => { let ptreve = Misc.toInt(event.currentTarget.value); this.rollData.selectedSort.data.ptreve_reel = ptreve; @@ -276,6 +281,12 @@ export class RdDRoll extends Dialog { HtmlUtility._showControlWhen($(".div-sort-ptreve-fixe"), !coutVariable); } + async setSelectedSigneDraconique(signe){ + this.rollData.signe = signe; + this.rollData.diffLibre = Misc.data(signe).data.difficulte, + $(".signe-difficulte").text(Misc.toSignedString(this.rollData.diffLibre)); + } + /* -------------------------------------------- */ async updateRollResult() { let rollData = this.rollData; diff --git a/module/rdd-tmr-dialog.js b/module/rdd-tmr-dialog.js index d593129c..b24a00ef 100644 --- a/module/rdd-tmr-dialog.js +++ b/module/rdd-tmr-dialog.js @@ -183,22 +183,25 @@ export class RdDTMRDialog extends Dialog { async activateListeners(html) { super.activateListeners(html); - HtmlUtility._showControlWhen($(".appliquerFatigue"), ReglesOptionelles.isUsing("appliquer-fatigue")); document.getElementById("tmrrow1").insertCell(0).append(this.pixiApp.view); if (this.viewOnly) { - html.find('#lancer-sort').remove(); - } - else { - // Roll Sort - html.find('#lancer-sort').click((event) => { - this.actor.rollUnSort(Misc.data(this.actor).data.reve.tmrpos.coord); - }); - } - if (this.viewOnly) { + html.find('.lancer-sort').remove(); + html.find('.lire-signe-draconique').remove(); return; } + HtmlUtility._showControlWhen($(".appliquerFatigue"), ReglesOptionelles.isUsing("appliquer-fatigue")); + HtmlUtility._showControlWhen($(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(this._getActorCoord())); + + // Roll Sort + html.find('.lancer-sort').click((event) => { + this.actor.rollUnSort(this._getActorCoord()); + }); + html.find('.lire-signe-draconique').click((event) => { + this.actor.rollLireSigneDraconique(this._getActorCoord()); + }); + html.find('#dir-top').click((event) => { this.moveFromKey("top"); }); @@ -235,6 +238,9 @@ export class RdDTMRDialog extends Dialog { /* -------------------------------------------- */ updateValuesDisplay() { + Array.from(document.getElementsByClassName("lire-signe-draconique")) + .forEach(it => HtmlUtility._showControlWhen(it, this.actor.isResonanceSigneDraconique(this._getActorCoord()))); + let ptsreve = document.getElementById("tmr-pointsreve-value"); const actorData = Misc.data(this.actor); ptsreve.innerHTML = actorData.data.reve.reve.value; diff --git a/templates/chat-resultat-lecture-signedraconique.html b/templates/chat-resultat-lecture-signedraconique.html new file mode 100644 index 00000000..4e1ba3cd --- /dev/null +++ b/templates/chat-resultat-lecture-signedraconique.html @@ -0,0 +1,11 @@ + +