#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 ! // Fight management !
let defenseMsg; let defenseMsg;
let encaisser = false; 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 // In case of fight, replace the message per dommages + localization. it indicates if result is OK or not
if (rollData.attackerRoll) { // Defense case ! if (rollData.attackerRoll) { // Defense case !
if (rolled.isSuccess) { if (rolled.isSuccess) {
@ -161,7 +161,7 @@ export class RdDActor extends Actor {
encaisser = true; encaisser = true;
} }
} else { // This is the attack roll! } else { // This is the attack roll!
if (rolled.isSuccess > 0) { if (rolled.isSuccess) {
rollData.domArmePlusDom = parseInt(rollData.arme.data.dommages); rollData.domArmePlusDom = parseInt(rollData.arme.data.dommages);
if (rollData.selectedCarac.label == "Mêlée") // +dom only for Melee if (rollData.selectedCarac.label == "Mêlée") // +dom only for Melee
rollData.domArmePlusDom += parseInt(this.data.data.attributs.plusdom.value); rollData.domArmePlusDom += parseInt(this.data.data.attributs.plusdom.value);
@ -189,14 +189,14 @@ export class RdDActor extends Actor {
let lvl = "" let lvl = ""
if (rollData.selectedSort) { // Lancement de sort ! if (rollData.selectedSort) { // Lancement de sort !
let draconic = rollData.selectedSort.data.draconic; 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 + 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 + ")"; specialStr += "<br>Depuis la case " + rollData.coord + " (" + TMRUtility.getTMRDescription(rollData.coord).label + ")";
lvl = rollData.selectedDraconic.name + "/" + rollData.selectedSort.name; lvl = rollData.selectedDraconic.name + "/" + rollData.selectedSort.name;
let costReve = rollData.selectedSort.data.ptreve;
let myReve = duplicate(this.data.data.reve.reve); let myReve = duplicate(this.data.data.reve.reve);
if (rollData.tache > 0) { // Réussite du sort ! if (rolled.isSuccess) { // Réussite du sort !
if (rollData.tache >= 4) costReve = Math.ceil(costReve / 2); if (rolled.tache >= 4) costReve = Math.ceil(costReve / 2);
if (costReve < 1) costReve = 1; if (costReve < 1) costReve = 1;
myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!! myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!!
if (myReve.value < 0) myReve.value = 0; if (myReve.value < 0) myReve.value = 0;
@ -211,7 +211,7 @@ export class RdDActor extends Actor {
this.currentTMR.updateSortReserve(); this.currentTMR.updateSortReserve();
} }
} else { } else {
if (rollData.tache == -4) { // Echec total ! if (rolled.tache == -4) { // Echec total !
costReve *= 2; costReve *= 2;
myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!! myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!!
if (myReve.value < 0) myReve.value = 0; if (myReve.value < 0) myReve.value = 0;
@ -231,9 +231,6 @@ export class RdDActor extends Actor {
} }
// Save it for fight in the flags area // 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); game.system.rdd.rollDataHandler[this.data._id] = duplicate(rollData);
// Final chat message // Final chat message
@ -642,7 +639,7 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollUnSort(coord) { async rollUnSort(coord) {
let draconicList = this.getDraconicList(); 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 = { let rollData = {
selectedCarac: this.data.data.carac.reve, selectedCarac: this.data.data.carac.reve,
@ -653,7 +650,9 @@ export class RdDActor extends Actor {
selectedSort: sortList[0], selectedSort: sortList[0],
coord: coord, coord: coord,
finalLevel: 0, 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); let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html', rollData);
new RdDRollDialog("sort", html, rollData, this ).render(true); new RdDRollDialog("sort", html, rollData, this ).render(true);
@ -663,11 +662,11 @@ export class RdDActor extends Actor {
async rollCarac( caracName ) async rollCarac( caracName )
{ {
let rollData = { let rollData = {
"selectedCarac": this.data.data.carac[caracName], selectedCarac: this.data.data.carac[caracName],
"bonusmalusTable": CONFIG.RDD.bonusmalus, bonusmalusTable: CONFIG.RDD.bonusmalus,
"etat": this.data.data.compteurs.etat.value, etat: this.data.data.compteurs.etat.value,
"finalLevel": 0, finalLevel: 0,
"bmValue": 0 bmValue: 0
} }
console.log(caracName, rollData); console.log(caracName, rollData);
let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', 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.finalLevelStr = (rollLevel > 0 ? "+" : "") + rollLevel;
rollData.rollTarget = RdDResolutionTable.computeChances(rollData.selectedCarac.value, rollData.finalLevel); 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); $("#roll-param").text(rollData.selectedCarac.value + " / " + rollData.finalLevelStr);
$("#compdialogTitle").text(RdDRollDialog._getTitle(rollData)); $("#compdialogTitle").text(RdDRollDialog._getTitle(rollData));
$(".table-resolution").remove(); $(".table-resolution").remove();
@ -79,8 +94,7 @@ export class RdDRollDialog extends Dialog {
// Update html, according to data // Update html, according to data
if (rollData.competence) { if (rollData.competence) {
// Set the default carac from the competence item // 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]; rollData.selectedCarac = rollData.carac[rollData.competence.data.defaut_carac];
$("#carac").val(rollData.competence.data.defaut_carac); $("#carac").val(rollData.competence.data.defaut_carac);
} }
@ -91,29 +105,33 @@ export class RdDRollDialog extends Dialog {
// Update ! // Update !
html.find('#bonusmalus').click((event) => { html.find('#bonusmalus').click((event) => {
rollData.bmValue = event.currentTarget.value; // Update the selected bonus/malus rollData.bmValue = event.currentTarget.value; // Update the selected bonus/malus
console.debug("RdDRollDialog","BM CLICKED !!!", rollData); //console.log("RdDRollDialog","BM CLICKED !!!", rollData);
updateRollResult(rollData); updateRollResult(rollData);
}); });
html.find('#carac').click((event) => { html.find('#carac').click((event) => {
let caracKey = event.currentTarget.value; let caracKey = event.currentTarget.value;
rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac this.rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac
console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData); //console.log("RdDRollDialog","CARAC CLICKED !!!", rollData);
updateRollResult(rollData); updateRollResult(rollData);
}); });
html.find('#draconic').click((event) => { html.find('#draconic').click((event) => {
let draconicKey = event.currentTarget.value; let draconicKey = Number(event.currentTarget.value);
rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac this.rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac
console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData); //console.log("RdDRollDialog","CARAC CLICKED !!!", rollData);
updateRollResult(rollData); updateRollResult(rollData);
}); });
html.find('#sort').click((event) => { html.find('#sort').click((event) => {
let sortKey = event.currentTarget.value; let sortKey = Number(event.currentTarget.value);
rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac this.rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac
console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData); //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); updateRollResult(rollData);
}); });
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -123,7 +141,11 @@ export class RdDRollDialog extends Dialog {
return etat + parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue); return etat + parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue);
} }
if (rollData.draconicList) { 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); return etat + parseInt(rollData.bmValue);
} }

View File

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

View File

@ -20,12 +20,34 @@
<select name="sort" id="sort" data-dtype="String"> <select name="sort" id="sort" data-dtype="String">
{{#select sort}} {{#select sort}}
{{#each sortList as |sort key|}} {{#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}} {{/each}}
{{/select}} {{/select}}
</select> </select>
</div> </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>
</div>
<div class="form-group"> <div class="form-group">
<label for="categorie">Etat général</label><label>{{numberFormat etat decimals=0 sign=true}}</label> <label for="categorie">Etat général</label><label>{{numberFormat etat decimals=0 sign=true}}</label>
</div> </div>