Add functionality for common checks, which can be affected by effects and be performed as macros

This commit is contained in:
Johannes Loher 2021-03-24 09:19:26 +01:00
parent 7fad6416fc
commit f038509910
8 changed files with 202 additions and 7 deletions

View file

@ -1,5 +1,7 @@
import { rollCheck } from "./roll-check";
import { rollItem } from "./roll-item";
export const macros = {
rollItem: rollItem,
rollCheck,
rollItem,
};

View file

@ -0,0 +1,43 @@
import { DS4Actor } from "../actor/actor";
import { Check } from "../actor/actor-prepared-data";
import { DS4 } from "../config";
import { getCanvas } from "../helpers";
import notifications from "../ui/notifications";
/**
* Creates a macro from a check drop.
* Get an existing roll check macro if one exists, otherwise create a new one.
* @param check - The name of the check to perform.
* @param slot - The hotbar slot to use.
*/
export async function createRollCheckMacro(check: Check, slot: string): Promise<void> {
const command = `game.ds4.macros.rollCheck("${check}");`;
const macro =
game.macros?.entities.find((m) => m.name === DS4.i18n.checks[check] && m.data.command === command) ??
(await Macro.create(
{
command,
name: DS4.i18n.checks[check],
type: "script",
// TODO: img, should be addressed in https://git.f3l.de/dungeonslayers/ds4/-/issues/79
flags: { "ds4.checkMacro": true },
},
{ displaySheet: false },
));
game.user?.assignHotbarMacro(macro, slot);
}
/**
* Executes the roll check macro for the given check.
*/
export async function rollCheck(check: Check): Promise<void> {
const speaker = ChatMessage.getSpeaker();
const actor = (getCanvas().tokens.get(speaker.token ?? "")?.actor ?? game.actors?.get(speaker.actor ?? "")) as
| DS4Actor
| null
| undefined;
if (!actor) {
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
}
return actor.rollCheck(check);
}

View file

@ -28,7 +28,6 @@ export async function createRollItemMacro(itemData: DS4ItemData, slot: string):
/**
* Executes the roll item macro for the given itemId.
* @param itemId
*/
export async function rollItem(itemId: string): Promise<void> {
const speaker = ChatMessage.getSpeaker();