fix: receptacle packets
This commit is contained in:
parent
34ee5f21ee
commit
1daa3ecd72
|
@ -1,12 +0,0 @@
|
|||
import {Packet} from '@avocado/net';
|
||||
|
||||
export class TraitItemQtyPacket extends Packet {
|
||||
|
||||
static get schema() {
|
||||
const schema = super.schema;
|
||||
schema.data.slotIndex = 'uint16';
|
||||
schema.data.qty = 'uint16';
|
||||
return schema;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
import {Packet} from '@avocado/net';
|
||||
|
||||
export class TraitItemSwapPacket extends Packet {
|
||||
|
||||
static get schema() {
|
||||
const schema = super.schema;
|
||||
schema.data.firstSlotIndex = 'uint16';
|
||||
schema.data.secondSlotIndex = 'uint16';
|
||||
return schema;
|
||||
}
|
||||
|
||||
}
|
15
common/packets/trait-update-receptacle-item-qty.packet.js
Normal file
15
common/packets/trait-update-receptacle-item-qty.packet.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import {Packet} from '@avocado/net';
|
||||
|
||||
export class TraitUpdateReceptacleItemQtyPacket extends Packet {
|
||||
|
||||
static get schema() {
|
||||
return {
|
||||
...super.schema,
|
||||
data: {
|
||||
slotIndex: 'uint16',
|
||||
qty: 'uint16',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
}
|
15
common/packets/trait-update-receptacle-item-swap.packet.js
Normal file
15
common/packets/trait-update-receptacle-item-swap.packet.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import {Packet} from '@avocado/net';
|
||||
|
||||
export class TraitUpdateReceptacleItemSwapPacket extends Packet {
|
||||
|
||||
static get schema() {
|
||||
return {
|
||||
...super.schema,
|
||||
data: {
|
||||
firstSlotIndex: 'uint16',
|
||||
secondSlotIndex: 'uint16',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,12 @@
|
|||
import {compose} from '@avocado/core';
|
||||
import {Entity, StateProperty, Trait} from '@avocado/entity';
|
||||
|
||||
import {TraitItemQtyPacket} from '../packets/trait-item-qty.packet';
|
||||
import {TraitItemSwapPacket} from '../packets/trait-item-swap.packet';
|
||||
import {
|
||||
TraitUpdateReceptacleItemQtyPacket,
|
||||
} from '../packets/trait-update-receptacle-item-qty.packet';
|
||||
import {
|
||||
TraitUpdateReceptacleItemSwapPacket,
|
||||
} from '../packets/trait-update-receptacle-item-swap.packet';
|
||||
|
||||
const decorate = compose(
|
||||
StateProperty('slotCount', {
|
||||
|
@ -65,14 +69,14 @@ export class Receptacle extends decorate(Trait) {
|
|||
|
||||
acceptPacket(packet) {
|
||||
// Quantity update.
|
||||
if (packet instanceof TraitItemQtyPacket) {
|
||||
if (packet instanceof TraitUpdateReceptacleItemQtyPacket) {
|
||||
const item = this.entity.itemInSlot(packet.data.slotIndex);
|
||||
if (item) {
|
||||
item.qty = packet.data.qty;
|
||||
}
|
||||
}
|
||||
// Slot swap.
|
||||
if (packet instanceof TraitItemSwapPacket) {
|
||||
if (packet instanceof TraitUpdateReceptacleItemSwapPacket) {
|
||||
// NULL destination slot === remove.
|
||||
const {firstSlotIndex, secondSlotIndex} = packet.data;
|
||||
if (NULL_SLOT === secondSlotIndex) {
|
||||
|
@ -94,7 +98,7 @@ export class Receptacle extends decorate(Trait) {
|
|||
const slotIndex = this.itemSlotIndex(item);
|
||||
// Valid quantity; update client.
|
||||
if (newQty > 0) {
|
||||
this.packetUpdates.push(new TraitItemQtyPacket({
|
||||
this.packetUpdates.push(new TraitUpdateReceptacleItemQtyPacket({
|
||||
slotIndex,
|
||||
qty: item.qty,
|
||||
}, this.entity));
|
||||
|
@ -128,7 +132,7 @@ export class Receptacle extends decorate(Trait) {
|
|||
mergeItem(item) {
|
||||
}
|
||||
|
||||
packetsForUpdate() {
|
||||
packets(informed) {
|
||||
const packetsForUpdate = this.packetUpdates;
|
||||
this.packetUpdates = [];
|
||||
return packetsForUpdate;
|
||||
|
@ -161,7 +165,7 @@ export class Receptacle extends decorate(Trait) {
|
|||
this.removeListenersForItem(item);
|
||||
delete this.slotItems[slotIndex];
|
||||
if (AVOCADO_SERVER) {
|
||||
this.packetUpdates.push(new TraitItemSwapPacket({
|
||||
this.packetUpdates.push(new TraitUpdateReceptacleItemSwapPacket({
|
||||
firstSlotIndex: slotIndex,
|
||||
secondSlotIndex: NULL_SLOT,
|
||||
}, this.entity));
|
||||
|
|
Loading…
Reference in New Issue
Block a user