Owyn лет назад: 6
Родитель
Сommit
9593f79907
3 измененных файлов с 68 добавлено и 75 удалено
  1. 47 48
      index.js
  2. 14 17
      manifest.json
  3. 7 10
      module.json

+ 47 - 48
index.js

@@ -6,7 +6,6 @@ module.exports = function boxOpener(dispatch){
 		enabled = false,
 		boxEvent = null,
 		gacha_detected = false,
-		gacha_contract = 0,
 		isLooting = false,
 		location = null,
 		timer = null,
@@ -15,8 +14,8 @@ module.exports = function boxOpener(dispatch){
 		statOpened = 0,
 		statUsed = 0,
 		statStarted = null,
-		scanning = false/*,
-		inventory = null*/;
+		scanning = false,
+		inventory = null;
 		
 	command.add('box', () => {
 		if(!enabled && !scanning)
@@ -95,7 +94,6 @@ module.exports = function boxOpener(dispatch){
 		});*/
 		
 		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){
@@ -107,75 +105,76 @@ module.exports = function boxOpener(dispatch){
 				let d = new Date();
 				statStarted = d.getTime();
 				enabled = true;
-				timer = dispatch.setTimeout(openBox,delay);
-				//return true; // for consistency of sent data
+				timer = setTimeout(openBox,delay);
+				return true; // for consistency of sent data
 			}
 		});
 		
-		hook('S_SYSTEM_MESSAGE_LOOT_ITEM', 'raw', () => {
+		hook('S_SYSTEM_MESSAGE_LOOT_ITEM', 1, event => {
 			if(!gacha_detected && !isLooting && boxEvent)
 			{
 				isLooting = true;
+				statOpened++;
 				if(!useDelay)
 				{
-					dispatch.clearTimeout(timer);
+					clearTimeout(timer);
 					openBox();
 				}
 			}
 		});
 		
-		hook('S_GACHA_END', 'raw', () => {
-			if(boxEvent && gacha_detected)
+		hook('S_GACHA_END', dispatch.majorPatchVersion >= 99 ? 3 : 1, event => {
+			if(boxEvent)
 			{
-				dispatch.clearTimeout(timer);
-				if(useDelay) timer = dispatch.setTimeout(openBox,delay);
-				else process.nextTick(openBox);
+				statOpened++;
+				if(!useDelay)
+				{
+					clearTimeout(timer);
+					openBox();
+				}
 			}
 		});
 		
 		hook('S_SYSTEM_MESSAGE', 1, event => {
-			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))
+			const msg = dispatch.parseSystemMessage(event.message);
+			if(msg.id === 'SMT_ITEM_MIX_NEED_METERIAL' || msg.id === 'SMT_CANT_CONVERT_NOW')
 			{
 				command.message("Box can not be opened anymore, stopping");
 				stop();
 			}
-		});
+        });
 		
-		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;
-		});
-
-		hook('S_CANCEL_CONTRACT', 1, event => {
-			if (!gacha_detected || event.type !== 53) return;
-			gacha_contract = 0;
-			stop();
-		});
+		hook('S_GACHA_START', 1, event => {
+			gacha_detected = true;
+			if(dispatch.majorPatchVersion >= 99)
+			{
+				dispatch.toServer('C_GACHA_TRY', 2,{
+					id:event.id,
+					amount: 1
+				});
+			}
+			else
+			{
+				dispatch.toServer('C_GACHA_TRY', 1,{
+					id:event.id
+				});
+			}
+        });
+			
 	}
 	
 	function openBox() 
 	{
 		if(dispatch.game.inventory.getTotalAmount(boxEvent.id) > 0)
 		{
-			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);
+			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
 			}
-			statOpened++;
+			timer = setTimeout(openBox,delay);
 		}
 		else
 		{
@@ -202,14 +201,14 @@ module.exports = function boxOpener(dispatch){
 		}
 		else
 		{
-			if(gacha_detected && gacha_contract) 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);
+			clearTimeout(timer);
 			enabled = false;
 			gacha_detected = false;
-			gacha_contract = 0;
 			boxEvent = null;
+			if(useDelay && statOpened == 0)
+			{
+				statOpened = statUsed;
+			}
 			let d = new Date();
 			let t = d.getTime();
 			let timeElapsedMSec = t-statStarted;

+ 14 - 17
manifest.json

@@ -1,19 +1,16 @@
 {
-    "files": {
-        "README.md": "8b1704eff4c6f1989542d77d59666e28bfda029392946c5688d88af94cced028",
-        "index.js": "c08d63bf5d400bef0f91e9dd249460654f285d1e7a3aca22534b2b791cd845d7",
-        "module.json": "e760be348e9e9758c29a714b0950bdebb3fe773c0f4b3c02013bb833bb315ae6"
-    },
-    "defs": {
-        "C_GACHA_CANCEL": 1,
-        "C_GACHA_TRY": 1,
-        "C_PLAYER_LOCATION": 5,
-        "C_USE_ITEM": 3,
-        "S_CANCEL_CONTRACT": 1,
-        "S_GACHA_END": "raw",
-        "S_GACHA_START": "raw",
-        "S_REQUEST_CONTRACT": 1,
-        "S_SYSTEM_MESSAGE": 1,
-        "S_SYSTEM_MESSAGE_LOOT_ITEM": "raw"
-    }
+	"files": {
+		"README.md": "8b1704eff4c6f1989542d77d59666e28bfda029392946c5688d88af94cced028",
+		"index.js": "bf0aefef5aa8dfc98b24efb1c7c008df8b1ca84f3418ddd901f96ef342f1f0c2",
+		"module.json": "c40095006cfede1be501b2c0204dd2d778cd963dc0cb26e33dc3c8a839123fab"
+	},
+	"defs": {
+		"C_GACHA_TRY": [1,2],
+		"C_PLAYER_LOCATION": 5,
+		"C_USE_ITEM": 3,
+		"S_GACHA_END": [1,3],
+		"S_GACHA_START": 1,
+		"S_SYSTEM_MESSAGE": 1,
+		"S_SYSTEM_MESSAGE_LOOT_ITEM": 1
+	}
 }

+ 7 - 10
module.json

@@ -1,12 +1,9 @@
 {
-    "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"
 }