Refactor: extrait méthodes communes

- suppression de casetmr lors de visite/conquete
- suppression de toutes les cases TMRs liées
- notification lors de suppression d'une casetmr pour enlever la queue

# Conflicts:
#	module/actor.js
This commit is contained in:
Vincent Vandemeulebrouck 2021-02-28 01:50:15 +01:00
parent 944dd103d2
commit 3f4d52487d
7 changed files with 47 additions and 52 deletions

View File

@ -3205,6 +3205,9 @@ export class RdDActor extends Actor {
case 'souffle': case 'souffle':
await this.onDeleteOwnedDraconique(item, options, id); await this.onDeleteOwnedDraconique(item, options, id);
break; break;
case 'casetmr':
await this.onDeleteOwnedCaseTmr(item, options, id);
break;
} }
} }
@ -3226,6 +3229,13 @@ export class RdDActor extends Actor {
} }
} }
async onDeleteOwnedCaseTmr(item, options, id) {
let draconique = Draconique.all().find(it => it.isCase(item));
if (draconique) {
draconique.onActorDeleteCaseTmr(this, item)
}
}
notifyGestionTeteSouffleQueue(item, manualMessage = true) { notifyGestionTeteSouffleQueue(item, manualMessage = true) {
ChatMessage.create({ ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),

View File

@ -558,8 +558,10 @@ export class RdDTMRDialog extends Dialog {
await this._conquerir(tmr, { await this._conquerir(tmr, {
difficulte: -9, difficulte: -9,
action: 'Conquérir la cité', action: 'Conquérir la cité',
onConqueteReussie: r => EffetsDraconiques.fermetureCites.onConquete(r.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr)), onConqueteReussie: r => EffetsDraconiques.fermetureCites.onVisiteSupprimer(r.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr)),
onConqueteEchec: r => this.close(), onConqueteEchec: r => {
this.close()
},
canClose: false canClose: false
}); });
} }
@ -576,8 +578,8 @@ export class RdDTMRDialog extends Dialog {
await this._conquerir(tmr, { await this._conquerir(tmr, {
difficulte: -7, difficulte: -7,
action: 'Conquérir', action: 'Conquérir',
onConqueteReussie: r => EffetsDraconiques.conquete.onConquete(r.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr)), onConqueteReussie: r => EffetsDraconiques.conquete.onVisiteSupprimer(r.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr)),
onConqueteEchec: r => { }, onConqueteEchec: r => this.close(),
canClose: false canClose: false
}); });
} }
@ -639,8 +641,8 @@ export class RdDTMRDialog extends Dialog {
dialog.render(true); dialog.render(true);
} }
async validerPelerinage(tmr) { async validerVisite(tmr) {
await EffetsDraconiques.pelerinage.onFinPelerinage(this.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr)); await EffetsDraconiques.pelerinage.onVisiteSupprimer(this.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr));
} }
@ -836,7 +838,7 @@ export class RdDTMRDialog extends Dialog {
await this.manageCaseHumide(tmr); await this.manageCaseHumide(tmr);
await this.conquerirCiteFermee(tmr); await this.conquerirCiteFermee(tmr);
await this.conquerirTMR(tmr); await this.conquerirTMR(tmr);
await this.validerPelerinage(tmr); await this.validerVisite(tmr);
await this.declencheSortEnReserve(tmr.coord); await this.declencheSortEnReserve(tmr.coord);
await this.actor.checkSoufflePeage(tmr); await this.actor.checkSoufflePeage(tmr);
} }

View File

@ -35,11 +35,4 @@ export class Conquete extends Draconique {
await this.createCaseTmr(actor, 'Conquête: ' + conquete.label, conquete, queue._id); await this.createCaseTmr(actor, 'Conquête: ' + conquete.label, conquete, queue._id);
} }
async onConquete(actor, tmr, onRemoveToken) {
let existants = actor.data.items.filter(it => this.isCase(it, tmr.coord));
for (let casetmr of existants) {
await actor.deleteOwnedItem(casetmr.data.sourceid);
onRemoveToken(tmr, casetmr);
}
}
} }

View File

@ -24,10 +24,6 @@ export class Desorientation extends Draconique {
return Object.keys(TMRType).filter(it => !dejaDesorientes.includes(it)); return Object.keys(TMRType).filter(it => !dejaDesorientes.includes(it));
} }
async onActorDeleteOwned(actor, souffle) {
await this._supprimerCasesTmr(actor, souffle);
}
code() { return 'desorientation' } code() { return 'desorientation' }
tooltip(linkData) { return `Désorientation, cette case n'existe plus !` } tooltip(linkData) { return `Désorientation, cette case n'existe plus !` }
img() { return 'icons/svg/explosion.svg' } img() { return 'icons/svg/explosion.svg' }
@ -51,11 +47,5 @@ export class Desorientation extends Draconique {
} }
} }
async _supprimerCasesTmr(actor, souffle) {
let caseTmrs = actor.data.items.filter(it => it.data.sourceId == souffle._id);
for (let casetmr of caseTmrs) {
await actor.deleteOwnedItem(casetmr._id);
}
}
} }

View File

@ -7,8 +7,7 @@ const registeredEffects = [
/** /**
* Définition des informations d'une "draconique" (queue, ombre, tête, souffle) qui influence les TMR * Définition des informations d'une "draconique" (queue, ombre, tête, souffle) qui influence les TMR
*/ */
export class Draconique export class Draconique {
{
static isCaseTMR(element) { return element.type == 'casetmr'; } static isCaseTMR(element) { return element.type == 'casetmr'; }
static isQueueDragon(element) { return element.type == 'queue' || element.type == 'ombre'; } static isQueueDragon(element) { return element.type == 'queue' || element.type == 'ombre'; }
static isSouffleDragon(element) { return element.type == 'souffle'; } static isSouffleDragon(element) { return element.type == 'souffle'; }
@ -28,6 +27,7 @@ export class Draconique
static all() { static all() {
return Object.values(registeredEffects); return Object.values(registeredEffects);
} }
static get(code) { static get(code) {
return registeredEffects[code]; return registeredEffects[code];
} }
@ -56,10 +56,11 @@ export class Draconique
} }
async onActorDeleteOwned(actor, item) { async onActorDeleteOwned(actor, item) {
let caseTmrs = actor.data.items.filter(it => this.isCase(it) && it.data.sourceid == item._id); this.deleteCasesTmr(actor, item);
for (let casetmr of caseTmrs) { return false;
await actor.deleteOwnedItem(casetmr._id);
} }
async onActorDeleteCaseTmr(actor, casetmr) {
return false; return false;
} }
/** /**
@ -127,4 +128,19 @@ export class Draconique
}); });
} }
async deleteCasesTmr(actor, draconique) {
let caseTmrs = actor.data.items.filter(it => this.isCase(it) && it.data.sourceid == draconique._id);
for (let casetmr of caseTmrs) {
await actor.deleteOwnedItem(casetmr._id);
}
}
async onVisiteSupprimer(actor, tmr, onRemoveToken) {
let existants = actor.data.items.filter(it => this.isCase(it, tmr.coord));
for (let casetmr of existants) {
await actor.deleteOwnedItem(casetmr._id);
onRemoveToken(tmr, casetmr);
}
}
} }

View File

@ -35,11 +35,4 @@ export class FermetureCites extends Draconique {
await this.createCaseTmr(actor, 'Fermeture: ' + tmr.label, tmr, souffle._id); await this.createCaseTmr(actor, 'Fermeture: ' + tmr.label, tmr, souffle._id);
} }
} }
async onConquete(actor, tmr, onRemoveToken) {
const citeFermee = actor.data.items.find(it => this.isCase(it, tmr.coord));
await actor.deleteOwnedItem(citeFermee._id);
onRemoveToken(tmr, citeFermee);
}
} }

View File

@ -30,13 +30,4 @@ export class Pelerinage extends Draconique {
decallage: tmrConstants.right decallage: tmrConstants.right
}); });
} }
async onFinPelerinage(actor, tmr, onRemoveToken) {
const pelerinages = actor.data.items.filter(it => this.isCase(it, tmr.coord));
for (let p of pelerinages){
await actor.deleteOwnedItem(p.data.sourceid);
onRemoveToken(tmr, p);
}
}
} }