Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
173 lines (159 loc) · 4.53 KB
/
Copy pathindex.js
File metadata and controls
173 lines (159 loc) · 4.53 KB
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
"use strict";
/**
* IMPORTS
*/
const {
getCtx,
initCtx,
makeHook,
atlasIds,
queueSave,
newLocation,
locationSort,
customLocations,
getCustomLocations
} = require("./utils");
const journalOptions = require("./commands");
const command = require("command");
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 = getCtx(this);
ctx.gameId = evt.gameId;
ctx.tpTo = ctx.currentContract = undefined;
ctx.slotAtlas = -1;
}
function getContract(evt) { getCtx(this).currentContract = evt.type; }
function nullContract() { getCtx(this).currentContract = undefined; }
function nullDestination() { getCtx(this).tpTo = undefined; }
/**
* TO INFINITY AND BEYOND
*/
function teleportTo(evt) {
const ctx = getCtx(this);
return ctx.tpTo ? (
Object.assign(evt.loc, ctx.tpTo), true
) : undefined;
}
function onVilList(evt) {
const ctx = getCtx(this);
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 = undefined;
}
function onLoadTpList(evt) {
const ctx = getCtx(this);
ctx.tpTo = undefined;
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 = getCtx(this);
ctx.slotAtlas = -1;
for (const { item, slot } of evt.inventory) {
if (atlasIds.has(item)) {
return void(ctx.slotAtlas = slot);
}
}
}
function onActionEnd(evt) {
const ctx = getCtx(this);
if (evt.gameId.equals(ctx.gameId) && evt.type !== 37) {
ctx.tpTo = ctx.currentContract = undefined;
}
}
function onTpToPos(evt) {
const ctx = getCtx(this);
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_PCBANGINVENTORY_USE_SLOT", 1, { slot: 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 = getCtx(this);
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({ send: _.send.bind(_), cmd: command(_) });
const hook = makeHook(_, ctx);
webui(_, ctx);
ctx.cmd.add("journal", journalOptions, ctx);
const r = "raw";
hook( "S_LOGIN", 10, onLogin);
hook( "S_SPAWN_ME", 2, teleportTo);
hook( "S_LOAD_TOPO", 3, teleportTo);
hook( "S_ACTION_END", 5, onActionEnd);
hook( "C_TELEPORT_TO_POS", 1, onTpToPos);
hook( "C_PLAYER_LOCATION", r, nullDestination);
hook( "S_CANCEL_CONTRACT", r, nullContract);
hook( "S_REQUEST_CONTRACT", 1, getContract);
hook( "S_VILLAGE_LIST_TO_TELEPORT", 1, onVilList);
hook( "S_PCBANGINVENTORY_DATALIST", 1, onPcBangDatalist);
hook( "S_LOAD_TELEPORT_TO_POS_LIST", 1, onLoadTpList);
hook("C_DELETE_TELEPORT_TO_POS_LIST", 1, onDelTpPos);
}
module.exports = InfiniteJournalism;