forked from CatAnnaDev/dg-teleport
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
86 lines (75 loc) · 2.8 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
module.exports = function DGTeleport(mod) {
const cmd = mod.command || mod.require.command;
const path = require('path');
const dungeons = jsonRequire('./dungeon-list.json');
mod.dispatch.addDefinition('C_REQUEST_EVENT_MATCHING_TELEPORT', 0, path.join(__dirname, 'C_REQUEST_EVENT_MATCHING_TELEPORT.0.def'));
cmd.add(["dg", "go"], (value) => {
if (value && value.length > 0) value = value.toLowerCase();
if (value) {
const dungeon = search(value);
if (!dungeon) {
cmd.message(`Cannot find dungeon [${value}]`);
return;
}
teleport(dungeon);
} else {
tpList();
}
});
function jsonRequire(data) {
delete require.cache[require.resolve(data)];
return require(data);
}
const gui = {
parse(array, title, d = '') {
for (let i = 0; i < array.length; i++) {
if (d.length >= 16000) {
d += `Gui data limit exceeded, some values may be missing.`;
break;
}
if (array[i].command) d += `<a href="admincommand:/@${array[i].command}">${array[i].text}</a>`;
else if (!array[i].command) d += `${array[i].text}`;
else continue;
}
mod.toClient('S_ANNOUNCE_UPDATE_NOTIFICATION', 1, {
id: 0,
title: title,
body: d,
});
},
};
function tpList() {
if (Object.keys(dungeons).length > 0) {
let list = [];
dungeons.forEach((x) => {
list.push({
text: `<font color="${x.color}" size="+20">* ${x.name} Ilevel: ${x.ilvl} Coins: ${x.coins} </font><br>`,
command: `dg ${x.dg[0]}`,
});
});
gui.parse(list, `<font color="#E0B0FF">Dungeon Teleport List</font>`);
list = [];
}
}
function search(value) {
return dungeons.find((e) => e.dg.map((x) => x.toLowerCase()).includes(value) || (value.length > 3 && e.name.toLowerCase().includes(value)));
}
function teleport(dungeon) {
let success = false;
mod.send('C_REQUEST_EVENT_MATCHING_TELEPORT', 0, {
quest: dungeon.quest,
instance: dungeon.instance,
});
const zoneLoaded = mod.hook('S_LOAD_TOPO', 'raw', (e) => {
success = true;
mod.unhook(zoneLoaded);
cmd.message(`Successfully teleported to ${dungeon.name}.`);
})
mod.setTimeout(() => {
if (!success) {
mod.unhook(zoneLoaded);
cmd.message(`You cannot teleport to ${dungeon.name}. Check your iLvl.`);
}
}, 1000);
}
};