From 558fc568c9528856b14836deafcef2cc0a122ab6 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 26 May 2019 11:59:39 -0500 Subject: [PATCH] feat: ability to set entity as not damaging other entity --- common/combat/damaging.trait.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/common/combat/damaging.trait.js b/common/combat/damaging.trait.js index 7145c39..bc0622d 100644 --- a/common/combat/damaging.trait.js +++ b/common/combat/damaging.trait.js @@ -20,6 +20,7 @@ export class Damaging extends Trait { constructor(entity, params, state) { super(entity, params, state); this._collidingWith = []; + this._doesNotDamage = []; const damageSpecsJSON = this.params.damageSpecs; this._damageSpecs = damageSpecsJSON.map((damageSpec) => { return { @@ -33,6 +34,10 @@ export class Damaging extends Trait { this._damagingSound = this.params.damagingSound; } + doesNotDamageEntity(entity) { + return -1 !== this._doesNotDamage.indexOf(entity); + } + get damageSpecs() { return this._damageSpecs; } @@ -41,11 +46,33 @@ export class Damaging extends Trait { return this._damagingSound; } + methods() { + return { + + setDoesDamage: (entity) => { + const index = this._doesNotDamage.indexOf(entity); + if (-1 !== index) { + this._doesNotDamage.splice(index, 1); + } + }, + + setDoesNotDamage: (entity) => { + if (-1 === this._doesNotDamage.indexOf(entity)) { + this._doesNotDamage.push(entity); + } + }, + + }; + } + tick(elapsed) { if (AVOCADO_SERVER) { const isCollidingWith = this.entity.isCollidingWith; for (let i = 0; i < isCollidingWith.length; i++) { const entity = isCollidingWith[i]; + if (this.doesNotDamageEntity(entity)) { + continue; + } if (entity.is('vulnerable')) { if (!entity.isInvulnerable) { entity.takeDamageFrom(this.entity);