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