Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item buttons on actor sheets unable to reference actor roll data #63

Open
asacolips opened this issue Mar 3, 2024 · 0 comments
Open

Comments

@asacolips
Copy link
Contributor

asacolips commented Mar 3, 2024

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

  1. Create a new actor
  2. Create a Number attribute named foo with the value set to 1
  3. Create a Formula attribute named bar with the value set to @foo + 1
  4. Create an item on the actor
  5. Create a Formula attribute on the item named fooRoll with the value set to d20 + @foo
  6. Create a Formula attribute on the item named barRoll with the value set to d20 + @bar
  7. Click the buttons for each roll on the actor's items tab.

Expected

  • fooRoll should generate a roll with the formula d20 + 1
  • barRoll should generate a roll with the formula d20 + 1 + 1

Actual

  • fooRoll works as expected
  • barRoll causes a fatal error due to no prop being found for @foo in the @foo + 1 formula.
  • 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>`
    });
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant