This repository has been archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
156 lines (145 loc) · 4.44 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
const Vec3 = require('tera-vec3');
const request = require('request');
const bosses = require('./bosses.json');
module.exports = function WorldBossHelper(mod) {
if (mod.isClassic) {
mod.log('Classic Server is not supported. Module disabled.');
return;
}
let bossName;
let currentChannel;
let mobIds = [];
mod.command.add('wbh', {
$default() {
mod.command.message('World Boss Helper module. Usage:');
mod.command.message(' /8 wbh - Turn module on/off');
mod.command.message(' /8 wbh alert - Turn popup alerts on/off');
mod.command.message(' /8 wbh msg - Turn system messages on/off');
mod.command.message(' /8 wbh mark - Turn boss markers on/off');
mod.command.message(' /8 wbh clear - Attempt to clear markers');
mod.command.message(' /8 wbh ui - Open ingame WB Timers UI');
},
alert() {
mod.settings.alerted = !mod.settings.alerted;
mod.command.message(mod.settings.alerted ? 'System popup notice: enabled.' : 'System popup notice: disabled.');
},
msg() {
mod.settings.messager = !mod.settings.messager;
mod.command.message(mod.settings.messager ? 'System message: enabled.' : 'System message: disabled.');
},
mark() {
mod.settings.marker = !mod.settings.marker;
mod.command.message(mod.settings.marker ? 'Markers: enabled.' : 'Markers: disabled.');
},
clear() {
mod.command.message('Markers cleared.');
for (let id of mobIds) {
despawnItem(id);
}
},
ui() {
mod.send('S_OPEN_AWESOMIUM_WEB_URL', 1, {
url: 'tera.zone/worldboss/ingame.php?serverId=' + mod.game.me.serverId
});
},
$none() {
mod.settings.enabled = !mod.settings.enabled;
mod.command.message(mod.settings.enabled ? 'Module: enabled.' : 'Module: disabled.');
if (!mod.settings.enabled) {
for (let id of mobIds) {
despawnItem(id);
}
}
}
})
mod.game.me.on('change_zone', () => {
mobIds = [];
})
mod.hook('S_CURRENT_CHANNEL', 2, event => {
currentChannel = event.channel;
})
mod.hook('S_SPAWN_NPC', 11, event => {
if (!mod.settings.enabled) return;
let boss;
if (boss = bosses.filter(b => b.huntingZoneId.includes(event.huntingZoneId) && b.templateId === event.templateId)[0]) {
bossName = boss.name;
if (mod.settings.marker) {
spawnItem(event.loc, event.gameId);
mobIds.push(event.gameId);
}
if (mod.settings.alerted) {
notice('Found boss: ' + bossName + '!');
}
if (mod.settings.messager) {
mod.command.message('Found boss: ' + bossName + '!');
}
}
})
mod.hook('S_DESPAWN_NPC', 3, {order: -100}, event => {
if (!mod.settings.enabled) return;
if (mobIds.includes(event.gameId)) {
if (mod.settings.alerted && bossName) {
if (event.type == 5) {
request.post('https://tera.zone/worldboss/upload.php', {
form: {
region: mod.region,
serverId: mod.game.me.serverId,
boss: bossName,
channel: currentChannel,
}
}, function(err, httpResponse, body) {
if (err) {
console.error(err);
} else {
console.log('[world-boss] ' + body);
}
});
if (mod.settings.alerted) {
notice(bossName + ' is dead!');
}
if (mod.settings.messager) {
mod.command.message('' + bossName + ' is dead!');
}
} else if (event.type == 1) {
if (mod.settings.alerted) {
notice(bossName + ' is out of range...');
}
if (mod.settings.messager) {
mod.command.message('' + bossName + ' is out of range...');
}
}
}
bossName = null;
despawnItem(event.gameId);
mobIds.splice(mobIds.indexOf(event.gameId), 1);
}
})
function spawnItem(loc, gameId) {
mod.send('S_SPAWN_DROPITEM', 6, {
gameId: gameId*100n,
loc: loc,
item: mod.settings.itemId,
amount: 1,
expiry: 600000,
owners: [{
id: 0
}]
});
}
function despawnItem(gameId) {
mod.send('S_DESPAWN_DROPITEM', 4, {
gameId: gameId*100n,
});
}
function notice(msg) {
mod.send('S_DUNGEON_EVENT_MESSAGE', 2, {
type: 42,
chat: 0,
channel: 0,
message: msg
});
}
this.destructor = function() {
mod.command.remove('wbh');
}
}