foundryvtt / dnd5e

An implementation of the 5th Edition game system for Foundry Virtual Tabletop (http://foundryvtt.com).
MIT License
339 stars 226 forks source link

item/activity rollRecharge ignores message.create set to false in dnd5e.preRollRechargeV2 but honors it when set via dnd5e.preRollRecharge #4751

Open tposney opened 1 week ago

tposney commented 1 week ago

Due to the roll refactor rollRecharge ignores changing message.create to false preRollRechargeV2. In the code createMessage (which determines display the chat card or not) is recorded before calling BasicRoll.build, but after the preRollRecharge hook fires, so that changes made in preRollRechargeV2 are ignored, but changes made in preRollRecharge are honored.

I could not see any simple way to resolve the issue but wanted to understand if this is a wont fix and will work around it.,


    if ( "dnd5e.preRollRecharge" in Hooks.events ) {
      foundry.utils.logCompatibilityWarning(
        "The `dnd5e.preRollRecharge` hook has been deprecated and replaced with `dnd5e.preRollRechargeV2`.",
        { since: "DnD5e 4.0", until: "DnD5e 4.4" }
      );
      const hookData = {
        formula: rollConfig.rolls[0].parts[0], data: rollConfig.rolls[0].data,
        target: rollConfig.rolls[0].options.target, chatMessage: messageConfig.create
      };
      if ( Hooks.call("dnd5e.preRollRecharge", this, hookData) === false ) return;
      rollConfig.rolls[0].parts[0] = hookData.formula;
      rollConfig.rolls[0].data = hookData.data;
      rollConfig.rolls[0].options.target = hookData.target;
      messageConfig.create = hookData.chatMessage;
    }

    const createMessage = messageConfig.create !== false;
    messageConfig.create = false;
    const rolls = await CONFIG.Dice.BasicRoll.build(rollConfig, dialogConfig, messageConfig);
    ```js