feat: ability to set entity as not damaging other entity
This commit is contained in:
parent
d3648834ba
commit
558fc568c9
|
@ -20,6 +20,7 @@ export class Damaging extends Trait {
|
||||||
constructor(entity, params, state) {
|
constructor(entity, params, state) {
|
||||||
super(entity, params, state);
|
super(entity, params, state);
|
||||||
this._collidingWith = [];
|
this._collidingWith = [];
|
||||||
|
this._doesNotDamage = [];
|
||||||
const damageSpecsJSON = this.params.damageSpecs;
|
const damageSpecsJSON = this.params.damageSpecs;
|
||||||
this._damageSpecs = damageSpecsJSON.map((damageSpec) => {
|
this._damageSpecs = damageSpecsJSON.map((damageSpec) => {
|
||||||
return {
|
return {
|
||||||
|
@ -33,6 +34,10 @@ export class Damaging extends Trait {
|
||||||
this._damagingSound = this.params.damagingSound;
|
this._damagingSound = this.params.damagingSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doesNotDamageEntity(entity) {
|
||||||
|
return -1 !== this._doesNotDamage.indexOf(entity);
|
||||||
|
}
|
||||||
|
|
||||||
get damageSpecs() {
|
get damageSpecs() {
|
||||||
return this._damageSpecs;
|
return this._damageSpecs;
|
||||||
}
|
}
|
||||||
|
@ -41,11 +46,33 @@ export class Damaging extends Trait {
|
||||||
return this._damagingSound;
|
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) {
|
tick(elapsed) {
|
||||||
if (AVOCADO_SERVER) {
|
if (AVOCADO_SERVER) {
|
||||||
const isCollidingWith = this.entity.isCollidingWith;
|
const isCollidingWith = this.entity.isCollidingWith;
|
||||||
for (let i = 0; i < isCollidingWith.length; i++) {
|
for (let i = 0; i < isCollidingWith.length; i++) {
|
||||||
const entity = isCollidingWith[i];
|
const entity = isCollidingWith[i];
|
||||||
|
if (this.doesNotDamageEntity(entity)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (entity.is('vulnerable')) {
|
if (entity.is('vulnerable')) {
|
||||||
if (!entity.isInvulnerable) {
|
if (!entity.isInvulnerable) {
|
||||||
entity.takeDamageFrom(this.entity);
|
entity.takeDamageFrom(this.entity);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user