Browse Source

Merge pull request #4 from Risenio/master

Patch 93 support.
Owyn 6 years ago
parent
commit
1ddeb7d598
3 changed files with 65 additions and 53 deletions
  1. 39 32
      index.js
  2. 16 14
      manifest.json
  3. 10 7
      module.json

+ 39 - 32
index.js

@@ -6,6 +6,7 @@ module.exports = function boxOpener(dispatch){
 		enabled = false,
 		enabled = false,
 		boxEvent = null,
 		boxEvent = null,
 		gacha_detected = false,
 		gacha_detected = false,
+		gacha_contract = 0,
 		isLooting = false,
 		isLooting = false,
 		location = null,
 		location = null,
 		timer = null,
 		timer = null,
@@ -14,8 +15,8 @@ module.exports = function boxOpener(dispatch){
 		statOpened = 0,
 		statOpened = 0,
 		statUsed = 0,
 		statUsed = 0,
 		statStarted = null,
 		statStarted = null,
-		scanning = false,
-		inventory = null;
+		scanning = false/*,
+		inventory = null*/;
 		
 		
 	command.add('box', () => {
 	command.add('box', () => {
 		if(!enabled && !scanning)
 		if(!enabled && !scanning)
@@ -94,6 +95,7 @@ module.exports = function boxOpener(dispatch){
 		});*/
 		});*/
 		
 		
 		hook('C_USE_ITEM', 3, event =>{
 		hook('C_USE_ITEM', 3, event =>{
+			if(gacha_detected) return false; // Prevent spaming right click on gacha-type box while its already opening.
 			if(!scanning) return
 			if(!scanning) return
 		
 		
 			if(scanning){
 			if(scanning){
@@ -105,66 +107,71 @@ module.exports = function boxOpener(dispatch){
 				let d = new Date();
 				let d = new Date();
 				statStarted = d.getTime();
 				statStarted = d.getTime();
 				enabled = true;
 				enabled = true;
-				timer = setTimeout(openBox,delay);
-				return true; // for consistency of sent data
+				timer = dispatch.setTimeout(openBox,delay);
+				//return true; // for consistency of sent data
 			}
 			}
 		});
 		});
 		
 		
-		hook('S_SYSTEM_MESSAGE_LOOT_ITEM', 1, event => {
+		hook('S_SYSTEM_MESSAGE_LOOT_ITEM', 'raw', () => {
 			if(!gacha_detected && !isLooting && boxEvent)
 			if(!gacha_detected && !isLooting && boxEvent)
 			{
 			{
 				isLooting = true;
 				isLooting = true;
-				statOpened++;
 				if(!useDelay)
 				if(!useDelay)
 				{
 				{
-					clearTimeout(timer);
+					dispatch.clearTimeout(timer);
 					openBox();
 					openBox();
 				}
 				}
 			}
 			}
 		});
 		});
 		
 		
-		hook('S_GACHA_END', 1, event => {
+		hook('S_GACHA_END', 'raw', () => {
 			if(boxEvent)
 			if(boxEvent)
 			{
 			{
-				statOpened++;
 				if(!useDelay)
 				if(!useDelay)
 				{
 				{
-					clearTimeout(timer);
-					openBox();
+					dispatch.clearTimeout(timer);
+					process.nextTick(openBox);
 				}
 				}
 			}
 			}
 		});
 		});
 		
 		
 		hook('S_SYSTEM_MESSAGE', 1, event => {
 		hook('S_SYSTEM_MESSAGE', 1, event => {
-			const msg = dispatch.parseSystemMessage(event.message);
-			if(msg.id === 'SMT_ITEM_MIX_NEED_METERIAL' || msg.id === 'SMT_CANT_CONVERT_NOW')
+			const msg = dispatch.parseSystemMessage(event.message).id;
+			if(['SMT_ITEM_MIX_NEED_METERIAL', 'SMT_CANT_CONVERT_NOW', 'SMT_GACHA_NO_MORE_ITEM_SHORT', 'SMT_NOTI_LEFT_LIMITED_GACHA_ITEM', 'SMT_GACHA_CANCEL', 'SMT_COMMON_NO_MORE_ITEM_TO_USE'].includes(msg))
 			{
 			{
 				command.message("Box can not be opened anymore, stopping");
 				command.message("Box can not be opened anymore, stopping");
 				stop();
 				stop();
 			}
 			}
-        });
+		});
 		
 		
-		hook('S_GACHA_START', 1, event => {
-			gacha_detected = true;
-			dispatch.toServer('C_GACHA_TRY', 1,{
-				id:event.id
+		hook('S_REQUEST_CONTRACT', 1, event => {
+			if(event.type !== 53) return;
+			dispatch.hookOnce('S_GACHA_START', 'raw', () => {
+				gacha_detected = true;
+				gacha_contract = event.id;
+				openBox();
+				return false;
 			})
 			})
-        });
-			
+			return false;
+		});
 	}
 	}
 	
 	
 	function openBox() 
 	function openBox() 
 	{
 	{
 		if(dispatch.game.inventory.getTotalAmount(boxEvent.id) > 0)
 		if(dispatch.game.inventory.getTotalAmount(boxEvent.id) > 0)
 		{
 		{
-			boxEvent.loc = location.loc;
-			boxEvent.w = location.w;
-			dispatch.toServer('C_USE_ITEM', 3, boxEvent);
-			if(useDelay)
-			{
-				statUsed++;	// counter for used items other than boxes
+			if(gacha_detected) dispatch.toServer('C_GACHA_TRY', 1, { id: gacha_contract });
+			else {
+				boxEvent.loc = location.loc;
+				boxEvent.w = location.w;
+				dispatch.toServer('C_USE_ITEM', 3, boxEvent);
+				if(useDelay)
+				{
+					statUsed++;	// counter for used items other than boxes
+				}
+				timer = dispatch.setTimeout(openBox,delay);
 			}
 			}
-			timer = setTimeout(openBox,delay);
+			statOpened++;
 		}
 		}
 		else
 		else
 		{
 		{
@@ -191,14 +198,14 @@ module.exports = function boxOpener(dispatch){
 		}
 		}
 		else
 		else
 		{
 		{
-			clearTimeout(timer);
+			if(gacha_detected) dispatch.toServer('C_GACHA_CANCEL', 1, { id: gacha_contract });
+			if(useDelay && statOpened === 0) statOpened = statUsed;
+			if(!gacha_detected) statOpened += 1; // Add the box we used at start if not gacha.
+			dispatch.clearTimeout(timer);
 			enabled = false;
 			enabled = false;
 			gacha_detected = false;
 			gacha_detected = false;
+			gacha_contract = 0;
 			boxEvent = null;
 			boxEvent = null;
-			if(useDelay && statOpened == 0)
-			{
-				statOpened = statUsed;
-			}
 			let d = new Date();
 			let d = new Date();
 			let t = d.getTime();
 			let t = d.getTime();
 			let timeElapsedMSec = t-statStarted;
 			let timeElapsedMSec = t-statStarted;

+ 16 - 14
manifest.json

@@ -1,16 +1,18 @@
 {
 {
-	"files": {
-		"README.md": "8b1704eff4c6f1989542d77d59666e28bfda029392946c5688d88af94cced028",
-		"index.js": "57e8472449f0eb606187fd45189dcb40016eac4f5ba97dfa483b7116769c3dfc",
-		"module.json": "c40095006cfede1be501b2c0204dd2d778cd963dc0cb26e33dc3c8a839123fab"
-	},
-	"defs": {
-		"C_GACHA_TRY": 1,
-		"C_PLAYER_LOCATION": 5,
-		"C_USE_ITEM": 3,
-		"S_GACHA_END": 1,
-		"S_GACHA_START": 1,
-		"S_SYSTEM_MESSAGE": 1,
-		"S_SYSTEM_MESSAGE_LOOT_ITEM": 1
-	}
+    "files": {
+        "README.md": "8b1704eff4c6f1989542d77d59666e28bfda029392946c5688d88af94cced028",
+        "index.js": "3f1a3efbe8e0424877a3d7ae93b3d6d259eebf4edc9fd7932236e344d8abca0e",
+        "module.json": "e760be348e9e9758c29a714b0950bdebb3fe773c0f4b3c02013bb833bb315ae6"
+    },
+    "defs": {
+        "C_GACHA_CANCEL": 1,
+        "C_GACHA_TRY": 1,
+        "C_PLAYER_LOCATION": 5,
+        "C_USE_ITEM": 3,
+        "S_GACHA_END": "raw",
+        "S_GACHA_START": "raw",
+        "S_REQUEST_CONTRACT": 1,
+        "S_SYSTEM_MESSAGE": 1,
+        "S_SYSTEM_MESSAGE_LOOT_ITEM": "raw"
+    }
 }
 }

+ 10 - 7
module.json

@@ -1,9 +1,12 @@
 {
 {
-	"disableAutoUpdate": false,
-	"name": "generic-box-opener-item-user",
-	"author": "Owyn",
-	"description": "Mass-Opens boxes",
-	"options": { "niceName": "<font color='#FDD017'>Box</font>", "guiName": "Generic Box Opener & Item user" },
-	"servers": ["https://raw.githubusercontent.com/Owyn/generic-box-opener-item-user/master/"],
-	"supportUrl": "https://github.com/Owyn/generic-box-opener-item-user/issues"
+    "disableAutoUpdate": false,
+    "name": "generic-box-opener-item-user",
+    "author": "Owyn",
+    "description": "Mass-Opens boxes",
+    "options": {
+        "niceName": "<font color='#FDD017'>Box</font>",
+        "guiName": "Generic Box Opener & Item user"
+    },
+    "servers": ["https://raw.githubusercontent.com/Owyn/generic-box-opener-item-user/master/"],
+    "supportUrl": "https://github.com/Owyn/generic-box-opener-item-user/issues"
 }
 }