Fukki лет назад: 7
Родитель
Сommit
49781c6b4b
2 измененных файлов с 16 добавлено и 8 удалено
  1. 15 7
      index.js
  2. 1 1
      manifest.json

+ 15 - 7
index.js

@@ -1,7 +1,7 @@
 const path = require('path'); const fs = require('fs');
 const path = require('path'); const fs = require('fs');
 module.exports = function AutoPOT(mod) {
 module.exports = function AutoPOT(mod) {
 	const cmd = mod.command || mod.require.command, map = new WeakMap();
 	const cmd = mod.command || mod.require.command, map = new WeakMap();
-	let config = getConfig(), hpPot = getHP(), mpPot = getMP(), TmpData = [], aRes = null, aLoc = null, wLoc = 0;
+	let config = getConfig(), hpPot = getHP(), mpPot = getMP(), TmpData = [], aRes = null, aLoc = null, wLoc = 0, invUpdate = false, gPot = null;
 	mod.game.initialize(['me', 'contract', 'inventory']);
 	mod.game.initialize(['me', 'contract', 'inventory']);
 
 
 	if (!map.has(mod.dispatch || mod)) {
 	if (!map.has(mod.dispatch || mod)) {
@@ -231,11 +231,19 @@ module.exports = function AutoPOT(mod) {
 			useMP(Math.round(s2n(e.currentMp) / s2n(e.maxMp) * 100));
 			useMP(Math.round(s2n(e.currentMp) / s2n(e.maxMp) * 100));
 	});
 	});
 	
 	
-	mod.hook('S_INVEN', 19, () => {
-		for(let hp = 0; hp < hpPot.length; hp++)
-			hpPot[hp][1].amount = mod.game.inventory.getTotalAmount(s2n(hpPot[hp][0]));
-		for(let mp = 0; mp < mpPot.length; mp++)
-			mpPot[mp][1].amount = mod.game.inventory.getTotalAmount(s2n(mpPot[mp][0]));
+	mod.hook('S_INVEN', 19, e => {
+		if (!invUpdate) {
+			invUpdate = true;
+			for(let hp = 0; hp < hpPot.length; hp++) {
+				gPot = e.items.filter(item => item.id === s2n(hpPot[hp][0]));
+				if (gPot.length > 0) hpPot[hp][1].amount = gPot.reduce(function (a, b) {return a + b.amount;}, 0);
+			}
+			for(let mp = 0; mp < mpPot.length; mp++) {
+				gPot = e.items.filter(item => item.id === s2n(mpPot[mp][0]));
+				if (gPot.length > 0) mpPot[mp][1].amount = gPot.reduce(function (a, b) {return a + b.amount;}, 0);
+			}
+			invUpdate = false;
+		}
 	});
 	});
 	
 	
 	mod.hook('S_RETURN_TO_LOBBY', 'raw', () => {
 	mod.hook('S_RETURN_TO_LOBBY', 'raw', () => {
@@ -244,7 +252,7 @@ module.exports = function AutoPOT(mod) {
 		for (let mp = 0; mp < mpPot.length; mp++)
 		for (let mp = 0; mp < mpPot.length; mp++)
 			mpPot[mp][1].amount = 0;
 			mpPot[mp][1].amount = 0;
 		if (aRes) clearTimeout(aRes);
 		if (aRes) clearTimeout(aRes);
-		aRes = null;
+		aRes = null; invUpdate = false;
 	});
 	});
 	
 	
 	mod.game.me.on('resurrect', () => { 
 	mod.game.me.on('resurrect', () => { 

+ 1 - 1
manifest.json

@@ -1,6 +1,6 @@
 {
 {
 	"files": {
 	"files": {
-		"index.js": "4dd787fad474f7f3b02afbcb10942c31b88611bbbdca44b7efa1714a2875dcfb"
+		"index.js": "e5ed2e4bbdf60b237412aabc84774e41cbd9abd3112fc0efb80fc4b59edcc241"
 	},
 	},
 	"defs": {
 	"defs": {
 		"C_ADMIN": 1,
 		"C_ADMIN": 1,