diff --git a/module/actor.js b/module/actor.js index 22229bd9..cf25a7a0 100644 --- a/module/actor.js +++ b/module/actor.js @@ -700,13 +700,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ detectSurEncombrement( ) { let diffEnc = Number(this.encTotal) - Number(this.data.data.attributs.encombrement.value); - if ( diffEnc > 0 ) { // Sur-encombrement - let malus = Math.round( diffEnc); - malus = (malus == 0) ? 1 : malus; // Always 1 at least - //console.log("Sur enc malus", malus); - return malus; - } - return 0; + return Math.min(0, Math.ceil(diffEnc)); } /* -------------------------------------------- */ @@ -770,7 +764,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getEtatGeneral() { - return (this.data.data.compteurs && this.data.data.compteurs.etat) ? this.data.data.compteurs.etat.value : 0; + return this.data.data.compteurs?.etat?.value ?? 0; } /* -------------------------------------------- */ @@ -784,11 +778,13 @@ export class RdDActor extends Actor { } // Pour les autres let state = - (data.sante.vie.max - data.sante.vie.value); - if (data.sante.fatigue) // Creatures n'ont pas de fatigue + if (data.sante.fatigue){ + // Creatures n'ont pas de fatigue 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 += data.compteurs.ethylisme.value; - } + } + // Ajout de l'éthylisme + state += Math.min(0, (data.compteurs?.ethylisme?.value ??0)); + data.compteurs.etat.value = state; if ( data.compteurs && data.compteurs.surenc) { data.compteurs.surenc.value = - this.detectSurEncombrement(); diff --git a/module/rdd-bonus.js b/module/rdd-bonus.js index e5b7c156..aadd6e55 100644 --- a/module/rdd-bonus.js +++ b/module/rdd-bonus.js @@ -66,11 +66,11 @@ export class RdDBonus { /* -------------------------------------------- */ static _dmgArme(rollData) { - return rollData.arme ? parseInt(rollData.arme.data.dommages) : 0; + return parseInt(rollData.arme?.data.dommages ?? 0); } static _peneration(rollData) { - return rollData.arme ? parseInt(rollData.arme.data.penetration) : 0; + return parseInt(rollData.arme?.data.penetration ?? 0); } /* -------------------------------------------- */ diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 8d9ea3f8..b1d755b0 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -18,12 +18,12 @@ export class RdDCombat { static createUsingTarget(attacker) { const target = RdDCombat.getTarget(); if (target == undefined) { - ui.notifications.warn((game.user.targets && game.user.targets.size > 1) + ui.notifications.warn( (game.user.targets?.size ??0) > 1 ? "Vous devez choisir une seule cible à attaquer!" : "Vous devez choisir une cible à attaquer!"); } - const defender = target ? target.actor : undefined; - const defenderTokenId = target ? target.data._id : undefined; + const defender = target?.actor; + const defenderTokenId = target?.data._id; return this.create(attacker, defender, defenderTokenId, target) } @@ -68,8 +68,8 @@ export class RdDCombat { // 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, + attackerId: sender?.data._id, + defenderId: recipient?.data._id, defenderTokenId: defenderTokenId, rollData: duplicate(rollData), rollMode: true @@ -128,7 +128,7 @@ export class RdDCombat { case '#particuliere-attaque': return await this.choixParticuliere(rollData, event.currentTarget.attributes['data-mode'].value); case '#parer-button': { const armeId = event.currentTarget.attributes['data-armeid']; - return this.parade(rollData, armeId ? armeId.value : undefined); + return this.parade(rollData, armeId?.value); } case '#esquiver-button': return this.esquive(rollData); case '#encaisser-button': return this.encaisser(rollData, event.currentTarget.attributes['data-defenderTokenId'].value); @@ -182,7 +182,7 @@ export class RdDCombat { options: { height: 540 } }, { name: 'jet-attaque', - label: 'Attaque: ' + (arme ? arme.name : competence.name), + label: 'Attaque: ' + (arme?.name ?? competence.name), callbacks: [ this.attacker.createCallbackExperience(), { condition: r => (RdDCombat.isReussite(r) && !RdDCombat.isParticuliere(r)), action: r => this._onAttaqueNormale(r) }, diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index b113b872..521d760a 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -122,7 +122,7 @@ export class RdDResolutionTable { list.push({ label: surprise.descr, value: surprise.attaque }); } if (rollData.diffLibre != undefined) { - const label = rollData.selectedSort ? rollData.selectedSort.name : 'Libre'; + const label = rollData.selectedSort?.name ?? 'Libre'; list.push({ label: label, value: rollData.diffLibre }); } if (rollData.diffConditions != undefined) { @@ -131,11 +131,11 @@ export class RdDResolutionTable { if (rollData.etat != undefined) { list.push({ label: 'Etat', value: rollData.etat }); } - if (rollData.selectedCarac != undefined && rollData.moral != undefined && rollData.selectedCarac.label == 'Volonté') { - list.push({ label: 'Moral', value: rollData.selectedCarac != undefined && rollData.moral != undefined && rollData.selectedCarac.label == 'Volonté' ? rollData.moral : undefined }); + if (rollData.selectedCarac?.label == 'Volonté' && rollData.moral != undefined) { + list.push({ label: 'Moral', value: rollData.moral }); } if (RdDResolutionTable.isAjustementAstrologique(rollData)) { - list.push({ label: 'Astrologique', value: rollData.ajustementAstrologique || 0 }); + list.push({ label: 'Astrologique', value: rollData.ajustementAstrologique ?? 0 }); } if (rollData.rolled.bonus && rollData.selectedSort) { list.push({ descr: `Bonus de case: ${rollData.rolled.bonus}%` }); diff --git a/module/rdd-roll.js b/module/rdd-roll.js index 31ff9a14..11a9ad05 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -38,12 +38,12 @@ export class RdDRoll extends Dialog { 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, + diffConditions: rollData.arme ? RdDBonus.bonusAttaque(rollData.surpriseDefenseur) : 0, diffLibre: rollData.competence?.data.default_diffLibre ?? 0, editLibre: true, editConditions: true, forceValue: actor.getForceValue(), - malusArmureValue: (actor.isPersonnage() && actor.data.data.attributs && actor.data.data.attributs.malusarmure) ? actor.data.data.attributs.malusarmure.value : 0, + malusArmureValue: actor.isPersonnage() ? actor.data.data.attributs?.malusarmure?.value ?? 0 : 0, surencMalusFlag: actor.isPersonnage() ? (actor.data.data.compteurs.surenc.value < 0) : false, surencMalusValue: actor.isPersonnage() ? actor.data.data.compteurs.surenc.value : 0, surencMalusApply: false, @@ -111,10 +111,10 @@ export class RdDRoll extends Dialog { var dialog = this; function updateRollResult(rollData) { - rollData.dmg = rollData.attackerRoll ? rollData.attackerRoll.dmg : RdDBonus.dmg(rollData, actor.getBonusDegat()); + rollData.dmg = rollData.attackerRoll?.dmg ?? RdDBonus.dmg(rollData, actor.getBonusDegat()); rollData.finalLevel = dialog._computeFinalLevel(rollData); rollData.caracValue = parseInt(rollData.selectedCarac.value); - rollData.coupsNonMortels = (rollData.attackerRoll ? rollData.attackerRoll.dmg.mortalite : rollData.dmg.mortalite) == 'non-mortel'; + rollData.coupsNonMortels = (rollData.attackerRoll?.dmg.mortalite ?? rollData.dmg.mortalite) == 'non-mortel'; let dmgText = Misc.toSignedString(rollData.dmg.total); if (rollData.coupsNonMortels) { dmgText = '(' + dmgText + ')'; diff --git a/module/rdd-utility.js b/module/rdd-utility.js index edd83018..314e200a 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -673,10 +673,8 @@ export class RdDUtility { /* -------------------------------------------- */ static currentFatigueMalus( value, max) { - max = (max < 16) ? 16 : max; - max = (max > 30) ? 30 : max; - value = (value > max*2) ? max*2 : value; - value = (value < 0) ? 0 : value; + max = Math.min(1, Math.max(max, 60)); + value = Math.min(max*2, Math.max(0, value)); let fatigueTab = fatigueMatrix[max]; let fatigueRem = value;