foundryvtt-reve-de-dragon/module/tmr/urgence-draconique.js

56 lines
2.1 KiB
JavaScript
Raw Normal View History

import { ChatUtility } from "../chat-utility.js";
import { Grammar } from "../grammar.js";
2021-03-29 18:08:18 +02:00
import { Misc } from "../misc.js";
import { RdDRollTables } from "../rdd-rolltables.js";
import { TMRUtility } from "../tmr-utility.js";
2023-11-15 22:14:00 +01:00
import { tmrTokenZIndex } from "../tmr-constants.js";
import { Draconique } from "./draconique.js";
import { ITEM_TYPES } from "../item.js";
2023-11-15 22:14:00 +01:00
import { TMRAnimations } from "./animation.js";
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) {
const coordSortsReserve = actor.itemTypes[ITEM_TYPES.sortreserve].map(it => it.system.coord) ?? [];
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();
ChatMessage.create({
whisper: ChatUtility.getOwners(actor),
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}`
});
await actor.createEmbeddedDocuments('Item', [ideeFixe]);
await actor.deleteEmbeddedDocuments('Item', [queue.id]);
}
else {
2021-03-29 18:08:18 +02:00
const demiReve = actor.getDemiReve();
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);
}
}
async onActorDeleteCaseTmr(actor, casetmr) {
2022-09-07 09:01:23 +02:00
await actor.deleteEmbeddedDocuments('Item', [casetmr.system.sourceid]);
}
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' }
createSprite(pixiTMR) {
2023-11-15 22:14:00 +01:00
return TMRAnimations.withAnimation(
pixiTMR.sprite(this.code(), {
zIndex: tmrTokenZIndex.conquete,
2023-11-15 22:14:00 +01:00
decallage: pixiTMR.sizes.decallage(0, 0),
taille: () => pixiTMR.sizes.half,
}),
pixiTMR,
TMRAnimations.changeZoom()
)
}
}