index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. module.exports = function NpcSummoner(mod) {
  2. let zoneHw = false;
  3. mod.dispatch.addDefinition("C_REQUEST_CONTRACT", 50, [
  4. ["name", "refString"],
  5. ["data", "refBytes"],
  6. ["type", "int32"],
  7. ["target", "int64"],
  8. ["value", "int32"],
  9. ["name", "string"],
  10. ["data", "bytes"]
  11. ]);
  12. Object.keys(mod.settings.npc).forEach(name => {
  13. mod.command.add(name, () => {
  14. const npc = mod.settings.npc[name];
  15. const buffer = Buffer.alloc(4);
  16. buffer.writeUInt32LE(npc.value);
  17. mod.send("C_REQUEST_CONTRACT", 50, {
  18. type: npc.type,
  19. target: npc.id,
  20. value: npc.value,
  21. name: "",
  22. data: buffer
  23. });
  24. });
  25. });
  26. mod.command.add("broker", () =>
  27. mod.toClient("S_NPC_MENU_SELECT", 1, { type: 28 })
  28. );
  29. mod.hook("S_LOAD_TOPO", 3, event => {
  30. zoneHw = event.zone === 7031;
  31. });
  32. mod.hook("S_SPAWN_NPC", 12, packet => {
  33. if (zoneHw) {
  34. const npc = Object.values(mod.settings.npc).find(e => e.templateId !== undefined && e.templateId === packet.templateId);
  35. if (npc) {
  36. npc.id = parseInt(packet.gameId);
  37. }
  38. }
  39. });
  40. this.destructor = () => {
  41. zoneHw = false;
  42. mod.command.remove(["broker", ...Object.keys(mod.settings.npc)]);
  43. };
  44. };