-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
224 lines (201 loc) · 7.38 KB
/
index.js
File metadata and controls
224 lines (201 loc) · 7.38 KB
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
class Servant {
constructor(info) {
this.ID = Number(info.id);
this.UniqueID = Number(info.dbid);
this.Name = info.name;
}
stringify() {
return {name: this.Name, id: this.ID.toString(), dbid: this.UniqueID.toString()};
}
}
class Player {
constructor() {
this.w;
this.loc;
}
}
const brooch = [19702, 19703, 19705, 19706, 51011, 51028, 51029, 51030, 98404, 98405, 98406, 88875, 88876, 88877, 88878, 88879, 88880, 88881, 88882]
module.exports = function AutoPet(mod) {
const Vec3 = require('tera-vec3');
mod.game.initialize("inventory");
let gameId,
UniqueID = null,
charId,
petId = null,
getbondSkill = false
let inCombat = false;
let petSummoned = false;
let newServant = null;
let mainServant = null;
let player = new Player();
let petGameId;
// Commands
mod.command.add('pet', (sub, subc, value) => {
switch(sub) {
case 'save':
if (newServant) {
saveServant();
} else {
mod.command.message("You must summon a pet first before you can save it.")
}
break;
case 'feed':
let n = Number(subc);
if (isNaN(n) || n >= 100 || n < 0) {
mod.command.message("Pet Stamina % must be set between 1 and 99.")
} else {
mod.settings.feedWhenBelow = n;
mod.command.message(`Auto feed is now set to <font color="#5da8ce">${n}%</font>`)
}
break;
case 'on':
mod.settings.characters[charId].enabled = 1
mod.command.message('Module <font color="#00FF00">Enabled</font> for <font color="#00BFFF">' + mod.settings.characters[charId].name + '</font>')
break;
case 'off':
mod.settings.characters[charId].enabled = 0
mod.command.message('Module <font color="#FF0000">Disabled</font> for <font color="#00BFFF">' + mod.settings.characters[charId].name + '</font>')
break;
case 'bond':
getbondSkill = true
mod.command.message('Press your pet skill now to save it in the config' )
break;
case 'delay':
mod.settings.characters[charId].delay = value
mod.command.message('Bracing Force will be delayed by <font color="#DB3DCE">' + value + 'ms</font> after using brooch.')
break;
default:
mod.settings.enabled = !mod.settings.enabled;
mod.command.message(`Auto Pet is now ${mod.settings.enabled ? '<font color="#5dce6a">Enabled</font>' : '<font color="#dc4141">Disabled</font>'}.`)
}
})
mod.hook('S_LOGIN', 14, event => {
gameId = event.gameId;
charId = `${event.playerId}_${event.serverId}`;
if (mod.settings.characters[charId] == undefined) {
mod.settings.characters[charId] = {
"name": event.name,
"enabled": 1,
"bondSkill": 0,
"delay": 1
}
}
})
mod.hook('C_USE_ITEM', 3, event => {
if(mod.settings.characters[charId].enabled == 1&& brooch.includes(event.id) && petId !== null) {
setTimeout(function(){
mod.send('C_START_SERVANT_ACTIVE_SKILL', 1, {
gameId: petId,
skill: mod.settings.characters[charId].bondSkill
})
}, mod.settings.characters[charId].delay)
}
})
mod.hook('S_REQUEST_SPAWN_SERVANT', 4, event => {
if(event.ownerId === gameId) petId = event.gameId
})
mod.hook('S_REQUEST_DESPAWN_SERVANT', 1, event => {
if(event.gameId === petId) petId = null
})
mod.hook('C_START_SERVANT_ACTIVE_SKILL', 1, event => {
if(getbondSkill) {
getbondSkill = false
mod.settings.characters[charId].bondSkill = event.skill
mod.command.message('Bracing Force Skill ID <font color="#F1D448">' + event.skill + '</font> saved for <font color="#00BFFF">' + mod.settings.characters[charId].name + '</font>')
}
})
// Game states
mod.game.me.on('enter_combat', () => {
inCombat = true;
})
mod.game.me.on('leave_combat', () => {
inCombat = false;
})
// Hooks
mod.hook('C_PLAYER_LOCATION', 5, (event) => {
let x = (event.loc.x + event.dest.x) / 2;
let y = (event.loc.y + event.dest.y) / 2;
let z = (event.loc.z + event.dest.z) / 2;
player.loc = new Vec3(x, y, z);
player.w = event.w;
})
mod.hook('S_REQUEST_SPAWN_SERVANT', 4, (event) => {
if (event.ownerId == mod.game.me.gameId) {
newServant = new Servant(event);
petSummoned = true;
petGameId = event.gameId;
if (mainServant == null || newServant.ID != mainServant.ID) {
mod.command.message(`Use 'pet save' to save <font color="#30e785">"${event.name}"</font> as your default pet`);
}
}
})
mod.hook('S_REQUEST_DESPAWN_SERVANT', 1, (event) => {
if (event.gameId == petGameId) {
petSummoned = false;
newServant = null;
}
})
mod.hook('S_UPDATE_SERVANT_INFO', 1, (event) => {
if (event.dbid == mainServant.UniqueID) {
const energy = (event.energy / 300) * 100;
if (energy <= mod.settings.feedWhenBelow && !inCombat && petSummoned && mod.settings.enabled) {
feedPet();
}
}
})
mod.hook('S_VISIT_NEW_SECTION', 1, (event) => {
const key = `${mod.game.me.serverId}_${mod.game.me.playerId}`;
const playerPet = mod.settings.servantsList[key];
if (playerPet != undefined) {
mainServant = new Servant(playerPet);
}
if (mainServant && !petSummoned && mod.settings.enabled) {
SummonPet();
}
})
// Functions
function SummonPet() {
mod.send('C_REQUEST_SPAWN_SERVANT', 1, {
servantId : mainServant.ID,
uniqueId : mainServant.UniqueID,
unk : 0
})
}
function saveServant() {
const newKey = `${mod.game.me.serverId}_${mod.game.me.playerId}`;
mod.settings.servantsList[newKey] = newServant.stringify();
mod.command.message(`Saved <font color="#30e785">"${newServant.Name}"</font> as your default pet."`);
mainServant = newServant;
}
function feedPet() {
const foods = mod.settings.petFood;
let foodFound = false;
foods.forEach(food => {
let Food = mod.game.inventory.findInBagOrPockets(food.id)
if (Food) {
foodFound = true;
givePetFood(Food);
return;
}
})
if (!foodFound) {
mod.command.message("You don't have any pet food in inventory!")
}
}
function givePetFood(food) {
mod.send('C_USE_ITEM', 3, {
gameId: mod.game.me.gameId,
id: food.id,
dbid: food.dbid,
target: 0,
amount: 1,
dest: 0,
loc: player.loc,
w: player.w,
unk1: 0,
unk2: 0,
unk3: 0,
unk4: true
})
}
}