Fukki 7 years ago
parent
commit
6aafc2ceb1
2 changed files with 32 additions and 12 deletions
  1. 31 11
      index.js
  2. 1 1
      manifest.json

+ 31 - 11
index.js

@@ -2,7 +2,7 @@ const path = require('path'); const fs = require('fs');
 module.exports = function AutoPOT(mod) {
 	const cmd = mod.command || mod.require.command, map = new WeakMap();
 	let config = getConfig(), hpPot = getHP(), mpPot = getMP(), aLoc = null, wLoc = 0;
-	let gPot = null, inUpdate = false, TmpData = [], aRes = {cd: null, delay: 5000};
+	let gPot = null, invUpdate = false, TmpData = [], aRes = null;
 	mod.game.initialize(['me', 'contract']);
 
 	if (!map.has(mod.dispatch || mod)) {
@@ -83,6 +83,7 @@ module.exports = function AutoPOT(mod) {
 				config.mp = !config.mp;
 				msg(`MP pot has ${config.mp ? 'Enable' : 'Disable'}.`);
 				break;
+			case 'info':
 			case 'option':
 			case 'status':
 			case 'debug':
@@ -106,6 +107,9 @@ module.exports = function AutoPOT(mod) {
 				{
 					text: `<font color="#4DD0E1" size="+20">Notice: </font>${TFString(config.notice)}`
 				},
+				{
+					text: `<font color="#4DD0E1" size="+20">Delay After Resurrect: </font> <font color="#4DE19C" size="+20">${config.delayafterRes}</font>`
+				},
 				{
 					text: `<br><font color="#4DD0E1" size="+24">===== Status =====</font><br>`
 				},
@@ -131,7 +135,7 @@ module.exports = function AutoPOT(mod) {
 					text: `<font color="#4DD0E1" size="+20">Battleground: </font>${TFString(mod.game.me.inBattleground)}`
 				},
 				{
-					text: `<font color="#4DD0E1" size="+20">CivilUnrest: </font>${TFString(mod.game.me.zone === 152)}`
+					text: `<font color="#4DD0E1" size="+20">Civil Unrest: </font>${TFString(mod.game.me.zone === 152)}`
 				});
 				TmpData.push({
 					text: `<br><font color="#4DD0E1" size="+24">===== HP Potion =====</font><br>`
@@ -195,8 +199,8 @@ module.exports = function AutoPOT(mod) {
 	});
 	
 	mod.hook('S_INVEN', mod.majorPatchVersion > 79 ? 18 : 17, e => {
-		if (!inUpdate) {
-			inUpdate = true;
+		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);
@@ -205,7 +209,7 @@ module.exports = function AutoPOT(mod) {
 				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);
 			}
-			inUpdate = false;
+			invUpdate = false;
 		}
 	});
 	
@@ -217,11 +221,13 @@ module.exports = function AutoPOT(mod) {
 	});
 	
 	mod.hook('S_RETURN_TO_LOBBY', 'raw', () => {
-		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;
+		if (aRes) clearTimeout(aRes);
+		invUpdate = false;
+		aRes = null;
 	});
 	
 	mod.hook('C_PLAYER_LOCATION', 5, e => {
@@ -235,12 +241,12 @@ module.exports = function AutoPOT(mod) {
 	});
 	
 	mod.game.me.on('resurrect', () => { 
-		if (aRes.cd) clearTimeout(aRes.cd);
-		aRes.cd = setTimeout(() => {aRes.cd = null;}, aRes.delay);
+		if (aRes) clearTimeout(aRes);
+		aRes = setTimeout(() => {aRes = null;}, config.delayafterRes);
 	});
 	
 	function useHP(nowHP) {
-		if (config.hp && (mod.game.isIngame && !mod.game.isInLoadingScreen && !aRes.cd && mod.game.me.alive && !mod.game.me.mounted && !mod.game.contract.active)) {
+		if (config.hp && (mod.game.isIngame && !mod.game.isInLoadingScreen && !aRes && mod.game.me.alive && !mod.game.me.mounted && !mod.game.contract.active)) {
 			for (let hp = 0; hp < hpPot.length; hp++) {
 				if (!hpPot[hp][1].inCd && hpPot[hp][1].amount > 0 && ((!config.slaying && nowHP <= hpPot[hp][1].use_at && (hpPot[hp][1].inCombat ? mod.game.me.inCombat : true)) || (config.slaying && nowHP <= hpPot[hp][1].slay_at && mod.game.me.inCombat)) && (hpPot[hp][1].inBattleground ? (mod.game.me.inBattleground || mod.game.me.zone === 152) : !mod.game.me.inBattleground)) {
 					useItem(hpPot[hp]); hpPot[hp][1].inCd = true; hpPot[hp][1].amount--; setTimeout(function () {hpPot[hp][1].inCd = false;}, hpPot[hp][1].cd * 1000);
@@ -251,7 +257,7 @@ module.exports = function AutoPOT(mod) {
 	}
 	
 	function useMP(nowMP) {
-		if (config.mp && (mod.game.isIngame && !mod.game.isInLoadingScreen && !aRes.cd && mod.game.me.alive && !mod.game.me.mounted && !mod.game.contract.active)) {
+		if (config.mp && (mod.game.isIngame && !mod.game.isInLoadingScreen && !aRes && mod.game.me.alive && !mod.game.me.mounted && !mod.game.contract.active)) {
 			for (let mp = 0; mp < mpPot.length; mp++) {
 				if (!mpPot[mp][1].inCd && mpPot[mp][1].amount > 0 && nowMP <= mpPot[mp][1].use_at && (mpPot[mp][1].inCombat ? mod.game.me.inCombat : true) && (mpPot[mp][1].inBattleground ? (mod.game.me.inBattleground || mod.game.me.zone === 152) : !mod.game.me.inBattleground)) {
 					useItem(mpPot[mp]); mpPot[mp][1].inCd = true; mpPot[mp][1].amount--; setTimeout(function () {mpPot[mp][1].inCd = false;}, mpPot[mp][1].cd * 1000);
@@ -282,13 +288,27 @@ module.exports = function AutoPOT(mod) {
 		let data = {};
 		try {
 			data = jsonRequire('./config.json');
+			//--- Update Config !!START!! ---//
+			if (!data.delayafterRes || !data.slaying) {
+				data = {
+					enabled: data.enabled || true,
+					hp: data.hp || false,
+					mp: data.mp || true,
+					slaying: data.slaying || false,
+					notice: data.notice || false,
+					delayafterRes: data.delayafterRes ||2000
+				}
+				jsonSave('config.json', data);
+			}
+			//--- Update Config !!END!! ---//
 		} catch (e) {
 			data = {
 				enabled: true,
 				hp: false,
 				mp: true,
 				slaying: false,
-				notice: false
+				notice: false,
+				delayafterRes: 2000
 			}
 			jsonSave('config.json', data);
 		}

+ 1 - 1
manifest.json

@@ -1,6 +1,6 @@
 {
 	"files": {
-		"index.js": "900c94dc952d22d5154dd3b9e1512dbd4ea1ee716136908b36dfacaf8ddb371c"
+		"index.js": "37a20ef304d4b8f50a70616d2fb82389ef22d4e025b26a9c69472ce58fd16033"
 	},
 	"defs": {
 		"C_ADMIN": 1,