From 3975d7f52948d5b5b233a44a1b29b4bf72faeb4c Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 18 Dec 2020 22:14:48 +0100 Subject: [PATCH 1/6] =?UTF-8?q?Fix=20Armure=20et=20d=C3=A9t=C3=A9rioration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit regex incorrecte --- module/actor.js | 18 ++++++++++++------ templates/item-armure-sheet.html | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/module/actor.js b/module/actor.js index ba777e43..71beea7e 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1686,12 +1686,18 @@ export class RdDActor extends Actor { dmg = 0; // Reset it if ( update.data.deterioration >= 10) { update.data.deterioration = 0; - if ( update.data.protection.toString().length == 1 ) - update.data.protection = "1d"+update.data.protection+"-0"; - else { - let regex = /d\(d+)\-(\d+)/g; - let res = regex.exec( update.data.protection ); - update.data.protection = "1d"+res[1]+"-"+(parseInt(res[2])+1); + let res = /\d+^/.exec(update.data.protection); + if ( res ) + update.data.protection = "1d"+update.data.protection; + // if ( update.data.protection.toString().length == 1 ) + // update.data.protection = "1d"+update.data.protection; + else if (res = /(\d+d\d+)(\-\d+)?/.exec( update.data.protection )) + { + let malus = Misc.toInt(res[2]) - 1; + update.data.protection = res[1] + malus; + } + else{ + ui.notifications.warn(`La valeur d'armure de votre ${item.name} est incorrecte`) } ChatMessage.create( {content: "Détérioration d'armure: " + update.data.protection } ); } diff --git a/templates/item-armure-sheet.html b/templates/item-armure-sheet.html index 7ca1a573..e2bcb8af 100644 --- a/templates/item-armure-sheet.html +++ b/templates/item-armure-sheet.html @@ -10,7 +10,7 @@
- +
From ea4b7a7b2243775681724d7af746ed7461214dd2 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 18 Dec 2020 22:15:17 +0100 Subject: [PATCH 2/6] =?UTF-8?q?S=C3=A9paration=20d=C3=A9fense=20et=20encai?= =?UTF-8?q?ssement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/rdd-combat.js | 127 ++++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 55 deletions(-) diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 6a6a46d1..1abff7a6 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -20,7 +20,9 @@ export class RdDCombat { if (target == undefined) { ui.notifications.warn("Vous devez choisir une seule cible à attaquer!"); } - return this.create(attacker, target ? target.actor : undefined, target) + const defender = target ? target.actor : undefined; + const defenderTokenId = target ? target.data._id : undefined; + return this.create(attacker, defender, defenderTokenId, target) } /* -------------------------------------------- */ @@ -34,8 +36,8 @@ export class RdDCombat { } /* -------------------------------------------- */ - static create(attacker, defender, target = undefined) { - return new RdDCombat(attacker, defender, target) + static create(attacker, defender, defenderTokenId, target = undefined) { + return new RdDCombat(attacker, defender, defenderTokenId, target) } /* -------------------------------------------- */ @@ -45,22 +47,40 @@ export class RdDCombat { const dataDefenderTokenId = event.currentTarget.attributes['data-defenderTokenId']; if (dataDefenderTokenId) { - let defenderToken = canvas.tokens.get(dataDefenderTokenId.value); + const defenderTokenId = dataDefenderTokenId.value; + let defenderToken = canvas.tokens.get(defenderTokenId); let defender = defenderToken.actor; - return this.create(attacker, defender); + return RdDCombat.create(attacker, defender, defenderTokenId); } - return this.createUsingTarget(attacker) + return RdDCombat.createUsingTarget(attacker) } - /* -------------------------------------------- */ - constructor(attacker, defender, target) { - this.attacker = attacker; - this.defender = defender; - this.target = target; - this.attackerId = this.attacker.data._id; - this.defenderId = this.defender.data._id; - this.defenderTokenId = target ? target.data._id : undefined; + + static _sendRollMessage(sender, recipient, defenderTokenId, topic, message, rollData) { + let chatMessage = { + content: message, + whisper: ChatUtility.getWhisperRecipients("blindroll", recipient.name), + }; + + // envoyer le message au destinataire + if (!game.user.isGM || recipient.hasPlayerOwner) { + let data = { + attackerId: sender ? sender.data._id : undefined, + defenderId: recipient ? recipient.data._id : undefined, + defenderTokenId: defenderTokenId, + rollData: duplicate(rollData), + rollMode: true + }; + mergeObject(data, chatMessage); + game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: topic, data: data}); + } else { + chatMessage.whisper = [game.user]; + } + + if (game.user.isGM) { // Always push the message to the MJ + ChatMessage.create(chatMessage); + } } /* -------------------------------------------- */ @@ -73,6 +93,16 @@ export class RdDCombat { } } + /* -------------------------------------------- */ + constructor(attacker, defender, defenderTokenId, target) { + this.attacker = attacker; + this.defender = defender; + this.target = target; + this.attackerId = this.attacker.data._id; + this.defenderId = this.defender.data._id; + this.defenderTokenId = defenderTokenId; + } + /* -------------------------------------------- */ async onEvent(button, event) { let rollData = game.system.rdd.rollDataHandler[this.attackerId]; @@ -91,7 +121,6 @@ export class RdDCombat { } } - /* -------------------------------------------- */ static isEchec(rollData) { switch (rollData.surprise) { @@ -240,55 +269,43 @@ export class RdDCombat { ChatUtility.chatWithRollMode(chatOptions, this.attacker.name) if (this.target) { - this._messageDefenseur(rollData); + this._sendMessageDefense(rollData); } } /* -------------------------------------------- */ - _messageDefenseur(rollData) { - console.log("RdDCombat._messageDefenseur", rollData, " / ", this.attacker, this.target, this.target.actor.isToken, this.attacker.data._id, rollData.competence.data.categorie); + _sendMessageDefense(rollData) { + console.log("RdDCombat._sendMessageDefense", rollData, " / ", this.attacker, this.target, this.attackerId, rollData.competence.data.categorie); - let content = "" + this.defender.name + " doit se défendre :"; + let message = this._buildMessageDefense(rollData); + // encaisser + message += this._buildMessageEncaisser(rollData) + ""; + + RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_defense", message, rollData); + } + + _buildMessageDefense(rollData) { + let message = "" + this.defender.name + " doit se défendre :"; if (this.defender.getSurprise() != 'totale') { // parades for (const arme of this._filterArmesParade(this.defender.data.items, rollData.competence.data.categorie)) { - content += "
Parer avec " + arme.name + ""; + message += "
Parer avec " + arme.name + ""; } // corps à corps if (rollData.dmg.mortalite != 'mortel') { - content += "
Parer à mains nues"; + message += "
Parer à mains nues"; } // esquive if (rollData.competence.data.categorie == 'melee' || rollData.competence.data.categorie == "lancer" || rollData.competence.data.categorie == 'competencecreature') { - content += "
Esquiver"; + message += "
Esquiver"; } } + return message; + } - // encaisser - content += "
Encaisser à " + Misc.toSignedString(rollData.dmg.total) + " !"; - content += "
" - - let defense = { - title: "Défense en combat", - content: content, - whisper: ChatUtility.getWhisperRecipients("blindroll", this.defender.name), - attackerId: this.attackerId, - defenderTokenId: this.defenderTokenId, - rollMode: true, - rollData: duplicate(rollData) - }; - - // envoyer le message de defense - if (!game.user.isGM || this.defender.hasPlayerOwner) { - game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_defense", data: defense }); - } else { - defense.whisper = [game.user]; - } - - if (game.user.isGM) { // Always push the message to the MJ - ChatMessage.create(defense); - } + _buildMessageEncaisser(rollData) { + return "
Encaisser à " + Misc.toSignedString(rollData.dmg.total) + " !"; } /* -------------------------------------------- */ @@ -296,7 +313,7 @@ export class RdDCombat { switch (categorie) { case 'tir': case 'lancer': - return items.filter(item => + return items.filter(item => item.type == 'arme' && item.data.competence.toLowerCase().match("bouclier")); default: @@ -479,7 +496,8 @@ export class RdDCombat { await this.computeRecul(rollData, true); // TODO: gestion message pour chance/encaissement - this.encaisser(rollData.attackerRoll); + this._sendMessageEncaisser(rollData.attackerRoll); + } /* -------------------------------------------- */ @@ -575,10 +593,10 @@ export class RdDCombat { ChatUtility.chatWithRollMode(chatOptions, this.defender.name) await this.computeRecul(rollData, true); - this.encaisser(rollData.attackerRoll); + this._sendMessageEncaisser(rollData.attackerRoll); } - - + + /* -------------------------------------------- */ async computeDeteriorationArme(rollData) { const attackerRoll = rollData.attackerRoll; @@ -661,11 +679,10 @@ export class RdDCombat { } } - /* -------------------------------------------- */ - encaisser(attackerRoll) { - // TODO: gestion message pour chance/encaissement - this.encaisser(attackerRoll, this.defenderTokenId); + _sendMessageEncaisser(rollData){ + let message = "" + this.defender.name + " doit:" + this._buildMessageEncaisser(rollData); + RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_encaisser", message, rollData); } /* -------------------------------------------- */ From 15d67e72a314586126a2173506436c57ac3b6b5c Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 18 Dec 2020 23:48:41 +0100 Subject: [PATCH 3/6] =?UTF-8?q?Explications=20des=20difficult=C3=A9s=20de?= =?UTF-8?q?=20jets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor.js | 12 ++++-------- module/rdd-combat.js | 18 ++++++------------ module/rdd-resolution-table.js | 16 +++++++++++----- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/module/actor.js b/module/actor.js index 71beea7e..88b2e4ef 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1271,8 +1271,7 @@ export class RdDActor extends Actor { // Final chat message let chatOptions = { content: "Test : " + rollData.selectedCarac.label + " / " + rollData.selectedDraconic.name + " / " + rollData.selectedSort.name + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat - + RdDResolutionTable.explain(rolled) + + RdDResolutionTable.explainRollData(rollData) + explications } @@ -1310,8 +1309,7 @@ export class RdDActor extends Actor { // Final chat message let chatOptions = { content: "Test : " + rollData.selectedCarac.label + " / " + resumeCompetence + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat - + RdDResolutionTable.explain(rolled) + + RdDResolutionTable.explainRollData(rollData) + explications } @@ -1410,8 +1408,7 @@ export class RdDActor extends Actor { // Message de résultat ChatUtility.chatWithRollMode({ content: "Test de Tache : " + rollData.tache.name + " - " + rollData.selectedCarac.label + " / " + rollData.competence.name + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat - + "
" + RdDResolutionTable.explain(rollData.rolled) + + RdDResolutionTable.explainRollData(rollData) + "
Points de taches : " + rollData.rolled.ptTache + ", ajustement qualité: " + rollData.rolled.ptQualite }, this.name); // Message spécifique de la tâche @@ -1432,8 +1429,7 @@ export class RdDActor extends Actor { _competenceResult(rollData) { ChatUtility.chatWithRollMode({ content: "Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat - + RdDResolutionTable.explain(rollData.rolled) + + RdDResolutionTable.explainRollData(rollData) + "
Points de taches : " + rollData.rolled.ptTache + ", ajustement qualité: " + rollData.rolled.ptQualite }, this.name); } diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 1abff7a6..f9d3dae6 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -262,8 +262,7 @@ export class RdDCombat { // Final chat message let chatOptions = { content: "Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat - + RdDResolutionTable.explain(rollData.rolled) + + RdDResolutionTable.explainRollData(rollData) + explications } ChatUtility.chatWithRollMode(chatOptions, this.attacker.name) @@ -345,8 +344,7 @@ export class RdDCombat { console.log("RdDCombat.onAttaqueEchec >>>", rollData); let chatOptions = { content: "Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat - + RdDResolutionTable.explain(rollData.rolled) + + RdDResolutionTable.explainRollData(rollData) + (this.target ? "
Cible : " + this.defender.data.name : "") } ChatUtility.chatWithRollMode(chatOptions, this.attacker.name) @@ -456,8 +454,7 @@ export class RdDCombat { let chatOptions = { content: "Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat - + RdDResolutionTable.explain(rollData.rolled) + + RdDResolutionTable.explainRollData(rollData) + "
Attaque parée!" } ChatUtility.chatWithRollMode(chatOptions, this.defender.name) @@ -487,8 +484,7 @@ export class RdDCombat { let chatOptions = { content: "Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat - + RdDResolutionTable.explain(rollData.rolled) + + RdDResolutionTable.explainRollData(rollData) + explications } @@ -557,8 +553,7 @@ export class RdDCombat { console.log("RdDCombat._onEsquiveNormal >>>", rollData); let chatOptions = { content: "Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat - + RdDResolutionTable.explain(rollData.rolled) + + RdDResolutionTable.explainRollData(rollData) + "
Attaque esquivée!" } ChatUtility.chatWithRollMode(chatOptions, this.defender.name) @@ -585,8 +580,7 @@ export class RdDCombat { let chatOptions = { content: "Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "" - + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat - + RdDResolutionTable.explain(rollData.rolled) + + RdDResolutionTable.explainRollData(rollData) + explications } diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index e1a9686b..67439ad5 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -86,7 +86,13 @@ export class RdDResolutionTable { } message += '' + rolled.quality + '' return message; + } + static explainRollData(rollData) { + let message = "
Difficultés libre: " + rollData.diffLibre + " / conditions: " + Misc.toSignedString(rollData.diffConditions) + + " / état: " + rollData.etat; + message += RdDResolutionTable.explain(rollData.rolled) + return message; } /* -------------------------------------------- */ @@ -163,7 +169,7 @@ export class RdDResolutionTable { } return rollData.rolled.isETotal; } - + /* -------------------------------------------- */ static isParticuliere(rollData) { if (rollData.arme && rollData.surprise) { @@ -240,11 +246,11 @@ export class RdDResolutionTable { } /* -------------------------------------------- */ - static buildHTMLResults( caracValue, levelValue) { - let cell = this.computeChances( caracValue, levelValue); + static buildHTMLResults(caracValue, levelValue) { + let cell = this.computeChances(caracValue, levelValue); let descr = $(''); - descr.append("Particulière : " + cell.part+ " - Significative : " + cell.sign + " - Réussite : "+cell.score); - descr.append("
Echec Particulier : " + cell.epart + " - Echec Total : " + cell.etotal ); + descr.append("Particulière : " + cell.part + " - Significative : " + cell.sign + " - Réussite : " + cell.score); + descr.append("
Echec Particulier : " + cell.epart + " - Echec Total : " + cell.etotal); descr.append("
"); return descr; } From 6f22c4ab18dfa6b6fb677e2469165833c536be64 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 18 Dec 2020 23:57:28 +0100 Subject: [PATCH 4/6] =?UTF-8?q?Volont=C3=A9=20ajust=C3=A9=20par=20moral?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor.js | 5 +++++ module/rdd-resolution-table.js | 3 +++ module/rdd-roll.js | 38 ++++++++++++++++++-------------- templates/dialog-competence.html | 1 + templates/dialog-roll-carac.html | 1 + 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/module/actor.js b/module/actor.js index 88b2e4ef..356a0049 100644 --- a/module/actor.js +++ b/module/actor.js @@ -109,6 +109,11 @@ export class RdDActor extends Actor { return this.data.type == 'creature' || this.data.type == 'entite'; } + /* -------------------------------------------- */ + isPersonnage() { + return this.data.type == 'personnage'; + } + /* -------------------------------------------- */ getReveActuel() { return this.data.data.reve.reve.value; diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 67439ad5..b65ad195 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -92,6 +92,9 @@ export class RdDResolutionTable { let message = "
Difficultés libre: " + rollData.diffLibre + " / conditions: " + Misc.toSignedString(rollData.diffConditions) + " / état: " + rollData.etat; message += RdDResolutionTable.explain(rollData.rolled) + if (rollData.selectedCarac == rollData.carac.volonte) { + message += " / moral: " + rollData.moral; + } return message; } diff --git a/module/rdd-roll.js b/module/rdd-roll.js index 6070a707..3a22fc1f 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -33,6 +33,7 @@ export class RdDRoll extends Dialog { ajustementsConditions: CONFIG.RDD.ajustementsConditions, difficultesLibres: CONFIG.RDD.difficultesLibres, etat: actor.data.data.compteurs.etat.value, + moral: actor.isPersonnage() ? actor.data.data.compteurs.moral.value : 0, carac: actor.data.data.carac, finalLevel: 0, diffConditions: rollData.arme ? RdDBonus.bonusAttaque(rollData.surpriseDefenseur) :0, @@ -40,9 +41,9 @@ export class RdDRoll extends Dialog { editLibre: true, editConditions: true, forceValue: actor.getForceValue(), - malusArmureValue: (actor.type == 'personnage ' && actor.data.data.attributs && actor.data.data.attributs.malusarmure) ? actor.data.data.attributs.malusarmure.value : 0, - surencMalusFlag: actor.type == 'personnage ' ? (actor.data.data.compteurs.surenc.value < 0) : false, - surencMalusValue: actor.type == 'personnage ' ? actor.data.data.compteurs.surenc.value : 0, + malusArmureValue: (actor.isPersonnage() && actor.data.data.attributs && actor.data.data.attributs.malusarmure) ? actor.data.data.attributs.malusarmure.value : 0, + surencMalusFlag: actor.isPersonnage() ? (actor.data.data.compteurs.surenc.value < 0) : false, + surencMalusValue: actor.isPersonnage() ? actor.data.data.compteurs.surenc.value : 0, surencMalusApply: false, isNatation: rollData.competence ? rollData.competence.name.toLowerCase().includes("natation") : false, useEncForNatation: false, @@ -103,10 +104,11 @@ export class RdDRoll extends Dialog { var rollData = this.rollData; var actor = this.actor; + var dialog = this; function updateRollResult(rollData) { let caracValue = parseInt(rollData.selectedCarac.value) - let rollLevel = RdDRoll._computeFinalLevel(rollData); + let rollLevel = dialog._computeFinalLevel(rollData); rollData.dmg = rollData.attackerRoll ? rollData.attackerRoll.dmg : RdDBonus.dmg(rollData, actor.getBonusDegat()); rollData.finalLevel = rollLevel; rollData.caracValue = caracValue; @@ -116,7 +118,8 @@ export class RdDRoll extends Dialog { dmgText = '(' + dmgText + ')'; } - HtmlUtility._showControlWhen(".etat-general", !RdDRoll._isIgnoreEtatGeneral(rollData)); + HtmlUtility._showControlWhen(".diffMoral", rollData.selectedCarac == actor.data.data.carac.volonte); + HtmlUtility._showControlWhen(".etat-general", !dialog._isIgnoreEtatGeneral(rollData)); // Sort management if (rollData.selectedSort) { @@ -128,7 +131,7 @@ export class RdDRoll extends Dialog { // Mise à jour valeurs $("#roll-param").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel)); - $("#compdialogTitle").text(RdDRoll._getTitle(rollData)); + $("#compdialogTitle").text(dialog._getTitle(rollData)); $('#coupsNonMortels').prop('checked', rollData.coupsNonMortels); $("#dmg-arme-actor").text(dmgText); $("#defenseur-surprise").text(RdDBonus.description(rollData.surpriseDefenseur)); @@ -213,28 +216,29 @@ export class RdDRoll extends Dialog { }); } - static _isIgnoreEtatGeneral(rollData) { + _isIgnoreEtatGeneral(rollData) { return rollData.selectedCarac.ignoreEtatGeneral; } /* -------------------------------------------- */ - static _computeFinalLevel(rollData) { - const etat = RdDRoll._isIgnoreEtatGeneral(rollData) ? 0 : Misc.toInt(rollData.etat); + _computeFinalLevel(rollData) { + const etat = this._isIgnoreEtatGeneral(rollData) ? 0 : Misc.toInt(rollData.etat); const diffConditions = Misc.toInt(rollData.diffConditions); const malusEnc = (rollData.surencMalusApply) ? rollData.surencMalusValue : 0; const bonusTactique = RdDBonus.bonusAttaque(rollData.tactique); const malusEncNatation = (rollData.useEncForNatation) ? -rollData.encValueForNatation : 0; const ajustementChance = rollData.selectedCarac.label.toLowerCase().includes('chance') ? rollData.ajustementAstrologique : 0; // Gestion malus armure - const malusArmureValue = RdDRoll._computeMalusArmure(rollData); + const malusArmureValue = this._computeMalusArmure(rollData); - const diffLibre = RdDRoll._computeDiffLibre(rollData); - const diffCompetence = RdDRoll._computeDiffCompetence(rollData); + const diffLibre = this._computeDiffLibre(rollData); + const diffCompetence = this._computeDiffCompetence(rollData); + const diffMoral = rollData.selectedCarac == this.actor.data.data.carac.volonte ? rollData.moral : 0; - return etat + diffCompetence + diffLibre + diffConditions + malusEnc + malusEncNatation + malusArmureValue + ajustementChance + bonusTactique; + return etat + diffCompetence + diffLibre + diffMoral + diffConditions + malusEnc + malusEncNatation + malusArmureValue + ajustementChance + bonusTactique; } - static _computeDiffCompetence(rollData) { + _computeDiffCompetence(rollData) { if (rollData.competence) { return Misc.toInt(rollData.competence.data.niveau); } @@ -244,7 +248,7 @@ export class RdDRoll extends Dialog { return 0; } - static _computeDiffLibre(rollData) { + _computeDiffLibre(rollData) { let diffLibre = Misc.toInt(rollData.diffLibre); if (rollData.draconicList && rollData.selectedSort) { return RdDItemSort.getDifficulte(rollData.selectedSort, diffLibre); @@ -252,7 +256,7 @@ export class RdDRoll extends Dialog { return diffLibre; } - static _computeMalusArmure(rollData) { + _computeMalusArmure(rollData) { let malusArmureValue = 0; if (rollData.malusArmureValue != 0 && (rollData.selectedCarac.label == "Agilité" || rollData.selectedCarac.label == "Dérobée")) { $("#addon-message").text("Malus armure appliqué : " + rollData.malusArmureValue); @@ -264,7 +268,7 @@ export class RdDRoll extends Dialog { } /* -------------------------------------------- */ - static _getTitle(rollData) { + _getTitle(rollData) { if (rollData.competence) { // If a weapon is there, add it in the title let armeTitle = (rollData.arme) ? " (" + rollData.arme.name + ") " : ""; diff --git a/templates/dialog-competence.html b/templates/dialog-competence.html index 6cfb1a2d..4f869ae0 100644 --- a/templates/dialog-competence.html +++ b/templates/dialog-competence.html @@ -33,6 +33,7 @@ {{/each}} {{/select}} +
{{#if arme}}
diff --git a/templates/dialog-roll-carac.html b/templates/dialog-roll-carac.html index 2f8182fe..bfaac5c0 100644 --- a/templates/dialog-roll-carac.html +++ b/templates/dialog-roll-carac.html @@ -17,6 +17,7 @@ {{/each}} {{/select}} +
{{>"systems/foundryvtt-reve-de-dragon/templates/dialog-roll-surenc.html"}}
From df7d39f38edfe9cdccd72aa2db359e819073f3bf Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 19 Dec 2020 01:14:02 +0100 Subject: [PATCH 5/6] =?UTF-8?q?Moral=20sur=20=C3=A9thylisme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor-humanoide-sheet.js | 1 + module/actor.js | 67 +++++++++++++++++++++------------ module/rdd-utility.js | 4 +- templates/niveau-ethylisme.html | 16 ++++---- 4 files changed, 53 insertions(+), 35 deletions(-) diff --git a/module/actor-humanoide-sheet.js b/module/actor-humanoide-sheet.js index a7360cf9..aee867bd 100644 --- a/module/actor-humanoide-sheet.js +++ b/module/actor-humanoide-sheet.js @@ -46,6 +46,7 @@ export class RdDActorHumanoideSheet extends ActorSheet { data.data.competencecreature = data.itemsByType["competencecreature"]; data.data.isGM = game.user.isGM; + data.data.compteurs.ethylisme.nom = RdDUtility.getNomEthylisme(data.data.compteurs.ethylisme.value); RdDUtility.filterItemsPerTypeForSheet(data ); RdDUtility.buildArbreDeConteneur( this, data ); diff --git a/module/actor.js b/module/actor.js index 356a0049..8102b7fa 100644 --- a/module/actor.js +++ b/module/actor.js @@ -202,8 +202,8 @@ export class RdDActor extends Actor { let message = { whisper: ChatUtility.getWhisperRecipientsAndGMs( this.name ), content : "" - }; + const blessures = duplicate(this.data.data.blessures); console.log("dormirChateauDormant", blessures) await this._recupererBlessures(message, "legere", blessures.legeres.liste.filter(b => b.active), []); @@ -316,6 +316,8 @@ export class RdDActor extends Actor { } await this.update( {"data.blessures": blessures } ); } + await this.update({ "data.compteurs.ethylisme.value": 0 }); + await this.update({ "data.compteurs.ethylisme.nb_doses": 0 }); await this.santeIncDec("vie", this.data.data.sante.vie.max - this.data.data.sante.vie.value); await this.santeIncDec("endurance", this.data.data.sante.endurance.max - this.data.data.sante.endurance.value); if (this.data.data.sante.fatigue){ @@ -335,12 +337,26 @@ export class RdDActor extends Actor { }; await this.recupereEndurance(message); for (let i=0; iVous dégrisez un peu (${RdDUtility.getNomEthylisme(ethylisme.value)})`; + } + } + } + /* -------------------------------------------- */ async recupereEndurance(message) { const manquant = this._computeEnduranceMax() - this.data.data.sante.endurance.value; @@ -680,18 +696,15 @@ export class RdDActor extends Actor { return; } // Pour les autres - let state = 0, surenc = 0; - state = state - (data.sante.vie.max - data.sante.vie.value); + let state = - (data.sante.vie.max - data.sante.vie.value); if (data.sante.fatigue) // Creatures n'ont pas de fatigue - state = state + RdDUtility.currentFatigueMalus(data.sante.fatigue.value, data.sante.endurance.max); + state += RdDUtility.currentFatigueMalus(data.sante.fatigue.value, data.sante.endurance.max); if (data.compteurs && data.compteurs.ethylisme && data.compteurs.ethylisme.value < 0 ) { // Ajout de l'éthylisme - state = state + data.compteurs.ethylisme.value; + state += data.compteurs.ethylisme.value; } - state = state; data.compteurs.etat.value = state; if ( data.compteurs && data.compteurs.surenc) { - surenc = -this.detectSurEncombrement(); - data.compteurs.surenc.value = surenc; + data.compteurs.surenc.value = - this.detectSurEncombrement(); } } @@ -1063,28 +1076,32 @@ export class RdDActor extends Actor { let msgText = RdDResolutionTable.explain(rollEthylisme) + "
"; if (rollEthylisme.isSuccess ) { ethylisme.nb_doses = ethylisme.nb_doses + 1; - msgText += "Vous avez réussi votre jet d'éthylisme, votre vous avez désormais " + ethylisme.nb_doses + " doses sans effet."; + msgText += `Vous avez réussi votre jet d'éthylisme, vous avez consommé ${ethylisme.nb_doses} doses sans effet.`; } else { - ethylisme.value = ethylisme.value - 1; - if ( ethylisme.value > 7) ethylisme.value = 7; // Niveau max + ethylisme.value = Math.max(ethylisme.value -1, -7); + let enduranceLost = new Roll("1d6").roll().total; await this.santeIncDec("endurance", -enduranceLost); - msgText += "Vous avez échoué à votre jet d'éthylisme, votre niveau d'éthylisme est de " + ethylisme.value - + "(" + RdDUtility.getNomEthylisme(ethylisme.value) + ")."; + const ajustementEthylique = ethylisme.value; // Qui a bu boira (p 164) - let rollVolonte = await RdDResolutionTable.roll( this.data.data.carac.volonte.value, -ethylisme.value); + let rollVolonte = await RdDResolutionTable.roll( this.data.data.carac.volonte.value, Math.min(ajustementEthylique, 0) + this.data.data.compteurs.moral.value); + msgText += `Vous avez échoué à votre jet d'éthylisme, vous êtes maintenant ${RdDUtility.getNomEthylisme(ajustementEthylique)} (${ajustementEthylique}).` msgText += "
" + RdDResolutionTable.explain(rollVolonte) + "
"; - if ( rollVolonte.isSuccess) - msgText += "Qui a bu boira : vous êtes libre de continuer à boire ou pas."; - else - msgText += "Qui a bu boira : vous avez une envie irrépréssible de reprendre un verre."; - } - await this.update( { 'data.compteurs.ethylisme': ethylisme} ); - const message = { - content: msgText, - whisper: ChatMessage.getWhisperRecipients(game.user.name) - }; - ChatMessage.create(message); + msgText += "Qui a bu boira : " +(rollVolonte.isSuccess + ? "vous êtes libre de continuer à boire ou pas." + : "vous avez une envie irrépréssible de reprendre un verre."); + + } + await this.update( { 'data.compteurs.ethylisme': ethylisme} ); + const message = { + content: msgText, + whisper: ChatMessage.getWhisperRecipients(game.user.name) + }; + ChatMessage.create(message); + + if (rollEthylisme.isEchec && ethylisme.value == 0) { + await this.jetDeMoral('heureuse'); // note: en, théorie, un deuxième jet de moral peut avoir lieu le même jour si lme premier est manqué, qui fait perdre du moral si raté... + } } /* -------------------------------------------- */ diff --git a/module/rdd-utility.js b/module/rdd-utility.js index b6aeb54f..18a1e430 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -203,8 +203,8 @@ export class RdDUtility { /* -------------------------------------------- */ static getNomEthylisme( niveauEthylisme ) { - let index = Math.abs(niveauEthylisme); - return nomEthylisme[index]; + let index = -niveauEthylisme; + return index <0 ? 'Aucun' : nomEthylisme[index]; } /* -------------------------------------------- */ diff --git a/templates/niveau-ethylisme.html b/templates/niveau-ethylisme.html index 9a1efcbd..0e187a02 100644 --- a/templates/niveau-ethylisme.html +++ b/templates/niveau-ethylisme.html @@ -1,9 +1,9 @@ - - - - - - - - + + + + + + + + From 887a47b8f8ae7d1573eadfa6f7eb1bf8ffa09e18 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 19 Dec 2020 01:45:03 +0100 Subject: [PATCH 6/6] Dissolution/exaltation sur stress --- module/actor.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/module/actor.js b/module/actor.js index 8102b7fa..178110e3 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1117,16 +1117,31 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async transformerStress(message) { - const stress = Misc.toInt(this.data.data.compteurs.stress.value); + let compteurs = duplicate(this.data.data.compteurs); + const stress = Misc.toInt(compteurs.stress.value); + if (stress<=0) { return; } + + let stressRoll = await this._stressRoll(); let convertis = Math.floor(stress * stressRoll.factor); - - let compteurs = duplicate(this.data.data.compteurs); - compteurs.experience.value += convertis; compteurs.stress.value = Math.max(stress - convertis - 1, 0); + + let dissolution = Math.max(0, Misc.toInt(compteurs.dissolution.value)); + let exaltation = Math.max(0, Misc.toInt(compteurs.exaltation.value)); + const annule = Math.min(dissolution, exaltation); + dissolution -= annule; + exaltation -= annule; + if (dissolution>0) { + const perdus = Math.min(dissolution, convertis); + convertis -= perdus; + dissolution -= perdus; + } + compteurs.experience.value += convertis + exaltation; + compteurs.dissolution.value = dissolution; + compteurs.exaltation.value = 0; message.content += "
Vous transformez " + convertis + " points de Stress en Expérience" + stressRoll.comment; await this.update({ "data.compteurs": compteurs }); }