Dmitry S 4 years ago
parent
commit
e2eb83eff1
5 changed files with 75 additions and 33 deletions
  1. 1 0
      README.md
  2. 42 16
      index.js
  3. 7 6
      manifest.json
  4. 2 2
      module.json
  5. 23 9
      settings_migrator.js

+ 1 - 0
README.md

@@ -13,6 +13,7 @@ Toolbox(/8) | Command description
 **cbank** | Wardrobe (Costume Bank)
 **store** | Merchant
 **sstore** | Specialty Store
+**bel** | Bellicarium Credit Merchant
 **vg** | Vanguard Initiative Credit Merchant
 
 **Note:** You need to visit the Highwatch after the first installation of the module, as well as after the release of a new patch of the game to update the NPC identifiers.

+ 42 - 16
index.js

@@ -1,5 +1,6 @@
 module.exports = function NpcSummoner(mod) {
-	let zoneHw = false;
+	let debug = false;
+	let debugData = [];
 
 	mod.dispatch.addDefinition("C_REQUEST_CONTRACT", 50, [
 		["name", "refString"],
@@ -18,35 +19,60 @@ module.exports = function NpcSummoner(mod) {
 
 			buffer.writeUInt32LE(npc.value);
 			mod.send("C_REQUEST_CONTRACT", 50, {
-				type: npc.type,
-				target: npc.id,
-				value: npc.value,
-				name: "",
-				data: buffer
+				"type": npc.type,
+				"target": npc.gameId,
+				"value": npc.value,
+				"name": "",
+				"data": buffer
 			});
 		});
 	});
 
 	mod.command.add("broker", () =>
-		mod.toClient("S_NPC_MENU_SELECT", 1, { type: 28 })
+		mod.send("S_NPC_MENU_SELECT", 1, { "type": 28 })
 	);
 
-	mod.hook("S_LOAD_TOPO", 3, event => {
-		zoneHw = event.zone === 7031;
+	mod.command.add("npcsummoner", () => {
+		debug = !debug;
+		mod.command.message(`Module debug ${debug ? "enabled" : "disabled"}`);
 	});
 
-	mod.hook("S_SPAWN_NPC", 12, packet => {
-		if (zoneHw) {
-			const npc = Object.values(mod.settings.npc).find(e => e.templateId !== undefined && e.templateId === packet.templateId);
+	mod.hook("S_SPAWN_NPC", mod.majorPatchVersion >= 101 ? 12 : 11, event => {
+		const npc = Object.values(mod.settings.npc).find(n =>
+			n.huntingZoneId === event.huntingZoneId &&
+			n.templateId === event.templateId
+		);
 
-			if (npc) {
-				npc.id = parseInt(packet.gameId);
-			}
+		if (npc) {
+			npc.gameId = parseInt(event.gameId);
 		}
 	});
 
+	mod.hook("S_DIALOG", 2, event => {
+		if (!debug) return;
+
+		debugData = [
+			"Detected NPC:",
+			`   "value": ${event.options[0]?.type}`,
+			`   "gameId": ${event.gameId}`,
+			`   "templateId": ${event.questId}`,
+			`   "huntingZoneId": ${event.huntingZoneId}`
+		];
+	});
+
+	mod.hook("S_REQUEST_CONTRACT", 1, event => {
+		if (!debug) return;
+
+		debugData.push(`   "type": ${event.type}`);
+		debugData.forEach(data => {
+			console.log(data);
+			mod.command.message(data);
+		});
+
+		debugData = [];
+	});
+
 	this.destructor = () => {
-		zoneHw = false;
 		mod.command.remove(["broker", ...Object.keys(mod.settings.npc)]);
 	};
 };

+ 7 - 6
manifest.json

@@ -1,14 +1,15 @@
 {
     "files": {
-        "README.md": "18bf09cf92eadb42820d8d172c293aed65ca055cfee519cd960e8ade9f9e6212",
-        "index.js": "9d5fd32d95978d97d882efa757c343b4d5f2f049b365cd4541ff89839bc36171",
-        "module.json": "0dd610430ea1eb46d05a7650bc1974616cc8842e90d498d3a7128fe61c5c6de5",
-        "settings_migrator.js": "da402468235eade6a090bf1949a8fbcd1711a5af6eb1fb257ca512fe6edc7a00"
+        "README.md": "0f33c2024c759e629dc82331a4e5170eb3971d187718cd2463927398bdf31b53",
+        "index.js": "30f6cb173e1f97c6a0259815b7500b3216e58ebbdc20f3356f678613ed074a3b",
+        "module.json": "8e134de2ba3fddfd99eef15c49458b9033d69b94028f181d207e34b56f6a419c",
+        "settings_migrator.js": "b5e0675a2dfad88da4ce517fa2c8c66916133e7d380be9008b8268d2fe2baf00"
     },
     "defs": {
         "C_REQUEST_CONTRACT": 50,
-        "S_LOAD_TOPO": 3,
+        "S_DIALOG": 2,
         "S_NPC_MENU_SELECT": 1,
-        "S_SPAWN_NPC": 12
+        "S_REQUEST_CONTRACT": 1,
+        "S_SPAWN_NPC": 11
     }
 }

+ 2 - 2
module.json

@@ -4,12 +4,12 @@
     "description": "Summon any NPC (merchant, bank, broker) from anywhere",
     "options": {
         "niceName": "NPC Summoner",
-        "settingsVersion": 2,
+        "settingsVersion": 3,
         "settingsFile": "config.json",
         "reloadable": true,
         "settingsMigrator": "settings_migrator.js"
     },
     "servers": ["https://raw.githubusercontent.com/hsdn/npc-summoner/master/"],
     "disableAutoUpdate": false,
-    "version": "10/22/2021"
+    "version": "5/1/2022"
 }

+ 23 - 9
settings_migrator.js

@@ -1,7 +1,11 @@
+/* eslint-disable no-param-reassign */
 "use strict";
 
 const DefaultSettings = {
 	"npc": {
+		// For bank NPC.
+		// The "type" is a "type" from S_REQUEST_CONTRACT packet.
+		// The "value" is a "container" from S_VIEW_WARE_EX packet.
 		"bank": {
 			"type": 26,
 			"value": 1
@@ -18,23 +22,35 @@ const DefaultSettings = {
 			"type": 26,
 			"value": 12
 		},
+		// For other NPCs.
+		// You can use "npcsummoner" command to enable debug for get values.
 		"store": {
 			"type": 9,
 			"value": 70310,
-			"id": null,
-			"templateId": 2019
+			"gameId": null,
+			"templateId": 2019,
+			"huntingZoneId": 183
 		},
 		"sstore": {
 			"type": 9,
 			"value": 250,
-			"id": null,
-			"templateId": 2109
+			"gameId": null,
+			"templateId": 2109,
+			"huntingZoneId": 183
+		},
+		"bel": {
+			"type": 50,
+			"value": 141,
+			"gameId": null,
+			"templateId": 2045,
+			"huntingZoneId": 183
 		},
 		"vg": {
 			"type": 49,
 			"value": 609,
-			"id": null,
-			"templateId": 2058
+			"gameId": null,
+			"templateId": 2058,
+			"huntingZoneId": 183
 		}
 	}
 };
@@ -59,7 +75,7 @@ module.exports = function MigrateSettings(from_ver, to_ver, settings) {
 
 				for (const option in oldsettings) {
 					if (settings[option] !== undefined) {
-						settings[option] = MigrateOption(settings[option], oldsettings[option], ["id"]);
+						settings[option] = MigrateOption(settings[option], oldsettings[option], ["gameId"]);
 					}
 				}
 		}
@@ -80,8 +96,6 @@ function MigrateOption(option, oldoption, excludes) {
 	}
 
 	if (Object.getPrototypeOf(option) === Object.prototype) {
-		option = { ...option, ...oldoption };
-
 		for (const key of Object.keys(option)) {
 			if (excludes.includes(key)) {
 				option[key] = oldoption[key] || null;