Méthode de fenêtre de jet partagée

This commit is contained in:
Vincent Vandemeulebrouck 2023-03-10 22:24:52 +01:00
parent ffccc819f1
commit e470d76ea0

View File

@ -332,34 +332,42 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */
async roll() {
const carac = mergeObject(
duplicate(this.system.carac),
const carac = mergeObject(duplicate(this.system.carac),
{
'reve-actuel': this.getCaracReveActuel(),
'chance-actuelle': this.getCaracChanceActuelle()
});
let rollData = {
carac: carac,
selectedCarac: carac.apparence,
selectedCaracName: 'apparence',
competences: this.itemTypes['competence']
};
await this._openRollDialog({
name: `jet-${this.id}`,
label: `Jet de ${this.name}`,
template: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll.html',
rollData: {
carac: carac,
selectedCarac: carac.apparence,
selectedCaracName: 'apparence',
competences: this.itemTypes['competence']
},
callbackAction: r => this.$onRollCaracResult(r)
});
}
async _openRollDialog({ name, label, template, rollData, callbackAction }) {
const dialog = await RdDRoll.create(this, rollData,
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll.html' },
{ html: template },
{
name: `jet-${this.id}`,
label: `Jet de ${this.name}`,
name: name,
label: label,
callbacks: [
this.createCallbackExperience(),
this.createCallbackAppelAuMoral(),
{ action: r => this._onRollCaracResult(r) }
{ action: callbackAction }
]
}
);
});
dialog.render(true);
}
async prepareChateauDormant(consigne) {
if (consigne.ignorer) {
return;
@ -2089,22 +2097,21 @@ export class RdDActor extends RdDBaseActor {
}
/* -------------------------------------------- */
filterSortList(sortList, coord) {
$filterSortList(sortList, coord) {
let tmr = TMRUtility.getTMR(coord);
let letfilteredList = []
let filtered = []
for (let sort of sortList) {
if (sort.system.caseTMR.toLowerCase().includes('variable')) {
letfilteredList.push(sort);
filtered.push(sort);
} else if (sort.system.caseTMRspeciale.toLowerCase().includes('variable')) {
letfilteredList.push(sort);
filtered.push(sort);
} else if (sort.system.caseTMR.toLowerCase() == tmr.type) {
letfilteredList.push(sort);
filtered.push(sort);
} else if (sort.system.caseTMR.toLowerCase().includes('special') && sort.system.caseTMRspeciale.toLowerCase().includes(coord.toLowerCase())) {
letfilteredList.push(sort);
filtered.push(sort);
}
}
return letfilteredList;
return filtered;
}
/* -------------------------------------------- */
@ -2136,52 +2143,39 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */
async rollUnSort(coord) {
let sortList = duplicate(this.getSortList()); // Duplication car les pts de reve sont modifiés dans le sort
if (!sortList || sortList.length == 0) {
ui.notifications.info("Aucun sort disponible!");
return;
}
sortList = this.filterSortList(sortList, coord);
if (!sortList || sortList.length == 0) {
ui.notifications.info("Aucun sort disponible pour cette case !");
return;
}
if (EffetsDraconiques.isSortImpossible(this)) {
ui.notifications.error("Une queue ou un souffle vous empèche de lancer de sort!");
return;
}
// Duplication car les pts de reve sont modifiés dans le sort
let sorts = duplicate(this.$filterSortList(this.getSortList(), coord));
if (sorts.length == 0) {
ui.notifications.info(`Aucun sort disponible en ${TMRUtility.getTMR(coord).label} !`);
return;
}
if (this.currentTMR) this.currentTMR.minimize(); // Hide
let draconicList = this.computeDraconicAndSortIndex(sortList);
const draconicList = this.computeDraconicAndSortIndex(sorts);
const reve = duplicate(this.system.carac.reve);
let rollData = {
carac: { 'reve': reve },
forceCarac: { 'reve': reve },
selectedCarac: reve,
draconicList: draconicList,
competence: draconicList[0],
sortList: sortList,
selectedSort: sortList[0],
tmr: TMRUtility.getTMR(coord),
diffLibre: RdDItemSort.getDifficulte(sortList[0], -7), // Per default at startup
coutreve: Array(30).fill().map((item, index) => 1 + index),
}
const dialog = await RdDRoll.create(this, rollData,
{
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html',
close: html => { this.currentTMR.maximize() } // Re-display TMR
await this._openRollDialog({
name: 'lancer-un-sort',
label: 'Lancer un sort',
template: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html',
rollData: {
carac: { 'reve': reve },
forceCarac: { 'reve': reve },
selectedCarac: reve,
draconicList: draconicList,
competence: draconicList[0],
sortList: sorts,
selectedSort: sorts[0],
tmr: TMRUtility.getTMR(coord),
diffLibre: RdDItemSort.getDifficulte(sorts[0], -7), // Per default at startup
coutreve: Array(30).fill().map((item, index) => 1 + index),
},
{
name: 'lancer-un-sort',
label: 'Lancer un sort',
callbacks: [
this.createCallbackExperience(),
{ action: r => this._rollUnSortResult(r) }
]
}
);
dialog.render(true);
callbackAction: r => this._rollUnSortResult(r)
});
}
/* -------------------------------------------- */
@ -2288,29 +2282,21 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */
async rollCarac(caracName, jetResistance = undefined) {
let rollData = {
selectedCarac: this.getCaracByName(caracName),
competences: this.itemTypes['competence'],
jetResistance: jetResistance ? caracName : undefined
};
const dialog = await RdDRoll.create(this, rollData,
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html' },
{
name: 'jet-' + caracName,
label: 'Jet ' + Grammar.apostrophe('de', rollData.selectedCarac.label),
callbacks: [
this.createCallbackExperience(),
this.createCallbackAppelAuMoral(),
{ action: r => this._onRollCaracResult(r) }
]
}
);
dialog.render(true);
await this._openRollDialog({
name: 'jet-' + caracName,
label: 'Jet ' + Grammar.apostrophe('de', rollData.selectedCarac.label),
template: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html',
rollData: {
selectedCarac: this.getCaracByName(caracName),
competences: this.itemTypes['competence'],
jetResistance: jetResistance ? caracName : undefined
},
callbackAction: r => this.$onRollCaracResult(r)
});
}
/* -------------------------------------------- */
async _onRollCaracResult(rollData) {
async $onRollCaracResult(rollData) {
// Final chat message
await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-general.html');
}
@ -2374,19 +2360,14 @@ export class RdDActor extends RdDBaseActor {
// Transformer la competence de créature
RdDItemCompetenceCreature.setRollDataCreature(rollData)
}
console.log("rollCompetence !!!", rollData);
const dialog = await RdDRoll.create(this, rollData,
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html' },
{
name: 'jet-competence',
label: 'Jet ' + Grammar.apostrophe('de', rollData.competence.name),
callbacks: [
this.createCallbackExperience(),
this.createCallbackAppelAuMoral(),
{ action: r => this.$onRollCompetence(r) }
]
});
dialog.render(true);
await this._openRollDialog({
name: 'jet-competence',
label: 'Jet ' + Grammar.apostrophe('de', rollData.competence.name),
template: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html',
rollData: rollData,
callbackAction: r => this.$onRollCompetence(r)
});
}
/* -------------------------------------------- */
@ -2427,39 +2408,31 @@ export class RdDActor extends RdDBaseActor {
}
/* -------------------------------------------- */
async rollTache(id) {
async rollTache(id, options = {}) {
const tacheData = this.getTache(id)
const compData = this.getCompetence(tacheData.system.competence)
compData.system.defaut_carac = tacheData.system.carac; // Patch !
let rollData = {
competence: compData,
tache: tacheData,
diffLibre: tacheData.system.difficulte,
diffConditions: 0,
use: { libre: false, conditions: true },
carac: {}
};
rollData.carac[tacheData.system.carac] = duplicate(this.system.carac[tacheData.system.carac]); // Single carac
console.log("rollTache !!!", rollData);
const dialog = await RdDRoll.create(this, rollData,
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html' },
{
name: 'jet-competence',
label: 'Jet de Tâche ' + tacheData.name,
callbacks: [
this.createCallbackExperience(),
this.createCallbackAppelAuMoral(),
{ action: r => this._tacheResult(r) }
]
});
dialog.render(true);
await this._openRollDialog({
name: 'jet-competence',
label: 'Jet de Tâche ' + tacheData.name,
template: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html',
rollData: {
competence: compData,
tache: tacheData,
diffLibre: tacheData.system.difficulte,
diffConditions: 0,
use: { libre: false, conditions: true },
carac: {
[tacheData.system.carac]: duplicate(this.system.carac[tacheData.system.carac])
}
},
callbackAction: r => this._tacheResult(r, options)
});
}
/* -------------------------------------------- */
async _tacheResult(rollData) {
async _tacheResult(rollData, options) {
// Mise à jour de la tache
rollData.appliquerFatigue = ReglesOptionelles.isUsing("appliquer-fatigue");
rollData.tache = duplicate(rollData.tache);
@ -2481,7 +2454,7 @@ export class RdDActor extends RdDBaseActor {
}
/* -------------------------------------------- */
async _rollArt(artData, selected, oeuvre, callBackResult = r => this._resultArt(r)) {
async _rollArt(artData, selected, oeuvre, callbackAction = r => this._resultArt(r)) {
oeuvre.system.niveau = oeuvre.system.niveau ?? 0;
mergeObject(artData,
{
@ -2499,18 +2472,14 @@ export class RdDActor extends RdDBaseActor {
artData.forceCarac = {};
artData.forceCarac[selected] = duplicate(this.system.carac[selected]);
}
const dialog = await RdDRoll.create(this, artData,
{ html: `systems/foundryvtt-reve-de-dragon/templates/dialog-roll-${oeuvre.type}.html` },
{
name: `jet-${artData.art}`,
label: `${artData.verbe} ${oeuvre.name}`,
callbacks: [
this.createCallbackExperience(),
this.createCallbackAppelAuMoral(),
{ action: r => callBackResult(r) }
]
});
dialog.render(true);
await this._openRollDialog({
name: `jet-${artData.art}`,
label: `${artData.verbe} ${oeuvre.name}`,
template: `systems/foundryvtt-reve-de-dragon/templates/dialog-roll-${oeuvre.type}.html`,
rollData: artData,
callbackAction: callbackAction
});
}
/* -------------------------------------------- */
@ -2778,25 +2747,18 @@ export class RdDActor extends RdDBaseActor {
}
/* -------------------------------------------- */
async rollAppelChance(onSuccess = () => { }, onEchec = () => { }) {
// Stocke si utilisation de la chance
let rollData = { selectedCarac: this.getCaracByName('chance-actuelle'), surprise: '' };
const dialog = await RdDRoll.create(this, rollData,
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html' },
{
name: 'appelChance',
label: 'Appel à la chance',
callbacks: [
this.createCallbackExperience(),
{ action: r => this._appelChanceResult(r, onSuccess, onEchec) },
]
}
);
dialog.render(true);
async rollAppelChance(onSuccess = () => {}, onEchec = () => {}) {
await this._openRollDialog({
name: 'appelChance',
label: 'Appel à la chance',
template: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html',
rollData: { selectedCarac: this.getCaracByName('chance-actuelle'), surprise: '' },
callbackAction: r => this._appelChanceResult(r, onSuccess, onEchec)
});
}
/* -------------------------------------------- */
async _appelChanceResult(rollData, onSuccess = () => { }, onEchec = () => { }) {
async _appelChanceResult(rollData, onSuccess, onEchec) {
await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-appelchance.html')
if (rollData.rolled.isSuccess) {
await this.setFlag(SYSTEM_RDD, 'utilisationChance', true);