7
7
- Options to temporarily disable Item Cache blocking packets
8
8
- Find how the data comes back from Item Cache to the client and use that
9
9
- Make Item Cache update a global variable for player gold
10
- - See if there are any options in the Item Cache config
11
10
- Just drop gold-checking all together (maybe just have a toggle-able option for it)
12
11
- 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)
14
12
*/
15
13
module . exports = function skillUpdateLogger ( mod ) {
16
- let playerId = 0 ;
17
- let playerLevel = 0 ;
18
14
let playerGold = 0 ;
19
- let purchaseList = [ ] ;
15
+ let skillLearnList = [ ] ;
20
16
let hookSLL = null ;
21
17
let hookInv = null ;
22
18
let hookStatus = null ;
23
19
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 } ) ; } ;
25
23
const DEBUG_LOG = ( logMessage ) => { console . log ( GET_DATE_STAMP ( ) + logMessage ) } ;
26
24
const GET_DATE_STAMP = ( ) => {
27
25
let d = new Date ( ) ;
28
26
return "[" + d . getHours ( ) + ":" + d . getMinutes ( ) + ":" + d . getSeconds ( ) + ":" + d . getMilliseconds ( ) + "] " ;
29
27
} ;
30
28
const LEARN_NEW_SKILLS = ( ) => {
31
- HOOK_NEXT_INV ( ) ;
29
+ TEMP_LISTEN_PLAYER_GOLD ( ) ;
32
30
global . invCacheOverride = 1 ;
33
31
mod . send ( 'C_SHOW_INVEN' , 1 , { unk : 1 } ) ;
34
32
} ;
35
- const HOOK_NEXT_INV = ( ) => {
33
+ const TEMP_LISTEN_PLAYER_GOLD = ( ) => {
36
34
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 ( ) ) {
40
36
mod . unhook ( hookInv ) ;
41
37
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 ( ) ;
44
41
}
45
42
} ) ;
46
- }
47
- const HOOK_NEXT_SLL = ( ) => {
43
+ } ;
44
+ const TEMP_LISTEN_SLL = ( ) => {
48
45
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 ;
51
46
mod . unhook ( hookSLL ) ;
52
47
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
+ }
55
55
} ) ;
56
56
} ;
57
57
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 => {
60
61
if ( playerGold >= skill . price ) {
61
62
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 } ` ) ;
63
63
playerGold -= BigInt ( skill . price ) ;
64
64
} 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 } . ` ) ;
66
66
}
67
67
} ) ;
68
- playerGold = 0 ;
69
- purchaseList = [ ] ;
70
68
}
71
69
} ;
72
70
const WAIT_UNTIL_COMBAT_END = ( ) => {
73
71
hookStatus = mod . hook ( `S_USER_STATUS` , 2 , ( event ) => {
74
- if ( event . status === 0 ) {
72
+ if ( event . gameId === getGameId ( ) && event . status === 0 ) {
75
73
mod . unhook ( hookStatus ) ;
76
74
hookStatus = null ;
77
75
TRY_PURCHASE_SKILLS ( ) ;
78
76
}
79
- } )
77
+ } ) ;
80
78
} ;
81
79
82
- mod . hook ( `S_LOGIN` , 12 , ( event ) => {
83
- playerId = event . gameId ;
84
- playerLevel = event . level ;
85
- } ) ;
86
-
87
80
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...` ) ;
90
83
LEARN_NEW_SKILLS ( ) ;
91
84
}
92
85
} ) ;
93
86
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
+ } ) ;
98
90
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
+ } ) ;
102
97
} ;
0 commit comments