31 lines
827 B
JavaScript
31 lines
827 B
JavaScript
/*
|
|
@Packet name Harpoons
|
|
@Packet identifier 154
|
|
@Description Sends the
|
|
@Data pId, (harpoonId, damage, amount), selectedHarpoon
|
|
@Structure -
|
|
*/
|
|
|
|
module.exports = function (data) {
|
|
const { harpoon, selected } = data;
|
|
|
|
const packetLength = harpoon.length * 6 + 2 + 1;
|
|
const buffer = new ArrayBuffer(packetLength);
|
|
const view = new DataView(buffer);
|
|
|
|
view.setUint8(0, 154);
|
|
view.setUint8(1, packetLength);
|
|
|
|
for (let i = 0; i < harpoon.length; i++) {
|
|
const harp = harpoon[i];
|
|
|
|
view.setUint8(i * 6 + 2, harp.id);
|
|
view.setUint8(i * 6 + 3, 0);
|
|
view.setUint32(i * 6 + 4, harp.amount);
|
|
};
|
|
|
|
view.setUint8(2 + harpoon.length * 6, selected);
|
|
|
|
return buffer;
|
|
};
|