forked from Andu2/FEH-Mass-Simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
9555 lines (8781 loc) · 338 KB
/
code.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
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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//Load resource from Google
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
google.charts.load('current', {packages: ['corechart']});
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//Load from browser cache
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
var option_menu = localStorage['option_menu'] || "options";
var option_colorFilter = localStorage['option_colorFilter'] || "all";
var option_rangeFilter = localStorage['option_rangeFilter'] || "all";
var option_typeFilter = localStorage['option_typeFilter'] || "all";
var option_viewFilter = localStorage['option_viewFilter'] || "all";
var option_sortOrder = localStorage['option_sortOrder'] || "worst";
var option_showOnlyMaxSkills = localStorage['option_showOnlyMaxSkills'] || "true";
var option_showOnlyDuelSkills = localStorage['option_showOnlyDuelSkills'] || "true";
var option_autoCalculate = localStorage['option_autoCalculate'] || "true";
var option_saveSettings = localStorage['option_saveSettings'] || "true";
var option_saveFilters = localStorage['option_saveFilters'] || "false";
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//Load JSON from database
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
var data = {};
// Load JSON text from server hosted file and return JSON parsed object
function loadJSON(filePath) {
// Load JSON file;
var json = loadTextFileAjaxSync(filePath, "application/json");
// Parse JSON
return JSON.parse(json);
}
// Load text with Ajax synchronously: takes path to file and optional MIME type
function loadTextFileAjaxSync(filePath, mimeType)
{
var xmlhttp = new XMLHttpRequest();
//Using synchronous request
xmlhttp.open("GET", filePath, false);
if (mimeType != null) {
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType(mimeType);
}
}
try {
xmlhttp.send();
}catch(error) {
console.log("Invalid target address.");
return null
}
if (xmlhttp.status == 200)
{
return xmlhttp.responseText;
}else {
console.log("Invalid xmlhttp.status.");
return null;
}
}
data.heroes = loadJSON('json/hero.json');
data.heroSkills = loadJSON('json/hero_skill.json');
data.skills = loadJSON('json/skill.json');
data.prereqs = loadJSON('json/skill_prereq.json');
data.refine = loadJSON('json/weapon_refine.json');
data.lists = loadJSON('json/custom_lists.json')
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//Initialize variables and data structure
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
var debug = false;
data.weaponTypes = ["sword","lance","axe","redtome","bluetome","greentome","dragon","redbow","bluebow","greenbow","graybow","bow","reddagger","bluedagger","greendagger","graydagger","dagger","staff"];
data.rangedWeapons = ["redtome","bluetome","greentome","redbow","bluebow","greenbow","graybow","bow","reddagger","bluedagger","greendagger","graydagger","dagger","staff"];
data.meleeWeapons = ["sword","lance","axe","dragon"];
data.physicalWeapons = ["sword","lance","axe","redbow","bluebow","greenbow","graybow","bow","reddagger","bluedagger","greendagger","graydagger","dagger"];
data.magicalWeapons = ["redtome","bluetome","greentome","dragon","staff"];
data.moveTypes = ["infantry","armored","flying","cavalry","mounted"];
data.colors = ["red","blue","green","gray"];
data.skillSlots = ["weapon","refine","assist","special","a","b","c","s"];
data.buffTypes = ["buffs","debuffs","spur"];
data.buffStats = ["hp","atk","spd","def","res"];
data.stats = ["hp","atk","spd","def","res"];
data.support = ["s","s-","a","a-","b","b-","c","c-"];
data.blessType = ["atk","spd","def","res"];
//Growth shifts of 3 are what make some banes/boons +/- 4
//growth table from https://feheroes.wiki/Stat_Growth
data.growths = [
[6, 8, 9, 11, 13, 14, 16, 18, 19, 21, 23, 24, 26],
[7, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 26, 28],
[7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33],
[8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 31, 33, 35],
[8, 10, 13, 15, 17, 19, 22, 24, 26, 28, 30, 33, 35, 37]
];
//Remember: heroes, skills, prereqs, and heroskills arrays come from PHP-created script
//Sort hero array by name
data.heroes.sort(function(a,b){
//console.log(a.name + ", " + b.name + ": " + a.name>b.name);
return (a.name.toLowerCase() > b.name.toLowerCase())*2-1;
})
//Sort skills array by name
data.skills.sort(function(a,b){
//console.log(a.name + ", " + b.name + ": " + a.name>b.name);
return (a.name.toLowerCase() + a.slot > b.name.toLowerCase() + b.slot)*2-1;
})
data.heroPossibleSkills = [];
data.heroBaseSkills = [];
data.heroMaxSkills = [[],[],[],[],[]]; //2d array; 1st num rarity, 2nd num skillindex
data.skillsThatArePrereq = [];
//Prereq exceptions are:
//Sol, Ardent Sacrifice, Luna, Astra, Assault, Sacred Cowl,
//Armorslayer+, Killing Edge+, Raudrwolf+, Heavy Spear+, Killer Lance+, Blarwolf+, Rexcalibur+
//Wo Dao+, Bolganone+, Hammer+, Killer Axe+, Gronnwolf+, Assassin's Bow+, Killer Bow+
data.skillPrereqExceptions = [
125, 137, 162, 168, 170, 193,
6, 10, 38, 74, 76, 87,
14, 28, 50, 52, 64, 107, 111, 424
];
data.enemyPrompts = {
//Just for fun, special messages for some of my favorites ;)
"default":"Enemies to fight:",
"Effie":"Who to crush:",
"Karel":"Time to feast:",
"Nino":"Do my best:",
"Sharena":"My turn!:"
}
//Make list of all skill ids that are a strictly inferior prereq to exclude from dropdown boxes
for(var i = 0; i < data.prereqs.length;i++){
if(data.skillsThatArePrereq.indexOf(data.prereqs[i].required_id)==-1 && data.skillPrereqExceptions.indexOf(data.prereqs[i].required_id)==-1){
data.skillsThatArePrereq.push(data.prereqs[i].required_id);
}
}
//Find hero skills
for(var i = 0; i < data.heroes.length;i++){
data.heroPossibleSkills.push(getValidSkills({index:i}));
var baseSkills = getHeroSkills(i);
data.heroBaseSkills.push(baseSkills);
for(var j = 0; j < 5; j++){
data.heroMaxSkills[j].push(getMaxSkills(baseSkills,j));
}
}
function initOptions(){
//Initializes options from localStorage or from scratch
//Holder for options that aren't hero-specific
options = {};
options.saveSettings = true;
options.autoCalculate = true;
options.buffStartTurn = 1;
options.debuffStartTurn = 1;
//options.threatenRule = "Neither";
options.ployBehavior = "Orthogonal";
options.showOnlyMaxSkills = true;
options.hideUnaffectingSkills = true;
options.colorFilter = "all";
options.rangeFilter = "all";
options.typeFilter = "all";
options.viewFilter = "all";
options.sortOrder = "worst";
options.customEnemyList = 0;
options.customEnemySelected = -1;
options.roundInitiators = ["Challenger","Enemy"];
//Holder for side-specific options
options.chilled_challenger = false;
options.chilled_enemy = false;
options.panic_challenger = false;
options.panic_enemy = false;
options.rush_challenger = false;
options.rush_enemy = false;
options.flash_challenger = false;
options.flash_enemy = false;
options.pulse_challenger = false;
options.pulse_enemy = false;
options.movement_challenger = false;
options.movement_enemy = false;
options.harsh_command_challenger = false;
options.harsh_command_enemy = false;
options.candlelight_challenger = false;
options.candlelight_enemy = false;
options.defensive_challenger = false;
options.defensive_enemy = false;
options.close_def_challenger = false;
options.close_def_enemy = false;
options.distant_def_challenger = false;
options.distant_def_enemy = false;
options.threaten_challenger = false;
options.threaten_enemy = false;
options.galeforce_challenger = true;
options.galeforce_enemy = true;
options.sweep_challenger = true;
options.sweep_enemy = true;
options.odd_buff_challenger = true;
options.odd_buff_enemy = true;
//Holder for statistic values;
options.chartType = "enemies by color";
statistics = {};
statistics.challenger = {};
statistics.enemies = {};
statistics.challenger.res_hp_max = -1;
statistics.challenger.res_hp_min = -1;
statistics.challenger.res_hp_avg = -1;
statistics.enemies.res_hp_max = -1;
statistics.enemies.res_hp_min = -1;
statistics.enemies.res_hp_avg = -1;
statistics.enemies.list = [];
statistics.enemies.red = 0;
statistics.enemies.red_outcome = [0,0,0];
statistics.enemies.blue = 0;
statistics.enemies.blue_outcome = [0,0,0];
statistics.enemies.green = 0;
statistics.enemies.green_outcome = [0,0,0];
statistics.enemies.gray = 0;
statistics.enemies.gray_outcome = [0,0,0];
statistics.enemies.infantry = 0;
statistics.enemies.infantry_outcome = [0,0,0];
statistics.enemies.armored = 0;
statistics.enemies.armored_outcome = [0,0,0];
statistics.enemies.flying = 0;
statistics.enemies.flying_outcome = [0,0,0];
statistics.enemies.cavalry = 0;
statistics.enemies.cavalry_outcome = [0,0,0];
statistics.enemies.melee = 0;
statistics.enemies.melee_outcome = [0,0,0];
statistics.enemies.ranged = 0;
statistics.enemies.ranged_outcome = [0,0,0];
statistics.wins = { min: 0, average: 0, max: 0, count: 0};
statistics.losses = { min: 0, average: 0, max: 0, count: 0};
statistics.inconclusives_challenger = { min: 0, average: 0, max: 0, count: 0};
statistics.inconclusives_enemy = { min: 0, average: 0, max: 0, count: 0};
//Holder for challenger options and pre-calculated stats
challenger = {};
challenger.challenger = true;
challenger.index = -1;
challenger.merge = 0;
challenger.rarity = 5;
challenger.boon = "none";
challenger.bane = "none";
challenger.summoner = "none";
challenger.ally = "none";
challenger.bless_1 = "none";
challenger.bless_2 = "none";
challenger.bless_3 = "none";
//The following 6 arrays will be set from arrays generated in the heroes array so they don't have to be re-calculated
challenger.naturalSkills = []; //Skills the hero has without having to inherit
challenger.validWeaponSkills = [];
challenger.validRefineSkills = [];
challenger.validAssistSkills = [];
challenger.validSpecialSkills = [];
challenger.validASkills = [];
challenger.validBSkills = [];
challenger.validCSkills = [];
challenger.weapon = -1;
challenger.refine = -1;
challenger.assist = -1;
challenger.special = -1;
challenger.a = -1;
challenger.b = -1;
challenger.c = -1;
challenger.s = -1;
challenger.statOffset = {"hp":0,"atk":0,"spd":0,"def":0,"res":0};
challenger.hp = 0;
challenger.atk = 0;
challenger.spd = 0;
challenger.def = 0;
challenger.res = 0;
challenger.bst = 0;
challenger.spt = 0;
challenger.buffs = {"hp":0,"atk":0,"spd":0,"def":0,"res":0};
challenger.debuffs = {"hp":0,"atk":0,"spd":0,"def":0,"res":0};
challenger.spur = {"hp":0,"atk":0,"spd":0,"def":0,"res":0};
challenger.currenthp = 0;
challenger.damage = 0;
challenger.HpPercent = 4;
challenger.precharge = 0;
challenger.adjacent = 1;
challenger.adjacent2 = 1;
challenger.adjacent_foe = 1;
challenger.adjacent2_foe = 1;
challenger.movementbuff = "hone";
//Holder for enemy options and pre-calculated stats
enemies = {};
enemies.fl = {}; //Full list
enemies.fl.isFl = true;
enemies.fl.list = []; //May not actually use - might be too much redundant data
enemies.fl.include = {"melee":1,"ranged":1,"red":1,"blue":1,"green":1,"gray":1,"physical":1,"magical":1,"infantry":1,"cavalry":1,"flying":1,"armored":1,"staff":0,"nonstaff":1};
enemies.fl.merge = 0;
enemies.fl.rarity = 5;
enemies.fl.boon = "none";
enemies.fl.bane = "none";
enemies.fl.summoner = "none";
enemies.fl.ally = "none";
enemies.fl.bless_1 = "none";
enemies.fl.bless_2 = "none";
enemies.fl.bless_3 = "none";
enemies.fl.naturalSkills = [];
enemies.fl.validWeaponSkills = getValidSkills(enemies.fl,"weapon");
enemies.fl.validRefineSkills = getValidSkills(enemies.fl,"refine");
enemies.fl.validAssistSkills = getValidSkills(enemies.fl,"assist");
enemies.fl.validSpecialSkills = getValidSkills(enemies.fl,"special");
enemies.fl.validASkills = getValidSkills(enemies.fl,"a");
enemies.fl.validBSkills = getValidSkills(enemies.fl,"b");
enemies.fl.validCSkills = getValidSkills(enemies.fl,"c");
enemies.fl.validSSkills = getValidSkills(enemies.fl,"s");
enemies.fl.avgHp = 0;
enemies.fl.avgAtk = 0;
enemies.fl.avgSpd = 0;
enemies.fl.avgDef = 0;
enemies.fl.avgRes = 0;
enemies.fl.weapon = -1;
enemies.fl.refine = -1;
enemies.fl.assist = -1;
enemies.fl.special = -1;
enemies.fl.a = -1;
enemies.fl.b = -1;
enemies.fl.c = -1;
enemies.fl.s = -1;
enemies.fl.replaceWeapon = 0;
enemies.fl.replaceRefine = 0;
enemies.fl.replaceAssist = 0;
enemies.fl.replaceSpecial = 0;
enemies.fl.replaceA = 0;
enemies.fl.replaceB = 0;
enemies.fl.replaceC = 0;
enemies.fl.buffs = {"hp":0,"atk":0,"spd":0,"def":0,"res":0};
enemies.fl.debuffs = {"hp":0,"atk":0,"spd":0,"def":0,"res":0};
enemies.fl.spur = {"hp":0,"atk":0,"spd":0,"def":0,"res":0};
enemies.fl.damage = 0;
enemies.fl.precharge = 0;
enemies.fl.adjacent = 1;
enemies.fl.adjacent2 = 1;
enemies.fl.adjacent_foe = 1;
enemies.fl.adjacent2_foe = 1;
enemies.cl = {}; //Custom list
enemies.cl.list = [];
enemies.cl.avgHp = 0;
enemies.cl.avgAtk = 0;
enemies.cl.avgSpd = 0;
enemies.cl.avgDef = 0;
enemies.cl.avgRes = 0;
enemies.cl.hp = 0;
enemies.cl.atk = 0;
enemies.cl.spd = 0;
enemies.cl.def = 0;
enemies.cl.res = 0;
//Custom List Adjustments
enemies.cl.merges = 0;
enemies.cl.damages = 0;
enemies.cl.HpPercent = 4;
enemies.cl.status = "all";
enemies.cl.statusbuff = 4;
enemies.cl.movement = "all";
enemies.cl.movementbuff = "hone";
// //now set stored values
// //(setting and resetting just in case new options are defined)
// var storedOptions = JSON.parse(localStorage.getItem("options"));
// var storedChallenger = JSON.parse(localStorage.getItem("challenger"));
// var storedEnemies = JSON.parse(localStorage.getItem("enemies"));
// replaceRecursive(options,storedOptions);
// replaceRecursive(challenger,storedChallenger);
// replaceRecursive(enemies,storedEnemies);
if(options.customEnemySelected >= enemies.cl.list.length){
options.customEnemySelected = enemies.cl.list.length - 1;
}
}
initOptions();
var fightResults = []; //Needs to be global variable to get info for tooltip
var resultHTML = []; //Needs to be a global variable to flip sort order without
var showingTooltip = false;
var calcuwaiting = false;
var calcuwaitTime = 0;
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//Put DOM stuff in place
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function(){
//Show incompatibility message: code does not work fr IE<9
//(Analytics show that the % of people who use IE<9 on my site is EXTREMELY low, like 1 in 30,000)
if(![].forEach){
console.log("Unsupported JavaScript");
$("#update_text").html("Your browser does not appear to support some of the code this app uses (JavaScript ES5). The app probably won't work.");
}
//Load or Reset Settings
if (option_saveSettings == "false"){initSettings();}
//Populate hero select options
var heroHTML = "<option value=-1 class=\"hero_option\">Select Hero</option>";
for(var i = 0; i < data.heroes.length; i++){
heroHTML += "<option value=" + i + " class=\"hero_option\">" + data.heroes[i].name + "</option>";
}
//Initiate hero lists
var listHTML = "<option value=-1 class=\"hero_option\">New List</option>";
//Inject select2 UI with matcher for hero lists
$("#challenger_list, #cl_enemy_list").html(listHTML).select2({selectOnClose: true, dropdownAutoWidth : true, matcher: matchStartHeroesList});
//Inject select2 UI with matcher for data.heroes
$("#challenger_name, #cl_enemy_name").html(heroHTML).select2({selectOnClose: true, dropdownAutoWidth : true, matcher: matchStartHeroes});
//Inject select2 UI with matcher for data.skills
$("#challenger_weapon, #challenger_assist, #challenger_special, #challenger_a, #challenger_b, #challenger_c, #challenger_s").select2({selectOnClose: true, dropdownAutoWidth : true, matcher: matchStartSkills});
$("#enemies_weapon, #enemies_assist, #enemies_special, #enemies_a, #enemies_b, #enemies_c, #enemies_s").select2({selectOnClose: true, dropdownAutoWidth : true, matcher: matchStartSkills});
$("#cl_enemy_weapon, #cl_enemy_assist, #cl_enemy_special, #cl_enemy_a, #cl_enemy_b, #cl_enemy_c, #cl_enemy_s").select2({selectOnClose: true, dropdownAutoWidth : true, matcher: matchStartSkills});
$("#enemies_weapon, #enemies_assist, #enemies_special, #enemies_a, #enemies_b, #enemies_c, #enemies_s").select2({selectOnClose: true, dropdownAutoWidth : true, matcher: matchStartSkills});
//Inject select2 UI with matcher for data.refine
$("#challenger_refine, #enemies_refine, #cl_enemy_refine, #enemies_refine").select2({selectOnClose: true, dropdownAutoWidth : true, matcher: matchStartRefine});
//Inject select2 UI for Full List overwrite options
$("#enemies_weapon_overwrite, #enemies_assist_overwrite, #enemies_special_overwrite, #enemies_a_overwrite, #enemies_b_overwrite, #enemies_c_overwrite").select2({selectOnClose: true, dropdownAutoWidth : true, minimumResultsForSearch: -1});
//Load Custom Lists
listHTML = "<option value=0> Filtered Full List</option>";
listHTML += "<option value=1> Custom List</option>";
for(var i = 0; i < data.lists.length; i++){
listHTML += "<option value=" + (i + 2) + ">" + data.lists[i].name + "</option>";
}
$("#enemies_mode").html(listHTML).select2({dropdownAutoWidth : true, width: '145px'});
//Set Options UI
showOptions(option_menu);
$('input:radio[class=menu_button][value=' + option_menu + ']').prop('checked', true);
//Set filter UI
if (option_saveFilters == "true"){
options.colorFilter = option_colorFilter;
$('#color_results').val(option_colorFilter).trigger('change.select2');
options.rangeFilter = option_rangeFilter;
$('#range_results').val(option_rangeFilter).trigger('change.select2');
options.typeFilter = option_typeFilter;
$('#type_results').val(option_typeFilter).trigger('change.select2');
options.viewFilter = option_viewFilter;
$('#view_results').val(option_viewFilter).trigger('change.select2');
options.sortOrder = option_sortOrder;
$('#sort_results').val(option_sortOrder).trigger('change.select2');
}else{
resetFilter();
}
//Set chart UI
//TODO: cache this as well
$('#chart_type').val("enemies by color").trigger('change.select2');
//Set Settings UI
$('#saveSettings').prop('checked', (option_saveSettings == "true"));
options.showOnlyMaxSkills = (option_showOnlyMaxSkills == "true");
$('#rules_prereqs').prop('checked', (option_showOnlyMaxSkills == "true"));
options.hideUnaffectingSkills = (option_showOnlyDuelSkills == "true");
$('#rules_hideunaffecting').prop('checked', (option_showOnlyDuelSkills == "true"));
options.autoCalculate = (option_autoCalculate == "true");
$('#autoCalculate').prop('checked', (option_autoCalculate == "true"));
setSkillOptions(enemies.fl);
initEnemyList();
updateFullUI();
//Create listener on whole body and check data-var to see which var to replace
//TODO: make click listeners work similarly
$("input, select").on("change", function(e){
var dataVar = $(this).attr("data-var");
if(dataVar){
var varsThatChangeStats = [
".buffs.hp",".debuffs.hp",".rarity",".merge",".boon",".bane",".summoner",".ally",".bless_1",".bless_2",".bless_3",".weapon",".refine",".a",".s",".replaceWeapon",".replaceRefine",".replaceA"
];
var varsThatChangeSkills = [
".rarity",".replaceWeapon",".replaceRefine",".replaceAssist",".replaceSpecial",".replaceA",".replaceB",".replaceC","enemies.fl.weapon","enemies.fl.refine",
"enemies.fl.assist","enemies.fl.special","enemies.fl.a","enemies.fl.b","enemies.fl.c","enemies.fl.s"
];
var varsThatUpdateFl = [
".boon",".bane",".summoner",".ally",".bless_1",".bless_2",".bless_2",".precharge",".adjacent",".adjacent2",".adjacent_foe",".adjacent2_foe",".damage",".rarity",".merge"
]
var newVal = $(this).val();
var useCalcuwait = false;
var blockCalculate = false;
var hero;
if(beginsWith(dataVar,"challenger.")){
hero = challenger;
}
else if(beginsWith(dataVar,"enemies.fl")){
hero = enemies.fl;
}
else if(beginsWith(dataVar,"enemies.cl.list")){
if(options.customEnemySelected == -1){
addClEnemy();
}
hero = enemies.cl.list[options.customEnemySelected];
}
var inputType = $(this).attr("type");
if(inputType == "number"){
var min = $(this).attr("min");
var max = $(this).attr("max");
useCalcuwait = true;
if(typeof min != "undefined" && typeof max != "undefined"){
newVal = verifyNumberInput(this,min,max);
}
else{
newVal = parseInt(newVal);
}
}
else if(inputType == "checkbox"){
newVal = $(this).is(":checked");
}
//Change val to numeric if it looks numeric
//All numbers used by this program are ints
if($.isNumeric(newVal)){
newVal = parseInt(newVal);
}
changeDataVar(dataVar,newVal);
//Stuff specific to changing skill
if(endsWith(dataVar,".weapon") || endsWith(dataVar,".assist")|| endsWith(dataVar,".special") || endsWith(dataVar,".a") || endsWith(dataVar,".b") || endsWith(dataVar,".c") || endsWith(dataVar,".s")){
if(newVal != -1){
//***This does nothing?***
var dataToPass = data.skills[newVal].name;
if(endsWith(dataVar,".s")){
//Rename s skills to differentate from regular skills
dataToPass = "s_" + dataToPass;
}
//***This does nothing?***
}
}
//Stuff specific to changing weapon option
if(endsWith(dataVar,".weapon")){
//Update refine options
updateRefineUI(hero);
hero.refine = -1;
}
//Stuff specific to changing chart type
if(endsWith(dataVar,".chartType")){
drawChart();
blockCalculate = true;
}
//Stuff specific to changing hero
if(endsWith(dataVar,".index")){
if(newVal != -1){
//find hero's starting skills
initHero(hero);
if(hero.challenger){
}
else{
updateClList();
}
}
}
else if(endsWith(dataVar,".showOnlyMaxSkills") || endsWith(dataVar,".hideUnaffectingSkills")){
blockCalculate = true;
updateChallengerUI();
updateEnemyUI();
//Not hero so won't automatically update uis
}
else if(endsWith(dataVar,".viewFilter") || endsWith(dataVar,".sortOrder")){
blockCalculate = true;
}
else if(endsWith(dataVar,".autoCalculate")){
if(newVal == 0){
blockCalculate = true;
}
}
//Stuff specific to changing filter
if(endsWith(dataVar,".colorFilter")){
localStorage['option_colorFilter'] = newVal;
}
if(endsWith(dataVar,".rangeFilter")){
localStorage['option_rangeFilter'] = newVal;
}
if(endsWith(dataVar,".typeFilter")){
localStorage['option_typeFilter'] = newVal;
}
if(endsWith(dataVar,".viewFilter")){
localStorage['option_viewFilter'] = newVal;
}
if(endsWith(dataVar,".sortOrder")){
localStorage['option_sortOrder'] = newVal;
}
/*TODO: chartType cache
if(endsWith(dataVar,".chartType")){
localStorage['option_chartType'] = newVal;
}
*/
//Cache Settings
if(endsWith(dataVar,".showOnlyMaxSkills")){
localStorage['option_showOnlyMaxSkills'] = (options.showOnlyMaxSkills ? "true" : "false");
}
if(endsWith(dataVar,".hideUnaffectingSkills")){
localStorage['option_showOnlyDuelSkills'] = (options.hideUnaffectingSkills ? "true" : "false");
}
if(endsWith(dataVar,".autoCalculate")){
localStorage['option_autoCalculate'] = (options.autoCalculate ? "true" : "false");
}
if(endsWith(dataVar,".saveSettings")){
localStorage['option_saveSettings'] = (options.saveSettings ? "true" : "false");
}
if(endsWith(dataVar,".saveFilters")){
localStorage['option_saveFilters'] = (options.saveFilters ? "true" : "false");
}
for(var i = 0; i < varsThatUpdateFl.length; i++){
if(endsWith(dataVar,varsThatUpdateFl[i])){
updateFlEnemies();
break;
}
}
for(var i = 0; i < varsThatChangeSkills.length; i++){
if(endsWith(dataVar,varsThatChangeSkills[i])){
setSkills(hero);
break;
}
}
for(var i = 0; i < varsThatChangeStats.length; i++){
if(endsWith(dataVar,varsThatChangeStats[i])){
setStats(hero);
break;
}
}
//Update custom enemy when list changes
if (endsWith(dataVar, ".customEnemySelected")){
updateEnemyUI();
//Scroll to middle of list
$('#cl_enemylist_list').scrollTop((options.customEnemySelected - 6.5) * 25 - 10);
}
//Update health
if (endsWith(dataVar, ".currenthp") && hero){
updateHealth(newVal, hero);
}
//Update adjacent units values
if (endsWith(dataVar, ".adjacent") || endsWith(dataVar, ".adjacent2") || endsWith(dataVar, ".adjacent_foe") || endsWith(dataVar, ".adjacent2_foe")){
updateAdjacentValues(dataVar, hero);
}
//Update special charge
if (endsWith(dataVar, ".pulse_challenger") && challenger){
updateChallengerUI();
}
if (endsWith(dataVar, ".pulse_enemy")){
updateEnemyUI();
}
if(hero && hero.challenger){
updateChallengerUI();
}
else if(typeof hero != "undefined"){
updateEnemyUI();
}
if(!blockCalculate){
if(useCalcuwait){
calcuWait(300);
}
else{
calculate();
}
}
else{
outputResults()
}
}
//Don't check parent elements
e.stopPropagation();
});
$(".wideincludebutton, .thinincludebutton").click(function(){
var includeRule = this.id.substring(8);
if(enemies.fl.include[includeRule]){
enemies.fl.include[includeRule] = 0;
$(this).removeClass("included");
$(this).addClass("notincluded");
}
else{
enemies.fl.include[includeRule] = 1;
$(this).removeClass("notincluded");
$(this).addClass("included");
}
initEnemyList();
updateEnemyUI()
calculate();
});
$("#add_turn_challenger_reset").click(function(){
resetTurn("Challenger");
})
$("#add_turn_enemy_reset").click(function(){
resetTurn("Enemy");
})
$("#add_turn_challenger").click(function(){
addTurn("Challenger");
})
$("#add_turn_enemy").click(function(){
addTurn("Enemy");
})
//Copy Function Buttons
$(".button_copy").click(function(){
if(this.id == "copy_enemy"){
copyEnemy();
}else{
copyChallenger();
}
})
//Custom List Adjustment Buttons
$(".adj_apply_button").click(function(){
if (this.id == "apply_total_health_challenger"){
adjustHp(false, true);
}else if (this.id == "apply_movement_buff_challenger"){
adjustBuff(false, true);
}
if (enemies.cl.list.length > 0){
if (this.id == "apply_hero_merge"){
adjustCustomListMerge();
}else if (this.id == "apply_damage_taken"){
adjustHp(true);
}else if (this.id == "apply_total_health"){
adjustHp(false);
}else if (this.id == "apply_status_buff"){
adjustBuff(true);
}else if (this.id == "apply_movement_buff"){
adjustBuff(false);
}
calculate();
}
})
//Custom List Reset Buttons
$(".adj_reset_button").click(function(){
if (this.id == "reset_health_challenger"){
resetHp(true);
}else if (this.id == "reset_buff_challenger"){
resetBuffs(true);
}else if (this.id == "reset_health"){
resetHp(false);
}else if (this.id == "reset_buff"){
resetBuffs(false);
}
calculate();
})
//Import/Export Buttons
$(".button_importexport").click(function(){
var target = "challenger";
var type = "import";
if(this.id.indexOf("enemies") != -1){
target = "enemies";
}
if(this.id.indexOf("export") != -1){
type = "export";
}
showImportDialog(target,type);
})
$(".menu_button").click(function() {
showOptions($('input[name=menu]:checked').val());
});
$("#import_exit").click(function(){
hideImportDialog();
})
$("#enemies_mode").change(function(){
switchEnemySelect($(this).val());
})
$("#reset_challenger").click(function(){
resetHero(challenger);
})
$("#reset_enemies").click(function(){
resetHero(enemies.fl);
})
$("#reset_cl_enemy").click(function(){
if(enemies.cl.list[options.customEnemySelected]){
resetHero(enemies.cl.list[options.customEnemySelected]);
}
})
$(document).mousemove(function(e){
if(showingTooltip){
var tooltipHeight = $("#frame_tooltip").height();
if(e.pageY + (tooltipHeight/2) + 10 > $("body").height()){
$("#frame_tooltip").css({
"left": e.pageX + 20 + "px",
"top": e.pageY - tooltipHeight - 10 + "px"
});
}
else{
$("#frame_tooltip").css({
"left": e.pageX + 20 + "px",
"top": e.pageY - (tooltipHeight/2) + "px"
});
}
}
});
// $(window).unload(function(){
// //store options
// localStorage.setItem("options",JSON.stringify(options));
// localStorage.setItem("challenger",JSON.stringify(challenger));
// localStorage.setItem("enemies",JSON.stringify(enemies));
// })
//Show update notice if hasn't been show for this cookie
doUpdateNotice();
});
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//Data manipulating helper functions
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
function initSettings(){
localStorage['option_menu'] = "options";
localStorage['option_colorFilter'] = "all";
localStorage['option_rangeFilter'] = "all";
localStorage['option_typeFilter'] = "all";
localStorage['option_viewFilter'] = "all";
localStorage['option_sortOrder'] = "worst";
localStorage['option_showOnlyMaxSkills'] = "true";
localStorage['option_showOnlyDuelSkills'] = "true";
localStorage['option_autoCalculate'] = "true";
}
function initHero(hero, alreadyHasSkills){
if(hero.index != -1){
hero.naturalSkills = data.heroBaseSkills[hero.index];
hero.validWeaponSkills = getValidSkills(hero,"weapon");
hero.validRefineSkills = getValidSkills(hero,"refine");
hero.validAssistSkills = getValidSkills(hero,"assist");
hero.validSpecialSkills = getValidSkills(hero,"special");
hero.validASkills = getValidSkills(hero,"a");
hero.validBSkills = getValidSkills(hero,"b");
hero.validCSkills = getValidSkills(hero,"c");
hero.validSSkills = getValidSkills(hero,"s");
if(!alreadyHasSkills){
setSkills(hero);
}
else{
//validate that the skills it already has are okay
if(!hero.rarity){
hero.rarity = 5;
}
data.skillSlots.forEach(function(slot){
//console.log(data.heroes[hero.index].name + " valid" + capitalize(slot) + "Skills");
if(hero["valid" + capitalize(slot) + "Skills"].indexOf(hero[slot]) == -1){
hero[slot] = -1;
}
});
}
hero.validRefineSkills = getValidRefineSkills(hero,"refine");
setSkillOptions(hero);
setStats(hero);
}
}
function initEnemyList(){
setFlEnemies();
updateFlEnemies();
setSkills(enemies.fl);
setStats(enemies.fl);
}
function getValidSkills(hero,slot){
//returns an array of indices on "skills" array for skills that hero can learn
//If hero has no index, returns all skills in slot except unique
//if not given slot, gives all
var validSkills = [];
//If slot is refine, get valid refine skills
if (slot == "refine"){
return getValidRefineSkills(hero);
}
//Otherwise, get other skills
for(var i = 0; i < data.skills.length; i++){
var inheritRules = data.skills[i].inheritrule.split(","); //Thanks Galeforce (melee,physical)
if(!slot || data.skills[i].slot == slot){
if(hero.index != undefined){
var attackType = getAttackTypeFromWeapon(data.heroes[hero.index].weapontype);
var inheritRuleMatches = 0;
for(var ruleNum = 0; ruleNum < inheritRules.length; ruleNum++){
//console.log("Trying " + slot + ": " + data.skills[i].name);
//can only use if hero starts with it
if(inheritRules[ruleNum] == "unique"){
if(hero.naturalSkills){
for(var j = 0; j < hero.naturalSkills.length; j++){
if(hero.naturalSkills[j][0] == data.skills[i].skill_id){
inheritRuleMatches++;
}
}
}
}
//inherit if weapon is right attacking type
else if(attackType == inheritRules[ruleNum]){
inheritRuleMatches++;
}
//inherit if weapon is right
else if(data.weaponTypes.indexOf(inheritRules[ruleNum])!=-1){
if(data.heroes[hero.index].weapontype==inheritRules[ruleNum]){
inheritRuleMatches++;
}
}
//inherit if movetype is right
else if(data.moveTypes.indexOf(inheritRules[ruleNum])!=-1){
if(inheritRules[ruleNum] === "mounted"){
if(data.heroes[hero.index].movetype == "cavalry" || data.heroes[hero.index].movetype == "flying"){
inheritRuleMatches++;
}
}
else{
if(data.heroes[hero.index].movetype==inheritRules[ruleNum]){
inheritRuleMatches++;
}
}
}
//inherit if not a certain weapon
else if(data.weaponTypes.indexOf(inheritRules[ruleNum].replace("non",""))!=-1){
if(data.heroes[hero.index].weapontype!=inheritRules[ruleNum].replace("non","")){