refactor: harm
This commit is contained in:
parent
0083f9ecfa
commit
c4db9846c6
|
@ -16,8 +16,8 @@ export default {
|
||||||
buildInvoke(['entity', 'emitParticleJson'], [
|
buildInvoke(['entity', 'emitParticleJson'], [
|
||||||
logParticle(blood([255, 0, 0]), 5),
|
logParticle(blood([255, 0, 0]), 5),
|
||||||
]),
|
]),
|
||||||
buildInvoke(['from', 'playSound'], [
|
buildInvoke(['harm', 'from', 'playSound'], [
|
||||||
buildExpression(['from', 'harmfulSound']),
|
buildExpression(['harm', 'from', 'harmfulSound']),
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
|
@ -153,7 +153,7 @@ export default () => class Harmful extends decorate(Trait) {
|
||||||
const harm = {
|
const harm = {
|
||||||
amount: Math.abs(amount),
|
amount: Math.abs(amount),
|
||||||
isDamage: power >= 0,
|
isDamage: power >= 0,
|
||||||
from: this.entity.instanceUuid,
|
from: this.entity,
|
||||||
affinity,
|
affinity,
|
||||||
};
|
};
|
||||||
entity.emit('tookHarm', harm);
|
entity.emit('tookHarm', harm);
|
||||||
|
|
|
@ -19,19 +19,14 @@ export default (latus) => class Vulnerable extends Trait {
|
||||||
#isNotHarmedBy = [];
|
#isNotHarmedBy = [];
|
||||||
|
|
||||||
acceptHarm(harm) {
|
acceptHarm(harm) {
|
||||||
const {from, affinity} = harm;
|
|
||||||
const context = new Context(
|
const context = new Context(
|
||||||
{
|
{
|
||||||
entity: [this.entity, 'entity'],
|
entity: [this.entity, 'entity'],
|
||||||
from: [from, 'entity'],
|
|
||||||
harm: [harm, 'harm'],
|
harm: [harm, 'harm'],
|
||||||
},
|
},
|
||||||
latus,
|
latus,
|
||||||
);
|
);
|
||||||
if (from && from.is('Emitter')) {
|
this.interactions(this.entity, harm, context, 'client');
|
||||||
from.emitParticle('harmful');
|
|
||||||
}
|
|
||||||
this.interactions(this.entity, affinity, context, 'client');
|
|
||||||
this.entity.emit('acceptedHarm', harm);
|
this.entity.emit('acceptedHarm', harm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,11 +213,11 @@ export default (latus) => class Vulnerable extends Trait {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interactions(harmed, harmingAffinity, context, side) {
|
interactions(harmed, {affinity}, context, side) {
|
||||||
const interactions = latus.get('%interactions');
|
const interactions = latus.get('%interactions');
|
||||||
flatten(
|
flatten(
|
||||||
harmed.affinities()
|
harmed.affinities()
|
||||||
.map((harmedAffinity) => interactions(harmingAffinity, harmedAffinity)),
|
.map((harmedAffinity) => interactions(affinity, harmedAffinity)),
|
||||||
).forEach((interaction) => {
|
).forEach((interaction) => {
|
||||||
if (interaction.actions[side]) {
|
if (interaction.actions[side]) {
|
||||||
const actions = new Actions(compile(interaction.actions[side], latus));
|
const actions = new Actions(compile(interaction.actions[side], latus));
|
||||||
|
@ -276,16 +271,14 @@ export default (latus) => class Vulnerable extends Trait {
|
||||||
tookHarm: (harm) => {
|
tookHarm: (harm) => {
|
||||||
if ('client' !== process.env.SIDE) {
|
if ('client' !== process.env.SIDE) {
|
||||||
this.#harms.push(harm);
|
this.#harms.push(harm);
|
||||||
const {from, affinity} = harm;
|
|
||||||
const context = new Context(
|
const context = new Context(
|
||||||
{
|
{
|
||||||
entity: [this.entity, 'entity'],
|
entity: [this.entity, 'entity'],
|
||||||
from: [this.entity.list.findEntity(from), 'entity'],
|
|
||||||
harm: [harm, 'harm'],
|
harm: [harm, 'harm'],
|
||||||
},
|
},
|
||||||
latus,
|
latus,
|
||||||
);
|
);
|
||||||
this.interactions(this.entity, affinity, context, 'server');
|
this.interactions(this.entity, harm, context, 'server');
|
||||||
this.markAsDirty();
|
this.markAsDirty();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -334,7 +327,10 @@ export default (latus) => class Vulnerable extends Trait {
|
||||||
|
|
||||||
packets() {
|
packets() {
|
||||||
return this.#harms.length > 0
|
return this.#harms.length > 0
|
||||||
? [['Harm', this.#harms]]
|
? [['Harm', this.#harms.map((harm) => ({
|
||||||
|
...harm,
|
||||||
|
from: harm.from.instanceUuid,
|
||||||
|
}))]]
|
||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user