2021-02-28 01:56:17 +01:00
|
|
|
import { ChatUtility } from "../chat-utility.js";
|
|
|
|
import { Grammar } from "../grammar.js";
|
2021-03-29 18:08:18 +02:00
|
|
|
import { Misc } from "../misc.js";
|
2021-02-28 01:56:17 +01:00
|
|
|
import { RdDRollTables } from "../rdd-rolltables.js";
|
|
|
|
import { tmrColors, tmrConstants, tmrTokenZIndex, TMRUtility } from "../tmr-utility.js";
|
|
|
|
import { Draconique } from "./draconique.js";
|
|
|
|
|
|
|
|
export class UrgenceDraconique extends Draconique {
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
type() { return 'queue' }
|
|
|
|
match(item) { return Draconique.isQueueDragon(item) && Grammar.toLowerCaseNoAccent(item.name).includes('urgence draconique'); }
|
|
|
|
manualMessage() { return false }
|
|
|
|
async onActorCreateOwned(actor, queue) {
|
2021-03-29 18:08:18 +02:00
|
|
|
const coordSortsReserve = (Misc.templateData(actor).reve.reserve?.list.map(it => it.coord)) ?? [];
|
2021-02-28 01:56:17 +01:00
|
|
|
if (coordSortsReserve.length == 0) {
|
|
|
|
// La queue se transforme en idée fixe
|
2021-03-29 18:08:18 +02:00
|
|
|
const ideeFixe = await RdDRollTables.getIdeeFixe();
|
2021-02-28 01:56:17 +01:00
|
|
|
ChatMessage.create({
|
|
|
|
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
|
2021-03-29 18:08:18 +02:00
|
|
|
content: `En l'absence de sorts en réserve, l'urgence draconique de ${actor.name} se transforme en ${ideeFixe.name}`
|
2021-02-28 01:56:17 +01:00
|
|
|
});
|
2021-03-25 03:18:27 +01:00
|
|
|
await actor.createEmbeddedDocuments('Item',[ideeFixe]);
|
2021-02-28 01:56:17 +01:00
|
|
|
await actor.deleteOwnedItem(queue._id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
2021-03-29 18:08:18 +02:00
|
|
|
const demiReve = actor.getDemiReve();
|
|
|
|
coordSortsReserve.sort(Misc.ascending(t => TMRUtility.distanceTMR(t, demiReve)));
|
|
|
|
const tmr = TMRUtility.getTMR(coordSortsReserve[0]);
|
2021-02-28 01:56:17 +01:00
|
|
|
await this.createCaseTmr(actor, 'Urgence draconique: ' + tmr.label, tmr, queue._id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async onActorDeleteCaseTmr(actor, casetmr) {
|
|
|
|
await actor.deleteOwnedItem(casetmr.data.sourceid);
|
|
|
|
}
|
|
|
|
|
|
|
|
code() { return 'urgence' }
|
|
|
|
tooltip(linkData) { return `Urgence draconique!` }
|
|
|
|
img() { return 'icons/svg/hazard.svg' }
|
|
|
|
|
|
|
|
createSprite(pixiTMR) {
|
|
|
|
return pixiTMR.sprite(this.code(),
|
|
|
|
{
|
|
|
|
zIndex: tmrTokenZIndex.conquete,
|
|
|
|
color: tmrColors.queues,
|
|
|
|
taille: tmrConstants.full,
|
|
|
|
decallage: { x: 2, y: 0 }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|