-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathplugin.ts
More file actions
149 lines (124 loc) · 4.38 KB
/
plugin.ts
File metadata and controls
149 lines (124 loc) · 4.38 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
import * as ap from 'archipelago.js';
import {WorldData, ItemInfo} from './item-data.model';
import {readJsonFromFile} from './utils';
import {applyPatches} from "./patches/index";
import type * as _ from 'nax-module-cache/src/headers/nax/moduleCache.d.ts'
declare global {
namespace sc {
var randoData: WorldData;
var multiWorldHud: sc.MultiWorldHudBox;
}
}
export default class MwRandomizer {
baseDirectory: string;
randoData!: WorldData;
itemdb: any;
constructor(mod: {baseDirectory: string}) {
this.baseDirectory = mod.baseDirectory;
}
getColoredStatus(status: string) {
switch (status.toLowerCase()) {
case ap.CONNECTION_STATUS.CONNECTED.toLowerCase():
return `\\c[2]${status}\\c[0]`;
case ap.CONNECTION_STATUS.DISCONNECTED.toLowerCase():
return `\\c[1]${status}\\c[0]`;
case ap.CONNECTION_STATUS.WAITING_FOR_AUTH.toLowerCase():
case ap.CONNECTION_STATUS.CONNECTING.toLowerCase():
return `\\c[3]${status}\\c[0]`;
}
}
getItemInfo(item: ap.NetworkItem): ItemInfo {
let gameName: string = sc.multiworld.client.data.players[item.player].game;
let gameInfo: ap.GamePackage = sc.multiworld.client.data.package.get(gameName)!;
if (gameInfo.item_id_to_name[item.item] == undefined) {
gameInfo = sc.multiworld.gamepackage;
gameName = "CrossCode";
}
if (gameInfo.item_id_to_name[item.item] == undefined) {
return {icon: "ap-item-default", label: "Unknown", player: "Archipelago", level: 0, isScalable: false};
}
const playerId = sc.multiworld.client.players.get(item.player);
const playerName = playerId?.alias ?? playerId?.name;
let label = gameInfo.item_id_to_name[item.item];
let player = playerName ? playerName : "Archipelago";
if (gameName == "CrossCode") {
const comboId: number = item.item;
let level = 0;
let icon = "item-default";
let isScalable = false;
if (comboId >= sc.multiworld.baseNormalItemId) {
const [itemId, _] = sc.multiworld.getItemDataFromComboId(item.item);
const dbEntry = sc.inventory.getItem(itemId);
if (dbEntry) {
icon = dbEntry.icon + sc.inventory.getRaritySuffix(dbEntry.rarity);
isScalable = dbEntry.isScalable || false;
if (dbEntry.type == sc.ITEMS_TYPES.EQUIP) {
level = dbEntry.level;
}
}
}
return {icon, label, player, level, isScalable};
}
let cls = "unknown";
if (item.flags & ap.ITEM_FLAGS.PROGRESSION) {
cls = "prog";
} else if (item.flags & ap.ITEM_FLAGS.NEVER_EXCLUDE) {
cls = "useful";
} else if (item.flags & ap.ITEM_FLAGS.TRAP) {
cls = "trap";
} else if (item.flags == 0) {
cls = "filler";
}
let icon = `ap-item-${cls}`;
return {icon, label, player, level: 0, isScalable: false};
}
getGuiString(item: {icon: string; label: string}): string {
return `\\i[${item.icon}]${item.label}`;
}
async prestart() {
window.moduleCache.registerModPrefix("mw-rando", this.baseDirectory.substring(7));
ig.lib = this.baseDirectory.substring(7);
ig._loadScript("mw-rando.multiworld-model");
let randoData: WorldData = await readJsonFromFile(this.baseDirectory + "data/out/data.json");
this.randoData = randoData;
sc.randoData = randoData;
let itemdb = await readJsonFromFile("assets/data/item-database.json");
this.itemdb = itemdb;
// For those times JS decides to override `this`
// Used several times in the injection code
let plugin = this;
applyPatches(this);
sc.PartyModel.inject({
addPartyMember(name: string, ...args) {
this.parent(name, ...args);
sc.party.getPartyMemberModel(name).setSpLevel(sc.model.player.spLevel);
},
});
let mwIcons = new ig.Font(plugin.baseDirectory.substring(7) + "assets/media/font/icons-multiworld.png", 16, ig.MultiFont.ICON_START);
let index = sc.fontsystem.font.iconSets.length;
sc.fontsystem.font.pushIconSet(mwIcons);
sc.fontsystem.font.setMapping({
"mw-item": [index, 0],
"ap-logo": [index, 2],
"ap-item-unknown": [index, 2],
"ap-item-trap": [index, 3],
"ap-item-filler": [index, 4],
"ap-item-useful": [index, 5],
"ap-item-prog": [index, 6],
});
sc.CrossCode.inject({
init() {
this.parent();
sc.multiWorldHud = new sc.MultiWorldHudBox();
sc.gui.rightHudPanel.addHudBox(sc.multiWorldHud);
},
gotoTitle(...args) {
if (sc.multiworld.client.status == ap.CONNECTION_STATUS.CONNECTED) {
sc.multiworld.client.disconnect();
// sc.multiworld.updateConnectionStatus();
}
this.parent(...args);
},
});
}
}