Gestion des signes draconiques #455

Closed
vincent.vandeme wants to merge 233 commits from v1.4-signes-draconiques into master
5 changed files with 143 additions and 117 deletions
Showing only changes of commit 3be9be92ec - Show all commits

View File

@ -324,12 +324,13 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
getDraconicList() {
return this.items.filter(it => Misc.data(it).type == 'competence' && Misc.templateData(it).categorie == 'draconic')
.sort(Misc.descending(it => Misc.templateData(it).niveau));
}
/* -------------------------------------------- */
getBestDraconic() {
const list = this.getDraconicList().sort(Misc.descending(it => Misc.templateData(it).niveau));
const list = this.getDraconicList();
if (list.length == 0) {
return { name: "Aucun", data: { name: "Aucun", data: { niveau: -11 } } };
return { name: "Aucun", data: { name: "Aucun", data: { niveau: 0 } } };
}
return duplicate(list[0]);
}
@ -1968,28 +1969,29 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
filterDraconicList(sortList) {
let draconicDone = {};
let newDraconicList = [];
let draconicList = this.getDraconicList();
let bestDraconic = this.getBestDraconic();
computeDraconicAndSortIndex(sortList) {
let draconicList = this.getDraconicList().map(d => duplicate(Misc.data(d)));
for (let sort of sortList) {
let voie = sort.data.draconic;
let draconic = RdDItemCompetence.getVoieDraconic(draconicList, voie);
//console.log(draconicList, bestDraconic, draconic, voie);
if (sort.name.toLowerCase().includes('aura')) {
draconic = bestDraconic;
let draconicsSort = this.getDraconicsSort(draconicList, sort).map(it => it.name);
for (let index = 0; index < draconicList.length && sort.data.listIndex==undefined; index++){
if (draconicsSort.includes(draconicList[index].name)){
sort.data.listIndex = index;
}
}
// TODO: duplicate sur Misc.data?
draconic = duplicate(Misc.data(draconic));
if (draconicDone[draconic.name] == undefined) {
draconic.data.defaut_carac = 'reve';
newDraconicList.push(draconic);
draconicDone[draconic.name] = newDraconicList.length - 1; // Patch local pour relier facilement voie/compétence
}
sort.data.listIndex = draconicDone[draconic.name] || 0;
}
return newDraconicList;
return draconicList;
}
getDraconicsSort(draconicList, sort) {
//console.log(draconicList, bestDraconic, draconic, voie);
switch (Grammar.toLowerCaseNoAccent(sort.name)) {
case "lecture d'aura":
case "detection d'aura":
return draconicList;
case "annulation de magie":
return draconicList.filter(it => !Grammar.toLowerCaseNoAccent(Misc.data(it).name).includes('thanatos'));
}
return [RdDItemCompetence.getVoieDraconic(draconicList, sort.data.draconic)];
}
/* -------------------------------------------- */
@ -2010,7 +2012,7 @@ export class RdDActor extends Actor {
}
if (this.currentTMR) this.currentTMR.minimize(); // Hide
let draconicList = this.filterDraconicList(sortList);
let draconicList = this.computeDraconicAndSortIndex(sortList);
const actorData = Misc.data(this);
let rollData = {
forceCarac: { 'reve': duplicate(actorData.data.carac.reve) },
@ -2029,6 +2031,7 @@ export class RdDActor extends Actor {
const dialog = await RdDRoll.create(this, rollData,
{
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html',
options: { height: 600 },
close: html => { this.currentTMR.maximize() } // Re-display TMR
},
{
@ -2036,17 +2039,9 @@ export class RdDActor extends Actor {
label: 'Lancer un sort',
callbacks: [
this.createCallbackExperience(),
{ action: r => this._rollUnSortResult(r, false) }
{ action: r => this._rollUnSortResult(r) }
]
},
{
name: 'mettre-en-reserve',
label: 'Mettre un sort en réserve',
callbacks: [
this.createCallbackExperience(),
{ action: r => this._rollUnSortResult(r, true) }
]
},
}
);
dialog.render(true);
}
@ -2096,17 +2091,11 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async _rollUnSortResult(rollData, isSortReserve = false) {
async _rollUnSortResult(rollData) {
let rolled = rollData.rolled;
let selectedSort = rollData.selectedSort;
let closeTMR = !isSortReserve;
if (selectedSort.data.isrituel && isSortReserve) {
ui.notifications.error("Impossible de mettre le rituel '" + selectedSort.name + "' en réserve");
this.currentTMR.close(); // Close TMR !
return;
}
rollData.isSortReserve = isSortReserve;
rollData.isSortReserve = rollData.mettreEnReserve && !selectedSort.data.isrituel;
rollData.show = {}
rollData.depenseReve = Number(selectedSort.data.ptreve_reel);
@ -2127,7 +2116,6 @@ export class RdDActor extends Actor {
if (rollData.isSortReserve) {
await this.sortMisEnReserve(rollData, selectedSort);
closeTMR = false;
}
}
else {
@ -2147,10 +2135,10 @@ export class RdDActor extends Actor {
reveActuel = Math.max(reveActuel - rollData.depenseReve, 0);
await this.update({ "data.reve.reve.value": reveActuel });
if (closeTMR) {
this.currentTMR.close(); // Close TMR !
} else {
if (rollData.isSortReserve) {
this.currentTMR.maximize(); // Re-display TMR
} else {
this.currentTMR.close(); // Close TMR !
}
// Final chat message
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-sort.html');

View File

@ -1,7 +1,6 @@
import { RollDataAjustements } from "./rolldata-ajustements.js";
import { HtmlUtility } from "./html-utility.js";
import { RdDItemCompetence } from "./item-competence.js";
import { RdDItemMeditation } from "./item-meditation.js";
import { RdDItemSort } from "./item-sort.js";
import { Misc } from "./misc.js";
import { RdDBonus } from "./rdd-bonus.js";
@ -64,7 +63,7 @@ export class RdDRoll extends Dialog {
surprise: actor.getSurprise(false),
canClose: true
};
mergeObject(rollData, defaultRollData, { recursive: true, overwrite: false });
if (rollData.forceCarac) {
rollData.carac = rollData.forceCarac;
@ -169,7 +168,8 @@ export class RdDRoll extends Dialog {
$("#carac").val(defaut_carac);
}
if (rollData.selectedSort) {
$("#draconic").val(rollData.selectedSort.data.listIndex); // Uniquement a la selection du sort, pour permettre de changer
dialog.setSelectedSort(rollData.selectedSort);
$(".draconic").val(rollData.selectedSort.data.listIndex); // Uniquement a la selection du sort, pour permettre de changer
}
RdDItemSort.setCoutReveReel(rollData.selectedSort);
$("#diffLibre").val(Misc.toInt(rollData.diffLibre));
@ -194,20 +194,16 @@ export class RdDRoll extends Dialog {
this.rollData.selectedCarac = this.rollData.carac[caracKey]; // Update the selectedCarac
this.updateRollResult();
});
html.find('#draconic').change((event) => {
html.find('.roll-draconic').change((event) => {
let draconicKey = Misc.toInt(event.currentTarget.value);
this.rollData.competence = this.rollData.draconicList[draconicKey]; // Update the selectedCarac
this.updateRollResult();
});
html.find('#sort').change((event) => {
html.find('.roll-sort').change((event) => {
let sortKey = Misc.toInt(event.currentTarget.value);
this.rollData.selectedSort = this.rollData.sortList[sortKey]; // Update the selectedCarac
this.rollData.bonus = RdDItemSort.getCaseBonus(this.rollData.selectedSort, this.rollData.tmr.coord);
this.rollData.diffLibre = RdDItemSort.getDifficulte(this.rollData.selectedSort, -7)
RdDItemSort.setCoutReveReel(this.rollData.selectedSort);
$("#draconic").val(this.rollData.selectedSort.data.listIndex); // Uniquement a la selection du sort, pour permettre de changer
$("#diffLibre").val(this.rollData.diffLibre);
this.setSelectedSort(this.rollData.sortList[sortKey]);
this.updateRollResult();
$("#diffLibre").val(this.rollData.diffLibre);
});
html.find('#ptreve-variable').change((event) => {
let ptreve = Misc.toInt(event.currentTarget.value);
@ -257,6 +253,29 @@ export class RdDRoll extends Dialog {
});
}
async setSelectedSort(sort) {
this.rollData.selectedSort = sort; // Update the selectedCarac
this.rollData.competence = RdDItemCompetence.getVoieDraconic(this.rollData.draconicList, sort.data.draconic);
this.rollData.bonus = RdDItemSort.getCaseBonus(sort, this.rollData.tmr.coord);
this.rollData.diffLibre = RdDItemSort.getDifficulte(sort, -7);
RdDItemSort.setCoutReveReel(sort);
const htmlSortDescription = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html", { sort: sort });
$(".sort-ou-rituel").text(sort.data.isrituel ? "rituel" : "sort");
$(".bonus-case").text(`${this.rollData.bonus}%`);
$(".details-sort").remove();
$(".description-sort").append(htmlSortDescription);
$(".roll-draconic").val(sort.data.listIndex);
$(".div-sort-difficulte-fixe").text(Misc.toSignedString(sort.data.difficulte));
$(".div-sort-ptreve-fixe").text(sort.data.ptreve);
const diffVariable = RdDItemSort.isDifficulteVariable(sort);
const coutVariable = RdDItemSort.isCoutVariable(sort);
HtmlUtility._showControlWhen($(".div-sort-non-rituel"), !sort.data.isrituel);
HtmlUtility._showControlWhen($(".div-sort-difficulte-var"), diffVariable);
HtmlUtility._showControlWhen($(".div-sort-difficulte-fixe"), !diffVariable);
HtmlUtility._showControlWhen($(".div-sort-ptreve-var"), coutVariable);
HtmlUtility._showControlWhen($(".div-sort-ptreve-fixe"), !coutVariable);
}
/* -------------------------------------------- */
async updateRollResult() {
let rollData = this.rollData;
@ -270,11 +289,6 @@ export class RdDRoll extends Dialog {
if (rollData.coupsNonMortels) {
dmgText = `(${dmgText}) non-mortel`
}
if (rollData.selectedSort) {
rollData.bonus = RdDItemSort.getCaseBonus(rollData.selectedSort, rollData.tmr.coord);
HtmlUtility._showControlWhen($("#div-sort-difficulte"), RdDItemSort.isDifficulteVariable(rollData.selectedSort))
HtmlUtility._showControlWhen($("#div-sort-ptreve"), RdDItemSort.isCoutVariable(rollData.selectedSort))
}
RollDataAjustements.calcul(rollData, this.actor);
rollData.finalLevel = this._computeFinalLevel(rollData);

View File

@ -158,14 +158,14 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html',
// Partials
'systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html',
'systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html',
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-ajustements.html',
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffLibre.html',
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffCondition.html',
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-surenc.html',
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-enctotal.html',
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-moral.html',
'systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html',
'systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html',
// Calendrier
'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html',
'systems/foundryvtt-reve-de-dragon/templates/calendar-editor-template.html',

View File

@ -1,66 +1,80 @@
{{log 'lancer de sort' this}}
<form class="dialog-roll-sort">
<div class="form-group">
<label>Rêve : <label>{{numberFormat selectedCarac.value decimals=0 sign=false}}</label></label>
<label>TMR : {{tmr.label}} ({{tmr.coord}})</label>
</div>
<div class="form-group">
<label>Draconic </label>
<select name="draconic" id="draconic" data-dtype="String">
{{#select draconic}}
{{#each draconicList as |draconic key|}}
<option value={{key}}>{{draconic.name}} : {{draconic.data.niveau}}</option>
{{/each}}
{{/select}}
</select>
<label> &nbsp;Conditions</label>
<select name="diffConditions" id="diffConditions" data-dtype="number">
{{#select diffConditions}}
{{#each ajustementsConditions as |key|}}
<option value={{key}}>{{numberFormat key decimals=0 sign=true}}</option>
{{/each}}
{{/select}}
</select>
</div>
<div class="form-group">
<label>Sort </label>
<select name="sort" id="sort" data-dtype="String">
{{#select sort}}
{{#each sortList as |sort key|}}
<option value={{key}}>{{this.name}} - {{#if this.data.caseTMRspeciale}} {{this.data.caseTMRspeciale}} {{else}}{{this.data.caseTMR}}{{/if}} / R{{this.data.difficulte}} r {{sort.data.ptreve}} ({{sort.data.draconic}})</option>
{{/each}}
{{/select}}
</select>
</div>
<div class="form-group" id="div-sort-difficulte">
<label>Difficulté </label>
<select name="diffLibre" id="diffLibre" data-dtype="number">
{{#select diffLibre}}
{{#each difficultesLibres as |key|}}
<option value={{key}}>{{numberFormat key decimals=0 sign=true}}</option>
{{/each}}
{{/select}}
</select>
</div>
<div class="form-group" id="div-sort-ptreve">
<label>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>
<h2>Lancer le <span class="sort-ou-rituel">{{#if sort.data.isrituel}}rituel{{else}}sort{{/if}}</span>:
<select name="sort" class="roll-sort flex-grow" data-dtype="String">
{{#select sort}}
{{#each sortList as |sort key|}}
<option value={{key}}>{{this.name}} - {{#if this.data.caseTMRspeciale}} {{this.data.caseTMRspeciale}}
{{else}}{{this.data.caseTMR}}{{/if}} / R{{this.data.difficulte}} r {{sort.data.ptreve}} ({{sort.data.draconic}})
</option>
{{/each}}
{{/select}}
</select>
</h2>
<img class="chat-icon" src="{{competence.img}}" alt="{{competence.name}}" />
<div class="grid grid-2col">
<div class="flex-group-left">
<div class="flexrow">
<label for="tmr">TMR - {{tmr.coord}}:</label><label name="tmr">{{tmr.label}}</label>
</div>
<div class="flexrow">
<label for="carac">Rêve:</label><label name="carac">{{selectedCarac.value}}</label>
</div>
<div class="flexrow">
<label for="ptreve-variable">Points de Rêve: </label>
<select name="ptreve-variable" class="div-sort-ptreve-var" id="ptreve-variable" data-dtype="number">
{{#select ptreve-variable}}
{{#each coutreve as |cout key|}}
<option value={{cout}}>{{cout}}</option>
{{/each}}
{{/select}}
</select>
<label class="div-sort-ptreve-fixe">{{selectedSort.data.ptreve}}</select>
</div>
<div class="flexrow div-sort-non-rituel">
<label>Mettre en réserve</label>
<input class="checkbox-by-name" type="checkbox" name="mettreEnReserve" {{#if mettreEnReserve}}checked{{/if}} />
</div>
</div>
<div class="flex-group-left">
<div class="flexrow">
<label for="competence">Draconic:</label>
<select name="competence" class="roll-draconic" data-dtype="String">
{{#select draconic}}
{{#each draconicList as |draconic key|}}
<option value={{key}}>{{draconic.name}} : {{numberFormat draconic.data.niveau decimals=0 sign=true}}
</option>
{{/each}}
{{/select}}
</select>
</div>
<div class="flexrow">
<label for="diffLibre">Difficulté </label>
<select name="diffLibre" class="div-sort-difficulte-var" id="diffLibre" data-dtype="number">
{{#select diffLibre}}
{{#each difficultesLibres as |key|}}
<option value={{key}}>{{numberFormat key decimals=0 sign=true}}</option>
{{/each}}
{{/select}}
</select>
<label class="div-sort-difficulte-fixe">{{numberFormat selectedSort.data.difficulte decimals=0 sign=true}}</label>
</div>
{{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffCondition.html"}}
<div class="flexrow">
<label for="bonus-case">Bonus de case </label>
<label name="bonus-case" class="bonus-case">0%</label>
</div>
<div id="tableAjustements" class="flexrow"></div>
</div>
</div>
<div class="description-sort">
<hr>
{{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html" sort=selectedSort}}
</div>
<div id="tableAjustements">
</div>
<div id="tableResolution"></div>
<div id="tableProbaReussite"></div>
</form>
<script>
</script>
</script>

View File

@ -0,0 +1,10 @@
<div class="flex-group-left details-sort">
{{#if sort.data.cible}}<label><strong>Cible</strong>: {{sort.data.cible}}&nbsp;&nbsp;</label>{{/if}}
{{#if sort.data.JR}}<label><strong>JR</strong>: {{sort.data.JR}}&nbsp;&nbsp;</label>{{/if}}
{{#if sort.data.portee}}<label><strong>Portée</strong>: {{sort.data.portée}}&nbsp;&nbsp;</label>{{/if}}
{{#if sort.data.duree}}<label><strong>Durée</strong>: {{sort.data.duree}}&nbsp;&nbsp;</label>{{/if}}
{{#if sort.data.coutseuil}}<label><strong>Coût de seuil</strong>: {{sort.data.coutseuil}}</label>{{/if}}
</div>
<div class="details-sort">
{{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html" sort.data}}
</div>