2021-02-11 02:48:27 +01:00
|
|
|
import { ChatUtility } from "../chat-utility.js";
|
2021-02-12 18:31:49 +01:00
|
|
|
import { Grammar } from "../grammar.js";
|
|
|
|
import { tmrConstants, tmrTokenZIndex, TMRUtility } from "../tmr-utility.js";
|
2021-02-11 02:48:27 +01:00
|
|
|
import { Draconique } from "./draconique.js";
|
|
|
|
|
|
|
|
export class PresentCites extends Draconique {
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
type() { return 'tete' }
|
2021-02-12 18:31:49 +01:00
|
|
|
match(item) { return Draconique.isTeteDragon(item) && Grammar.toLowerCaseNoAccent(item.name).includes('present des cites'); }
|
2021-02-11 02:48:27 +01:00
|
|
|
manualMessage() { return false }
|
2021-02-12 18:31:49 +01:00
|
|
|
async onActorCreateOwned(actor, tete) { await this._ajouterPresents(actor, tete); }
|
2021-02-11 02:48:27 +01:00
|
|
|
|
|
|
|
code() { return 'present-cites' }
|
2021-02-12 01:16:02 +01:00
|
|
|
tooltip(linkData) { return `La ${this.tmrLabel(linkData)} a un présent` }
|
2021-05-02 21:08:50 +02:00
|
|
|
img() { return 'systems/foundryvtt-reve-de-dragon/icons/tmr/gift.webp' }
|
2021-02-11 02:48:27 +01:00
|
|
|
|
2021-02-12 18:31:49 +01:00
|
|
|
createSprite(pixiTMR) {
|
2021-02-11 02:48:27 +01:00
|
|
|
return pixiTMR.sprite(this.code(),
|
|
|
|
{
|
2021-02-12 15:01:10 +01:00
|
|
|
zIndex: tmrTokenZIndex.tetes,
|
2021-05-03 20:02:10 +02:00
|
|
|
alpha: 0.9,
|
2021-02-12 15:01:10 +01:00
|
|
|
taille: tmrConstants.third,
|
|
|
|
decallage: tmrConstants.topRight
|
2021-02-11 02:48:27 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-12 18:31:49 +01:00
|
|
|
async _ajouterPresents(actor, tete) {
|
2021-02-11 02:48:27 +01:00
|
|
|
let existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord);
|
2021-02-12 01:16:02 +01:00
|
|
|
if (existants.length > 0) {
|
2021-02-11 02:48:27 +01:00
|
|
|
ChatMessage.create({
|
2021-02-12 01:16:02 +01:00
|
|
|
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
|
2021-02-11 02:48:27 +01:00
|
|
|
content: "Vous avez encore des présents dans des cités, vous devrez tirer une autre tête pour remplacer celle ci!"
|
|
|
|
})
|
|
|
|
}
|
2021-02-12 01:16:02 +01:00
|
|
|
else {
|
2021-02-11 02:48:27 +01:00
|
|
|
let cites = TMRUtility.filterTMR(it => it.type == 'cite');
|
|
|
|
for (let tmr of cites) {
|
2021-03-29 23:41:08 +02:00
|
|
|
await this.createCaseTmr(actor, 'Présent: ' + tmr.label, tmr, tete.id);
|
2021-02-11 02:48:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-12 12:50:17 +01:00
|
|
|
|
|
|
|
async choisirUnPresent(casetmr, onChoixPresent) {
|
2021-02-12 01:44:27 +01:00
|
|
|
let d = new Dialog({
|
|
|
|
title: "Présent des cités",
|
2021-02-12 12:50:17 +01:00
|
|
|
content: `La ${this.tmrLabel(casetmr)} vous offre un présent, faite votre choix`,
|
2021-02-12 01:44:27 +01:00
|
|
|
buttons: {
|
2021-02-12 12:50:17 +01:00
|
|
|
messager: { icon: '<i class="fas fa-check"></i>', label: "Un Messager des rêves", callback: () => onChoixPresent('messager2d6') },
|
|
|
|
passeur: { icon: '<i class="fas fa-check"></i>', label: "Un Passeur des rêves", callback: () => onChoixPresent('passeur2d6') },
|
|
|
|
fleur: { icon: '<i class="fas fa-check"></i>', label: "Une Fleur des rêves", callback: () => onChoixPresent('fleur2d6') },
|
|
|
|
},
|
|
|
|
default: "fleur"
|
2021-02-12 01:44:27 +01:00
|
|
|
});
|
|
|
|
d.render(true);
|
|
|
|
}
|
|
|
|
|
2021-02-12 12:50:17 +01:00
|
|
|
async ouvrirLePresent(actor, casetmr) {
|
2021-03-29 23:41:08 +02:00
|
|
|
await actor.deleteEmbeddedDocuments('Item', [casetmr.id]);
|
2021-02-12 12:50:17 +01:00
|
|
|
}
|
2021-02-11 02:48:27 +01:00
|
|
|
}
|