diff --git a/common/combat/damage.packet.js b/common/combat/damage.packet.js index 5dec51d..326b2c8 100644 --- a/common/combat/damage.packet.js +++ b/common/combat/damage.packet.js @@ -3,18 +3,19 @@ import {Packet} from '@avocado/net'; export class DamagePacket extends Packet { static get schema() { - const schema = super.schema; - schema.data.damages = [ - { - amount: 'varuint', - damageSpec: { - affinity: 'uint8', + return { + ...super.schema, + data: [ + { + amount: 'varuint', + damageSpec: { + affinity: 'uint8', + }, + from: 'uint32', + isDamage: 'bool', }, - from: 'uint32', - isDamage: 'bool', - }, - ]; - return schema; + ] + } } } diff --git a/common/combat/vulnerable.trait.js b/common/combat/vulnerable.trait.js index 9ea2c19..ac2936e 100644 --- a/common/combat/vulnerable.trait.js +++ b/common/combat/vulnerable.trait.js @@ -83,9 +83,8 @@ export class Vulnerable extends Trait { acceptPacket(packet) { if (packet instanceof DamagePacket) { - const damages = packet.data.damages; - for (let i = 0; i < damages.length; ++i) { - const damage = damages[i]; + for (let i = 0; i < packet.data.length; ++i) { + const damage = packet.data[i]; if (this.entity.is('listed') && this.entity.list) { damage.from = this.entity.list.findEntity(damage.from); } @@ -137,15 +136,12 @@ export class Vulnerable extends Trait { this._isInvulnerable = isInvulnerable; } - packetsForUpdate() { - const packets = []; + packets(informed) { if (this.damages.length > 0) { - packets.push(new DamagePacket({ - damages: this.damages, - }, this.entity)); + const {damages} = this; this.damages = []; + return new DamagePacket(damages); } - return packets; } listeners() {