/* @Packet name EntityNew @Packet identifier 134 @Description Holds data about the entity that a player encountered @Data - @Structure - */ module.exports.player = function (data) { const destinationX = data.currentNode[0]; const destinationY = data.currentNode[1]; const curHP = data.hp.current; const maxHP = data.hp.maximum; const x = data.position.x; const y = data.position.y; const name = data.name; const guild = data.guildTag; const id = data.id; const mapID = data.mapID; const speed = data.speed; const typeID = data.typeID; const textureID = data.textureID; const isMoving = data.isMoving; const pirateLevel = data.pirateLevel; const globalRank = data.globalRank; const levelRank = data.levelRank; let packetLength = 28 + name.length + (guild ? guild.length : 0) + 1 + 4; if (isMoving) packetLength += 4; const buffer = new ArrayBuffer(packetLength); const view = new DataView(buffer); view.setUint8(0, 134); view.setUint8(1, packetLength); view.setUint8(2, typeID); view.setUint32(3, id); view.setUint32(7, curHP); view.setUint32(11, maxHP); view.setUint16(15, x); view.setUint16(17, y); view.setUint16(19, speed); view.setUint8(21, pirateLevel); view.setUint8(22, mapID); view.setUint8(23, textureID); view.setUint8(24, isMoving); view.setUint8(25, globalRank); view.setUint8(26, levelRank); view.setUint8(27, name.length); view.setUint8(28, guild ? guild.length : 0); if (isMoving) { view.setUint16(29, destinationX); view.setUint16(31, destinationY); }; const nameBuffer = Buffer.from(name); for (const pair of nameBuffer.entries()) { const index = pair[0]; view.setUint8(isMoving ? index + 33 : index + 29, pair[1]); }; if (guild) { const guildBuffer = Buffer.from(guild); for (const pair of guildBuffer.entries()) { const index = pair[0]; view.setUint8(isMoving ? index + 33 + name.length : index + 29 + name.length, pair[1]); }; view.setUint32(isMoving ? guild.length + name.length + 33 : guild.length + name.length + 29, data.guildColor); }; const metadata = [curHP / maxHP, x, y, typeID]; return { buffer, metadata }; }; module.exports.npc = function (data) { const destinationX = data.path[0]; const destinationY = data.path[1]; const { id, speed, size, typeID, entityTypeID, behaviourBits, activeEffectsBits, isAdmiral, isMoving, isSpeedLowered } = data; const packetLength = (isMoving ? 31 : 27) + 1; const buffer = new ArrayBuffer(packetLength); const view = new DataView(buffer); const curHP = data.hp.current; const maxHP = data.hp.maximum; const x = data.position.x; const y = data.position.y; const intermediatePositionX = 0 const intermediatePositionY = 0 view.setUint8(0, 134); view.setUint8(1, packetLength); view.setUint8(2, typeID) view.setUint32(3, id); view.setUint8(7, entityTypeID) view.setUint32(8, curHP); view.setUint32(12, maxHP); view.setUint16(16, x); view.setUint16(18, y); view.setUint16(20, speed); view.setUint8(22, activeEffectsBits); view.setUint8(23, +isMoving); view.setUint8(24, +isSpeedLowered); view.setUint8(25, +isAdmiral); view.setUint8(26, activeEffectsBits); view.setUint8(27, size); if (isMoving) { view.setUint16(28, destinationX); view.setUint16(30, destinationY); }; const metadata = [curHP / maxHP, x, y, typeID]; return { buffer, metadata }; }; module.exports.monster = function (data) { const packetLength = 20 + 1; const buffer = new ArrayBuffer(packetLength); const view = new DataView(buffer); const { typeID, id, position, isAdmiral, entityTypeID, hp } = data; view.setUint8(0, 134); view.setUint8(1, packetLength); view.setUint8(2, typeID); view.setUint32(3, id); view.setUint8(7, entityTypeID); view.setUint8(8, isAdmiral); view.setUint32(9, hp.current); view.setUint32(13, hp.maximum); view.setUint16(17, position.x); view.setUint16(19, position.y); const metadata = [hp.current / hp.maximum, position.x, position.y, typeID]; return { buffer, metadata }; }; module.exports.tower = function (data) { const packetlength = (data.guildTag ? 23 : 20) + 1 + 4; const buffer = new ArrayBuffer(packetlength); const view = new DataView(buffer); const { hp, position, guildTag, id, entityTypeID, typeID, guildColor, order } = data; view.setUint8(0, 134); view.setUint8(1, packetlength); view.setUint8(2, typeID); view.setUint32(3, id); view.setUint16(7, position.x); view.setUint16(9, position.y); view.setUint32(11, hp.current); view.setUint32(15, hp.maximum); view.setUint8(19, entityTypeID); view.setUint8(20, order); if (guildTag) { const guildBuffer = Buffer.from(guildTag); for (const pair of guildBuffer.entries()) { const index = pair[0]; view.setUint8(21 + index, pair[1]); }; view.setUint32(24, guildColor); }; const metadata = [hp.current / hp.maximum, position.x, position.y, typeID]; return { buffer, metadata }; }; module.exports.collectable = function (data) { const packetLength = 11 + 1; const buffer = new ArrayBuffer(packetLength); const view = new DataView(buffer); const { typeID, id, entityTypeID, position } = data; view.setUint8(0, 134); view.setUint8(1, packetLength); view.setUint8(2, typeID); view.setUint32(3, id); view.setUint8(7, entityTypeID); view.setUint16(8, position.x); view.setUint16(10, position.y); const metadata = [position.x, position.y, typeID]; return { buffer, metadata }; };