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:
parent
944dd103d2
commit
3f4d52487d
@ -3205,6 +3205,9 @@ export class RdDActor extends Actor {
|
||||
case 'souffle':
|
||||
await this.onDeleteOwnedDraconique(item, options, id);
|
||||
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) {
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
|
||||
|
@ -558,8 +558,10 @@ export class RdDTMRDialog extends Dialog {
|
||||
await this._conquerir(tmr, {
|
||||
difficulte: -9,
|
||||
action: 'Conquérir la cité',
|
||||
onConqueteReussie: r => EffetsDraconiques.fermetureCites.onConquete(r.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr)),
|
||||
onConqueteEchec: r => this.close(),
|
||||
onConqueteReussie: r => EffetsDraconiques.fermetureCites.onVisiteSupprimer(r.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr)),
|
||||
onConqueteEchec: r => {
|
||||
this.close()
|
||||
},
|
||||
canClose: false
|
||||
});
|
||||
}
|
||||
@ -576,8 +578,8 @@ export class RdDTMRDialog extends Dialog {
|
||||
await this._conquerir(tmr, {
|
||||
difficulte: -7,
|
||||
action: 'Conquérir',
|
||||
onConqueteReussie: r => EffetsDraconiques.conquete.onConquete(r.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr)),
|
||||
onConqueteEchec: r => { },
|
||||
onConqueteReussie: r => EffetsDraconiques.conquete.onVisiteSupprimer(r.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr)),
|
||||
onConqueteEchec: r => this.close(),
|
||||
canClose: false
|
||||
});
|
||||
}
|
||||
@ -639,8 +641,8 @@ export class RdDTMRDialog extends Dialog {
|
||||
dialog.render(true);
|
||||
}
|
||||
|
||||
async validerPelerinage(tmr) {
|
||||
await EffetsDraconiques.pelerinage.onFinPelerinage(this.actor, tmr, (casetmr) => this.removeToken(tmr, casetmr));
|
||||
async validerVisite(tmr) {
|
||||
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.conquerirCiteFermee(tmr);
|
||||
await this.conquerirTMR(tmr);
|
||||
await this.validerPelerinage(tmr);
|
||||
await this.validerVisite(tmr);
|
||||
await this.declencheSortEnReserve(tmr.coord);
|
||||
await this.actor.checkSoufflePeage(tmr);
|
||||
}
|
||||
|
@ -35,11 +35,4 @@ export class Conquete extends Draconique {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,6 @@ export class Desorientation extends Draconique {
|
||||
return Object.keys(TMRType).filter(it => !dejaDesorientes.includes(it));
|
||||
}
|
||||
|
||||
async onActorDeleteOwned(actor, souffle) {
|
||||
await this._supprimerCasesTmr(actor, souffle);
|
||||
}
|
||||
|
||||
code() { return 'desorientation' }
|
||||
tooltip(linkData) { return `Désorientation, cette case n'existe plus !` }
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,8 +7,7 @@ const registeredEffects = [
|
||||
/**
|
||||
* 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 isQueueDragon(element) { return element.type == 'queue' || element.type == 'ombre'; }
|
||||
static isSouffleDragon(element) { return element.type == 'souffle'; }
|
||||
@ -28,6 +27,7 @@ export class Draconique
|
||||
static all() {
|
||||
return Object.values(registeredEffects);
|
||||
}
|
||||
|
||||
static get(code) {
|
||||
return registeredEffects[code];
|
||||
}
|
||||
@ -56,10 +56,11 @@ export class Draconique
|
||||
}
|
||||
|
||||
async onActorDeleteOwned(actor, item) {
|
||||
let caseTmrs = actor.data.items.filter(it => this.isCase(it) && it.data.sourceid == item._id);
|
||||
for (let casetmr of caseTmrs) {
|
||||
await actor.deleteOwnedItem(casetmr._id);
|
||||
this.deleteCasesTmr(actor, item);
|
||||
return false;
|
||||
}
|
||||
|
||||
async onActorDeleteCaseTmr(actor, casetmr) {
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
@ -102,7 +103,7 @@ export class Draconique
|
||||
if (this.img()) {
|
||||
return pixiTMR.sprite(this.code());
|
||||
}
|
||||
else{
|
||||
else {
|
||||
return pixiTMR.circle()
|
||||
}
|
||||
}
|
||||
@ -120,11 +121,26 @@ export class Draconique
|
||||
return list.find(c => this.isCase(c, coord));
|
||||
}
|
||||
|
||||
async createCaseTmr(actor, label, tmr, sourceId=undefined) {
|
||||
async createCaseTmr(actor, label, tmr, sourceId = undefined) {
|
||||
await actor.createOwnedItem({
|
||||
name: label, type: 'casetmr', img: this.img(), _id: randomID(16),
|
||||
data: { coord: tmr.coord, specific: this.code(), sourceid:sourceId }
|
||||
data: { coord: tmr.coord, specific: this.code(), sourceid: sourceId }
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -35,11 +35,4 @@ export class FermetureCites extends Draconique {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,13 +30,4 @@ export class Pelerinage extends Draconique {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user