-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.js
More file actions
379 lines (328 loc) · 9.77 KB
/
Copy pathcommon.js
File metadata and controls
379 lines (328 loc) · 9.77 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
var metadata = null;
var metadata_ammunitions = null;
var metadata_equips = null;
var metadata_skills = null;
var army_details_library = {};
var labels = {
hidden: { // These hide the trooper until they are revealed and deployed
equips: [24], // HoloMask
skills: [29, 35, 238, 249, 33], // Camouflage, Combat Jump, Hidden Deployment, Impersonation, Parachutist
},
nfb: { // These cannot be used at the same time
equips: [183, 24, 104], // Albedo, Holomask, Holoprojector
hacks: ["Cybermask", "White Noise"],
skills: [249, 28], // Impersonation, Mimetism
},
private: { // The existance of these are hidden
skills: [26, 207, 119], // Chain of Command, Counterintelligence, Lieutenant
},
};
$.getJSON('https://api.corvusbelli.com/army/infinity/en/metadata', function(e) {
console.log(e);
metadata = e;
metadata_ammunitions = {};
for (var i in e.ammunitions) metadata_ammunitions[e.ammunitions[i].id] = e.ammunitions[i];
metadata_equips = {};
for (var i in e.equips) metadata_equips[e.equips[i].id] = e.equips[i];
metadata_skills = {};
for (var i in e.skills) metadata_skills[e.skills[i].id] = e.skills[i];
});
function interpret_code (code)
{
var reader = {
code: atob(code),
read_pos: 0,
read_int: function () {
var ret = this.code.charCodeAt(this.read_pos++);
if (ret >= 128) return (ret - 128)*256 + this.code.charCodeAt(this.read_pos++);
return ret;
},
read_string: function () {
var str_len = this.read_int();
var ret = this.code.substr(this.read_pos, str_len);
this.read_pos += str_len;
return ret;
}
};
var ret = {
faction_id: reader.read_int(),
faction_url: reader.read_string(),
list_name: reader.read_string(),
point_limit: reader.read_int(),
groups: [],
}
var i = reader.read_int();
while (i-- > 0)
{
var group = {
position: reader.read_int(),
troopers: [],
};
var j = reader.read_int();
while (j-- > 0)
{
var trooper = {
position: reader.read_int(),
unit_id: reader.read_int(),
profile_group_id: reader.read_int(),
option_id: reader.read_int(),
spec_ops: reader.read_int(),
};
if (trooper.spec_ops != 0) return "SPEC OPS IS NOT SUPPORTED";
group.troopers.push(trooper);
}
ret.groups.push(group);
}
if (reader.read_pos != reader.code.length) return "SOMETHING WENT WRONG READING THE CODE - INVALID CODE?";
return ret;
}
function load_army_code (code, on_success)
{
var ret = interpret_code(code);
if (typeof ret !== "object")
{
alert(ret);
return;
}
if (typeof army_details_library[ret.faction_id] == 'undefined')
{
$.getJSON("https://api.corvusbelli.com/army/units/en/" + ret.faction_id, function(e) {
var extras = {};
for (var i in e.filters.extras) extras[e.filters.extras[i].id] = e.filters.extras[i];
var chars = {};
for (var i in e.filters.chars) chars[e.filters.chars[i].id] = e.filters.chars[i];
var peripheral = {};
for (var i in e.filters.peripheral) peripheral[e.filters.peripheral[i].id] = e.filters.peripheral[i];
var type = {};
for (var i in e.filters.type) type[e.filters.type[i].id] = e.filters.type[i];
var weapons = {};
for (var i in e.filters.weapons) weapons[e.filters.weapons[i].id] = e.filters.weapons[i];
e.library = {
extras: extras,
chars: chars,
peripheral: peripheral,
type: type,
weapons: weapons,
};
army_details_library[ret.faction_id] = e;
on_success(army_details_library[ret.faction_id], ret);
});
}
else
{
on_success(army_details_library[ret.faction_id], ret);
}
}
function fetch_list_details (code, on_success)
{
load_army_code(code, function (army, list)
{
var ret = [];
for (var x in list.groups)
{
var ret_group = [];
for (var y in list.groups[x].troopers)
{
ret_group.push( resolve_trooper_details(army, list.groups[x].troopers[y]) );
}
ret.push(ret_group);
}
on_success (army, list, ret);
});
}
function resolve_trooper_details (army, trooper)
{
var unit_profile = null;
var profile_group = null;
var option_profile = null;
for (var i in army.units)
{
if (army.units[i].id == trooper.unit_id)
{
unit_profile = army.units[i];
for (var j in unit_profile.profileGroups)
{
if (unit_profile.profileGroups[j].id == trooper.profile_group_id)
{
profile_group = unit_profile.profileGroups[j];
for (var k in profile_group.options)
{
if (profile_group.options[k].id == trooper.option_id)
{
option_profile = profile_group.options[k];
break;
}
}
break;
}
}
break;
}
}
// -- Check for if the ids were correctly resolved into profiles
if (unit_profile == null)
{
alert("THERE WAS A PROBLEM TRYING TO RESOLVE THE UNIT PROFILE FOR A TROOPER");
console.log([trooper, army]);
return;
}
if (profile_group == null)
{
alert("THERE WAS A PROBLEM TRYING TO RESOLVE THE PROFILE GROUP FOR A TROOPER");
console.log([trooper, army, unit_profile]);
return;
}
if (option_profile == null)
{
alert("THERE WAS A PROBLEM TRYING TO RESOLVE THE OPTION PROFILE FOR A TROOPER");
console.log([trooper, army, unit_profile, option_profile]);
return;
}
// -- Check for compatability against what this app is currently capable of
if (profile_group.profiles.length != 1)
{
alert("CANNOT CURRENTLY PROCESS UNITS WITH MULTIPLE PROFILES - different profiles may have different skills, equips, attributes, weapons");
}
if (profile_group.profiles[0].includes.length != 0 || option_profile.includes.length != 0)
{
alert("CANNOT CURRENTLY PROCESS UNITS WITH INCLUDED PROFILES");
}
// TODO:
// Secondary profile attributes
// Secondary profile skills/equipment/weapons
// Included profiles
var attributes = {};
// -- Process the main profile
var p = profile_group.profiles[0];
// Attributes
var attributes = {
name: p.name,
move: p.move,
cc: p.cc,
bs: p.bs,
ph: p.ph,
wip: p.wip,
arm: p.arm,
bts: p.bts,
w: p.w,
str: p.str, // true or false to indicate what 'w' is
s: p.s,
type: army.library.type[p.type].name,
};
var abilities = [];
var weapons = [];
weapons = weapons.concat(profile_group.profiles[0].weapons);
weapons = weapons.concat(option_profile.weapons);
for (var i in weapons)
{
var w = weapons[i];
if (w.hasOwnProperty("extra") && w.extra != null && w.extra.length > 1)
alert("UNEXPECTED SKILL WITH MORE THAN 1 EXTRA");
abilities.push({
id: w.id,
name: army.library.weapons[w.id].name,
type: "WEAPON",
extra: ( (w.hasOwnProperty("extra") && w.extra != null && w.extra.length == 1) ? army.library.extras[w.extra[0]] : null ),
is_private: false,
});
}
var skills = [];
skills = skills.concat(profile_group.profiles[0].skills);
skills = skills.concat(option_profile.skills);
for (var i in skills)
{
var s = skills[i];
if (s.hasOwnProperty("extra") && s.extra != null && s.extra.length > 1)
alert("UNEXPECTED SKILL WITH MORE THAN 1 EXTRA");
abilities.push({
id: s.id,
name: metadata_skills[s.id].name,
type: "SKILL",
extra: ( (s.hasOwnProperty("extra") && s.extra != null && s.extra.length == 1) ? army.library.extras[s.extra[0]] : null ),
is_private: labels.private.skills.includes(s.id),
});
}
var equips = [];
equips = equips.concat(profile_group.profiles[0].equip);
equips = equips.concat(option_profile.equip);
for (var i in equips)
{
var e = equips[i];
if (e.hasOwnProperty("extra") && e.extra != null && e.extra.length > 1)
alert("UNEXPECTED SKILL WITH MORE THAN 1 EXTRA");
abilities.push({
id: e.id,
name: metadata_equips[e.id].name,
type: "EQUIPMENT",
extra: ( (e.hasOwnProperty("extra") && e.extra != null && e.extra.length == 1) ? army.library.extras[e.extra[0]] : null ),
is_private: false,
});
}
return {
name: option_profile.name,
attributes: attributes,
abilities: abilities,
raw: {unit_profile:unit_profile, profile_group:profile_group, option_profile:option_profile},
get_all_skills: function (include_private = false)
{
var ret = [];
for (var i in this.abilities)
{
if (this.abilities[i].is_private && include_private == false) continue;
if (this.abilities[i].type != "SKILL") continue;
ret.push(this.abilities[i]);
}
return ret;
},
get_all_equipment: function (include_private = false)
{
var ret = [];
for (var i in this.abilities)
{
if (this.abilities[i].is_private && include_private == false) continue;
if (this.abilities[i].type != "EQUIPMENT") continue;
ret.push(this.abilities[i]);
}
return ret;
},
get_all_weapons: function (include_private = false)
{
var ret = [];
for (var i in this.abilities)
{
if (this.abilities[i].is_private && include_private == false) continue;
if (this.abilities[i].type != "WEAPON") continue;
ret.push(this.abilities[i]);
}
return ret;
},
has_hidden_ability: function()
{
for (var i in this.abilities)
{
var a = this.abilities[i];
if (a.type == "SKILL" && labels.hidden.skills.includes(a.id))
return true;
if (a.type == "EQUIPMENT" && labels.hidden.equips.includes(a.id))
return true;
}
return false;
},
get_weapon_profiles: function (include_private = false)
{
var ret = [];
for (var i in metadata.weapons)
{
var w = metadata.weapons[i];
for (var j in this.abilities)
{
var a = this.abilities[j];
if (a.is_private && include_private == false) continue;
if (w.type != a.type || w.id != a.id) continue;
ret.push(w);
}
}
return ret;
},
};
}