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

View File

@ -270,7 +270,7 @@ export class RdDActor extends Actor {
this.computeRecul( rollData, encaisser );
} else { // This is the attack roll!
if (rolled.isSuccess) {
let target = this.getTarget();
let target = this._getTarget();
if (await this.targetEntiteNonAccordee(target, 'avant-defense')) {
return;
}
@ -1273,91 +1273,104 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async rollCarac( caracName )
{
let carac;
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 carac = this.getCaracByName(caracName);
let rollData = {
selectedCarac: carac,
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
difficultesLibres: CONFIG.RDD.difficultesLibres,
etat: this.data.data.compteurs.etat.value,
finalLevel: 0,
diffConditions: 0,
diffLibre: 0,
malusArmureValue: (this.data.data.attributs) ? this.data.data.attributs.malusarmure.value : 0,
surencMalusFlag: (this.data.data.compteurs.surenc.value < 0),
surencMalusValue: this.data.data.compteurs.surenc.value,
surencMalusApply: false,
isNatation: false,
useEncForNatation: false
}
console.log(caracName, rollData);
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', rollData);
new RdDRollDialog("carac", html, rollData, this ).render(true);
selectedCarac: carac,
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
difficultesLibres: CONFIG.RDD.difficultesLibres,
etat: this.data.data.compteurs.etat.value,
finalLevel: 0,
diffConditions: 0,
diffLibre: 0,
malusArmureValue: (this.data.data.attributs) ? this.data.data.attributs.malusarmure.value : 0,
surencMalusFlag: (this.data.data.compteurs.surenc.value < 0),
surencMalusValue: this.data.data.compteurs.surenc.value,
surencMalusApply: false,
isNatation: false,
useEncForNatation: false
}
console.log(caracName, rollData);
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', rollData);
new RdDRollDialog("carac", html, rollData, this ).render(true);
}
/* -------------------------------------------- */
getSortList() {
return this.data.items.filter(item => item.type == "sort");
}
/* -------------------------------------------- */
getDraconicList() {
return this.data.items.filter(item => item.data.categorie == 'draconic')
}
/* -------------------------------------------- */
async displayTMR(mode="normal")
getCaracByName(caracName) {
switch (caracName)
{
let isRapide= mode == "rapide"
if (mode != "visu")
{
let minReveValue = (isRapide) ? 3 : 2;
if (this.getReveActuel() < minReveValue ) {
ChatMessage.create( {
content: "Vous n'avez plus assez de Points de Reve pour monter dans les Terres Médianes",
whisper: ChatMessage.getWhisperRecipients(game.user.name) } );
return;
}
}
// Notification au MJ
ChatMessage.create( { content: game.user.name + " est monté dans les TMR en mode : " + mode, whisper: ChatMessage.getWhisperRecipients("GM") } );
let data = {
fatigue: {
malus: RdDUtility.calculMalusFatigue(this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max),
html: "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max ).html() + "</table>"
},
draconic: this.getDraconicList(),
sort: this.getSortList(),
caracReve: this.data.data.carac.reve.value,
pointsReve: this.getReveActuel(),
isRapide: isRapide
}
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', data );
this.currentTMR = new RdDTMRDialog(html, this, data, mode);
this.currentTMR.render(true);
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
}
}
/* -------------------------------------------- */
rollArme( armeName, competenceName=undefined )
/* -------------------------------------------- */
getSortList() {
return this.data.items.filter(item => item.type == "sort");
}
/* -------------------------------------------- */
getDraconicList() {
return this.data.items.filter(item => item.data.categorie == 'draconic')
}
/* -------------------------------------------- */
async displayTMR(mode="normal")
{
let isRapide= mode == "rapide"
if (mode != "visu")
{
let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName));
if (armeItem ) {
if ( competenceName == undefined) competenceName = armeItem.data.competence;
this.rollCompetence( competenceName, armeItem );
} else {
this.rollCompetence( armeName ); //Bypass mode!
let minReveValue = (isRapide) ? 3 : 2;
if (this.getReveActuel() < minReveValue ) {
ChatMessage.create( {
content: "Vous n'avez plus assez de Points de Reve pour monter dans les Terres Médianes",
whisper: ChatMessage.getWhisperRecipients(game.user.name) } );
return;
}
}
// Notification au MJ
ChatMessage.create( { content: game.user.name + " est monté dans les TMR en mode : " + mode, whisper: ChatMessage.getWhisperRecipients("GM") } );
let data = {
fatigue: {
malus: RdDUtility.calculMalusFatigue(this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max),
html: "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max ).html() + "</table>"
},
draconic: this.getDraconicList(),
sort: this.getSortList(),
caracReve: this.data.data.carac.reve.value,
pointsReve: this.getReveActuel(),
isRapide: isRapide
}
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', data );
this.currentTMR = new RdDTMRDialog(html, this, data, mode);
this.currentTMR.render(true);
}
/* -------------------------------------------- */
rollArme( armeName, competenceName=undefined ) {
let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName));
if (armeItem ) {
if ( competenceName == undefined) competenceName = armeItem.data.competence;
this.rollCompetence( competenceName, armeItem );
} else {
this.rollCompetence( armeName ); //Bypass mode!
}
}
/* -------------------------------------------- */
async rollCompetence( name, armeItem=undefined, attackerRoll=undefined, attacker = undefined) {
let competence = RdDUtility.findCompetence( this.data.items, name);
@ -1415,7 +1428,7 @@ export class RdDActor extends Actor {
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', rollData);
if (rollData.arme) {
if (await this.targetEntiteNonAccordee(this.getTarget(), 'avant-attaque')) {
if (await this.targetEntiteNonAccordee(this._getTarget(), 'avant-attaque')) {
return;
}
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) {
for (let target of game.user.targets) {
return target;
@ -1435,8 +1447,7 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async equiperObjet( itemID )
{
async equiperObjet( itemID ) {
let item = this.getOwnedItem(itemID);
if ( item && item.data.data ) {
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 ) {
if (attacker && !await attacker.accorder(this, 'avant-encaissement')) {
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 { Misc } from "./misc.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js";
@ -72,25 +73,12 @@ export class RdDRollDialog extends Dialog {
rollData.finalLevel = rollLevel;
rollData.caracValue = caracValue
if (RdDRollDialog._isEtatGeneralApplicable(rollData)) {
$(".etat-general").show();
}
else {
$(".etat-general").hide();
}
HtmlUtility._showControlWhen(".etat-general", !RdDRollDialog._isIgnoreEtatGeneral(rollData));
// Sort management
if ( rollData.selectedSort ) {
//console.log("Toggle show/hide", rollData.selectedSort);
if (RdDItemSort.isDifficulteVariable(rollData.selectedSort)) {
$("#div-sort-difficulte").show();
} else {
$("#div-sort-difficulte").hide();
}
if (RdDItemSort.isCoutVariable(rollData.selectedSort)) {
$("#div-sort-ptreve").show();
} else {
$("#div-sort-ptreve").hide();
}
HtmlUtility._showControlWhen("#div-sort-difficulte",RdDItemSort.isDifficulteVariable(rollData.selectedSort));
HtmlUtility._showControlWhen("#div-sort-ptreve", RdDItemSort.isCoutVariable(rollData.selectedSort));
}
// Mise à jour valeurs
@ -173,16 +161,13 @@ export class RdDRollDialog extends Dialog {
});
}
static _isEtatGeneralApplicable(rollData) {
if (rollData.selectedCarac.label == 'Chance') return false;
if (rollData.selectedCarac.label == 'Rêve Actuel') return false;
return true;
static _isIgnoreEtatGeneral(rollData) {
return rollData.selectedCarac.ignoreEtatGeneral;
}
/* -------------------------------------------- */
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);
let malusEnc = (rollData.surencMalusApply ) ? rollData.surencMalusValue : 0;
let diffLibre = Misc.toInt(rollData.diffLibre);

View File

@ -131,7 +131,7 @@
</ul>
<ul class="carac-list alterne-list">
<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"/>
<a class="item-control stress-test" id="chance-appel">Utiliser</a>
</li>