feat: integrate with ds4 item roll functionality

This commit is contained in:
Johannes Loher 2022-05-19 03:25:18 +02:00
parent bff39c4776
commit ac99c75731
3 changed files with 42 additions and 1 deletions

View file

@ -1,6 +1,8 @@
{
"TICKWERK.AdvanceTicks": "Auf der Tickleiste Vorrücken",
"TICKWERK.NumberOfTicks": "Anzahl an Ticks",
"TICKWERK.SettingDS4ReactToRollItemHookName": "Item Würfelwurf Integration",
"TICKWERK.SettingDS4ReactToRollItemHookHint": "Zeige den Dialog zum Vorrücken auf der Tickleiste nachdem auf ein Item gewürfelt worden ist.",
"TICKWERK.StopWaiting": "Abwarten Beenden",
"TICKWERK.Tick": "Tick",
"TICKWERK.Wait": "Abwarten",

View file

@ -1,6 +1,8 @@
{
"TICKWERK.AdvanceTicks": "Advance on the Tickbar",
"TICKWERK.NumberOfTicks": "Number of Ticks",
"TICKWERK.SettingDS4ReactToRollItemHookName": "Item Roll Integration",
"TICKWERK.SettingDS4ReactToRollItemHookHint": "Show the dialog for advancing on the tickbar after item rolls.",
"TICKWERK.StopWaiting": "Stop Waiting",
"TICKWERK.Tick": "Tick",
"TICKWERK.Wait": "Wait",

View file

@ -3,12 +3,15 @@
// SPDX-License-Identifier: MIT
import { packageId } from '../constants';
import { getGame } from '../helpers';
import type { TickwerkCombatant } from '../data/documents/combatant';
export const registerDS4SpecificFunctionality = () => {
if (CONFIG.tickwerk === undefined) CONFIG.tickwerk = {};
foundry.utils.mergeObject(CONFIG.tickwerk, { getTiebreaker, getInitiativeFormula });
registerRollItemSetting();
Hooks.on('ds4.rollItem', onRollItem);
};
const getTiebreaker = async (combatant: TickwerkCombatant, combatants: TickwerkCombatant[]): Promise<number> => {
@ -79,3 +82,37 @@ interface ActorData {
};
};
}
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Hooks {
interface StaticCallbacks {
'ds4.rollItem': (item: Item) => void;
}
}
}
const onRollItem = (item: Item) => {
const game = getGame();
if (game.settings.get(packageId, 'ds4.reactToRollItemHook')) {
if (['weapon', 'spell'].includes(item.type) && item.actor?.id) {
const combatants = item.actor
.getActiveTokens(false, true)
.map((token) => game.combat?.getCombatantByToken(token.id ?? ''));
for (const combatant of combatants) {
if (combatant?.parent?.started) combatant?.advanceTicksDialog();
}
}
}
};
const registerRollItemSetting = () => {
getGame().settings.register(packageId, 'ds4.reactToRollItemHook', {
name: 'TICKWERK.SettingDS4ReactToRollItemHookName',
hint: 'TICKWERK.SettingDS4ReactToRollItemHookHint',
scope: 'client',
config: true,
type: Boolean,
default: true,
});
};