forked from hsdn/tera-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.js
225 lines (194 loc) · 5.06 KB
/
lib.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
const HIGHLIGHT_ITEM = 110684; // Tier 21 Superior Twin Swords
const HIGHLIGHT_ITEM_BLUE = 89542; // Annihilation Disc (x1 effect)
const HIGHLIGHT_ITEM_PURPLE = 89543; // Annihilation Disc (x2 effect)
const HIGHLIGHT_ITEM_RED = 206960; // Zenobia's Breeze Crate
const MARKER_ITEM = 88704; // Velika Banquet Coin
function SpawnItem(item, angle, distance, delay, duration, handlers, event, entity) {
angle = Math.PI * angle / 180;
SpawnObject("item", false, item,
0, 0,
angle, distance,
delay, duration,
null,
handlers, event, entity
);
}
function SpawnMarker(target, angle, distance, delay, duration, highlight, label, handlers, event, entity) {
if (!label) {
label = ["SAFE SPOT", "SAFE"];
}
angle = Math.PI * angle / 180;
SpawnObject("build_object", target, 1,
0, 0,
angle, distance,
delay, duration,
label,
handlers, event, entity
);
if (highlight) {
let item = HIGHLIGHT_ITEM;
switch (highlight) {
case "blue": item = HIGHLIGHT_ITEM_BLUE; break;
case "purple": item = HIGHLIGHT_ITEM_PURPLE; break;
case "red": item = HIGHLIGHT_ITEM_RED; break;
}
SpawnObject("item", target, item,
0, 0,
angle, distance,
delay, duration,
null,
handlers, event, entity
);
}
}
function SpawnPoint(item, angle, distance, delay, duration, handlers, event, entity) {
angle = Math.PI * angle / 180;
SpawnObject("collection", false, item,
0, 0,
angle, distance,
delay, duration,
null,
handlers, event, entity
);
}
function SpawnVector(item, offsetAngle, offsetDistance, angle, length, delay, duration, handlers, event, entity) {
angle = angle * Math.PI / 180;
for (let radius = 50; radius <= length; radius += 50) {
SpawnObject("collection", false, item,
offsetAngle, offsetDistance,
angle, radius,
delay, duration,
null,
handlers, event, entity
);
}
}
function SpawnCircle(target, item, offsetAngle, offsetDistance, interval, radius, delay, duration, handlers, event, entity) {
for (let angle = -Math.PI; angle <= Math.PI; angle += Math.PI * interval / 180) {
SpawnObject("collection", target, item,
offsetAngle, offsetDistance,
angle, radius,
delay, duration,
null,
handlers, event, entity
);
}
}
function SpawnSemicircle(degree1, degree2, item, offsetAngle, offsetDistance, interval, radius, delay, duration, handlers, event, entity) {
let db, dg;
if (degree1 <= 180 && degree2 <= 180) {
db = -degree1 / 180;
dg = degree2 / 180;
} else if (degree1 > 180 && degree2 > 180) {
db = -degree1 / 180;
dg = degree2 / 180;
} else {
db = -degree1 / 180;
dg = degree2 / 180;
for (let angle = -Math.PI * db; angle <= Math.PI; angle += Math.PI * interval / 180) {
SpawnObject("collection", false, item,
offsetAngle, offsetDistance,
angle, radius,
delay, duration,
null,
handlers, event, entity
);
}
for (let angle = Math.PI ; angle <= Math.PI * dg; angle += Math.PI * interval / 180) {
SpawnObject("collection", false, item,
offsetAngle, offsetDistance,
angle, radius,
delay, duration,
null,
handlers, event, entity
);
}
return;
}
for (let angle = -Math.PI * db; angle <= Math.PI * dg; angle += Math.PI * interval / 180) {
SpawnObject("collection", false, item,
offsetAngle, offsetDistance,
angle, radius,
delay, duration,
null,
handlers, event, entity
);
}
}
function SpawnObject(type, target, item, offsetAngle, offsetDistance, angle, distance, delay, duration, label, handlers, event, entity) {
let shield_loc;
// use local delay
setTimeout(() => {
if (target && entity.dest !== undefined) {
shield_loc = entity['dest'].clone();
} else if (entity.loc !== undefined) {
shield_loc = entity['loc'].clone();
} else {
return;
}
shield_loc.w = entity['loc'].w;
applyDistance(shield_loc, offsetDistance, 360 - offsetAngle);
switch (type) {
// S_SPAWN_COLLECTION
case "collection":
handlers['spawn']({
id: item,
sub_delay: duration,
distance: distance,
offset: angle
}, {
loc: shield_loc
});
break;
// S_SPAWN_DROPITEM
case "item":
handlers['spawn']({
sub_type: "item",
id: item,
sub_delay: duration,
distance: distance,
offset: angle
}, {
loc: shield_loc
});
break;
// S_SPAWN_BUILD_OBJECT
case "build_object":
handlers['spawn']({
sub_type: "build_object",
id: item,
sub_delay: duration,
distance: distance,
offset: angle,
ownerName: label[0],
message: label[1]
}, {
loc: shield_loc
});
break;
}
}, delay);
}
function applyDistance(loc, offsetDistance, offsetAngle) {
let r = loc.w; //(loc.w / 0x8000) * Math.PI;
let rads = (offsetAngle * Math.PI / 180);
let finalrad = r - rads;
loc.x += Math.cos(finalrad) * offsetDistance;
loc.y += Math.sin(finalrad) * offsetDistance;
return loc;
}
module.exports = {
HIGHLIGHT_ITEM,
HIGHLIGHT_ITEM_BLUE,
HIGHLIGHT_ITEM_PURPLE,
HIGHLIGHT_ITEM_RED,
MARKER_ITEM,
SpawnItem,
SpawnMarker,
SpawnPoint,
SpawnVector,
SpawnCircle,
SpawnSemicircle,
SpawnObject,
applyDistance
};