Fukki 7 years ago
parent
commit
c4c29e9a7c
2 changed files with 15 additions and 12 deletions
  1. 14 11
      index.js
  2. 1 1
      manifest.json

+ 14 - 11
index.js

@@ -1,7 +1,7 @@
 const path = require('path'); const fs = require('fs');
 module.exports = function AutoPOT(mod) {
 	const cmd = mod.command || mod.require.command;
-	let config = getConfig(), hpPot = getHP(), mpPot = getMP();
+	let config = getConfig(), hpPot = getHP(), mpPot = getMP(), inUpdate = false;
 	let gPot = null, isReady = false, isSlaying = false, nowHP = 0, nowMP = 0;
 	mod.game.initialize(['me', 'contract']);
 
@@ -42,17 +42,9 @@ module.exports = function AutoPOT(mod) {
 		}
 	});
 	
-	mod.hook('S_RETURN_TO_LOBBY', 'raw', () => {
-		if (config.enabled) {
-			for (let hp = 0; hp < hpPot.length; hp++)
-				hpPot[hp][1].amount = 0;
-			for (let mp = 0; mp < mpPot.length; mp++)
-				mpPot[mp][1].amount = 0;
-		}
-	});
-	
 	mod.hook('S_INVEN', 16, e => {
-		if (config.enabled) {
+		if (config.enabled && !inUpdate) {
+			inUpdate = true;
 			for(let i = 0; i < hpPot.length; i++) {
 				gPot = e.items.find(item => item.id === Number(hpPot[i][0]));
 				if (gPot) hpPot[i][1].amount = gPot.amount;
@@ -61,6 +53,7 @@ module.exports = function AutoPOT(mod) {
 				gPot = e.items.find(item => item.id === Number(mpPot[i][0]));
 				if (gPot) mpPot[i][1].amount = gPot.amount;
 			}
+			inUpdate = false;
 		}
 	});
 	
@@ -87,6 +80,16 @@ module.exports = function AutoPOT(mod) {
 			}
 		}
 	});
+	
+	mod.hook('S_RETURN_TO_LOBBY', 'raw', () => {
+		if (config.enabled) {
+			inUpdate = false;
+			for (let hp = 0; hp < hpPot.length; hp++)
+				hpPot[hp][1].amount = 0;
+			for (let mp = 0; mp < mpPot.length; mp++)
+				mpPot[mp][1].amount = 0;
+		}
+	});
 
 	function useItem(itemId) {
 		mod.send('C_USE_ITEM', 3, {

+ 1 - 1
manifest.json

@@ -1,6 +1,6 @@
 {
 	"files": {
-		"index.js": "f912b375e846a65fbfcfffb739f973d4f23065941ac41ce76fe80534c7c8ee3a"
+		"index.js": "1e81cc903c1ec27c289b6d02715a498154ecaf577d11e1cbd0897bc919a70e37"
 	},
 	"defs": {
 		"C_USE_ITEM": 3,