Actor Updating

question for ya'll, simple update issue i'm seeing that i'm sure someone understands. with my convenient effects module, i'm attempting to handle the spell Aid, which grants +5 healing and +5 max HP for the duration. i'm writing code to specifically do this, because active effects for this kind of stuff doesn't work. here's what i got

  /**
   * Adds actor data changes for specific effects
   *
   * @param {string} effectName - the effect name to handle
   * @param {Actor5e} actor - the effected actor
   */
  async addActorDataChanges(effectName, actor) {
    switch (effectName.toLowerCase()) {
      case 'aid':
        await this._addAidEffects(actor);
        break;
    }
  }

  async _addAidEffects(actor) {
    await actor.data.update({
      'data.attributes.hp.max': actor.data.data.attributes.hp.max + 5,
      'data.attributes.hp.value': actor.data.data.attributes.hp.value + 5,
    });
  }

  /**
   * Removes actor data changes for specific effects
   *
   * @param {string} effectName - the effect name to handle
   * @param {Actor5e} actor - the effected actor
   */
  async removeActorDataChanges(effectName, actor) {
    switch (effectName.toLowerCase()) {
      case 'aid':
        await this._removeAidEffects(actor);
        break;
    }
  }

  async _removeAidEffects(actor) {
    const newMax = actor.data.data.attributes.hp.max - 5;
    const value = actor.data.data.attributes.hp.value;

    await actor.data.update({
      'data.attributes.hp.max': newMax,
    });

    if (value > newMax) {
      await actor.data.update({
        'data.attributes.hp.value': newMax,
      });
    }
  }


This all works well and dandy... unless foundry is reloaded. Then all the changes are lost and the max HP is set back to whatever it was before. I'm passing in the Actor5e from the selected token on the canvas.

Anyone have any ideas?
Was this page helpful?