forked from tera-toolbox-mods/true-everful-nostrum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
248 lines (204 loc) · 7.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// Nostrum
const ITEMS_NOSTRUM = [152898, 184659, 201005, 201006, 201007, 201008, 201022, 855604];
const BUFFS_NOSTRUM = [4020, 4021, 4022, 4023, 4030, 4031, 4032, 4044];
// Premium Nostrum (Menma)
const ITEMS_NOSTRUM_PREMIUM = [280060, 280061];
const BUFFS_NOSTRUM_PREMIUM = [70244, 70243, 70245, 70228, 70233, 70232];
// Tempestuous Savage Draught
const ITEM_SAVAGE = 150942;
const BUFFS_SAVAGE = [1251];
// Other buffs
const BUFF_RES_INVINCIBLE = 1134;
const BUFF_PHOENIX = 6007;
const SettingsUI = require('tera-mod-ui').Settings;
const Vec3 = require('tera-vec3');
function ClientMod(mod) {
this.nostrum = [];
mod.clientInterface.once('ready', async () => {
this.nostrum = (await mod.queryData('/ItemData/Item@id=?/', [ITEMS_NOSTRUM_PREMIUM], true, false, ['id', 'requiredLevel'])).map(result => result.attributes);
});
}
function NetworkMod(mod) {
mod.game.initialize(['me', 'me.abnormalities', 'inventory', 'contract']);
// Load item data
const { nostrum } = mod.clientMod;
// Nostrum usage
let nostrum_items = new Map();
let item_cooldowns = {};
function itemCooldown(id) {
return Math.max(0, (item_cooldowns[mod.game.me.gameId].get(id) || 0) - Date.now());
}
// Abnormality tracking
function abnormalityDuration(id) {
const abnormality = mod.game.me.abnormalities[id];
return abnormality ? abnormality.remaining : 0n;
}
mod.hook('S_PREMIUM_SLOT_DATALIST', 2, event => {
event.sets.forEach(set => {
set.inventory.filter(entry => entry.type === 1).forEach(entry => {
const nostrum_match = nostrum.find(item => item.id === entry.id);
if (nostrum_match) {
nostrum_items.set(entry.id, {
data: nostrum_match,
packet: {
set: set.id,
slot: entry.slot,
type: entry.type,
id: entry.id
}
});
}
});
});
});
mod.hook('S_PREMIUM_SLOT_OFF', 'event', () => {
nostrum_items.clear();
});
mod.hook("S_START_COOLTIME_ITEM", 1, event => {
item_cooldowns[mod.game.me.gameId].set(event.item, Date.now() + (event.cooldown * 1000));
});
function usePremiumSlot(item) {
if (!item || mod.game.me.level < item.data.requiredLevel)
return;
mod.send('C_USE_PREMIUM_SLOT', 1, item.packet);
}
function useItem(item) {
if (itemCooldown(item) > 0)
return;
mod.send('C_USE_ITEM', 3, {
gameId: mod.game.me.gameId,
id: item,
dbid: 0,
target: 0,
amount: 1,
dest: new Vec3(0, 0, 0),
loc: new Vec3(0, 0, 0),
w: 0,
unk1: 0,
unk2: 0,
unk3: 0,
unk4: 1
});
}
function useNostrum() {
// Check if we want to use everful nostrum
if ((mod.settings.keep_resurrection_invincibility && abnormalityDuration(BUFF_RES_INVINCIBLE) > 0n) || abnormalityDuration(BUFF_PHOENIX) > 0n)
return;
const nostrum_item = nostrum_items.get(parseInt(mod.settings.nostrum_item));
// Use premium nostrum
if (nostrum_item) {
// Check if we need to use everful nostrum
if (!BUFFS_NOSTRUM_PREMIUM.some(buff => abnormalityDuration(buff) > BigInt(60 * 1000)))
usePremiumSlot(nostrum_item);
return;
}
// Search in inventory and use nostrum item (no premium)
for (const item of ITEMS_NOSTRUM) {
if (mod.game.inventory.findAllInBagOrPockets(item).length !== 0) {
// Check if we need to use everful nostrum
if (!BUFFS_NOSTRUM.some(buff => abnormalityDuration(buff) > BigInt(60 * 1000)))
useItem(item);
return;
}
}
}
function useSavage() {
// Check if a stronger buff is present
if (BUFFS_SAVAGE.some(buff => abnormalityDuration(buff) > BigInt(10 * 1000)))
return;
// Use savage item
if (mod.game.inventory.findAllInBagOrPockets(ITEM_SAVAGE).length !== 0)
useItem(ITEM_SAVAGE);
}
function useItems() {
// Check if enabled and premium items available
if (!mod.settings.enabled || (mod.settings.dungeon_only && !mod.game.me.inDungeon) || (!mod.settings.civil_unrest && mod.game.me.inCivilUnrest))
return;
// Check if we can use premium items right now
if (!mod.game.isIngame || mod.game.isInLoadingScreen || !mod.game.me.alive || mod.game.me.mounted || mod.game.me.inBattleground || mod.game.contract.active)
return;
useNostrum();
if (mod.settings.use_savage && (mod.game.me.inDungeon || (mod.settings.civil_unrest && mod.game.me.inCivilUnrest)))
useSavage();
}
// Main
let interval = null;
function start() {
stop();
interval = mod.setInterval(useItems, mod.settings.interval);
}
function stop() {
if (interval) {
mod.clearInterval(interval);
interval = null;
}
}
function isRunning() {
return !!interval;
}
mod.game.on('leave_loading_screen', () => {
if (!item_cooldowns[mod.game.me.gameId])
item_cooldowns[mod.game.me.gameId] = new Map();
});
mod.game.on('enter_game', () => {
if (!item_cooldowns[mod.game.me.gameId])
item_cooldowns[mod.game.me.gameId] = new Map();
start();
});
mod.game.on('leave_game', () => {
stop();
nostrum_items.clear();
});
mod.game.me.on('resurrect', () => {
// Reset interval to wait a bit until on-resurrection abnormalities (e.g. phoenix buffs) are applied to make sure we don't overwrite them
start();
});
// User interaction & settings UI
mod.command.add('ten', {
$default() {
if (ui) {
ui.show();
if (ui.ui.window) {
ui.ui.window.webContents.on("did-finish-load", () => {
ui.ui.window.webContents.executeJavaScript(
"!function(){var e=document.getElementById('close-btn');e.style.cursor='default',e.onclick=function(){window.parent.close()}}();"
);
});
}
} else {
mod.settings.enabled = !mod.settings.enabled;
mod.command.message(mod.settings.enabled ? 'enabled' : 'disabled');
}
},
on() {
mod.settings.enabled = true;
mod.command.message('enabled');
},
off() {
mod.settings.enabled = false;
mod.command.message('disabled');
}
});
let ui = null;
if (global.TeraProxy.GUIMode) {
ui = new SettingsUI(mod, require('./settings_structure'), mod.settings, {
width: 750,
height: 280,
resizable: false
});
ui.on('update', settings => {
mod.settings = settings;
if (isRunning()) {
stop();
start();
}
});
this.destructor = () => {
if (ui) {
ui.close();
ui = null;
}
};
}
};
module.exports = { ClientMod, NetworkMod };