index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. module.exports = function NpcSummoner(mod) {
  2. let debug = false;
  3. let debugData = [];
  4. mod.dispatch.addDefinition("C_REQUEST_CONTRACT", 50, [
  5. ["name", "refString"],
  6. ["data", "refBytes"],
  7. ["type", "int32"],
  8. ["target", "int64"],
  9. ["value", "int32"],
  10. ["name", "string"],
  11. ["data", "bytes"]
  12. ]);
  13. Object.keys(mod.settings.npc).forEach(name => {
  14. mod.command.add(name, () => {
  15. const npc = mod.settings.npc[name];
  16. const buffer = Buffer.alloc(4);
  17. buffer.writeUInt32LE(npc.value);
  18. mod.send("C_REQUEST_CONTRACT", 50, {
  19. "type": npc.type,
  20. "target": npc.gameId,
  21. "value": npc.value,
  22. "name": "",
  23. "data": buffer
  24. });
  25. });
  26. });
  27. mod.command.add("broker", () =>
  28. mod.send("S_NPC_MENU_SELECT", 1, { "type": 28 })
  29. );
  30. mod.command.add("npcsummoner", () => {
  31. debug = !debug;
  32. mod.command.message(`Module debug ${debug ? "enabled" : "disabled"}`);
  33. });
  34. mod.hook("S_SPAWN_NPC", mod.majorPatchVersion >= 101 ? 12 : 11, event => {
  35. const npc = Object.values(mod.settings.npc).find(n =>
  36. n.huntingZoneId === event.huntingZoneId &&
  37. n.templateId === event.templateId
  38. );
  39. if (npc) {
  40. npc.gameId = parseInt(event.gameId);
  41. }
  42. });
  43. mod.hook("S_DIALOG", 2, event => {
  44. if (!debug) return;
  45. debugData = [
  46. "Detected NPC:",
  47. ` "value": ${event.options[0]?.type}`,
  48. ` "gameId": ${event.gameId}`,
  49. ` "templateId": ${event.questId}`,
  50. ` "huntingZoneId": ${event.huntingZoneId}`
  51. ];
  52. });
  53. mod.hook("S_REQUEST_CONTRACT", 1, event => {
  54. if (!debug) return;
  55. debugData.push(` "type": ${event.type}`);
  56. debugData.forEach(data => {
  57. console.log(data);
  58. mod.command.message(data);
  59. });
  60. debugData = [];
  61. });
  62. this.destructor = () => {
  63. mod.command.remove(["broker", ...Object.keys(mod.settings.npc)]);
  64. };
  65. };