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";
|
2021-12-12 17:36:22 +01:00
|
|
|
import { TMRUtility } from "../tmr-utility.js";
|
2023-11-15 22:14:00 +01:00
|
|
|
import { tmrTokenZIndex } from "../tmr-constants.js";
|
2021-02-28 01:56:17 +01:00
|
|
|
import { Draconique } from "./draconique.js";
|
2023-11-15 22:19:33 +01:00
|
|
|
import { TYPES } from "../item.js";
|
2023-11-15 22:14:00 +01:00
|
|
|
import { TMRAnimations } from "./animation.js";
|
2021-02-28 01:56:17 +01:00
|
|
|
|
|
|
|
export class UrgenceDraconique extends Draconique {
|
|
|
|
|
|
|
|
type() { return 'queue' }
|
|
|
|
match(item) { return Draconique.isQueueDragon(item) && Grammar.toLowerCaseNoAccent(item.name).includes('urgence draconique'); }
|
|
|
|
manualMessage() { return false }
|
|
|
|
async onActorCreateOwned(actor, queue) {
|
2023-11-12 00:22:29 +01:00
|
|
|
const coordSortsReserve = actor.itemTypes[TYPES.sortreserve].map(it => it.system.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-29 23:41:08 +02:00
|
|
|
await actor.createEmbeddedDocuments('Item', [ideeFixe]);
|
|
|
|
await actor.deleteEmbeddedDocuments('Item', [queue.id]);
|
2021-02-28 01:56:17 +01:00
|
|
|
}
|
|
|
|
else {
|
2021-03-29 18:08:18 +02:00
|
|
|
const demiReve = actor.getDemiReve();
|
2021-12-12 17:36:22 +01:00
|
|
|
coordSortsReserve.sort(Misc.ascending(t => TMRUtility.distanceCoordTMR(t, demiReve)));
|
2021-03-29 18:08:18 +02:00
|
|
|
const tmr = TMRUtility.getTMR(coordSortsReserve[0]);
|
2023-11-15 22:14:00 +01:00
|
|
|
await this.createCaseTmr(actor, 'Urgence draconique', tmr, queue.id);
|
2021-02-28 01:56:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async onActorDeleteCaseTmr(actor, casetmr) {
|
2022-09-07 09:01:23 +02:00
|
|
|
await actor.deleteEmbeddedDocuments('Item', [casetmr.system.sourceid]);
|
2021-02-28 01:56:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
code() { return 'urgence' }
|
2023-11-15 22:14:00 +01:00
|
|
|
tooltip(linkData) { return `Urgence draconique` }
|
|
|
|
img() { return 'systems/foundryvtt-reve-de-dragon/icons/tmr/urgence.svg' }
|
2021-02-28 01:56:17 +01:00
|
|
|
|
|
|
|
createSprite(pixiTMR) {
|
2023-11-15 22:14:00 +01:00
|
|
|
return TMRAnimations.withAnimation(
|
|
|
|
pixiTMR.sprite(this.code(), {
|
2021-02-28 01:56:17 +01:00
|
|
|
zIndex: tmrTokenZIndex.conquete,
|
2023-11-15 22:14:00 +01:00
|
|
|
decallage: pixiTMR.sizes.decallage(0, 0),
|
|
|
|
taille: () => pixiTMR.sizes.half,
|
|
|
|
}),
|
|
|
|
pixiTMR,
|
|
|
|
TMRAnimations.changeZoom()
|
|
|
|
)
|
2021-02-28 01:56:17 +01:00
|
|
|
}
|
|
|
|
}
|