Skip to content

Commit 3a94062

Browse files
committed
Add gameId check to combat exit listener. Code cleanup.
1 parent 53a4a1b commit 3a94062

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed

index.js

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,96 +7,91 @@ TODO:
77
- Options to temporarily disable Item Cache blocking packets
88
- Find how the data comes back from Item Cache to the client and use that
99
- Make Item Cache update a global variable for player gold
10-
- See if there are any options in the Item Cache config
1110
- Just drop gold-checking all together (maybe just have a toggle-able option for it)
1211
- Automatically remove the new skill glyph popup notification when you level up (glyphs level 20)
13-
- Look further into the 'Me' class at \mods\tera-game-state\lib (mod.game.Me.inCombat/gameId)
1412
*/
1513
module.exports = function skillUpdateLogger(mod) {
16-
let playerId = 0;
17-
let playerLevel = 0;
1814
let playerGold = 0;
19-
let purchaseList = [];
15+
let skillLearnList = [];
2016
let hookSLL = null;
2117
let hookInv = null;
2218
let hookStatus = null;
2319
const COMMAND = mod.command;
24-
const SEND_C_SKILL_LEARN_LIST = () => { mod.send('C_SKILL_LEARN_LIST', 1, { unk: 0xFFFFFFFF }); };
20+
const getGameId = () => { return mod.game.me.gameId };
21+
const getLevel = () => { return mod.game.me.level };
22+
const REQUEST_SKILL_LEARN_LIST = () => { mod.send('C_SKILL_LEARN_LIST', 1, { unk: 0xFFFFFFFF }); };
2523
const DEBUG_LOG = (logMessage) => { console.log( GET_DATE_STAMP() + logMessage ) };
2624
const GET_DATE_STAMP = () => {
2725
let d = new Date();
2826
return "[" + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds() + ":" + d.getMilliseconds() + "] ";
2927
};
3028
const LEARN_NEW_SKILLS = () => {
31-
HOOK_NEXT_INV();
29+
TEMP_LISTEN_PLAYER_GOLD();
3230
global.invCacheOverride = 1;
3331
mod.send('C_SHOW_INVEN', 1, { unk: 1 });
3432
};
35-
const HOOK_NEXT_INV = () => {
33+
const TEMP_LISTEN_PLAYER_GOLD = () => {
3634
hookInv = mod.hook(`S_INVEN`, 16, (event) => {
37-
if (event.gameId === playerId) {
38-
playerGold = event.gold;
39-
COMMAND.message("Player Gold: " + playerGold);
35+
if (event.gameId === getGameId()) {
4036
mod.unhook(hookInv);
4137
hookInv = null;
42-
HOOK_NEXT_SLL();
43-
SEND_C_SKILL_LEARN_LIST();
38+
playerGold = event.gold;
39+
TEMP_LISTEN_SLL();
40+
REQUEST_SKILL_LEARN_LIST();
4441
}
4542
});
46-
}
47-
const HOOK_NEXT_SLL = () => {
43+
};
44+
const TEMP_LISTEN_SLL = () => {
4845
hookSLL = mod.hook(`S_SKILL_LEARN_LIST`, 1, (event) => {
49-
purchaseList = event.skillList.filter(skill => skill.level <= playerLevel && playerGold >= skill.price);
50-
global.invCacheOverride = 0;
5146
mod.unhook(hookSLL);
5247
hookSLL = null;
53-
console.log(purchaseList);
54-
if (purchaseList) { mod.game.me.inCombat ? WAIT_UNTIL_COMBAT_END() : TRY_PURCHASE_SKILLS(); }
48+
skillLearnList = event.skillList.filter(skill => skill.level <= getLevel() && playerGold >= skill.price);
49+
global.invCacheOverride = 0;
50+
if (Array.isArray(skillLearnList) && skillLearnList.length) {
51+
mod.game.me.inCombat ? WAIT_UNTIL_COMBAT_END() : TRY_PURCHASE_SKILLS();
52+
} else {
53+
COMMAND.message("No new skills to purchase.");
54+
}
5555
});
5656
};
5757
const TRY_PURCHASE_SKILLS = () => {
58-
if (playerGold && purchaseList) {
59-
purchaseList.forEach(skill => {
58+
if (playerGold && skillLearnList) {
59+
COMMAND.message(`${skillLearnList.length} new skills available. Learning skills...`);
60+
skillLearnList.forEach(skill => {
6061
if (playerGold >= skill.price) {
6162
mod.send(`C_SKILL_LEARN_REQUEST`, 1, { unk1: 0, skill: skill.skill, type: skill.type });
62-
COMMAND.message(`Purchasing skill: ${skill.skill} for price: ${skill.price}`);
6363
playerGold -= BigInt(skill.price);
6464
} else {
65-
COMMAND.message(`Not enough gold to purchase skill ${skill.skill} - Cost: ${skill.price}`);
65+
COMMAND.message(`Not enough gold to learn skill ${skill.skill} - Cost: ${skill.price}.`);
6666
}
6767
});
68-
playerGold = 0;
69-
purchaseList = [];
7068
}
7169
};
7270
const WAIT_UNTIL_COMBAT_END = () => {
7371
hookStatus = mod.hook(`S_USER_STATUS`, 2, (event) => {
74-
if (event.status === 0) {
72+
if (event.gameId === getGameId() && event.status === 0) {
7573
mod.unhook(hookStatus);
7674
hookStatus = null;
7775
TRY_PURCHASE_SKILLS();
7876
}
79-
})
77+
});
8078
};
8179

82-
mod.hook(`S_LOGIN`, 12, (event) => {
83-
playerId = event.gameId;
84-
playerLevel = event.level;
85-
});
86-
8780
mod.hook(`S_USER_LEVELUP`, 2, (event) => {
88-
if (event.gameId === playerId) {
89-
playerLevel = event.level;
81+
if (event.gameId === getGameId()) {
82+
COMMAND.message(`Congrats on level ${getLevel()}! Checking for new skills...`);
9083
LEARN_NEW_SKILLS();
9184
}
9285
});
9386

94-
COMMAND.add('testFlow', () => {
95-
HOOK_NEXT_INV();
96-
mod.send('C_SHOW_INVEN', 1, { unk: 1 });
97-
})
87+
COMMAND.add('learn', () => {
88+
LEARN_NEW_SKILLS();
89+
});
9890

99-
COMMAND.add('testCombat', () => {
100-
COMMAND.message('In Combat? ' + mod.game.me.inCombat);
101-
})
91+
COMMAND.add('testValues', () => {
92+
console.log('playerGameId = ' + getGameId());
93+
console.log('mod.game.me.gameId = ' + mod.game.me.gameId);
94+
console.log('Player Level: ' + getLevel());
95+
console.log('mod.game.me.level = ' + mod.game.me.level);
96+
});
10297
};

manifest.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files": {
3+
},
4+
"defs": {
5+
}
6+
}

module.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
"options": {
88
"niceName": "skill-instructor"
99
},
10-
"servers": [
11-
"https://raw.githubusercontent.com/borkmaster12/skill-instructor/master/"
12-
],
10+
"servers": [""],
1311
"supportUrl": "https://discord.gg/hVwJxM"
1412
}

0 commit comments

Comments
 (0)