Skip to content

Commit

Permalink
dnd5e 4 updates (#780)
Browse files Browse the repository at this point in the history
* Move from dnd5e.useItem to dnd5e.postUseActivity
  • Loading branch information
johnnolan authored Oct 11, 2024
1 parent 84a233b commit ea9111b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions MockData/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const actor: Actor = {
}),
setFlag: jest.fn().mockResolvedValue(2),
update: jest.fn().mockResolvedValue(true),
getRollData: jest.fn().mockResolvedValue(true),
system: {
details: {
level: 14,
Expand Down
1 change: 1 addition & 0 deletions __mocks__/roll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
return {
roll: jest.fn().mockResolvedValue(null),
evaluate: jest.fn().mockResolvedValue(null),
toMessage: jest.fn().mockResolvedValue(null),
create: jest.fn().mockResolvedValue(null),
render: jest.fn().mockResolvedValue(null),
};
Expand Down
6 changes: 3 additions & 3 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"library": "false",
"compatibility": {
"minimum": "12",
"verified": "12.328",
"verified": "12.331",
"maximum": "12"
},
"minimumCoreVersion": "12",
Expand All @@ -26,8 +26,8 @@
"type": "system",
"manifest": "https://raw.githubusercontent.com/foundryvtt/dnd5e/master/system.json",
"compatibility": {
"minimum": "3.2.1",
"verified": "3.2.1"
"minimum": "4.0.4",
"verified": "4.0.4"
}
}
]
Expand Down
8 changes: 4 additions & 4 deletions scripts/MagicSurgeCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe("MagicSurgeCheck", () => {
it("It calls Roll with 1D20", async () => {
await magicSurgeCheck.WildMagicSurgeRollCheck();

expect((global as any).Roll).toHaveBeenCalledWith("1D20");
expect((global as any).Roll).toHaveBeenCalled());
});
});

Expand Down Expand Up @@ -331,7 +331,7 @@ describe("MagicSurgeCheck", () => {
it("It calls Roll with 1D20", async () => {
await magicSurgeCheck.WildMagicSurgeRollCheck();

expect((global as any).Roll).toHaveBeenCalledWith("1D20");
expect((global as any).Roll).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -363,7 +363,7 @@ describe("MagicSurgeCheck", () => {
it("It calls Roll with 1D20", async () => {
await magicSurgeCheck.WildMagicSurgeRollCheck();

expect((global as any).Roll).toHaveBeenCalledWith("1D20");
expect((global as any).Roll).toHaveBeenCalled();
});
});

Expand Down Expand Up @@ -396,7 +396,7 @@ describe("MagicSurgeCheck", () => {

it("It calls Roll with 1D20", async () => {
await magicSurgeCheck.WildMagicSurgeRollCheck();
expect((global as any).Roll).toHaveBeenCalledWith("1d20");
expect((global as any).Roll).toHaveBeenCalled();
});
});
});
Expand Down
7 changes: 6 additions & 1 deletion scripts/MagicSurgeCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ class MagicSurgeCheck {
return;
}

return await new Roll(diceFormula).evaluate();
const data = this._actor ? this._actor.getRollData() : {};
const roll = new Roll(diceFormula, data);
await roll.evaluate({ allowInteractive: false });
await roll.toMessage();

return roll;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion scripts/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ Hooks.once("ready", async function () {
);
}

Hooks.on("dnd5e.useItem", (item: Item) => {
Hooks.on("dnd5e.postUseActivity", (activity: Item) => {
const item = activity.item;
if (item.actor) {
const tokenId = getTokenIdByActorId(item?.actor.id);
if (game.user?.isGM) {
Expand Down

0 comments on commit ea9111b

Please sign in to comment.