-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathCommonStatic.java
More file actions
654 lines (541 loc) · 15.2 KB
/
CommonStatic.java
File metadata and controls
654 lines (541 loc) · 15.2 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
package common;
import common.io.assets.Admin.StaticPermitted;
import common.io.json.JsonClass;
import common.io.json.JsonClass.NoTag;
import common.io.json.JsonField;
import common.pack.Context;
import common.pack.Identifier;
import common.pack.UserProfile;
import common.system.VImg;
import common.system.fake.FakeImage;
import common.util.Data;
import common.util.anim.ImgCut;
import common.util.anim.MaModel;
import common.util.pack.EffAnim.EffAnimStore;
import common.util.pack.NyCastle;
import common.util.pack.bgeffect.BackgroundEffect;
import common.util.stage.Music;
import common.util.unit.UnitLevel;
import java.io.File;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Character.isDigit;
public class CommonStatic {
public interface BattleConst {
float ratio = 768f / 2400f;// r = p/u
}
public static class BCAuxAssets {
// Res resources
public VImg[] slot = new VImg[3];
public VImg[][] ico = new VImg[2][];
public VImg[][] num = new VImg[9][11];
public VImg[][] battle = new VImg[3][];
public VImg[][] icon = new VImg[5][];
public VImg[] timer = new VImg[11];
public VImg emptyEdi = null;
public Map<Integer, VImg> gatyaitem = new HashMap<>();
public VImg XP;
public VImg[][] moneySign = new VImg[4][4]; //Money on, off/Cost on, off
public VImg[] spiritSummon = new VImg[4];
/**
* Use this if trait.icon is null
*/
public VImg dummyTrait;
// Background resources
public final List<ImgCut> iclist = new ArrayList<>();
// Available data for orb, will be used for GUI
// Map<Type, Map<Trait, Grades>>
public final Map<Integer, Map<Integer, List<Integer>>> ORB = new TreeMap<>();
public final Map<Integer, Integer> DATA = new HashMap<>();
// 0 = big size, 1 = small size
public FakeImage[][] TYPES = new FakeImage[2][];
public FakeImage[][] TRAITS = new FakeImage[2][];;
public FakeImage[][] GRADES = new FakeImage[2][];;
// NyCastle
public final VImg[][] main = new VImg[3][NyCastle.TOT];
public final NyCastle[] atks = new NyCastle[NyCastle.TOT];
// EffAnim
public final EffAnimStore effas = new EffAnimStore();
public final int[][] values = new int[Data.C_TOT][6];
public int[][] filter;
public final VImg[] rarity = new VImg[6];
public final VImg[] maxcat = new VImg[12];
// Form cuts
public ImgCut unicut, udicut;
// RandStage
public final int[][] randRep = new int[5][];
// def unit level
public UnitLevel defLv;
// bg effect
public final Map<Integer, BackgroundEffect> bgEffects = new HashMap<>();
}
@JsonClass(noTag = NoTag.LOAD)
public static class Config {
@JsonField(generic = { String.class, String.class })
public HashMap<String, String> localLangMap = new HashMap<>();
@JsonField(generic = { Integer.class, String.class })
public HashMap<Integer, String> localMusicMap = new HashMap<>();
// ImgCore
public int deadOpa = 10, fullOpa = 90;
public int[] ints = new int[] { 1, 1, 1, 2 };
public boolean ref = true, battle = false, icon = false;
public boolean twoRow = true;
/**
* Use this variable to unlock plus level for aku outbreak
*/
public boolean plus = false;
/**
* Use this variable to adjust level limit for aku outbreak
*/
public int levelLimit = 0;
// Lang
public Lang.Locale lang = Lang.Locale.EN;
/**
* Restoration target backup file, null means none
*/
public String backupFile;
/**
* Used for partial restoration
*/
public String backupPath;
/**
* Maximum number of backups, 0 means infinite
*/
public int maxBackup = 5;
/**
* Preferred level for units
*/
public int prefLevel = 50;
/**
* Decide whehter draw bg effect or not
*/
public boolean drawBGEffect = true;
/**
* Enable 6f button delay on spawn
*/
public boolean buttonDelay = true;
/**
* Color of background in viewer
*/
public int viewerColor = -1;
/**
* Make BCU show ex stage continuation pop-up if true
*/
public boolean exContinuation = false;
/**
* Make EX stage pop-up shown considering real chance
*/
public boolean realEx = false;
/**
* Make stage name image displayed in battle
*/
public boolean stageName = true;
/**
* Make battle shaken
*/
public boolean shake = true;
/**
* Replace old music when updated
*/
public boolean updateOldMusic = true;
/**
* Perform realistic BC levelings
*/
public boolean realLevel = false;
/**
* 60 fps mode if this is true for animation
*/
public boolean performanceModeAnimation = false;
/**
* 60 fps mode if this is true for battle
*/
public boolean performanceModeBattle = false;
}
public interface EditLink {
void review();
}
public interface FakeKey {
boolean pressed(int i, int j);
void remove(int i, int j);
}
public interface Itf {
/**
* exit
*/
void save(boolean save, boolean exit);
long getMusicLength(Music f);
@Deprecated
File route(String path);
void setSE(int mus);
void setSE(Identifier<Music> mus);
void setBGM(Identifier<Music> mus);
}
public static class Lang {
public enum Locale {
EN("en"),
ZH("zh"),
KR("kr"),
JP("jp"),
RU("ru"),
DE("de"),
FR("fr"),
ES("es"),
IT("it"),
TH("th");
public final String code;
Locale(String localeCode) {
code = localeCode;
}
@Override
public String toString() {
return code;
}
}
/**
* List of priorities that each language will display
*/
@StaticPermitted
public static final Locale[][] pref = {
{ Locale.EN, Locale.FR, Locale.IT, Locale.ES, Locale.DE, Locale.RU, Locale.JP, Locale.ZH, Locale.KR },
{ Locale.ZH, Locale.JP, Locale.EN, Locale.KR },
{ Locale.KR, Locale.JP, Locale.EN, Locale.ZH},
{ Locale.JP, Locale.EN, Locale.ZH, Locale.KR },
{ Locale.RU, Locale.EN, Locale.JP, Locale.ZH, Locale.KR },
{ Locale.DE, Locale.EN, Locale.JP, Locale.ZH, Locale.KR },
{ Locale.FR, Locale.EN, Locale.JP, Locale.ZH, Locale.KR },
{ Locale.ES, Locale.EN, Locale.JP, Locale.ZH, Locale.KR },
{ Locale.IT, Locale.EN, Locale.JP, Locale.ZH, Locale.KR },
{ Locale.TH, Locale.EN, Locale.JP, Locale.ZH, Locale.KR }
};
/**
* List of languages that are supported by Ponos
*/
@StaticPermitted
public static final CommonStatic.Lang.Locale[] supportedLanguage = {
CommonStatic.Lang.Locale.EN,
CommonStatic.Lang.Locale.ZH,
CommonStatic.Lang.Locale.JP,
CommonStatic.Lang.Locale.KR,
CommonStatic.Lang.Locale.DE,
CommonStatic.Lang.Locale.FR,
CommonStatic.Lang.Locale.ES,
CommonStatic.Lang.Locale.IT,
CommonStatic.Lang.Locale.TH
};
}
@StaticPermitted(StaticPermitted.Type.ENV)
public static Itf def;
@StaticPermitted(StaticPermitted.Type.ENV)
public static Context ctx;
@StaticPermitted(StaticPermitted.Type.FINAL)
public static final BigInteger max = new BigInteger(String.valueOf(Integer.MAX_VALUE));
@StaticPermitted(StaticPermitted.Type.FINAL)
public static final BigDecimal maxdbl = new BigDecimal(String.valueOf(Double.MAX_VALUE));
@StaticPermitted(StaticPermitted.Type.FINAL)
public static final BigInteger min = new BigInteger(String.valueOf(Integer.MIN_VALUE));
@StaticPermitted(StaticPermitted.Type.FINAL)
public static final BigDecimal mindbl = new BigDecimal(String.valueOf(Double.MIN_VALUE));
public static BCAuxAssets getBCAssets() {
return UserProfile.getStatic("BCAuxAssets", BCAuxAssets::new);
}
public static Config getConfig() {
return UserProfile.getStatic("config", Config::new);
}
public static boolean isInteger(String str) {
str = str.trim();
if(str.isEmpty())
return false;
for (int i = 0; i < str.length(); i++) {
if (!Character.isDigit(str.charAt(i))) {
if(str.charAt(i) != '-' || i != 0)
return false;
}
}
return true;
}
public static boolean isDouble(String str) {
int dots = 0;
for (int i = 0; i < str.length(); i++) {
if (!Character.isDigit(str.charAt(i))) {
if((i == 0 && str.charAt(i) != '-') || str.charAt(i) != '.' || dots > 0)
return false;
else
dots++;
}
}
return true;
}
public static int parseIntN(String str) {
int ans;
try {
ans = parseIntsN(str)[0];
} catch (Exception e) {
ans = -1;
}
return ans;
}
public static String verifyFileName(String str) {
return str.replaceAll("[\\\\/:*<>?\"|]|\\.+$", "_");
}
public static double parseDoubleN(String str) {
double ans;
try {
ans = parseDoublesN(str)[0];
} catch (Exception e) {
ans = -1.0;
}
return ans;
}
public static float parseFloatN(String str) {
float ans;
try {
ans = parseFloatsN(str)[0];
} catch (Exception e) {
ans = -1f;
}
return ans;
}
public static double[] parseDoublesN(String str) {
ArrayList<String> lstr = new ArrayList<>();
Matcher matcher = Pattern.compile("-?(([.|,]\\d+)|\\d+([.|,]\\d*)?)").matcher(str);
while (matcher.find())
lstr.add(matcher.group());
double[] result = new double[lstr.size()];
for (int i = 0; i < lstr.size(); i++)
result[i] = safeParseDouble(lstr.get(i));
return result;
}
public static float[] parseFloatsN(String str) {
ArrayList<String> lstr = new ArrayList<>();
Matcher matcher = Pattern.compile("-?(([.|,]\\d+)|\\d+([.|,]\\d*)?)").matcher(str);
while (matcher.find())
lstr.add(matcher.group());
float[] result = new float[lstr.size()];
for (int i = 0; i < lstr.size(); i++)
result[i] = safeParseFloat(lstr.get(i));
return result;
}
public static int[] parseIntsN(String str) {
ArrayList<String> lstr = new ArrayList<>();
int t = -1;
for (int i = 0; i < str.length(); i++)
if (t == -1) {
if (isDigit(str.charAt(i)) || str.charAt(i) == '-')
t = i;
} else if (!isDigit(str.charAt(i))) {
lstr.add(str.substring(t, i));
t = -1;
}
if (t != -1)
lstr.add(str.substring(t));
int ind = 0;
while (ind < lstr.size()) {
if (isDigit(lstr.get(ind).charAt(0)) || lstr.get(ind).length() > 1)
ind++;
else
lstr.remove(ind);
}
int[] ans = new int[lstr.size()];
for (int i = 0; i < lstr.size(); i++)
ans[i] = safeParseInt(lstr.get(i));
return ans;
}
public static int safeParseInt(String v) {
if(isInteger(v)) {
BigInteger big = new BigInteger(v);
if(big.compareTo(max) > 0) {
return Integer.MAX_VALUE;
} else if(big.compareTo(min) < 0) {
return Integer.MIN_VALUE;
} else {
return Integer.parseInt(v);
}
} else {
throw new IllegalStateException("Value "+v+" isn't a number");
}
}
public static double safeParseDouble(String v) {
if(isDouble(v)) {
BigDecimal big = new BigDecimal(v);
if(big.compareTo(maxdbl) > 0) {
return Double.MAX_VALUE;
} else if(big.compareTo(mindbl) < 0) {
return Double.MIN_VALUE;
} else {
return Double.parseDouble(v);
}
} else {
throw new IllegalStateException("Value "+v+" isn't a number");
}
}
public static float safeParseFloat(String v) {
if(isDouble(v)) {
BigDecimal big = new BigDecimal(v);
if(big.compareTo(maxdbl) > 0) {
return Float.MAX_VALUE;
} else if(big.compareTo(mindbl) < 0) {
return Float.MIN_VALUE;
} else {
return Float.parseFloat(v);
}
} else {
throw new IllegalStateException("Value "+v+" isn't a number");
}
}
public static String[] getPackContentID(String input) {
StringBuilder packID = new StringBuilder();
StringBuilder entityID = new StringBuilder();
boolean packEnd = false;
for (int i = 0; i < input.length(); i++) {
if (!packEnd) {
if (Character.toString(input.charAt(i)).matches("[0-9a-z]"))
packID.append(input.charAt(i));
else {
packEnd = true;
}
} else {
if (Character.isDigit(input.charAt(i)))
entityID.append(input.charAt(i));
}
}
return new String[] { packID.toString(), entityID.toString() };
}
public static String[] getPackEntityID(String input) {
String[] result = new String[2];
StringBuilder packID = new StringBuilder();
StringBuilder entityID = new StringBuilder();
boolean packEnd = false;
boolean findDigit = false;
for(int i = 0; i < input.length(); i++) {
if(!packEnd) {
if(Character.toString(input.charAt(i)).matches("[0-9a-z]"))
packID.append(input.charAt(i));
else {
packEnd = true;
findDigit = true;
}
} else {
if(findDigit) {
if(Character.isDigit(input.charAt(i))) {
entityID.append(input.charAt(i));
findDigit = false;
}
} else {
if(Character.isDigit(input.charAt(i))) {
entityID.append(input.charAt(i));
} else if(input.charAt(i) == 'r') {
entityID.append(input.charAt(i));
break;
} else {
break;
}
}
}
}
result[0] = packID.toString();
result[1] = entityID.toString();
return result;
}
public static long parseLongN(String str) {
long ans;
try {
ans = parseLongsN(str)[0];
} catch (Exception e) {
ans = -1;
}
return ans;
}
public static long[] parseLongsN(String str) {
ArrayList<String> lstr = new ArrayList<>();
int t = -1;
for (int i = 0; i < str.length(); i++)
if (t == -1) {
if (isDigit(str.charAt(i)) || str.charAt(i) == '-' || str.charAt(i) == '+')
t = i;
} else if (!isDigit(str.charAt(i))) {
lstr.add(str.substring(t, i));
t = -1;
}
if (t != -1)
lstr.add(str.substring(t));
int ind = 0;
while (ind < lstr.size()) {
if (isDigit(lstr.get(ind).charAt(0)) || lstr.get(ind).length() > 1)
ind++;
else
lstr.remove(ind);
}
long[] ans = new long[lstr.size()];
for (int i = 0; i < lstr.size(); i++)
ans[i] = Long.parseLong(lstr.get(i));
return ans;
}
/**
* play sound effect
*/
public static void setSE(int ind) {
def.setSE(ind);
}
/**
* play sound effect with identifier
*/
public static void setSE(Identifier<Music> mus) {
def.setSE(mus);
}
/**
* play background music
* @param music Music
*/
public static void setBGM(Identifier<Music> music) {
def.setBGM(music);
}
public static String toArrayFormat(int... data) {
StringBuilder res = new StringBuilder("{");
for (int i = 0; i < data.length; i++) {
if (i == data.length - 1) {
res.append(data[i]).append("}");
} else {
res.append(data[i]).append(", ");
}
}
return res.toString();
}
/**
* Gets the minimum position value for a data enemy.
*/
public static float dataEnemyMinPos(MaModel model) {
int x = ((model.confs[0][2] - model.parts[0][6]) * model.parts[0][8]) / model.ints[0];
return 2.5f * x;
}
/**
* Gets the minimum position value for a custom enemy.
*/
public static float customEnemyMinPos(MaModel model) {
int x = ((model.confs[0][2] - model.parts[0][6]) * model.parts[0][8]) / model.ints[0];
return 2.5f * x;
}
/**
* Gets the minimum position value for a data cat unit.
*/
public static int dataFormMinPos(MaModel model) {
int x = ((model.confs[1][2] - model.parts[0][6]) * model.parts[0][8]) / model.ints[0];
return 5 * x;
}
/**
* Gets the minimum position value for a custom cat unit.
*/
public static int customFormMinPos(MaModel model) {
int x = (-model.parts[0][6] * model.parts[0][8]) / model.ints[0];
return 5 * x;
}
/**
* Gets the boss spawn point for a castle.
* Credits to Domimmo314 for formula
*/
public static float bossSpawnPoint(int y, int z) {
return (float) (Math.floor(3200f + (y * z / 10f) - z * 1180 / 100f + z * 127 / 10f) / 4f);
}
}