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";
|
2021-12-12 17:36:22 +01:00
|
|
|
import { TMRUtility } from "../tmr-utility.js";
|
|
|
|
import { tmrConstants, tmrTokenZIndex } from "../tmr-constants.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) {
|
2022-06-12 12:14:55 +02:00
|
|
|
let existants = actor.items.filter(it => this.isCase(it)).map(it => it.system.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) {
|
2022-11-28 16:00:49 +01:00
|
|
|
const presents = await game.system.rdd.rencontresTMR.getPresentsCite()
|
2022-11-07 00:04:43 +01:00
|
|
|
const buttons = {};
|
|
|
|
presents.forEach(r => buttons['present'+r.id] = { icon: '<i class="fas fa-check"></i>', label: r.name, callback: async () => onChoixPresent(r) });
|
2021-02-12 01:44:27 +01:00
|
|
|
let d = new Dialog({
|
|
|
|
title: "Présent des cités",
|
2022-11-07 00:04:43 +01:00
|
|
|
content: `La ${this.tmrLabel(casetmr)} vous offre un présent, faites votre choix`,
|
|
|
|
buttons: buttons
|
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
|
|
|
}
|