|
|
@@ -2,8 +2,8 @@ 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, invUpdate = false, TmpData = [], aRes = null;
|
|
|
- mod.game.initialize(['me', 'contract']);
|
|
|
+ let invUpdate = false, TmpData = [], aRes = null;
|
|
|
+ mod.game.initialize(['me', 'contract', 'inventory']);
|
|
|
|
|
|
if (!map.has(mod.dispatch || mod)) {
|
|
|
map.set(mod.dispatch || mod, {});
|
|
|
@@ -214,27 +214,15 @@ module.exports = function AutoPOT(mod) {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- mod.hook('S_INVEN', mod.majorPatchVersion > 79 ? 18 : 17, 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('C_PLAYER_LOCATION', 5, e => {
|
|
|
+ aLoc = e.loc;
|
|
|
+ wLoc = e.w;
|
|
|
});
|
|
|
|
|
|
- /*mod.hook('S_PLAYER_STAT_UPDATE', 10, e => {
|
|
|
- if (config.enabled) {
|
|
|
- useHP(Math.round(s2n(e.hp) / s2n(e.maxHp) * 100));
|
|
|
- useMP(Math.round(s2n(e.mp) / s2n(e.maxMp) * 100));
|
|
|
- }
|
|
|
- });*/
|
|
|
+ mod.hook('S_SPAWN_ME', 3, e => {
|
|
|
+ aLoc = e.loc;
|
|
|
+ wLoc = e.w;
|
|
|
+ });
|
|
|
|
|
|
mod.hook('S_CREATURE_CHANGE_HP', 6, e => {
|
|
|
if (config.enabled && e.target === mod.game.me.gameId)
|
|
|
@@ -246,6 +234,17 @@ module.exports = function AutoPOT(mod) {
|
|
|
useMP(Math.round(s2n(e.currentMp) / s2n(e.maxMp) * 100));
|
|
|
});
|
|
|
|
|
|
+ mod.hook('S_INVEN', 'raw', () => {
|
|
|
+ if (!invUpdate) {
|
|
|
+ invUpdate = true;
|
|
|
+ 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]));
|
|
|
+ invUpdate = false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
mod.hook('S_RETURN_TO_LOBBY', 'raw', () => {
|
|
|
for (let hp = 0; hp < hpPot.length; hp++)
|
|
|
hpPot[hp][1].amount = 0;
|
|
|
@@ -256,23 +255,13 @@ module.exports = function AutoPOT(mod) {
|
|
|
aRes = null;
|
|
|
});
|
|
|
|
|
|
- mod.hook('C_PLAYER_LOCATION', 5, e => {
|
|
|
- aLoc = e.loc;
|
|
|
- wLoc = e.w;
|
|
|
- });
|
|
|
-
|
|
|
- mod.hook('S_SPAWN_ME', 3, e => {
|
|
|
- aLoc = e.loc;
|
|
|
- wLoc = e.w;
|
|
|
- });
|
|
|
-
|
|
|
mod.game.me.on('resurrect', () => {
|
|
|
if (aRes) clearTimeout(aRes);
|
|
|
aRes = setTimeout(() => {aRes = null;}, config.delayafterRes);
|
|
|
});
|
|
|
|
|
|
function useHP(nowHP) {
|
|
|
- if (config.hp && (mod.game.isIngame && !mod.game.isInLoadingScreen && !aRes && 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)) {
|
|
|
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);
|
|
|
@@ -283,7 +272,7 @@ module.exports = function AutoPOT(mod) {
|
|
|
}
|
|
|
|
|
|
function useMP(nowMP) {
|
|
|
- if (config.mp && (mod.game.isIngame && !mod.game.isInLoadingScreen && !aRes && 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)) {
|
|
|
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);
|
|
|
@@ -314,19 +303,6 @@ 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,
|