29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
|
// SPDX-FileCopyrightText: 2022 Johannes Loher
|
||
|
//
|
||
|
// SPDX-License-Identifier: MIT
|
||
|
|
||
|
import { getGame } from '../../helpers';
|
||
|
|
||
|
export const registerActiveEffectFunctionality = () => {
|
||
|
Hooks.on<Hooks.CreateDocument<typeof ActiveEffect>>('createActiveEffect', onActiveEffectChanged);
|
||
|
Hooks.on<Hooks.UpdateDocument<typeof ActiveEffect>>('updateActiveEffect', onActiveEffectChanged);
|
||
|
Hooks.on<Hooks.DeleteDocument<typeof ActiveEffect>>('deleteActiveEffect', onActiveEffectChanged);
|
||
|
};
|
||
|
|
||
|
const onActiveEffectChanged = (activeEffect: ActiveEffect) => {
|
||
|
const game = getGame();
|
||
|
const parent = activeEffect.parent;
|
||
|
const actorId = parent?.id;
|
||
|
if (!(parent instanceof Actor) || actorId === null || actorId === undefined) return;
|
||
|
const statusId = activeEffect.getFlag('core', 'statusId');
|
||
|
if (statusId === CONFIG.Combat.defeatedStatusId) {
|
||
|
const relevantCombats = game.combats?.filter((combat) => combat.getCombatantByActor(actorId) !== undefined) ?? [];
|
||
|
for (const combat of relevantCombats) {
|
||
|
combat.setupTurns();
|
||
|
if (combat === game.combat) {
|
||
|
ui.combat?.render();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|