Chance actuelle

+ amélioration show/hide: dispo pour toute application
 (Dialog, Sheet)
This commit is contained in:
Vincent Vandemeulebrouck 2020-12-06 18:41:54 +01:00
parent c5c6d6208d
commit 29eb489b27
5 changed files with 120 additions and 115 deletions

View File

@ -5,6 +5,7 @@
import { RdDUtility } from "./rdd-utility.js"; import { RdDUtility } from "./rdd-utility.js";
import { RdDEncaisser } from "./rdd-roll-encaisser.js"; import { RdDEncaisser } from "./rdd-roll-encaisser.js";
import { HtmlUtility } from "./html-utility.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDActorSheet extends ActorSheet { export class RdDActorSheet extends ActorSheet {
@ -90,7 +91,6 @@ export class RdDActorSheet extends ActorSheet {
this.armesList = duplicate(data.data.combat); this.armesList = duplicate(data.data.combat);
data.data.carac.taille.isTaille = true; // To avoid button link; data.data.carac.taille.isTaille = true; // To avoid button link;
data.data.carac.chance.isChance = true; // Ajouter chance actuelle et utiliser;
data.data.compteurs.chance.isChance = true; data.data.compteurs.chance.isChance = true;
data.data.blessures.resume = this.actor.computeResumeBlessure(data.data.blessures); data.data.blessures.resume = this.actor.computeResumeBlessure(data.data.blessures);
@ -190,11 +190,7 @@ export class RdDActorSheet extends ActorSheet {
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
if (game.user.isGM) { HtmlUtility._showControlWhen(".gm-only", game.user.isGM);
$(".gm-only").show();
} else {
$(".gm-only").hide();
}
// Everything below here is only needed if the sheet is editable // Everything below here is only needed if the sheet is editable
if (!this.options.editable) return; if (!this.options.editable) return;
@ -258,6 +254,10 @@ export class RdDActorSheet extends ActorSheet {
this.actor.rollCarac( caracName.toLowerCase() ); this.actor.rollCarac( caracName.toLowerCase() );
}); });
html.find('#chance-actuel').click((event) => {
this.actor.rollCarac( 'chance-actuel' );
});
// Roll Skill // Roll Skill
html.find('.competence-label a').click((event) => { html.find('.competence-label a').click((event) => {
let compName = event.currentTarget.text; let compName = event.currentTarget.text;

View File

@ -270,7 +270,7 @@ export class RdDActor extends Actor {
this.computeRecul( rollData, encaisser ); this.computeRecul( rollData, encaisser );
} else { // This is the attack roll! } else { // This is the attack roll!
if (rolled.isSuccess) { if (rolled.isSuccess) {
let target = this.getTarget(); let target = this._getTarget();
if (await this.targetEntiteNonAccordee(target, 'avant-defense')) { if (await this.targetEntiteNonAccordee(target, 'avant-defense')) {
return; return;
} }
@ -1273,15 +1273,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollCarac( caracName ) async rollCarac( caracName )
{ {
let carac; let carac = this.getCaracByName(caracName);
if ( caracName == "reveActuel") { // Fake carac for Reve Actuel
carac = {type: "number",
value: this.getReveActuel(),
label: "Rêve Actuel"
}
} else {
carac = this.data.data.carac[caracName];// Per default
}
let rollData = { let rollData = {
selectedCarac: carac, selectedCarac: carac,
ajustementsConditions: CONFIG.RDD.ajustementsConditions, ajustementsConditions: CONFIG.RDD.ajustementsConditions,
@ -1302,6 +1294,28 @@ export class RdDActor extends Actor {
new RdDRollDialog("carac", html, rollData, this ).render(true); new RdDRollDialog("carac", html, rollData, this ).render(true);
} }
getCaracByName(caracName) {
switch (caracName)
{
case 'reveActuel':
return {
label: 'Rêve Actuel',
value: this.getReveActuel(),
type: "number",
ignoreEtatGeneral: true
};
case 'chance-actuelle':
return {
type: "number",
value: this.getChanceActuel(),
label: 'Chance actuelle',
ignoreEtatGeneral: true
};
default:
return this.data.data.carac[caracName]; // Per default
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
getSortList() { getSortList() {
return this.data.items.filter(item => item.type == "sort"); return this.data.items.filter(item => item.type == "sort");
@ -1347,8 +1361,7 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
rollArme( armeName, competenceName=undefined ) rollArme( armeName, competenceName=undefined ) {
{
let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName)); let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName));
if (armeItem ) { if (armeItem ) {
if ( competenceName == undefined) competenceName = armeItem.data.competence; if ( competenceName == undefined) competenceName = armeItem.data.competence;
@ -1415,7 +1428,7 @@ export class RdDActor extends Actor {
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData); let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
if (rollData.arme) { if (rollData.arme) {
if (await this.targetEntiteNonAccordee(this.getTarget(), 'avant-attaque')) { if (await this.targetEntiteNonAccordee(this._getTarget(), 'avant-attaque')) {
return; return;
} }
new RdDRollDialog("arme", html, rollData, this, attacker).render(true); new RdDRollDialog("arme", html, rollData, this, attacker).render(true);
@ -1424,8 +1437,7 @@ export class RdDActor extends Actor {
} }
} }
/* -------------------------------------------- */ _getTarget() {
getTarget() {
if (game.user.targets && game.user.targets.size == 1) { if (game.user.targets && game.user.targets.size == 1) {
for (let target of game.user.targets) { for (let target of game.user.targets) {
return target; return target;
@ -1435,8 +1447,7 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async equiperObjet( itemID ) async equiperObjet( itemID ) {
{
let item = this.getOwnedItem(itemID); let item = this.getOwnedItem(itemID);
if ( item && item.data.data ) { if ( item && item.data.data ) {
let update = {_id: item._id, "data.equipe": !item.data.data.equipe }; let update = {_id: item._id, "data.equipe": !item.data.data.equipe };
@ -1476,7 +1487,6 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async encaisserDommages( attackerRoll, attacker = undefined ) { async encaisserDommages( attackerRoll, attacker = undefined ) {
if (attacker && !await attacker.accorder(this, 'avant-encaissement')) { if (attacker && !await attacker.accorder(this, 'avant-encaissement')) {
return; return;
} }

10
module/html-utility.js Normal file
View File

@ -0,0 +1,10 @@
export class HtmlUtility{
static _showControlWhen(control, condition) {
if (condition) {
$(control).show();
}
else {
$(control).hide();
}
}
}

View File

@ -1,3 +1,4 @@
import { HtmlUtility } from "./html-utility.js";
import { RdDItemSort } from "./item-sort.js"; import { RdDItemSort } from "./item-sort.js";
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js";
@ -72,25 +73,12 @@ export class RdDRollDialog extends Dialog {
rollData.finalLevel = rollLevel; rollData.finalLevel = rollLevel;
rollData.caracValue = caracValue rollData.caracValue = caracValue
if (RdDRollDialog._isEtatGeneralApplicable(rollData)) { HtmlUtility._showControlWhen(".etat-general", !RdDRollDialog._isIgnoreEtatGeneral(rollData));
$(".etat-general").show();
}
else {
$(".etat-general").hide();
}
// Sort management // Sort management
if ( rollData.selectedSort ) { if ( rollData.selectedSort ) {
//console.log("Toggle show/hide", rollData.selectedSort); //console.log("Toggle show/hide", rollData.selectedSort);
if (RdDItemSort.isDifficulteVariable(rollData.selectedSort)) { HtmlUtility._showControlWhen("#div-sort-difficulte",RdDItemSort.isDifficulteVariable(rollData.selectedSort));
$("#div-sort-difficulte").show(); HtmlUtility._showControlWhen("#div-sort-ptreve", RdDItemSort.isCoutVariable(rollData.selectedSort));
} else {
$("#div-sort-difficulte").hide();
}
if (RdDItemSort.isCoutVariable(rollData.selectedSort)) {
$("#div-sort-ptreve").show();
} else {
$("#div-sort-ptreve").hide();
}
} }
// Mise à jour valeurs // Mise à jour valeurs
@ -173,16 +161,13 @@ export class RdDRollDialog extends Dialog {
}); });
} }
static _isEtatGeneralApplicable(rollData) { static _isIgnoreEtatGeneral(rollData) {
if (rollData.selectedCarac.label == 'Chance') return false; return rollData.selectedCarac.ignoreEtatGeneral;
if (rollData.selectedCarac.label == 'Rêve Actuel') return false;
return true;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static _computeFinalLevel(rollData) { static _computeFinalLevel(rollData) {
const etat = RdDRollDialog._isEtatGeneralApplicable(rollData) ? Misc.toInt(rollData.etat) : 0; const etat = RdDRollDialog._isIgnoreEtatGeneral(rollData) ? 0 : Misc.toInt(rollData.etat);
const diffConditions = Misc.toInt(rollData.diffConditions); const diffConditions = Misc.toInt(rollData.diffConditions);
let malusEnc = (rollData.surencMalusApply ) ? rollData.surencMalusValue : 0; let malusEnc = (rollData.surencMalusApply ) ? rollData.surencMalusValue : 0;
let diffLibre = Misc.toInt(rollData.diffLibre); let diffLibre = Misc.toInt(rollData.diffLibre);

View File

@ -131,7 +131,7 @@
</ul> </ul>
<ul class="carac-list alterne-list"> <ul class="carac-list alterne-list">
<li class="competence flexrow list-item"> <li class="competence flexrow list-item">
<span class="generic-label" id="chance-actuel"><a>Chance actuelle</a></span> <span class="generic-label" id="chance-actuelle"><a>Chance actuelle</a></span>
<input class="compteur-edit" id="chance-edit" type="text" name="chance" value="{{data.compteurs.chance.value}}" data-dtype="number"/> <input class="compteur-edit" id="chance-edit" type="text" name="chance" value="{{data.compteurs.chance.value}}" data-dtype="number"/>
<a class="item-control stress-test" id="chance-appel">Utiliser</a> <a class="item-control stress-test" id="chance-appel">Utiliser</a>
</li> </li>