index.js 1.1 KB

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