-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
196 lines (179 loc) · 4.84 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
186
187
188
189
190
191
192
193
194
195
196
"use strict";
/**
* IMPORTS
*/
const {
initCtx,
makeHook,
atlasIds,
queueSave,
newLocation,
locationSort,
customLocations,
getCustomLocations
} = require("./utils");
const journalOptions = require("./commands");
const webui = require("./ui");
/**
* UNBREAK SOME REGIONS
*/
const specialCases = {
"7015": 71001,
"7013": 75001,
"7021": 80001,
"7022": 79001,
"7023": 77001
};
/**
* HELPERS
*/
function onLogin(evt) {
const ctx = this.__self;
ctx.gameId = evt.gameId;
ctx.tpTo = ctx.currentContract = null;
ctx.slotAtlas = -1;
}
function getContract(evt) {
this.__self.currentContract = evt.type;
}
function nullContract() {
this.__self.currentContract = null;
}
function nullDestination() {
this.__self.tpTo = null;
}
/**
* TO INFINITY AND BEYOND
*/
function teleportTo(evt) {
const ctx = this.__self;
return ctx.tpTo ? (
Object.assign(evt.loc, ctx.tpTo), true
) : null;
}
function onVilList(evt) {
const ctx = this.__self;
if (!ctx.enabled || !ctx.tpTo) return;
const zone = ctx.tpTo.zone;
const special = specialCases[zone];
if (special) {
ctx.send("C_TELEPORT_TO_VILLAGE", 1, {
id: special
});
return false;
}
for (let i = 0, arr = evt.locations, len = arr.length; i < len; ++i) {
const loc = arr[i];
if (loc.zone === zone) {
ctx.send("C_TELEPORT_TO_VILLAGE", 1, {
id: loc.id
});
return false;
}
}
ctx.cmd.message(`<font color="#ff0000">Zone ${zone} cannot be teleported to.</font>`);
ctx.tpTo = null;
}
function onLoadTpList(evt) {
const ctx = this.__self;
ctx.tpTo = null;
if (!ctx.enabled) return;
for (let i = 0, arr = evt.locations, len = arr.length; i < len; ++i) {
const loc = arr[i];
if (!loc) continue;
if (loc.name === "*\t*") {
if (ctx.newCustom) {
customLocations[customLocations.length] = newLocation(loc, ctx);
queueSave(customLocations.sort(locationSort));
ctx.cmd.message("Journal saved.");
ctx.newCustom = "";
}
ctx.send("C_DELETE_TELEPORT_TO_POS_LIST", 1, {
index: i
});
evt.locations.splice(i, 1);
--i;
--len;
continue;
}
loc.name += " *";
}
ctx.serverLocations = evt.locations;
evt.locations = [...evt.locations, ...getCustomLocations()];
return true;
}
function onPcBangDatalist(evt) {
const ctx = this.__self;
ctx.slotAtlas = -1;
for (let set of evt.sets) {
for (let inv of set.inventory) {
if (atlasIds.has(inv.id)) {
return void(ctx.slotAtlas = {
set: set.id,
slot: inv.slot,
type: inv.type,
id: inv.id
})
}
}
}
}
function onActionEnd(evt) {
const ctx = this.__self;
if (evt.gameId === ctx.gameId && evt.type !== 37) {
ctx.tpTo = ctx.currentContract = null;
}
}
function onTpToPos(evt) {
const ctx = this.__self;
if (!ctx.enabled) return;
const idx = evt.index;
const len = ctx.serverLocations.length;
if (idx >= len) {
if (ctx.slotAtlas !== -1) {
ctx.tpTo = customLocations[idx - len];
ctx.send("C_USE_PREMIUM_SLOT", 1,
ctx.slotAtlas
);
} else {
ctx.cmd.message(`<font color="#ff0000">You must have Elite status to teleport to a custom location.</font>`);
}
return false;
}
}
function onDelTpPos(evt) {
const ctx = this.__self;
if (!ctx.enabled) return;
const idx = evt.index;
const len = ctx.serverLocations.length;
if (idx >= len) {
queueSave(customLocations.splice(idx - len, 1));
ctx.send("S_LOAD_TELEPORT_TO_POS_LIST", 1, {
locations: [...ctx.serverLocations, ...getCustomLocations()]
});
return false;
}
}
/**
* INIT
*/
function InfiniteJournalism(_) {
const ctx = initCtx(_);
const hook = makeHook(_, ctx);
webui(_, ctx);
_.command.add("journal", journalOptions, ctx);
const r = "raw";
hook("S_LOGIN", 14, onLogin);
hook("S_SPAWN_ME", 3, teleportTo);
hook("S_LOAD_TOPO", 3, teleportTo);
hook("S_ACTION_END", 5, onActionEnd);
hook("C_TELEPORT_TO_POS", 1, onTpToPos);
hook("C_TELEPORT_TO_POS", r, nullDestination);
hook("S_CANCEL_CONTRACT", r, nullContract);
hook("S_REQUEST_CONTRACT", 1, getContract);
hook("S_VILLAGE_LIST_TO_TELEPORT", 1, onVilList);
hook("S_PREMIUM_SLOT_DATALIST", 2, onPcBangDatalist);
hook("S_LOAD_TELEPORT_TO_POS_LIST", 1, onLoadTpList);
hook("C_DELETE_TELEPORT_TO_POS_LIST", 1, onDelTpPos);
}
module.exports = InfiniteJournalism;