-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
185 lines (163 loc) · 4.5 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
module.exports = function PartnerGifter(mod) {
const command = mod.command;
const Vec3 = require('tera-vec3');
const config = require('./config.json');
const gifts = require('./gifts');
let enabled = true,
notice = false,
minEnergy = 80;
let configError1 = false,
configError2 = false;
let myGameId = null,
playerLocation = {},
invenItems = [],
partnerDbid = null,
partnerId = null,
findId = false,
onCd = false,
isGifting = false,
giftList = JSON.parse(JSON.stringify(gifts));
for (let i = 0; i < giftList.length; i++) {
giftList[i].amount = 0;
giftList[i].dbid = 0;
}
command.add('partnergifter', {
$none() {
enabled = !enabled;
command.message(`Partner Gifter Module is now: ${enabled ? "enabled" : "disabled"}.`);
},
$default() {
command.message("Invalid command! See README for the list of valid commands.")
},
notice() {
notice = !notice;
command.message(`Notice is now: ${notice ? "enabled" : "disabled"}.`);
},
find() {
findId = true;
command.message("Manually give gift to your partner to find out its Item ID.");
}
});
mod.hook('S_LOGIN', 13, (event) => {
loadConfig();
myGameId = event.gameId;
invenItems = [];
partnerDbid = null;
partnerId = null;
findId = false;
onCd = false;
isGifting = false;
});
mod.hook('S_LOAD_CLIENT_USER_SETTING', 'raw', () => {
if (!enabled) return;
process.nextTick(() => {
if (configError1) {
command.message('<font color="#FF0000">Error</font>: Detected corrupted/outdated config file - Please update');
}
else if (configError2) {
command.message('<font color="#FF0000">Error</font>: Unable to load the config file - Using default values for now');
}
});
});
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;
playerLocation.loc = new Vec3(x, y, z);
playerLocation.w = event.w;
});
mod.hook('S_INVEN', 18, (event) => {
if (!enabled) return;
invenItems = event.first ? event.items : invenItems.concat(event.items);
for (let i = 0; i < giftList.length; i++) {
if (invenItems.filter(function(a) { return a.id === giftList[i].id; }).length > 0) {
let invenIndex = invenItems.findIndex(a => a.id === giftList[i].id);
giftList[i].amount = invenItems[invenIndex].amount;
giftList[i].dbid = invenItems[invenIndex].dbid;
}
else {
giftList[i].amount = 0;
giftList[i].dbid = 0;
}
}
});
mod.hook('S_REQUEST_SPAWN_SERVANT', 1, (event) => {
if (myGameId === event.ownerId && event.fellowship >= 1){
partnerDbid = event.dbid;
partnerId = event.id;
if (!enabled) return;
processGifting(event.energy);
}
});
mod.hook('S_UPDATE_SERVANT_INFO', 1, (event) => {
if (!enabled) return;
if(partnerDbid === event.dbid && partnerId === event.id && event.fellowship >= 1){
processGifting(event.energy);
}
});
mod.hook('C_USE_ITEM', 3, (event) => {
if (findId){
command.message("Item ID: " + event.id);
findId = false;
}
});
function useServantFeedItem(gift) {
mod.toServer('C_USE_ITEM', 3, {
gameId: myGameId,
id: gift.id,
dbid: gift.dbid,
target: 0,
amount: 1,
dest: 0,
loc: playerLocation.loc,
w: playerLocation.w,
unk1: 0,
unk2: 0,
unk3: 0,
unk4: true
});
}
function giftPartner() {
for (let i = 0; i < giftList.length; i++) {
if (giftList[i].amount > 0) {
giftList[i].amount--;
onCd = true;
setTimeout(()=>{ onCd = false; }, giftList[i].cd * 1000);
isGifting = true;
setTimeout(()=>{ isGifting = false; }, 250);
if (notice) {
command.message('Gifted ' + giftList[i].name + '! You have <font color="#00FFFF">' + giftList[i].amount + '</font> remaining.');
}
useServantFeedItem(giftList[i]);
return;
}
}
command.message('<font color="#FDD017">Warning</font>: No gift found in your inventory!');
}
function processGifting(energy) {
let partnerEnergyPercent = Math.round((Number(energy) / 300) * 1000) / 10;
if (partnerEnergyPercent < minEnergy && !onCd) {
giftPartner();
}
}
function loadConfig() {
if (config) {
({enabled, notice, minEnergy} = config);
if (typeof enabled === 'undefined') {
enabled = true;
configError1 = true;
}
if (typeof notice === 'undefined') {
notice = false;
configError1 = true;
}
if (typeof minEnergy === 'undefined') {
minEnergy = 80;
configError1 = true;
}
}
else {
configError2 = true;
}
}
}