Fix retour en arrière sur le calendrier

This commit is contained in:
sladecraven 2020-12-21 15:15:58 +01:00
commit 84bca5d95c
13 changed files with 40 additions and 34 deletions

View File

@ -113,7 +113,7 @@ export class RdDActorSheet extends ActorSheet {
this.actor.computeEncombrementTotalEtMalusArmure();
// Common data
data.data.competenceByCategory = data.competenceByCategory;
data.data.encombrementTotal = this.actor.encombrementTotal;
data.data.encTotal = this.actor.encTotal;
data.data.isGM = game.user.isGM;
data.ajustementsConditions = CONFIG.RDD.ajustementsConditions;
data.difficultesLibres = CONFIG.RDD.difficultesLibres;

View File

@ -77,7 +77,7 @@ export class RdDActor extends Actor {
const actorData = this.data;
// Dynamic computing fields
this.encombrementTotal = 0;
this.encTotal = 0;
/*
// Auto-resize token
@ -158,7 +158,9 @@ export class RdDActor extends Actor {
return duplicate(list[0]);
}
getEncombrementTotal() {
return this.encTotal ? Math.floor(this.encTotal) : 0
}
/* -------------------------------------------- */
async deleteSortReserve(coordTMR) {
let reserve = duplicate(this.data.data.reve.reserve);
@ -618,7 +620,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
detectSurEncombrement( ) {
let diffEnc = Number(this.encombrementTotal) - Number(this.data.data.attributs.encombrement.value);
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
@ -630,7 +632,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async computeEncombrementTotalEtMalusArmure( ) {
let totalEnc = 0;
let encTotal = 0;
let malusArmureData = duplicate(this.data.data.attributs.malusarmure);
let newMalusArmure = 0;
for (const item of this.data.items) {
@ -643,13 +645,13 @@ export class RdDActor extends Actor {
if (!item.data.quantite) item.data.quantite = 1; // Auto-fix
item.data.encTotal = Number(item.data.encombrement) * Number(item.data.quantite);
//console.log("Enc:", item.name, item.data.encombrement, item.data.quantite, item.data.encTotal);
totalEnc += item.data.encTotal;
encTotal += item.data.encTotal;
} else {
item.data.encTotal = 0; // Force default enc
}
}
// Mise à jour valeur totale et états
this.encombrementTotal = totalEnc;
this.encTotal = encTotal;
this.detectSurEncombrement();
// Mise à jour éventuelle du malus armure
if (newMalusArmure != malusArmureData.value) {

View File

@ -5,7 +5,10 @@ export class RdDItemCompetence extends Item {
return name.toLowerCase().match(/(epée|épée|hache|fleau|fléau|masse|lance|hast|dague|bouclier)/);
}
static isArmeUneMain(competence) {
return competence.name.toLowerCase().includes("1 main");
return competence && competence.name.toLowerCase().includes("1 main");
}
static isMalusEncombrementTotal(competence) {
return competence && competence.name.toLowerCase().match(/(natation|acrobatie)/);
}
}

View File

@ -252,7 +252,7 @@ Hooks.once("ready", function() {
}
// Integration du TokenHUD
Hooks.on('renderTokenHUD', (app, html, data) => { RdDTokenHud.addTokenHudExtensions(app, html, data) });
Hooks.on('renderTokenHUD', (app, html, data) => { RdDTokenHud.addTokenHudExtensions(app, html, data._id) });
});
/* -------------------------------------------- */

View File

@ -1,4 +1,5 @@
import { HtmlUtility } from "./html-utility.js";
import { RdDItemCompetence } from "./item-competence.js";
import { RdDItemSort } from "./item-sort.js";
import { Misc } from "./misc.js";
import { RdDBonus } from "./rdd-bonus.js";
@ -45,9 +46,9 @@ export class RdDRoll extends Dialog {
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,
encValueForNatation: actor.encombrementTotal ? Math.floor(actor.encombrementTotal) : 0,
isMalusEncombrementTotal: RdDItemCompetence.isMalusEncombrementTotal(rollData.competence),
useMalusEncTotal: false,
encTotal: actor.getEncombrementTotal(),
ajustementAstrologique: actor.ajustementAstrologique()
}
mergeObject(rollData, defaultRollData, { overwrite: false });
@ -210,8 +211,8 @@ export class RdDRoll extends Dialog {
this.rollData.surencMalusApply = event.currentTarget.checked;
updateRollResult(rollData);
});
html.find('#useEncForNatation').change((event) => {
this.rollData.useEncForNatation = event.currentTarget.checked;
html.find('#useMalusEncTotal').change((event) => {
this.rollData.useMalusEncTotal = event.currentTarget.checked;
updateRollResult(rollData);
});
}
@ -226,7 +227,7 @@ export class RdDRoll extends Dialog {
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 malusEncTotal = (rollData.useMalusEncTotal) ? -rollData.encTotal : 0;
const ajustementChance = rollData.selectedCarac.label.toLowerCase().includes('chance') ? rollData.ajustementAstrologique : 0;
// Gestion malus armure
const malusArmureValue = this._computeMalusArmure(rollData);
@ -235,7 +236,7 @@ export class RdDRoll extends Dialog {
const diffCompetence = this._computeDiffCompetence(rollData);
const diffMoral = rollData.selectedCarac == this.actor.data.data.carac.volonte ? rollData.moral : 0;
return etat + diffCompetence + diffLibre + diffMoral + diffConditions + malusEnc + malusEncNatation + malusArmureValue + ajustementChance + bonusTactique;
return etat + diffCompetence + diffLibre + diffMoral + diffConditions + malusEnc + malusEncTotal + malusArmureValue + ajustementChance + bonusTactique;
}
_computeDiffCompetence(rollData) {

View File

@ -7,8 +7,8 @@ export class RdDTokenHud {
/* -------------------------------------------- */
static async addTokenHudExtensions(app, html, data) {
let token = canvas.tokens.get(data._id);
static async addTokenHudExtensions(app, html, tokenId) {
let token = canvas.tokens.get(tokenId);
let actor = token.actor;
let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id);
@ -17,10 +17,10 @@ export class RdDTokenHud {
if (!token.inCombat) return;
if (!combatant) return;
const dataUp = { combatant: combatant, armes: RdDTokenHud.buildListeActionsCombat(combatant) };
const hudData = { combatant: combatant, armes: RdDTokenHud.buildListeActionsCombat(combatant) };
// initiative
await RdDTokenHud._configureSubMenu(html.find('.control-icon.combat'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', dataUp,
await RdDTokenHud._configureSubMenu(html.find('.control-icon.combat'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', hudData,
(event) => {
let armeIndex = event.currentTarget.attributes['data-arme-id'].value;
let combatantId = event.currentTarget.attributes['data-combatant-id'].value;
@ -29,7 +29,7 @@ export class RdDTokenHud {
});
// combat
await RdDTokenHud._configureSubMenu(html.find('.control-icon.target'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', dataUp,
await RdDTokenHud._configureSubMenu(html.find('.control-icon.target'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', hudData,
(event) => {
let armeIndex = event.currentTarget.attributes['data-arme-id'].value;
let arme = armesList[armeIndex];
@ -48,8 +48,8 @@ export class RdDTokenHud {
}
/* -------------------------------------------- */
static async _configureSubMenu(insertionPoint, template, data, onMenuItem) {
const hud = $(await renderTemplate(template, data));
static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) {
const hud = $(await renderTemplate(template, hudData));
const imgHud = hud.find('img.rdd-hud-togglebutton');
const list = hud.find('div.rdd-hud-list');

View File

@ -179,7 +179,7 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-encaisser.html',
'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html',
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-surenc.html',
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-natation.html',
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-enctotal.html',
'systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html',
// Calendrier
'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html',

View File

@ -176,7 +176,7 @@
{{!-- Equipment Tab --}}
<div class="tab items" data-group="primary" data-tab="items">
<span cass=item-name>Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}}</span>
<span cass=item-name>Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}}</span>
<hr>
<span cass=item-name>Porté sur soi</span>
<ol class="item-list alterne-list">

View File

@ -176,7 +176,7 @@
{{!-- Equipment Tab --}}
<div class="tab items" data-group="primary" data-tab="items">
<span cass=item-name>Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}}</span>
<span cass=item-name>Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}}</span>
<ol class="item-list alterne-list">
<li class="competence-header flexrow">
<span class="competence-title competence-label">Nom</span>

View File

@ -597,7 +597,7 @@
{{!-- Equipment Tab --}}
<div class="tab items" data-group="primary" data-tab="items">
<span class="item-name">Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}} <b>{{data.surEncombrementMessage}}</b></span> -
<span class="item-name">Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}} <b>{{data.surEncombrementMessage}}</b></span> -
<span class="item-name"><a id="creer-un-objet">Créer un objet</a></span>
<ul class="item-list alterne-list">
<li class="competence-header flexrow">

View File

@ -65,7 +65,7 @@
</div>
{{>"systems/foundryvtt-reve-de-dragon/templates/dialog-roll-surenc.html"}}
{{>"systems/foundryvtt-reve-de-dragon/templates/dialog-roll-natation.html"}}
{{>"systems/foundryvtt-reve-de-dragon/templates/dialog-roll-enctotal.html"}}
<div id="resolutionTable">
</div>
<div id="resolutionValeurs">

View File

@ -0,0 +1,6 @@
{{#if isMalusEncombrementTotal}}
<div class="form-group">
<label for="xp">Appliquer l'encombrement total comme malus (-{{encTotal}} ) ? </label>
<input class="attribute-value" type="checkbox" id="useMalusEncTotal" name="useMalusEncTotal" {{#if useMalusEncTotal}}checked{{/if}}/>
</div>
{{/if}}

View File

@ -1,6 +0,0 @@
{{#if isNatation}}
<div class="form-group">
<label for="xp">Appliquer l'encombrement comme malus à la Natation (-{{encValueForNatation}} ) ? </label>
<input class="attribute-value" type="checkbox" id="useEncForNatation" name="useEncForNatation" {{#if useEncForNatation}}checked{{/if}}/>
</div>
{{/if}}