2022-05-16 02:08:27 +02:00
|
|
|
// 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;
|
2022-05-16 03:46:53 +02:00
|
|
|
|
2022-05-16 02:08:27 +02:00
|
|
|
const statusId = activeEffect.getFlag('core', 'statusId');
|
2022-05-16 03:46:53 +02:00
|
|
|
|
2022-05-16 02:08:27 +02:00
|
|
|
if (statusId === CONFIG.Combat.defeatedStatusId) {
|
|
|
|
const relevantCombats = game.combats?.filter((combat) => combat.getCombatantByActor(actorId) !== undefined) ?? [];
|
2022-05-16 03:46:53 +02:00
|
|
|
|
2022-05-16 02:08:27 +02:00
|
|
|
for (const combat of relevantCombats) {
|
|
|
|
combat.setupTurns();
|
|
|
|
if (combat === game.combat) {
|
|
|
|
ui.combat?.render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|