tickwerk/src/data/documents/active-effect.js

32 lines
981 B
JavaScript
Raw Normal View History

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('createActiveEffect', onActiveEffectChanged);
Hooks.on('updateActiveEffect', onActiveEffectChanged);
Hooks.on('deleteActiveEffect', onActiveEffectChanged);
2022-05-16 02:08:27 +02:00
};
const onActiveEffectChanged = (activeEffect) => {
2022-05-16 02:08:27 +02:00
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();
}
}
}
};