diff --git a/module/actor.js b/module/actor.js
index 924e4ada..64af0d3d 100644
--- a/module/actor.js
+++ b/module/actor.js
@@ -7,6 +7,8 @@ import { RdDUtility } from "./rdd-utility.js";
import { TMRUtility } from "./tmr-utility.js";
import { RdDRollDialog } from "./rdd-roll-dialog.js";
import { RdDTMRDialog } from "./rdd-tmr-dialog.js";
+import { Misc } from "./misc.js";
+
import { RdDResolutionTable } from "./rdd-resolution-table.js";
export class RdDActor extends Actor {
@@ -146,91 +148,45 @@ export class RdDActor extends Actor {
console.log(">>> ROLL", rollData, rolled);
let xpmsg = RdDResolutionTable.buildXpMessage(rolled, rollData.finalLevel);
- let specialStr = "
Points de taches : " + rolled.tache + ", Points de qualité: " + rolled.qualite;
+ let resumeCompetence = (rollData.competence) ? rollData.competence.name : rollData.bmValue;
+ let explications = "
Points de taches : " + rolled.tache + ", Points de qualité: " + rolled.qualite;
// Fight management !
let defenseMsg;
let encaisser = false;
if (rollData.arme || (rollData.competence && rollData.competence.name.toLowerCase() == 'esquive') ) {
+ explications = ""
// In case of fight, replace the message per dommages + localization. it indicates if result is OK or not
if (rollData.attackerRoll) { // Defense case !
if (rolled.isSuccess) {
- specialStr = "
Attaque parée/esquivée !";
+ explications += "
Attaque parée/esquivée !";
} else {
- specialStr = "
Esquive/Parade échouée, encaissement !";
+ explications += "
Esquive/Parade échouée, encaissement !";
encaisser = true;
}
} else { // This is the attack roll!
if (rolled.isSuccess) {
- if (rolled.tache >= 3) { // Critique !
+ if (rolled.isPart) { // Particulière !
console.log("TODO Gérer critique!");
}
- rollData.domArmePlusDom = parseInt(rollData.arme.data.dommages);
- if (rollData.selectedCarac.label == "Mêlée") // +dom only for Melee
- rollData.domArmePlusDom += parseInt(this.data.data.attributs.plusdom.value);
- if (rollData.selectedCarac.label == "Lancer") { // +dom only for Melee/Lancer
- let bdom = parseInt(this.data.data.attributs.plusdom.value);
- if (bdom > parseInt(rollData.arme.data.dommages))
- bdom = parseInt(rollData.arme.data.dommages);
- rollData.domArmePlusDom += bdom
- }
- let encaissement = new Roll("2d10 + @domArmePlusDom", {domArmePlusDom : rollData.domArmePlusDom});
- rollData.degats = parseInt(encaissement.roll().total);
+ rollData.domArmePlusDom = this._calculBonusDommages(rollData.selectedCarac, rollData.arme);
+ rollData.degats = new Roll("2d10").roll().total + rollData.domArmePlusDom;
rollData.loc = RdDUtility.getLocalisation();
for (let target of game.user.targets) {
defenseMsg = RdDUtility.buildDefenseChatCard(this, target, rollData);
- specialStr = "
Cible : " + target.actor.data.name;
+ explications += "
Cible : " + target.actor.data.name;
}
- specialStr += "
Dommages : " + rollData.degats + "
Localisation : " + rollData.loc.label;
+ explications += "
Dommages : " + rollData.degats + "
Localisation : " + rollData.loc.label;
} else {
- specialStr = "
Echec ! Pas de dommages";
+ explications = "
Echec ! Pas de dommages";
}
}
}
// Sort management
- let lvl = ""
if (rollData.selectedSort) { // Lancement de sort !
- let draconic = rollData.selectedSort.data.draconic;
- let costReve = rollData.selectedSort.data.ptreve_reel || rollData.selectedSort.data.ptreve; // cas de sort à ptreve variables
- specialStr = "
Lancement du sort " + rollData.selectedSort.name + " : " + draconic.charAt(0).toUpperCase() + draconic.slice(1) + "/" + rollData.selectedSort.data.difficulte +
- "/" + rollData.selectedSort.data.caseTMR + "/R" + costReve;
- specialStr += "
Depuis la case " + rollData.coord + " (" + TMRUtility.getTMRDescription(rollData.coord).label + ")";
- lvl = rollData.selectedDraconic.name + "/" + rollData.selectedSort.name;
- let myReve = duplicate(this.data.data.reve.reve);
- if (rolled.isSuccess) { // Réussite du sort !
- if (rolled.tache >= 3) costReve = Math.ceil(costReve / 2);
- if (costReve < 1) costReve = 1;
- myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!!
- if (myReve.value < 0) myReve.value = 0;
- await this.update({ "data.reve.reve": myReve });
- specialStr += "
Réussite du sort pour " + costReve + " Points de Rêve";
- if (!rollData.isSortReserve) {
- this.currentTMR.close(); // Close TMR !
- } else { // Mise en réserve
- let reserve = duplicate(this.data.data.reve.reserve);
- reserve.list.push({ coord: rollData.coord, sort: duplicate(rollData.selectedSort), draconic: duplicate(rollData.selectedDraconic) });
- await this.update({ "data.reve.reserve": reserve });
- this.currentTMR.updateSortReserve();
- }
- } else {
- if (rolled.tache == -4) { // Echec total !
- costReve *= 2;
- myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!!
- if (myReve.value < 0) myReve.value = 0;
- await this.update({ "data.reve.reve": myReve });
- specialStr += "
Echec TOTAL du sort : " + costReve + " Points de Rêve";
- } else {
- specialStr += "
Echec du sort !";
- }
- this.currentTMR.close(); // Close TMR !
- }
- if (myReve.value == 0) { // 0 points de reve
- ChatMessage.create({ title: "Zero Points de Reve !", content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" });
- this.currentTMR.close(); // Close TMR !
- }
- } else {
- lvl = (rollData.competence) ? rollData.competence.name : rollData.bmValue;
+ resumeCompetence = rollData.selectedDraconic.name + "/" + sort.name;
+ explications = await this._rollLancementDeSort(rollData, rolled);
}
// Save it for fight in the flags area
@@ -238,9 +194,10 @@ export class RdDActor extends Actor {
// Final chat message
let chatOptions = {
- content: "Test : " + rollData.selectedCarac.label + " / " + lvl + "
Jet : " +
- rollData.selectedCarac.value + " / " + rollData.finalLevelStr + " -> " + rolled.score + "%
Résutat : " + result + "
" +
- "" + quality + "" + specialStr + xpmsg,
+ content: "Test : " + rollData.selectedCarac.label + " / " + resumeCompetence + ""
+ + "
Jet : " + rollData.selectedCarac.value + " / " + rollData.finalLevelStr + " -> " + rolled.score + "%
Résutat : " + rolled.roll
+ + "
" + quality + ""
+ + explications + xpmsg,
user: game.user._id,
title: "Résultat du test"
}
@@ -266,6 +223,81 @@ export class RdDActor extends Actor {
}
}
+ _calculBonusDommages(carac, arme) {
+ const dmgArme = parseInt(arme.data.dommages);
+ const dmgPerso = parseInt(this.data.data.attributs.plusdom.value);
+ if (carac.label == "Tir") {
+ return dmgArme;
+ }
+ if (carac.label == "Lancer") {
+ return dmgArme + Math.min(dmgArme, dmgPerso);
+ }
+ return dmgArme + dmgPerso;
+ }
+
+ async _rollLancementDeSort(rollData, rolled) {
+
+ let sort = duplicate(rollData.selectedSort);
+
+ let closeTMR = true;
+ let coutReve = sort.data.ptreve_reel || sort.data.ptreve; // cas de sort à ptreve variables
+
+ let explications = "
Lancement du sort " + sort.name + " : " + Misc._upperFirst(sort.data.draconic)
+ + " pour "+coutReve+ " points de Rêve"
+ + "
Depuis la case " + rollData.coord + " (" + TMRUtility.getTMRDescription(rollData.coord).label + ")";
+
+ let myReve = duplicate(this.data.data.reve.reve);
+ if (rolled.isSuccess) { // Réussite du sort !
+ sort.ptreve_reel = coutReve;
+ if (rolled.isPart) {
+ coutReve = Math.max(Math.ceil(coutReve / 2), 1);
+ }
+ if (myReve.value > coutReve){
+ explications += "
Réussite du sort: " + coutReve + " points de Rêve sont dépensés";
+
+ if (rollData.isSortReserve) {
+ // Mise en réserve
+ myReve.value--;
+ await this.sortMisEnReserve(rollData, sort);
+ closeTMR = false;
+ }
+ }
+ else {
+ // Todo 0 pts de reve !!!!
+ explications += "
Pas assez de rêve";
+ mergeObject(rollData, RdDResolutionTable.getResultat("echec"));
+ }
+ } else {
+ if (rolled.isETotal) { // Echec total !
+ coutReve *= 2;
+ myReve.value = myReve.value - coutReve;
+ explications += "
Echec TOTAL du sort : " + coutReve + " Points de Rêve";
+ } else {
+ coutReve = 0
+ explications += "
Echec du sort !";
+ }
+ }
+
+ myReve.value = Math.max(myReve.value - coutReve, 0);
+ await this.update({ "data.reve.reve": myReve });
+
+ if (myReve.value == 0) { // 0 points de reve
+ ChatMessage.create({ title: "Zero Points de Reve !", content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" });
+ closeTMR = true;
+ }
+ if (closeTMR) {
+ this.currentTMR.close(); // Close TMR !
+ }
+ return explications
+ }
+
+ async sortMisEnReserve(rollData, sort) {
+ let reserve = duplicate(this.data.data.reve.reserve);
+ reserve.list.push({ coord: rollData.coord, sort: sort, draconic: duplicate(rollData.selectedDraconic) });
+ await this.update({ "data.reve.reserve": reserve });
+ this.currentTMR.updateSortReserve();
+ }
+
/* -------------------------------------------- */
updateCarac( caracName, caracValue )
{
@@ -404,13 +436,19 @@ export class RdDActor extends Actor {
let refoulement = duplicate(this.data.data.reve.refoulement);
refoulement.value = refoulement.value + value;
+
let total = new Roll("d20").roll().total;
if ( total <= refoulement.value ) {
- ChatMessage.create( { title : "Souffle de Dragon",
- content: game.user.name + " subit un Souffle de Dragon !" } );
refoulement.value = 0;
+
+ let souffle = RdDRollTables.getSouffle();
+ ChatMessage.create( { title : "Souffle de Dragon",
+ content: game.user.name + " subit un Souffle de Dragon : " + souffle.name } );
+ this.actor.createOwnedItem(souffle);
+
ret = "souffle";
}
+
await this.update( {"data.reve.refoulement": refoulement } );
return ret;
}
@@ -452,7 +490,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async updatePointsDeReve( value ) {
let reve = duplicate(this.data.data.reve.reve);
- reve.value = reve.value + value;
+ reve.value = Math.max(reve.value + value, 0);
await this.update( {"data.reve.reve": reve } );
}
@@ -633,9 +671,9 @@ export class RdDActor extends Actor {
let second = RdDResolutionTable.rollChances(target)
switch (second.qualite) {
case "part": case "sign":
- return { factor: 1.5, comment: "Double Particulière (150%) - " + result + " puis " + second }
+ return { factor: 1.5, comment: "Double Particulière (150%) - " + result.roll + " puis " + second.roll }
default:
- return { factor: 1, comment: "Particulière (100%) - " + result + " puis " + second }
+ return { factor: 1, comment: "Particulière (100%) - " + result.roll + " puis " + second.roll }
}
}
@@ -649,7 +687,7 @@ export class RdDActor extends Actor {
etat: this.data.data.compteurs.etat.value,
draconicList: draconicList,
sortList: sortList,
- selectedDraconic: draconicList[0],
+ selectedDraconic: this.getBestDraconic(),
selectedSort: sortList[0],
coord: coord,
finalLevel: 0,
@@ -720,10 +758,10 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
- async rollCompetence( compName, armeItem=undefined, attackerRoll=undefined )
+ async rollCompetence( name, armeItem=undefined, attackerRoll=undefined )
{
- let compItem = RdDUtility.findCompetence( this.data.items, compName);
- console.log("!!!!!!", compName, this.data.items, compItem);
+ let competence = RdDUtility.findCompetence( this.data.items, name);
+ console.log("rollCompetence !!!", competence, armeItem, attackerRoll);
// Common rollData values
let rollData = {
bonusmalusTable: CONFIG.RDD.bonusmalus,
@@ -733,23 +771,23 @@ export class RdDActor extends Actor {
finalLevel: 0
}
- if ( compItem.type == 'competencecreature') { // Specific case for Creatures
- if ( compItem.data.iscombat ) {
- armeItem = { name: compName, data: { dommages: compItem.data.dommages} };
+ if ( competence.type == 'competencecreature') { // Specific case for Creatures
+ if ( competence.data.iscombat ) {
+ armeItem = { name: name, data: { dommages: competence.data.dommages} };
}
- compItem.data.defaut_carac = "carac_creature"; // Fake default competence
- compItem.data.categorie = "creature"; // Fake default competence
- rollData.competence = compItem;
+ competence.data.defaut_carac = "carac_creature"; // Fake default competence
+ competence.data.categorie = "creature"; // Fake default competence
+ rollData.competence = competence;
rollData.arme = armeItem;
- rollData.carac = { carac_creature: { label: compName, value: compItem.data.carac_value } };
+ rollData.carac = { carac_creature: { label: name, value: competence.data.carac_value } };
} else { // Usual competence
- rollData.competence = compItem;
+ rollData.competence = competence;
rollData.arme = armeItem;
rollData.carac = this.data.data.carac;
}
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
- if (armeItem) {
+ if (rollData.arme) {
new RdDRollDialog("arme", html, rollData, this ).render(true);
} else {
new RdDRollDialog("competence", html, rollData, this ).render(true);
@@ -762,7 +800,6 @@ export class RdDActor extends Actor {
let item = this.getOwnedItem(itemID);
if ( item && item.data.data ) {
let update = {_id: item._id, "data.equipe": !item.data.data.equipe };
- //console.log(update);
await this.updateEmbeddedEntity("OwnedItem", update);
this.computeEncombrementTotal(); // Mise à jour encombrement
}
@@ -845,4 +882,7 @@ export class RdDActor extends Actor {
return data;
}
+
}
+
+
diff --git a/module/misc.js b/module/misc.js
new file mode 100644
index 00000000..962156f5
--- /dev/null
+++ b/module/misc.js
@@ -0,0 +1,11 @@
+
+
+/**
+ * This class is intended as a placeholder for utility methods unrelated
+ * to actual classes of the game system or of FoundryVTT
+ */
+export class Misc {
+ static _upperFirst(text) {
+ return text.charAt(0).toUpperCase() + text.slice(1);
+ }
+}
\ No newline at end of file
diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js
index 8286f633..2c9e4039 100644
--- a/module/rdd-resolution-table.js
+++ b/module/rdd-resolution-table.js
@@ -65,9 +65,20 @@ export class RdDResolutionTable {
return table;
}
+ static getResultat(code)
+ {
+ let resultat = reussites.filter(r => code == r.code);
+ if (resultat == undefined)
+ {
+ resultat = reussites.find(r => r.code == "error");
+ }
+ return resultat;
+ }
/* -------------------------------------------- */
static roll(carac, difficulte) {
- return this.rollChances(this.computeChances(carac, difficulte));
+ const chances = this.computeChances(carac, difficulte);
+ let rolled = this.rollChances(chances);
+ return rolled;
}
static rollChances(chances) {
diff --git a/module/rdd-roll-dialog.js b/module/rdd-roll-dialog.js
index f0dac596..60a8440c 100644
--- a/module/rdd-roll-dialog.js
+++ b/module/rdd-roll-dialog.js
@@ -48,8 +48,8 @@ export class RdDRollDialog extends Dialog {
}
/* -------------------------------------------- */
- performRollSort(html, isReserve = false) {
- this.rollData.isSortReserve = isReserve;
+ performRollSort(html, isSortReserve = false) {
+ this.rollData.isSortReserve = isSortReserve;
this.actor.performRoll(this.rollData);
}
diff --git a/module/rdd-rolltables.js b/module/rdd-rolltables.js
index 5f06a355..0ab3b7c9 100644
--- a/module/rdd-rolltables.js
+++ b/module/rdd-rolltables.js
@@ -12,7 +12,7 @@ export class RdDRollTables {
}
/* -------------------------------------------- */
- static async getSouffle(toChat) {
+ static async getSouffle(toChat = true) {
return RdDRollTables.genericGetTableResult("Souffles de Dragon", toChat);
}
diff --git a/module/rdd-tmr-dialog.js b/module/rdd-tmr-dialog.js
index 5774d3dd..1737f694 100644
--- a/module/rdd-tmr-dialog.js
+++ b/module/rdd-tmr-dialog.js
@@ -7,218 +7,187 @@ import { TMRUtility } from "./tmr-utility.js";
import { RdDRollTables } from "./rdd-rolltables.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js";
-/** Helper functions */
+const tmrConstants = {
+ col1_y: 30,
+ col2_y: 55,
+ cellw: 55,
+ cellh: 55,
+ gridx: 28,
+ gridy: 28
+}
+
export class RdDTMRDialog extends Dialog {
-
- /* -------------------------------------------- */
- constructor( html, actor, tmrData) {
-
- // Common conf
- let dialogConf = {
+
+ /* -------------------------------------------- */
+ constructor(html, actor, tmrData) {
+ const dialogConf = {
+ title: "Terres Médianes de Rêve",
content: html,
- buttons:
- {
- closeButton:
- {
- label: "Fermer",
- callback: html => this.close(html)
- }
- },
- default: "closeButton"
- }
- let dialogOptions = { classes: [ "tmrdialog"] }
-
- dialogConf.title = "Terres Médianes de Rêve",
- dialogOptions.width = 920;
- dialogOptions.height = 960;
- dialogOptions['z-index'] = 20;
-
+ buttons: {
+ closeButton: { label: "Fermer", callback: html => this.close(html) }
+ },
+ default: "closeButton"
+ }
+
+ const dialogOptions = {
+ classes: ["tmrdialog"],
+ width: 920, height: 980,
+ 'z-index': 20
+ }
super(dialogConf, dialogOptions);
-
- this.tmrdata = duplicate(tmrData);
- this.col1_y = 30;
- this.col2_y = 55;
- this.cellh = 55;
- this.cellw = 55;
+
+ this.tmrdata = duplicate(tmrData);
this.actor = actor;
this.nbFatigue = 1; // 1 premier point de fatigue du à la montée
this.rencontresExistantes = duplicate(this.actor.data.data.reve.rencontre.list);
this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list);
-
- //console.log(this.rencontresExistantes);
- this.pixiApp = new PIXI.Application( {width: 720, height: 860 } );
+ this.allTokens = []
+ this.pixiApp = new PIXI.Application({ width: 720, height: 860 });
}
-
- /* -------------------------------------------- */
+
+ /* -------------------------------------------- */
close() {
- this.actor.santeIncDec("fatigue", this.nbFatigue).then( super.close() ); // moving 1 cell costs 1 fatigue
- }
-
- /* -------------------------------------------- */
- displaySortReserve() {
- console.log(this.sortReserves);
- for (let sortReserve of this.sortReserves) {
- sortReserve.circle = new PIXI.Graphics();
- sortReserve.circle.beginFill(0x767610, 0.6);
- sortReserve.circle.drawCircle(0, 0, 6);
- sortReserve.circle.endFill();
- let coordXY = TMRUtility.convertToCellCoord( sortReserve.coord );
- let basey = (coordXY.x % 2 == 0) ? this.col1_y : this.col2_y;
- let myx = 28+(coordXY.x * this.cellw);
- let myy = basey+28+(coordXY.y * this.cellh);
- sortReserve.circle.x = myx - (this.cellw/2)+16;
- sortReserve.circle.y = myy - (this.cellh/2)+16;
- this.pixiApp.stage.addChild(sortReserve.circle);
- }
- }
-
- /* -------------------------------------------- */
- displayPreviousRencontres() {
- for (let rencontre of this.rencontresExistantes) {
- rencontre.circle = new PIXI.Graphics();
- rencontre.circle.beginFill(0x101010, 0.8);
- rencontre.circle.drawCircle(0, 0, 6);
- rencontre.circle.endFill();
- let coordXY = TMRUtility.convertToCellCoord( rencontre.coord );
- let basey = (coordXY.x % 2 == 0) ? this.col1_y : this.col2_y;
- let myx = 28+(coordXY.x * this.cellw);
- let myy = basey+28+(coordXY.y * this.cellh);
- rencontre.circle.x = myx - (this.cellw/2)+16;
- rencontre.circle.y = myy - (this.cellh/2)+16;
- this.pixiApp.stage.addChild(rencontre.circle);
- }
- }
-
- /* -------------------------------------------- */
- updatePreviousRencontres() {
- for (let rencontre of this.rencontresExistantes) {
- this.pixiApp.stage.removeChild( rencontre.circle );
- }
- this.rencontresExistantes = duplicate(this.actor.data.data.reve.rencontre.list);
- this.displayPreviousRencontres();
+ this.actor.santeIncDec("fatigue", this.nbFatigue).then(super.close()); // moving 1 cell costs 1 fatigue
}
- /* -------------------------------------------- */
- updateSortReserve() {
- for (let sortReserve of this.sortReserves) { //cleanup pixi icons
- this.pixiApp.stage.removeChild( sortReserve.circle );
+ /* -------------------------------------------- */
+ displaySortReserve() {
+ console.debug("displaySortReserve", this.sortReserves);
+ for (let sort of this.sortReserves) {
+ this._trackToken(this._tokenSortEnReserve(sort));
}
- this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list); // Then do it again!
+ }
+
+ /* -------------------------------------------- */
+ displayPreviousRencontres() {
+ console.debug("displayPreviousRencontres", this.rencontresExistantes);
+ for (let rencontre of this.rencontresExistantes) {
+ this._trackToken(this._tokenRencontre(rencontre));
+ }
+ }
+
+ /* -------------------------------------------- */
+ updatePreviousRencontres() {
+ this._removeTokens(t => t.rencontre != undefined);
+ this.rencontresExistantes = duplicate(this.actor.data.data.reve.rencontre.list);
+ this.displayPreviousRencontres();
+ }
+
+ /* -------------------------------------------- */
+ updateSortReserve() {
+ this._removeTokens(t => t.sort != undefined);
+ this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list);
this.displaySortReserve();
}
-
- /* -------------------------------------------- */
+
+ /* -------------------------------------------- */
async derober() {
- await this.actor.addTMRRencontre( this.currentRencontre );
+ await this.actor.addTMRRencontre(this.currentRencontre);
console.log("-> derober", this.currentRencontre);
- ChatMessage.create( { title: "TMR", content: game.user.name + " s'est dérobé et quitte les TMR.", user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") } );
+ this._tellToGM(this.actor.name + " s'est dérobé et quitte les TMR.");
this.close();
}
- /* -------------------------------------------- */
+ /* -------------------------------------------- */
async refouler(data) {
- ChatMessage.create( { title: "TMR", content: game.user.name + " a refoulé une rencontre.", user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") } );
- await this.actor.deleteTMRRencontreAtPosition( ); // Remove the stored rencontre if necessary
+ this._tellToGM(this.actor.name + " a refoulé une rencontre.");
+ await this.actor.deleteTMRRencontreAtPosition(); // Remove the stored rencontre if necessary
let result = await this.actor.ajouterRefoulement(1);
this.updatePreviousRencontres();
- if (result == "souffle") {
- let souffle = RdDRollTables.getSouffle();
- }
console.log("-> refouler", this.currentRencontre)
this.updateValuesDisplay();
}
- /* -------------------------------------------- */
- async matriser(data) {
- this.actor.deleteTMRRencontreAtPosition( ); // Remove the stored rencontre if necessary
+ /* -------------------------------------------- */
+ async maitriser(data) {
+ this.actor.deleteTMRRencontreAtPosition(); // Remove the stored rencontre if necessary
this.updatePreviousRencontres();
-
+
const draconic = this.actor.getBestDraconic();
const carac = this.actor.getCurrentReve();
+ // TODO: ajouter l'état général?
+ const etatGeneral = this.actor.data.data.compteurs.etat.value
const difficulte = draconic.data.niveau - this.currentRencontre.force;
console.log("Maitriser", carac, draconic.data.niveau, this.currentRencontre.force);
- const roll = RdDResolutionTable.roll(carac, difficulte);
-
- if (roll.isEchec) {
- TMRUtility.processRencontreEchec( this.actor, this.currentRencontre);
- ChatMessage.create( { title: "TMR", content: "Vous avez échoué à votre maîtrise d'un " . this.currentRencontre.name + " de force " +
- this.currentRencontre.force +
- "
Vous quittez brutalement les Terres Médianes !",
- user: game.user._id, whisper: [ game.user ] } );
- ChatMessage.create( { title: "TMR", content: game.user.name + " a perdu sa rencontre contre : " + this.currentRencontre.name + " de force " + this.currentRencontre.force, user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") } );
- this.close();
+ let rolled = RdDResolutionTable.roll(carac, difficulte);
+ let message = "
Test : Rêve actuel / " + draconic.name + " / " + this.currentRencontre.name + "" + "
"
+ + "
Jet : " + carac + " / " + difficulte + " -> " + rolled.score + "%
Résutat : " + rolled.roll;
+
+
+ if (rolled.isEchec) {
+ TMRUtility.processRencontreEchec(this.actor, this.currentRencontre);
+ this._tellToUser("Vous avez échoué à maîtriser un " + this.currentRencontre.name + " de force " + this.currentRencontre.force
+ + "
Vous quittez brutalement les Terres Médianes !" + message);;
+ this.close();
} else {
- TMRUtility.processRencontreReussite( this.actor, this.rencontre);
- ChatMessage.create( { title: "TMR", content: "Vous avez réussi votre maîtrise d'un " + this.currentRencontre.name + " de force " + this.currentRencontre.force, user: game.user._id, whisper: [ game.user ] } );
- ChatMessage.create( { title: "TMR", content: game.user.name + " a gagné sa rencontre contre : " + this.currentRencontre.name + " de force " + this.currentRencontre.force, user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") } );
+ TMRUtility.processRencontreReussite(this.actor, this.currentRencontre);
+ this._tellToUser("Vous avez réussi à maîtriser un " + this.currentRencontre.name + " de force " + this.currentRencontre.force + message);
}
console.log("-> matriser", this.currentRencontre);
this.updateValuesDisplay();
}
-
- /* -------------------------------------------- */
- async manageRencontre(coordTMR, cellDescr)
- {
- // Roll until diffent than '8'
- this.currentRencontre = undefined;
+ _tellToUser(message) {
+ ChatMessage.create({ title: "TMR", content: message, user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") });
+ }
+
+ /* -------------------------------------------- */
+ async manageRencontre(coordTMR, cellDescr) {
+
+ this.currentRencontre = undefined;
let rencontre = this.rencontresExistantes.find(prev => prev.coord == coordTMR);
- if (rencontre == undefined && new Roll("d7").roll().total == 7) {
- rencontre = TMRUtility.rencontreTMRRoll(coordTMR, cellDescr);
+ let deRencontre = new Roll("d7").roll();
+ console.log("manageRencontre", deRencontre, rencontre);
+ if (rencontre == undefined) {
+ if (deRencontre.total == 7) {
+ rencontre = TMRUtility.rencontreTMRRoll(coordTMR, cellDescr);
+ }
}
if (rencontre) { // Manages it
+ console.log("manageRencontre", rencontre)
this.currentRencontre = duplicate(rencontre);
- let dialog = new Dialog( { title: "Rencontre en TMR!",
- content: "Vous recontrez un " + rencontre.name + " de force " + rencontre.force + "
",
- buttons: {
- derober: {
- icon: '',
- label: "Se dérober",
- callback: () => this.derober()
- },
- refouler: {
- icon: '',
- label: "Refouler",
- callback: () => this.refouler()
- },
- maitiser: {
- icon: '',
- label: "Maîtriser",
- callback: () => this.matriser()
- }
- }
- } );
+ let dialog = new Dialog({
+ title: "Rencontre en TMR!",
+ content: "Vous recontrez un " + rencontre.name + " de force " + rencontre.force + "
",
+ buttons: {
+ derober: { icon: '', label: "Se dérober", callback: () => this.derober() },
+ refouler: { icon: '', label: "Refouler", callback: () => this.refouler() },
+ maitiser: { icon: '', label: "Maîtriser", callback: () => this.maitriser() }
+ },
+ default: "derober"
+ });
dialog.render(true);
}
}
-
- /* -------------------------------------------- */
- performRoll (html) {
- this.actor.performRoll( this.rollData );
+
+ /* -------------------------------------------- */
+ performRoll(html) {
+ this.actor.performRoll(this.rollData);
}
-
- /* -------------------------------------------- */
+
+ /* -------------------------------------------- */
updateValuesDisplay() {
let ptsreve = document.getElementById("pointsreve-value");
ptsreve.innerHTML = this.actor.data.data.reve.reve.value;
-
+
let tmrpos = document.getElementById("tmr-pos");
- let tmr = TMRUtility.getTMRDescription( this.actor.data.data.reve.tmrpos.coord );
- tmrpos.innerHTML = this.actor.data.data.reve.tmrpos.coord + " (" + tmr.label + ")";
-
+ let tmr = TMRUtility.getTMRDescription(this.actor.data.data.reve.tmrpos.coord);
+ console.log("updateValuesDisplay", this.actor.data.data.reve.tmrpos, tmr);
+ tmrpos.innerHTML = this.actor.data.data.reve.tmrpos.coord + " (" + tmr.label + ")";
+
let etat = document.getElementById("etatgeneral-value");
etat.innerHTML = this.actor.data.data.compteurs.etat.value;
let refoulement = document.getElementById("refoulement-value");
refoulement.innerHTML = this.actor.data.data.reve.refoulement.value;
-
+
let fatigueItem = document.getElementById("fatigue-table");
- fatigueItem.innerHTML = "