Dmitry S лет назад: 4
Родитель
Сommit
296291af0f
5 измененных файлов с 108 добавлено и 206 удалено
  1. 3 0
      .gitignore
  2. 0 7
      README.md
  3. 91 175
      index.js
  4. 5 17
      manifest.json
  5. 9 7
      module.json

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.eslintrc.json
+manifest-generator.bat
+manifest-generator.js

+ 0 - 7
README.md

@@ -1,5 +1,3 @@
-<img src=http://i.cubeupload.com/rF27Xw.jpg>
-
 # Box-opener
 # Box-opener
 TERA-proxy module that mass-opens boxes (any kind of boxes (gatcha or chests or whatever gives items) or mass-uses items (potions, bandages, whatever you'd like).
 TERA-proxy module that mass-opens boxes (any kind of boxes (gatcha or chests or whatever gives items) or mass-uses items (potions, bandages, whatever you'd like).
 
 
@@ -8,10 +6,5 @@ Type `!box` then open your inventory and right click the box you wish to open -
 
 
 `!boxdelay 3000` - set minimum delay in MS for box opening, 3000 means 3 sec. (if set to 0 and by default - it would open boxes as fast as possible using their minimal cooldown - works for every box\item which gives items, for other types of consumables which give nothing set a delay else it would use default timeout of 5.5 sec while opening those)
 `!boxdelay 3000` - set minimum delay in MS for box opening, 3000 means 3 sec. (if set to 0 and by default - it would open boxes as fast as possible using their minimal cooldown - works for every box\item which gives items, for other types of consumables which give nothing set a delay else it would use default timeout of 5.5 sec while opening those)
 
 
-<img src=http://i.cubeupload.com/Sr7lEW.jpg>
-
-## Requires
-https://github.com/tera-toolbox/tera-game-state  
-
 ## Credits
 ## Credits
 Most of the code came from https://github.com/spaacecats/mwa-box-opener and forked one and rootbeer opener
 Most of the code came from https://github.com/spaacecats/mwa-box-opener and forked one and rootbeer opener

+ 91 - 175
index.js

@@ -1,12 +1,12 @@
+/* eslint-disable no-param-reassign */
 
 
-module.exports = function boxOpener(dispatch){
+module.exports = function boxOpener(dispatch) {
 	const command = dispatch.command || dispatch.require.command;
 	const command = dispatch.command || dispatch.require.command;
-	
+
 	let	hooks = [],
 	let	hooks = [],
 		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,
@@ -15,239 +15,155 @@ module.exports = function boxOpener(dispatch){
 		statOpened = 0,
 		statOpened = 0,
 		statUsed = 0,
 		statUsed = 0,
 		statStarted = null,
 		statStarted = null,
-		scanning = false/*,
-		inventory = null*/;
-		
-	command.add('box', () => {
-		if(!enabled && !scanning)
-		{
+		scanning = false;
+
+	command.add("box", () => {
+		if (!enabled && !scanning) {
 			scanning = true;
 			scanning = true;
 			load();
 			load();
-			command.message('Please normally open a box now and the script will continue opening it');
-		}
-		else
-		{
+			command.message("Please normally open a box now and the script will continue opening it");
+		} else {
 			stop();
 			stop();
 		}
 		}
 	});
 	});
-		
-	command.add('boxdelay', (arg) => {
-		if(arg === "0")
-		{
+
+	command.add("boxdelay", (arg) => {
+		if (arg === "0") {
 			useDelay = false;
 			useDelay = false;
 			delay = 5500;
 			delay = 5500;
 			command.message("Turning OFF minimum box opening delay, enjoy the speed");
 			command.message("Turning OFF minimum box opening delay, enjoy the speed");
-		}
-		else if(!isNaN(arg))
-		{
+		} else if (!isNaN(arg)) {
 			useDelay = true;
 			useDelay = true;
 			delay = parseInt(arg);
 			delay = parseInt(arg);
-			command.message("Minimum box opening delay is set to: " + (delay / 1000) + " sec");
+			command.message(`Minimum box opening delay is set to: ${ delay / 1000 } sec`);
+		} else {
+			command.message(`Minimum box opening delay is set to: ${ useDelay ? `${delay / 1000 } sec` : "no delay"}`);
 		}
 		}
-		else
-		{
-			command.message("Minimum box opening delay is set to: " + (useDelay ? (delay / 1000) + " sec" : "no delay" ));
-		}
-    });
-	
-	dispatch.hook('C_PLAYER_LOCATION', 5, event =>{location = event});
-	
+	});
+
+	dispatch.hook("C_PLAYER_LOCATION", 5, event => {location = event;});
+
 	dispatch.game.initialize("inventory");
 	dispatch.game.initialize("inventory");
-	
-	dispatch.game.inventory.on('update', () => {
-		if(!enabled) return;
-		
-		isLooting = false; // event comes only after all S_SYSTEM_MESSAGE_LOOT_ITEM (probably)
+
+	dispatch.game.inventory.on("update", () => {
+		if (!enabled) return;
+
+		isLooting = false;
 	});
 	});
-	
-	function load()
-	{
-		/*hook('S_INVEN', 18, event =>{ // pre patch 85
-			if(!enabled) return
-			
-			isLooting = false; // S_INVEN comes only after all S_SYSTEM_MESSAGE_LOOT_ITEM
-
-			if(event.first) inventory = []
-			else if(!inventory) return
-
-			for(let item of event.items) inventory.push(item)
-
-			if(!event.more) 
-			{
-				let box = false
-				for(let item of inventory) 
-				{
-					if(item.slot < 40) continue 
-					if(item.id == boxId)
-					{
-						box = true
-					}
-				}
-				if(!box) 
-				{
-					command.message("You ran out of boxes, stopping");
-					stop();
-				}
-				inventory.splice(0,inventory.length)
-				inventory = [];
-				inventory = null
-			}
-		});*/
-		
-		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){
+
+	function load() {
+		hook("C_USE_ITEM", 3, event => {
+			if (!scanning) return;
+
+			if (scanning) {
 				boxEvent = event;
 				boxEvent = event;
 				boxEvent.dbid = 0n; // to open all inv slots
 				boxEvent.dbid = 0n; // to open all inv slots
-				command.message("Box set to: "+event.id+", proceeding to auto-open it with "  + (useDelay ? "a minimum " + (delay / 1000) + " sec delay" : "no delay" ));
+				command.message(`Box set to: ${event.id}, proceeding to auto-open it with ${ useDelay ? `a minimum ${ delay / 1000 } sec delay` : "no delay"}`);
 				scanning = false;
 				scanning = false;
-				
-				let d = new Date();
+
+				const d = new Date();
 				statStarted = d.getTime();
 				statStarted = d.getTime();
 				enabled = true;
 				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', () => {
-			if(!gacha_detected && !isLooting && boxEvent)
-			{
+
+		hook("S_SYSTEM_MESSAGE_LOOT_ITEM", 1, event => {
+			if (!gacha_detected && !isLooting && boxEvent) {
 				isLooting = true;
 				isLooting = true;
-				if(!useDelay)
-				{
+				statOpened++;
+				if (!useDelay) {
 					dispatch.clearTimeout(timer);
 					dispatch.clearTimeout(timer);
 					openBox();
 					openBox();
 				}
 				}
 			}
 			}
 		});
 		});
-		
-		hook('S_GACHA_END', 'raw', () => {
-			if(boxEvent && gacha_detected)
-			{
-				dispatch.clearTimeout(timer);
-				if(useDelay) timer = dispatch.setTimeout(openBox,delay);
-				else process.nextTick(openBox);
+
+		hook("S_GACHA_END", 1, () => {
+			if (boxEvent) {
+				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))
-			{
+
+		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") {
 				command.message("Box can not be opened anymore, stopping");
 				command.message("Box can not be opened anymore, stopping");
 				stop();
 				stop();
 			}
 			}
 		});
 		});
-		
-		hook('S_REQUEST_CONTRACT', dispatch.majorPatchVersion > 107 ? 2 : 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;
+			dispatch.send("C_GACHA_TRY", 1, {
+				"id": event.id
+			});
 		});
 		});
 	}
 	}
-	
-	function openBox() 
-	{
-		if(dispatch.game.inventory.getTotalAmount(boxEvent.id) > 0)
-		{
-			if(gacha_detected)
-			{
-				if(dispatch.majorPatchVersion >= 99)
-				{
-					dispatch.toServer('C_GACHA_TRY', 2,{
-						id:gacha_contract,
-						amount: 1
-					});
-				}
-				else
-				{
-					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);
+
+	function openBox() {
+		if (dispatch.game.inventory.getTotalAmount(boxEvent.id) > 0) {
+			boxEvent.loc = location.loc;
+			boxEvent.w = location.w;
+			dispatch.send("C_USE_ITEM", 3, boxEvent);
+			if (useDelay) {
+				statUsed++;	// counter for used items other than boxes
 			}
 			}
-			statOpened++;
-		}
-		else
-		{
+			timer = setTimeout(openBox, delay);
+		} else {
 			command.message("You ran out of boxes, stopping");
 			command.message("You ran out of boxes, stopping");
 			stop();
 			stop();
 		}
 		}
 	}
 	}
-	
-	function addZero(i) 
-	{
+
+	function addZero(i) {
 		if (i < 10) {
 		if (i < 10) {
-			i = "0" + i;
+			i = `0${ i}`;
 		}
 		}
 		return i;
 		return i;
 	}
 	}
 
 
-	function stop() 
-	{
+	function stop() {
 		unload();
 		unload();
-		if(scanning)
-		{
+		if (scanning) {
 			scanning = false;
 			scanning = false;
-			command.message('Scanning for a box is aborted');
-		}
-		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);
+			command.message("Scanning for a box is aborted");
+		} else {
+			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 timeElapsedMSec = t-statStarted;
+			const t = d.getTime();
+			const timeElapsedMSec = t - statStarted;
 			d = new Date(1970, 0, 1); // Epoch
 			d = new Date(1970, 0, 1); // Epoch
 			d.setMilliseconds(timeElapsedMSec);
 			d.setMilliseconds(timeElapsedMSec);
-			let h = addZero(d.getHours());
-			let m = addZero(d.getMinutes());
-			let s = addZero(d.getSeconds());
-			command.message('Box opener stopped. Opened: ' + statOpened + ' boxes. Time elapsed: ' + (h + ":" + m + ":" + s) + ". Per box: " + ((timeElapsedMSec / statOpened) / 1000).toPrecision(2) + " sec");
+			const h = addZero(d.getHours());
+			const m = addZero(d.getMinutes());
+			const s = addZero(d.getSeconds());
+			command.message(`Box opener stopped. Opened: ${ statOpened } boxes. Time elapsed: ${ h }:${ m }:${ s }. Per box: ${ ((timeElapsedMSec / statOpened) / 1000).toPrecision(2) } sec`);
 			statOpened = 0;
 			statOpened = 0;
 			statUsed = 0;
 			statUsed = 0;
 		}
 		}
 	}
 	}
-	
+
 	function unload() {
 	function unload() {
-		if(hooks.length) {
-			for(let h of hooks) dispatch.unhook(h)
+		if (hooks.length) {
+			for (const h of hooks) dispatch.unhook(h);
 
 
-			hooks = []
+			hooks = [];
 		}
 		}
 	}
 	}
 
 
 	function hook() {
 	function hook() {
-		hooks.push(dispatch.hook(...arguments))
+		hooks.push(dispatch.hook(...arguments));
 	}
 	}
-}
+};

+ 5 - 17
manifest.json

@@ -1,19 +1,7 @@
 {
 {
-	"files": {
-		"README.md": "8b1704eff4c6f1989542d77d59666e28bfda029392946c5688d88af94cced028",
-		"index.js": "f8d050b541b204ba5becdd779c570c371b7b4351d2153c194152169615109572",
-		"module.json": "c40095006cfede1be501b2c0204dd2d778cd963dc0cb26e33dc3c8a839123fab"
-	},
-	"defs": {
-		"C_GACHA_CANCEL": 1,
-		"C_GACHA_TRY": [1,2],
-		"C_PLAYER_LOCATION": 5,
-		"C_USE_ITEM": 3,
-		"S_CANCEL_CONTRACT": 1,
-		"S_GACHA_END": "raw",
-		"S_GACHA_START": "raw",
-		"S_REQUEST_CONTRACT": [1,2],
-		"S_SYSTEM_MESSAGE": 1,
-		"S_SYSTEM_MESSAGE_LOOT_ITEM": "raw"
-	}
+    "files": {
+        "README.md": "11ea6f81fe4e3cf47009ec6393b26d0366fb2c9d6c46b5ab7e9fe0e3a9620532",
+        "index.js": "bff411909d72da9d1d712904d864f8db5966db02926c20c63f4a7b79439bfdf1",
+        "module.json": "fd1686b8e0640fdc1a415358f2f8330f7e2af658d9a9322d0ac701f099d0f897"
+    }
 }
 }

+ 9 - 7
module.json

@@ -1,9 +1,11 @@
 {
 {
-	"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": {
+        "cliName": "Box",
+        "guiName": "Generic Box Opener & Item user"
+    },
+    "servers": ["https://raw.githubusercontent.com/tera-private-mods/generic-box-opener-item-user/master/"]
 }
 }