Fukki 8 years ago
parent
commit
8a452c92c0
2 changed files with 23 additions and 22 deletions
  1. 22 21
      index.js
  2. 1 1
      manifest.json

+ 22 - 21
index.js

@@ -2,7 +2,8 @@ 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;
 	const cmd = mod.command || mod.require.command;
 	let config = getConfig(), hpPot = getHP(), mpPot = getMP();
 	let config = getConfig(), hpPot = getHP(), mpPot = getMP();
-	let getInv = false, useCombat = false, isSlaying = false, nowHP = 0, nowMP = 0;
+	let gPot = null, isReady = false, isSlaying = false, nowHP = 0, nowMP = 0;
+	mod.game.initialize(['me', 'contract']);
 
 
 	cmd.add(['autopot', 'pot'], (arg1, arg2) => {
 	cmd.add(['autopot', 'pot'], (arg1, arg2) => {
 		if(arg1 && arg1.length > 0) arg1 = arg1.toLowerCase();
 		if(arg1 && arg1.length > 0) arg1 = arg1.toLowerCase();
@@ -51,36 +52,36 @@ module.exports = function AutoPOT(mod) {
 	
 	
 	mod.hook('S_INVEN', 16, e => {
 	mod.hook('S_INVEN', 16, e => {
 		if (config.enabled) {
 		if (config.enabled) {
-			let gHP = null, gMP = null;
 			for(let i = 0; i < hpPot.length; i++) {
 			for(let i = 0; i < hpPot.length; i++) {
-				gHP = e.items.find(item => item.id === Number(hpPot[i][0]));
-				if (gHP) hpPot[i][1].amount = gHP.amount;
+				gPot = e.items.find(item => item.id === Number(hpPot[i][0]));
+				if (gPot) hpPot[i][1].amount = gPot.amount;
 			}
 			}
 			for(let i = 0; i < mpPot.length; i++) {
 			for(let i = 0; i < mpPot.length; i++) {
-				gMP = e.items.find(item => item.id === Number(mpPot[i][0]));
-				if (gMP) mpPot[i][1].amount = gMP.amount;
+				gPot = e.items.find(item => item.id === Number(mpPot[i][0]));
+				if (gPot) mpPot[i][1].amount = gPot.amount;
 			}
 			}
 		}
 		}
 	});
 	});
 	
 	
 	mod.hook('S_PLAYER_STAT_UPDATE', 10, e => {
 	mod.hook('S_PLAYER_STAT_UPDATE', 10, e => {
-		if (config.enabled && config.hp) {
-			nowHP = Math.round(parseInt(e.hp) / parseInt(e.maxHp) * 100);
-			for (let hp = 0; hp < hpPot.length; hp++) {
-				useCombat = hpPot[hp][1].inCombat ? mod.game.me.inCombat : true;
-				if (!hpPot[hp][1].inCd && ((!isSlaying && nowHP <= hpPot[hp][1].use_at && useCombat) || (isSlaying && nowHP <= hpPot[hp][1].slay_at && mod.game.me.inCombat)) && hpPot[hp][1].amount > 0 && mod.game.me.alive && !mod.game.me.inBattleground &&!mod.game.me.mounted) {
-					useItem(hpPot[hp]); hpPot[hp][1].inCd = true; hpPot[hp][1].amount--; setTimeout(function () {hpPot[hp][1].inCd = false;}, hpPot[hp][1].cd * 1000);
-					if (config.notice) msg(`Used ${hpPot[hp][1].name}, still have ${(hpPot[hp][1].amount)} left.`);
+		if (config.enabled) {
+			isReady = mod.game.isIngame && !mod.game.isInLoadingScreen && mod.game.me.alive && !mod.game.me.inBattleground && !mod.game.me.mounted && !mod.game.contract.active;
+			if (config.hp && isReady) {
+				nowHP = Math.round(parseInt(e.hp) / parseInt(e.maxHp) * 100);
+				for (let hp = 0; hp < hpPot.length; hp++) {
+					if (!hpPot[hp][1].inCd && ((!isSlaying && nowHP <= hpPot[hp][1].use_at && (hpPot[hp][1].inCombat ? mod.game.me.inCombat : true)) || (isSlaying && nowHP <= hpPot[hp][1].slay_at && mod.game.me.inCombat)) && hpPot[hp][1].amount > 0) {
+						useItem(hpPot[hp]); hpPot[hp][1].inCd = true; hpPot[hp][1].amount--; setTimeout(function () {hpPot[hp][1].inCd = false;}, hpPot[hp][1].cd * 1000);
+						if (config.notice) msg(`Used ${hpPot[hp][1].name}, ${(hpPot[hp][1].amount)} left.`);
+					}
 				}
 				}
 			}
 			}
-		}
-		if (config.enabled && config.mp) {
-			nowMP = Math.round(parseInt(e.mp) / parseInt(e.maxMp) * 100);
-			for (let mp = 0; mp < mpPot.length; mp++) {
-				useCombat = mpPot[mp][1].inCombat ? mod.game.me.inCombat : true;
-				if (!mpPot[mp][1].inCd && nowMP <= mpPot[mp][1].use_at && mpPot[mp][1].amount > 0 && mod.game.me.alive && useCombat && !mod.game.me.inBattleground && !mod.game.me.mounted) {
-					useItem(mpPot[mp]); mpPot[mp][1].inCd = true; mpPot[mp][1].amount--; setTimeout(function () {mpPot[mp][1].inCd = false;}, mpPot[mp][1].cd * 1000);
-					if (config.notice) msg(`Used ${mpPot[mp][1].name}, still have ${(mpPot[mp][1].amount)} left.`);
+			if (config.mp && isReady) {
+				nowMP = Math.round(parseInt(e.mp) / parseInt(e.maxMp) * 100);
+				for (let mp = 0; mp < mpPot.length; mp++) {
+					if (!mpPot[mp][1].inCd && nowMP <= mpPot[mp][1].use_at && mpPot[mp][1].amount > 0 && (mpPot[mp][1].inCombat ? mod.game.me.inCombat : true)) {
+						useItem(mpPot[mp]); mpPot[mp][1].inCd = true; mpPot[mp][1].amount--; setTimeout(function () {mpPot[mp][1].inCd = false;}, mpPot[mp][1].cd * 1000);
+						if (config.notice) msg(`Used ${mpPot[mp][1].name}, ${(mpPot[mp][1].amount)} left.`);
+					}
 				}
 				}
 			}
 			}
 		}
 		}

+ 1 - 1
manifest.json

@@ -1,6 +1,6 @@
 {
 {
 	"files": {
 	"files": {
-		"index.js": "43605d476af5f84a5f4f82620c1c2eb9ebfa03e8215bf6c520a445058d29757c"
+		"index - Copy.js": "085c52391d1f04b4e998a1eb9be5d64232116149e3c31414b63b51581ab9c880"
 	},
 	},
 	"defs": {
 	"defs": {
 		"C_USE_ITEM": 3,
 		"C_USE_ITEM": 3,