Checkbox et regles d'appel au moral

This commit is contained in:
LeFelis 2021-02-09 23:23:40 +01:00
parent 0c7a0e413d
commit 771622564a
9 changed files with 107 additions and 11 deletions

View File

@ -1594,6 +1594,14 @@ export class RdDActor extends Actor {
};
}
/* -------------------------------------------- */
createCallbackAppelAuMoral() {
return {
condition: r => r.use.appelAuMoral && game.settings.get("core", "rollMode") != 'selfroll',
action: r => { console.log("createCallbackAppelAuMoral"); this.displayAppelAuMoral ; console.log(r.rolled.isEchec); this._appliquerAppelMoral(r, game.settings.get("core", "rollMode") != 'blindroll') }
};
}
/* -------------------------------------------- */
async checkCaracXP(caracName) {
let carac = this.data.data.carac[caracName];
@ -1665,6 +1673,27 @@ export class RdDActor extends Actor {
}
}
/* -------------------------------------------- */
async _appliquerAppelMoral(rollData, display = true) {
console.log("_appliquerAppelMoral");
console.log("_appliquerAppelMoral");
console.log("_appliquerAppelMoral");
console.log("_appliquerAppelMoral");
console.log(rollData);
console.log(this.name);
console.log(this);
if (!this.isPersonnage()) return;
if (!rollData.rolled.isEchec) return;
const waitUpdate = this.moralIncDec(-1); /* L'appel au moral a échoué. Le personnage perd un point de moral */
console.log("_appliquerAppelMoral : moral diminuer");
rollData.moralDiminuer = true;
rollData.moralActualiser = 7;
await waitUpdate;
rollData.moralActualiser = this.getMoralTotal();
console.log("rollData.moralDiminuer: "+rollData.moralDiminuer);
console.log("rollData.moralActualiser: "+rollData.moralActualiser);
}
/* -------------------------------------------- */
filterSortList(sortList, coord) {
let tmr = TMRUtility.getTMR( coord);
@ -1967,6 +1996,7 @@ export class RdDActor extends Actor {
label: 'Jet ' + Grammar.apostrophe('de', name),
callbacks: [
this.createCallbackExperience(),
this.createCallbackAppelAuMoral(),
{ action: r => this._competenceResult(r) }
]
});
@ -2210,7 +2240,9 @@ export class RdDActor extends Actor {
async _competenceResult(rollData) {
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-competence.html')
}
async _moralDecrease(rollData) {
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-competence.html')
}
/* -------------------------------------------- */
async rollAppelChance(onSuccess = () => { }, onEchec = () => { }) {
let rollData = { selectedCarac: this.getCaracByName('chance-actuelle'), surprise: '' };

View File

@ -1,3 +1,5 @@
import { Grammar } from "./grammar.js";
export class RdDCarac {
static isAgiliteOuDerivee(selectedCarac) {
@ -25,6 +27,6 @@ export class RdDCarac {
* ainsi que de Perception active et volontaire.
*/
static isActionPhysique(selectedCarac) {
return selectedCarac?.label.match(/(Apparence|Force|Agilité|Dextérité|Vue|Ouïe|Odorat-Goût|Empathie|Mêlée|Tir|Lancer|Dérobée)/);
return Grammar.toLowerCaseNoAccent(selectedCarac?.label).match(/(apparence|force|agilite|dexterite|vue|ouie|odorat|empathie|melee|tir|lancer|derobee)/);
}
}

View File

@ -37,7 +37,7 @@ export class RdDRoll extends Dialog {
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
difficultesLibres: CONFIG.RDD.difficultesLibres,
etat: actor.getEtatGeneral(),
moral: actor.getMoralTotal(),
moral: actor.getMoralTotal(), /* La valeur du moral pour les jets de volonté */
carac: actor.data.data.carac,
finalLevel: 0,
diffConditions: 0,
@ -46,14 +46,17 @@ export class RdDRoll extends Dialog {
surencMalusFlag: actor.isPersonnage() ? (actor.data.data.compteurs.surenc.value < 0) : false,
surencMalusValue: actor.getSurenc(),
useMalusSurenc: false,
use: { libre:true, conditions: true, surenc: false, encTotal: false, },
appelAuMoralDemander :false,
use: { libre:true, conditions: true, surenc: false, encTotal: false, appelAuMoral : false },
isMalusEncombrementTotal: RdDItemCompetence.isMalusEncombrementTotal(rollData.competence),
useMalusEncTotal: false,
encTotal: actor.getEncTotal(),
ajustementAstrologique: actor.ajustementAstrologique(),
surprise: actor.getSurprise(false),
}
console.log("defaultRollData.appelAuMoralFlag : "+defaultRollData.appelAuMoralFlag);
mergeObject(rollData, defaultRollData, { recursive: true, overwrite: false });
console.log("rollData.appelAuMoralFlag : "+rollData.appelAuMoralFlag);
if ( rollData.forceCarac) {
rollData.carac = rollData.forceCarac;
}
@ -187,6 +190,23 @@ export class RdDRoll extends Dialog {
this.rollData.useMalusEncTotal = event.currentTarget.checked;
this.updateRollResult();
});
html.find('#useAppelAuMoralCheckbox').change((event) => { /* l'appel au moral, qui donne un bonus de +1 */
console.log("#useAppelAuMoralCheckbox");
//console.log("surencMalusFlag : "+surencMalusFlag);
console.log("this.appelAuMoralFlag : "+this.appelAuMoralFlag);
console.log("this.rollData.moral : "+this.rollData.moral);
console.log("this.rollData.ajustements : "+this.rollData.ajustements);
console.log("this.rollData.ajustements.moral : "+this.rollData.ajustements.moral);
console.log("this.rollData.ajustements.moral.isVisible : "+this.rollData.ajustements.moral.isVisible);
console.log("event.currentTarget.checked : "+event.currentTarget.checked);
console.log("this.rollData.use.appelAuMoral : "+this.rollData.use.appelAuMoral);
this.rollData.appelAuMoralDemander = event.currentTarget.checked
// this.rollData.use.appelAuMoral = event.currentTarget.checked
console.log("this.rollData.moral : "+this.rollData.moral);
console.log("this.rollData.use.appelAuMoral : "+this.rollData.use.appelAuMoral);
this.updateRollResult();
});
// Section Méditation
html.find('.conditionMeditation').change((event) => {
let condition = event.currentTarget.attributes['id'].value;
@ -211,10 +231,28 @@ export class RdDRoll extends Dialog {
rollData.bonus = RdDItemSort.getCaseBonus(rollData.selectedSort, rollData.coord);
}
/* ! actor.isPersonnage() || */
if ( ! RdDCarac.isActionPhysique(rollData.selectedCarac) ) {
rollData.use.appelAuMoral = false;
} else {
rollData.use.appelAuMoral = rollData.appelAuMoralDemander;
}
RollDataAjustements.calcul(rollData, this.actor);
rollData.finalLevel = this._computeFinalLevel(rollData);
console.log("updateRollResult");
console.log("rollData.ajustements.moralTotal.used: "+rollData.ajustements.moralTotal.used);
console.log("rollData.ajustements.moral.used: "+rollData.ajustements.moral.used);
console.log("rollData.use.appelAuMoral: "+rollData.use.appelAuMoral);
console.log("rollData.selectedCarac: ");
console.log(rollData.selectedCarac);
console.log("RdDCarac.isActionPhysique(rollData.selectedCarac): "+RdDCarac.isActionPhysique(rollData.selectedCarac));
HtmlUtility._showControlWhen($(".diffMoral"), rollData.ajustements.moralTotal.used);
HtmlUtility._showControlWhen($(".diffAppelAuMoral"), RdDCarac.isActionPhysique(rollData.selectedCarac) );
HtmlUtility._showControlWhen($(".diffAppelAuMoral-checker"), RdDCarac.isActionPhysique(rollData.selectedCarac) );
HtmlUtility._showControlWhen($("#etat-general"), !RdDCarac.isIgnoreEtatGeneral(rollData.selectedCarac, rollData.competence));
HtmlUtility._showControlWhen($("#ajust-astrologique"), RdDResolutionTable.isAjustementAstrologique(rollData));

View File

@ -246,6 +246,7 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html',
// messages tchat
'systems/foundryvtt-reve-de-dragon/templates/chat-infojet.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-info-appel-au-moral.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-demande-defense.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-demande-attaque-particuliere.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-demande-attaque-etotal.html',

View File

@ -74,8 +74,8 @@ export const referenceAjustements = {
},
moral: {
isVisible: (rollData, actor) => RdDCarac.isActionPhysique(rollData.selectedCarac),
isUsed: (rollData, actor) => rollData.use?.moral,
getLabel: (rollData, actor) => 'Moral',
isUsed: (rollData, actor) => rollData.use?.appelAuMoral,
getLabel: (rollData, actor) => 'Appel au moral',
getValue: (rollData, actor) => 1
},
moralTotal: {

View File

@ -812,6 +812,22 @@ ul, li {
text-align: center;
}
.diffAppelAuMoral {
display: none !important;
}
.diffAppelAuMoral-checker{
display: inline-block;
background-image: url('../icons/moral-neutre.svg');
width: 20px;
height: 20px;
background-size: cover;
}
.diffAppelAuMoral:checked + .diffAppelAuMoral-checker {
background-image: url('../icons/moral-heureux.svg');
}
/* ======================================== */
/* Fatigue CSS */
.table-fatigue {

View File

@ -0,0 +1,4 @@
{{#if use.appelAuMoral}}<div>
{{alias}} fait appel {{#if (gt moral 0)}}au moral{{else}}à l'énergie du déspoir{{/if}} {{#if moralDiminuer}}et échoue, diminuant son moral.{{else}} et réussit.{{/if}}
{{^moralDiminuer}} Son moral reste inchangé à {{moral}}.{{/moralDiminuer}}
<div>{{/if}}

View File

@ -12,6 +12,7 @@
<div>
<span>{{#if rolled.ptTache}}{{rolled.ptTache}} points de tâche{{/if}}{{#if rolled.ptQualite}}{{#if rolled.ptTache}},{{/if}} ajustement Qualité {{numberFormat rolled.ptQualite decimals=0 sign=true}}{{/if}}</span>
</div>
{{> "systems/foundryvtt-reve-de-dragon/templates/chat-info-appel-au-moral.html"}}
{{~#if show.explications}}
<div>
{{show.explications}}

View File

@ -11,6 +11,8 @@
</select>
<label></label>
</div>
<input class="diffAppelAuMoral" id="useAppelAuMoralCheckbox" type="checkbox" name="appelAuMoralDemander" />
<label for="useAppelAuMoralCheckbox" class="diffAppelAuMoral-checker" id="diffAppelAuMoral-checker"></label>
<div class="form-group">
{{#if attackerRoll}}
<label for="categorie">Difficulté</label>