Add functionality for common checks, which can be affected by effects and be performed as macros
This commit is contained in:
parent
7fad6416fc
commit
f038509910
8 changed files with 202 additions and 7 deletions
|
@ -1,5 +1,7 @@
|
|||
import { rollCheck } from "./roll-check";
|
||||
import { rollItem } from "./roll-item";
|
||||
|
||||
export const macros = {
|
||||
rollItem: rollItem,
|
||||
rollCheck,
|
||||
rollItem,
|
||||
};
|
||||
|
|
43
src/module/macros/roll-check.ts
Normal file
43
src/module/macros/roll-check.ts
Normal 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);
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue