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

Create base AoE damage/heal classes #61

Open
shawncplus opened this issue Mar 7, 2019 · 0 comments
Open

Create base AoE damage/heal classes #61

shawncplus opened this issue Mar 7, 2019 · 0 comments
Labels
active PR Issue has a open PR waiting for review/merge enhancement New feature or request
Milestone

Comments

@shawncplus
Copy link
Member

Related to #60

Use-case

  • Player A uses a skill which coats the room in oil (adding an Oil-Covered effect to the room).
  • Player B uses an area of effect fire spell. The room's oil effect should be able to listen for AoE fire damage and explode dealing extra damage

Solution

Create new AreaOfEffectDamage and AreaOfEffectHeal classes in core which extend Damage and Heal respectively. They will have two differences from base damage/heal:

  • A Character[] getValidTargets(Room|Character commitTarget) method which will find valid targets based on where the damage is committed, e.g., if the commit target is a room it will return all players/npcs in the room. This method can be overridden by a subclass to customize valid targets.
  • An override of the commit(Character target) method to accept Room|Character target. If the target is a Room then it should call getValidTargets(room), call super.commit(target) for each valid target, then finally emit a areaDamage or areaHeal event on the room passing in AreaOfEffectDamage/Heal instance and the commit target.
class AreaOfEffectDamage extends Damage
{
  /**
   * @param {Room|Character} target
   */
  commit(room) {
    if (!(room instanceof Room)) {
      super.commit(target);
      return;
    }

    const targets = this.getValidTargets(room);
    for (const target of targets) {
      super.commit(target);
    }

    room.emit('areaDamage', this, targets);
  }

  /**
   * Override this method to customize valid targets such as
   * only targeting hostile npcs, or only targeting players, etc.
   * @param {Room} room
   * @return {Array<Character>}
   */
  getValidTargets(room) {
    return [...room.npcs];
  },
}
@shawncplus shawncplus added the enhancement New feature or request label Mar 7, 2019
@shawncplus shawncplus added the active PR Issue has a open PR waiting for review/merge label Aug 22, 2019
@shawncplus shawncplus added this to the 3.1 milestone Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
active PR Issue has a open PR waiting for review/merge enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant