feat: harms/harmedAs

This commit is contained in:
cha0s 2021-02-10 08:48:34 -06:00
parent 271886de78
commit b100b523f5
2 changed files with 27 additions and 10 deletions

View File

@ -46,6 +46,9 @@ export default (latus) => class Harmful extends decorate(Trait) {
// TODO newtons
harmKnockback: 500,
harmLock: 0.1,
harms: [
'indiscriminate',
],
harmSpecs: [],
};
}
@ -82,6 +85,10 @@ export default (latus) => class Harmful extends decorate(Trait) {
};
}
get harms() {
return this.params.harms;
}
// eslint-disable-next-line class-methods-use-this
hooks() {
return {
@ -132,14 +139,6 @@ export default (latus) => class Harmful extends decorate(Trait) {
);
},
};
if ('client' !== process.env.SIDE) {
listeners.collisionStart = (other, incident) => {
this.entity.harm({
entity: other,
incident,
});
};
}
return listeners;
}
@ -214,7 +213,7 @@ export default (latus) => class Harmful extends decorate(Trait) {
tick() {
if ('client' !== process.env.SIDE) {
if (this.entity.is('collider')) {
if (this.entity.is('Collider')) {
const {isCollidingWith} = this.entity;
for (let i = 0; i < isCollidingWith.length; i++) {
this.entity.harm(isCollidingWith[i]);

View File

@ -57,6 +57,7 @@ export default (latus) => class Vulnerable extends Trait {
expressions: [],
},
},
harmedAs: [],
modifiers: undefined,
};
}
@ -84,6 +85,10 @@ export default (latus) => class Vulnerable extends Trait {
this.#locks.clear();
}
get harmedAs() {
return this.params.harmedAs;
}
static harmTextSize(amount) {
const biggest = 16;
const smallest = biggest / 2;
@ -332,7 +337,20 @@ export default (latus) => class Vulnerable extends Trait {
if (this.#isInvulnerable) {
return false;
}
return -1 === this.#isNotHarmedBy.indexOf(entity);
if (-1 !== this.#isNotHarmedBy.indexOf(entity)) {
return false;
}
const {harms} = entity;
if (-1 !== harms.indexOf('indiscriminate')) {
return true;
}
const {harmedAs} = this;
for (let i = 0; i < harms.length; ++i) {
if (-1 !== harmedAs.indexOf(harms[i])) {
return true;
}
}
return false;
},
setHarmedBy: (entity) => {