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 ba777e43..178110e3 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; @@ -197,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), []); @@ -311,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){ @@ -330,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; @@ -675,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(); } } @@ -1058,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é... + } } /* -------------------------------------------- */ @@ -1095,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 }); } @@ -1271,8 +1308,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 +1346,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 +1445,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 +1466,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); } @@ -1686,12 +1719,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/module/rdd-combat.js b/module/rdd-combat.js index 6a6a46d1..f9d3dae6 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) { @@ -233,62 +262,49 @@ 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) 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 +312,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: @@ -328,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) @@ -439,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) @@ -470,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 } @@ -479,7 +492,8 @@ export class RdDCombat { await this.computeRecul(rollData, true); // TODO: gestion message pour chance/encaissement - this.encaisser(rollData.attackerRoll); + this._sendMessageEncaisser(rollData.attackerRoll); + } /* -------------------------------------------- */ @@ -539,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) @@ -567,18 +580,17 @@ 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 } 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 +673,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); } /* -------------------------------------------- */ diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index e1a9686b..b65ad195 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -86,7 +86,16 @@ 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) + if (rollData.selectedCarac == rollData.carac.volonte) { + message += " / moral: " + rollData.moral; + } + return message; } /* -------------------------------------------- */ @@ -163,7 +172,7 @@ export class RdDResolutionTable { } return rollData.rolled.isETotal; } - + /* -------------------------------------------- */ static isParticuliere(rollData) { if (rollData.arme && rollData.surprise) { @@ -240,11 +249,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; } 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/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/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"}}
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 @@
- +
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 @@ - - - - - - - - + + + + + + + +