Owyn лет назад: 7
Родитель
Сommit
4cf450afb9
3 измененных файлов с 30 добавлено и 16 удалено
  1. 2 2
      README.md
  2. 26 11
      index.js
  3. 2 3
      manifest.json

+ 2 - 2
README.md

@@ -6,12 +6,12 @@ TERA-proxy module that mass-opens boxes (any kind of boxes (gatcha or chests or
 ## Usage
 ## Usage
 Type `!box` then open your inventory and right click the box you wish to open - now it will continue opening
 Type `!box` then open your inventory and right click the box you wish to open - now it will continue opening
 
 
-`!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)
+`!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>
 <img src=http://i.cubeupload.com/Sr7lEW.jpg>
 
 
 ## Requires
 ## Requires
-https://github.com/pinkipi/command
+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

+ 26 - 11
index.js

@@ -15,7 +15,6 @@ module.exports = function boxOpener(dispatch){
 		statUsed = 0,
 		statUsed = 0,
 		statStarted = null,
 		statStarted = null,
 		scanning = false,
 		scanning = false,
-		boxId = 166901, // MWA box as default.
 		inventory = null;
 		inventory = null;
 		
 		
 	command.add('box', () => {
 	command.add('box', () => {
@@ -52,9 +51,17 @@ module.exports = function boxOpener(dispatch){
 	
 	
 	dispatch.hook('C_PLAYER_LOCATION', 5, event =>{location = event});
 	dispatch.hook('C_PLAYER_LOCATION', 5, event =>{location = event});
 	
 	
+	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)
+	});
+	
 	function load()
 	function load()
 	{
 	{
-		hook('S_INVEN', 18, event =>{
+		/*hook('S_INVEN', 18, event =>{ // pre patch 85
 			if(!enabled) return
 			if(!enabled) return
 			
 			
 			isLooting = false; // S_INVEN comes only after all S_SYSTEM_MESSAGE_LOOT_ITEM
 			isLooting = false; // S_INVEN comes only after all S_SYSTEM_MESSAGE_LOOT_ITEM
@@ -84,7 +91,7 @@ module.exports = function boxOpener(dispatch){
 				inventory = [];
 				inventory = [];
 				inventory = null
 				inventory = null
 			}
 			}
-		});
+		});*/
 		
 		
 		hook('C_USE_ITEM', 3, event =>{
 		hook('C_USE_ITEM', 3, event =>{
 			if(!scanning) return
 			if(!scanning) return
@@ -92,14 +99,14 @@ module.exports = function boxOpener(dispatch){
 			if(scanning){
 			if(scanning){
 				boxEvent = event;
 				boxEvent = event;
 				boxEvent.dbid = 0n; // to open all inv slots
 				boxEvent.dbid = 0n; // to open all inv slots
-				boxId = event.id;
-				command.message("Box set to: "+boxId+", 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();
 				let d = new Date();
 				statStarted = d.getTime();
 				statStarted = d.getTime();
 				enabled = true;
 				enabled = true;
 				timer = setTimeout(openBox,delay);
 				timer = setTimeout(openBox,delay);
+				return true; // for consistency of sent data
 			}
 			}
 		});
 		});
 		
 		
@@ -148,14 +155,22 @@ module.exports = function boxOpener(dispatch){
 	
 	
 	function openBox() 
 	function openBox() 
 	{
 	{
-		boxEvent.loc = location.loc;
-		boxEvent.w = location.w;
-		dispatch.toServer('C_USE_ITEM', 3, boxEvent);
-		if(useDelay)
+		if(dispatch.game.inventory.getTotalAmount(boxEvent.id) > 0)
 		{
 		{
-			statUsed++;	// counter for used items other than boxes
+			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 = setTimeout(openBox,delay);
+		}
+		else
+		{
+			command.message("You ran out of boxes, stopping");
+			stop();
 		}
 		}
-		timer = setTimeout(openBox,delay);
 	}
 	}
 	
 	
 	function addZero(i) 
 	function addZero(i) 

+ 2 - 3
manifest.json

@@ -1,7 +1,7 @@
 {
 {
 	"files": {
 	"files": {
-		"README.md": "4a82b827288a9d7f34cc1de1ff869ca1371d9a0144b960cf33f5501a56ff73b4",
-		"index.js": "7dc7d6ce42c5cf18457fd93c3d18b1f977e32814e72081ff4fb7c861f2c8d088",
+		"README.md": "8b1704eff4c6f1989542d77d59666e28bfda029392946c5688d88af94cced028",
+		"index.js": "57e8472449f0eb606187fd45189dcb40016eac4f5ba97dfa483b7116769c3dfc",
 		"module.json": "c40095006cfede1be501b2c0204dd2d778cd963dc0cb26e33dc3c8a839123fab"
 		"module.json": "c40095006cfede1be501b2c0204dd2d778cd963dc0cb26e33dc3c8a839123fab"
 	},
 	},
 	"defs": {
 	"defs": {
@@ -10,7 +10,6 @@
 		"C_USE_ITEM": 3,
 		"C_USE_ITEM": 3,
 		"S_GACHA_END": 1,
 		"S_GACHA_END": 1,
 		"S_GACHA_START": 1,
 		"S_GACHA_START": 1,
-		"S_INVEN": 18,
 		"S_SYSTEM_MESSAGE": 1,
 		"S_SYSTEM_MESSAGE": 1,
 		"S_SYSTEM_MESSAGE_LOOT_ITEM": 1
 		"S_SYSTEM_MESSAGE_LOOT_ITEM": 1
 	}
 	}