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 // TODO newtons
harmKnockback: 500, harmKnockback: 500,
harmLock: 0.1, harmLock: 0.1,
harms: [
'indiscriminate',
],
harmSpecs: [], 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 // eslint-disable-next-line class-methods-use-this
hooks() { hooks() {
return { 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; return listeners;
} }
@ -214,7 +213,7 @@ export default (latus) => class Harmful extends decorate(Trait) {
tick() { tick() {
if ('client' !== process.env.SIDE) { if ('client' !== process.env.SIDE) {
if (this.entity.is('collider')) { if (this.entity.is('Collider')) {
const {isCollidingWith} = this.entity; const {isCollidingWith} = this.entity;
for (let i = 0; i < isCollidingWith.length; i++) { for (let i = 0; i < isCollidingWith.length; i++) {
this.entity.harm(isCollidingWith[i]); this.entity.harm(isCollidingWith[i]);

View File

@ -57,6 +57,7 @@ export default (latus) => class Vulnerable extends Trait {
expressions: [], expressions: [],
}, },
}, },
harmedAs: [],
modifiers: undefined, modifiers: undefined,
}; };
} }
@ -84,6 +85,10 @@ export default (latus) => class Vulnerable extends Trait {
this.#locks.clear(); this.#locks.clear();
} }
get harmedAs() {
return this.params.harmedAs;
}
static harmTextSize(amount) { static harmTextSize(amount) {
const biggest = 16; const biggest = 16;
const smallest = biggest / 2; const smallest = biggest / 2;
@ -332,7 +337,20 @@ export default (latus) => class Vulnerable extends Trait {
if (this.#isInvulnerable) { if (this.#isInvulnerable) {
return false; 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) => { setHarmedBy: (entity) => {