#13 Support des sorts de difficulte et de cout variables + correction de regression

This commit is contained in:
sladecraven 2020-11-13 11:24:56 +01:00
parent e40b335886
commit a00f187f9f
4 changed files with 77 additions and 34 deletions

View File

@ -151,7 +151,7 @@ export class RdDActor extends Actor {
// Fight management !
let defenseMsg;
let encaisser = false;
if (rollData.arme || rollData.competence.name.toLowerCase() == 'esquive' ) {
if (rollData.arme || (rollData.competence && rollData.competence.name.toLowerCase() == 'esquive') ) {
// In case of fight, replace the message per dommages + localization. it indicates if result is OK or not
if (rollData.attackerRoll) { // Defense case !
if (rolled.isSuccess) {
@ -161,7 +161,7 @@ export class RdDActor extends Actor {
encaisser = true;
}
} else { // This is the attack roll!
if (rolled.isSuccess > 0) {
if (rolled.isSuccess) {
rollData.domArmePlusDom = parseInt(rollData.arme.data.dommages);
if (rollData.selectedCarac.label == "Mêlée") // +dom only for Melee
rollData.domArmePlusDom += parseInt(this.data.data.attributs.plusdom.value);
@ -189,14 +189,14 @@ export class RdDActor extends Actor {
let lvl = ""
if (rollData.selectedSort) { // Lancement de sort !
let draconic = rollData.selectedSort.data.draconic;
let costReve = rollData.selectedSort.data.ptreve_reel || rollData.selectedSort.data.ptreve; // cas de sort à ptreve variables
specialStr = "<br>Lancement du sort <strong>" + rollData.selectedSort.name + "</strong> : " + draconic.charAt(0).toUpperCase() + draconic.slice(1) + "/" + rollData.selectedSort.data.difficulte +
"/" + rollData.selectedSort.data.caseTMR + "/R" + rollData.selectedSort.data.ptreve;
"/" + rollData.selectedSort.data.caseTMR + "/R" + costReve;
specialStr += "<br>Depuis la case " + rollData.coord + " (" + TMRUtility.getTMRDescription(rollData.coord).label + ")";
lvl = rollData.selectedDraconic.name + "/" + rollData.selectedSort.name;
let costReve = rollData.selectedSort.data.ptreve;
let myReve = duplicate(this.data.data.reve.reve);
if (rollData.tache > 0) { // Réussite du sort !
if (rollData.tache >= 4) costReve = Math.ceil(costReve / 2);
if (rolled.isSuccess) { // Réussite du sort !
if (rolled.tache >= 4) costReve = Math.ceil(costReve / 2);
if (costReve < 1) costReve = 1;
myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!!
if (myReve.value < 0) myReve.value = 0;
@ -211,7 +211,7 @@ export class RdDActor extends Actor {
this.currentTMR.updateSortReserve();
}
} else {
if (rollData.tache == -4) { // Echec total !
if (rolled.tache == -4) { // Echec total !
costReve *= 2;
myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!!
if (myReve.value < 0) myReve.value = 0;
@ -231,9 +231,6 @@ export class RdDActor extends Actor {
}
// Save it for fight in the flags area
console.log("Saving Flag", this);
await this.setFlag('world', 'rollData', null);
await this.setFlag('world', 'rollData', rollData);
game.system.rdd.rollDataHandler[this.data._id] = duplicate(rollData);
// Final chat message
@ -642,7 +639,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async rollUnSort(coord) {
let draconicList = this.getDraconicList();
let sortList = this.getSortList();
let sortList = duplicate(this.getSortList()); // Duplication car les pts de reve sont modifiés dans le sort
let rollData = {
selectedCarac: this.data.data.carac.reve,
@ -653,7 +650,9 @@ export class RdDActor extends Actor {
selectedSort: sortList[0],
coord: coord,
finalLevel: 0,
bmValue: 0
bmValue: sortList[0].data.difficulte, // Per default at startup
coutreve: Array(20).fill().map((item, index) => 1 + index),
bonusmalusTable: CONFIG.RDD.bonusmalus
}
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html', rollData);
new RdDRollDialog("sort", html, rollData, this ).render(true);
@ -663,11 +662,11 @@ export class RdDActor extends Actor {
async rollCarac( caracName )
{
let rollData = {
"selectedCarac": this.data.data.carac[caracName],
"bonusmalusTable": CONFIG.RDD.bonusmalus,
"etat": this.data.data.compteurs.etat.value,
"finalLevel": 0,
"bmValue": 0
selectedCarac: this.data.data.carac[caracName],
bonusmalusTable: CONFIG.RDD.bonusmalus,
etat: this.data.data.compteurs.etat.value,
finalLevel: 0,
bmValue: 0
}
console.log(caracName, rollData);
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', rollData);

View File

@ -68,6 +68,21 @@ export class RdDRollDialog extends Dialog {
rollData.finalLevelStr = (rollLevel > 0 ? "+" : "") + rollLevel;
rollData.rollTarget = RdDResolutionTable.computeChances(rollData.selectedCarac.value, rollData.finalLevel);
// Sort management
if ( rollData.selectedSort ) {
//console.log("Toggle show/hide", rollData.selectedSort);
if (rollData.selectedSort.data.difficulte.toLowerCase() == "variable") {
$("#div-sort-difficulte").show();
} else {
$("#div-sort-difficulte").hide();
}
if (rollData.selectedSort.data.ptreve.toLowerCase() == "variable") {
$("#div-sort-ptreve").show();
} else {
$("#div-sort-ptreve").hide();
}
}
$("#roll-param").text(rollData.selectedCarac.value + " / " + rollData.finalLevelStr);
$("#compdialogTitle").text(RdDRollDialog._getTitle(rollData));
$(".table-resolution").remove();
@ -79,8 +94,7 @@ export class RdDRollDialog extends Dialog {
// Update html, according to data
if (rollData.competence) {
// Set the default carac from the competence item
console.log("RdDDialogRoll", rollData.competence.data.defaut_carac, rollData.carac);
//console.log("RdDDialogRoll", rollData.competence.data.defaut_carac, rollData.carac);
rollData.selectedCarac = rollData.carac[rollData.competence.data.defaut_carac];
$("#carac").val(rollData.competence.data.defaut_carac);
}
@ -91,29 +105,33 @@ export class RdDRollDialog extends Dialog {
// Update !
html.find('#bonusmalus').click((event) => {
rollData.bmValue = event.currentTarget.value; // Update the selected bonus/malus
console.debug("RdDRollDialog","BM CLICKED !!!", rollData);
//console.log("RdDRollDialog","BM CLICKED !!!", rollData);
updateRollResult(rollData);
});
html.find('#carac').click((event) => {
let caracKey = event.currentTarget.value;
rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac
console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData);
this.rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac
//console.log("RdDRollDialog","CARAC CLICKED !!!", rollData);
updateRollResult(rollData);
});
html.find('#draconic').click((event) => {
let draconicKey = event.currentTarget.value;
rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac
console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData);
let draconicKey = Number(event.currentTarget.value);
this.rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac
//console.log("RdDRollDialog","CARAC CLICKED !!!", rollData);
updateRollResult(rollData);
});
html.find('#sort').click((event) => {
let sortKey = event.currentTarget.value;
rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac
console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData);
let sortKey = Number(event.currentTarget.value);
this.rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac
//console.log("RdDRollDialog - Sort selection", rollData.selectedSort);
updateRollResult(rollData);
});
html.find('#ptreve-variable').click((event) => {
let ptreve = Number(event.currentTarget.value);
this.rollData.selectedSort.data.ptreve_reel = ptreve; // Update the selectedCarac
console.log("RdDRollDialog - Cout reve", ptreve);
updateRollResult(rollData);
});
}
/* -------------------------------------------- */
@ -123,7 +141,11 @@ export class RdDRollDialog extends Dialog {
return etat + parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue);
}
if (rollData.draconicList) {
return etat + parseInt(rollData.selectedDraconic.data.niveau) + parseInt(rollData.selectedSort.data.difficulte);
let difficulte = rollData.selectedSort.data.difficulte; // Sort de difficulté variable
if (difficulte.toLowerCase() == "variable") {
difficulte = parseInt(rollData.bmValue); // Récupérer la valeur de la listbox dans ce cas
}
return etat + parseInt(rollData.selectedDraconic.data.niveau) + parseInt(difficulte);
}
return etat + parseInt(rollData.bmValue);
}

View File

@ -2,7 +2,7 @@
"name": "foundryvtt-reve-de-dragon",
"title": "Rêve de Dragon",
"description": "Rêve de Dragon RPG for FoundryVTT",
"version": "0.9.36",
"version": "0.9.37",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.6",
"templateVersion": 44,

View File

@ -20,7 +20,29 @@
<select name="sort" id="sort" data-dtype="String">
{{#select sort}}
{{#each sortList as |sort key|}}
<option value={{key}}>{{sort.name}} : {{sort.data.niveau}} - {{sort.data.difficulte}} - {{sort.data.caseTMR}}</option>
<option value={{key}}>{{sort.name}} : {{sort.data.difficulte}} / {{sort.data.ptreve}} / {{sort.data.caseTMR}}</option>
{{/each}}
{{/select}}
</select>
</div>
<div class="form-group" id="div-sort-difficulte">
<label for="categorie">Difficulté </label>
<select name="bonusmalus" id="bonusmalus" data-dtype="number">
{{#select bonusmalus}}
{{#each bonusmalusTable as |bmvalue key|}}
<option value={{bmvalue}}>{{numberFormat bmvalue decimals=0 sign=true}}</option>
{{/each}}
{{/select}}
</select>
</div>
<div class="form-group" id="div-sort-ptreve">
<label for="categorie">Couts en Points de Rêve </label>
<select name="ptreve-variable" id="ptreve-variable" data-dtype="number">
{{#select ptreve-variable}}
{{#each coutreve as |cout key|}}
<option value={{cout}}>{{cout}}</option>
{{/each}}
{{/select}}
</select>