-
Notifications
You must be signed in to change notification settings - Fork 60
Description
While helping a user sort out roll formulas in the SWB discord server topic, I noticed that the buttons generated by items on an actor are unable to reference their parent actor's data for rolls. I'm not sure at what point in the process this is failing exactly, but the rough issue seems to be that their button formulas are written as @items.someItemAttrName and if someItemAttrName is a formula attribute referencing actor attributes, they're unable to drill deep enough in the roll data to work.
Steps to reproduce
- Create a new actor
- Create a Number attribute named
foowith the value set to1 - Create a Formula attribute named
barwith the value set to@foo + 1 - Create an item on the actor
- Create a Formula attribute on the item named
fooRollwith the value set tod20 + @foo - Create a Formula attribute on the item named
barRollwith the value set tod20 + @bar - Click the buttons for each roll on the actor's items tab.
Expected
fooRollshould generate a roll with the formulad20 + 1barRollshould generate a roll with the formulad20 + 1 + 1
Actual
fooRollworks as expectedbarRollcauses a fatal error due to no prop being found for@fooin the@foo + 1formula.- If rolling directly from the attributes tab of the items sheet, both formulas work as expected.
Workarounds
This appears to be happening due to either how getRollData() is returning for the actor, or possibly due to differences in how rolls are evaluated now versus when this feature was originally written for SWB. I was able to work around it by modifying SimpleActorSheet#_onItemRoll() to use the following logic:
/**
* Listen for roll buttons on items.
* @param {MouseEvent} event The originating left click event
*/
_onItemRoll(event) {
let button = $(event.currentTarget);
const li = button.parents(".item");
const item = this.actor.items.get(li.data("itemId"));
const actorRollData = this.actor.getRollData();
const rollData = Object.assign(
actorRollData,
actorRollData.items[item.name.slugify({strict: true})],
);
const rollFormula = Roll.replaceFormulaData(button.data('roll'), rollData);
let r = new Roll(rollFormula, rollData);
return r.toMessage({
user: game.user.id,
speaker: ChatMessage.getSpeaker({ actor: this.actor }),
flavor: `<h2>${item.name}</h2><h3>${button.text()}</h3>`
});
}