-
Notifications
You must be signed in to change notification settings - Fork 202
/
playerSpire.js
2394 lines (2361 loc) · 117 KB
/
playerSpire.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
var playerSpire = {
layout: [],
rowsAllowed: 1,
resetToRows: 1,
startingRunestones: 200,
runestones: 200,
spirestones: 0,
spentOnUpgrades: 0,
currentEnemies: 0,
selectedTrap: "",
enemiesKilled: 0,
escapees: 0,
difficulty: 1,
difficultyHidden: 1,
ticksSinceLastEnemy: 0,
strengthLocations: [],
lightColumns: [0, 0, 0, 0, 0],
smallMode: false,
popupOpen: false,
initialized: false,
wasCatchingUp: false,
nextUpgrade: -1,
nextTrap: -1,
tutorialStep: 0,
killedSinceLeak: 0,
savedLayout1: [],
savedLayout2: [],
layout1Note: "",
layout2Note: "",
peakThreat: 0,
nextIcon: 0,
dontDraw: false,
paused: false,
tooltipUpdate: null,
sealed: false,
lastCommand: '',
settings: {
fctTrap: true,
fctPoison: true,
fctRs: true,
fctStatic: false,
chillGradient: true,
enemyIcons: true,
trapIcons: true,
shockEffect: true,
percentHealth: false,
enemyFade: false
},
lootAvg: {
accumulator: 0,
average: 0,
counter: 0,
lastAvg: [0]
},
resetToDefault: function(){
this.layout = [];
this.rowsAllowed = 1;
this.resetToRows = 1;
this.startingRunestones = 200;
this.runestones = 200;
this.spirestones = 0;
this.spentOnUpgrades = 0;
this.currentEnemies = 0;
this.selectedTrap = "";
this.enemiesKilled = 0;
this.escapees = 0;
this.difficulty = 1;
this.difficultyHidden = 1;
this.ticksSinceLastEnemy = 0;
this.strengthLocations = [];
this.lightColumns = [0, 0, 0, 0, 0];
this.smallMode = false;
this.popupOpen = false;
this.initialized = false;
this.wasCatchingUp = false;
this.nextUpgrade = -1;
this.nextTrap = -1;
this.tutorialStep = 0;
this.killedSinceLeak = 0;
this.savedLayout = [];
this.savedLayout2 = [];
this.layout1Note = "";
this.layout2Note = "";
this.nextIcon = 0;
this.peakThreat = 0;
this.paused = false;
this.sealed = false;
this.settings = {
fctTrap: true,
fctPoison: true,
fctRs: true,
fctStatic: false,
chillGradient: true,
shockEffect: true,
enemyIcons: true,
trapIcons: true,
percentHealth: false,
enemyFade: false
}
this.lootAvg = {
accumulator: 0,
average: 0,
counter: 0,
lastAvg: [0]
}
for (var item in playerSpireTraps){
playerSpireTraps[item].owned = 0;
playerSpireTraps[item].level = 1;
playerSpireTraps[item].locked = true;
}
document.getElementById('playerSpireTab').style.display = 'none';
playerSpire.closePopup();
},
init: function(){
this.resetToDefault();
if (game.global.spiresCompleted < 1) return;
if (this.popupOpen)
this.openPopup();
else this.closePopup();
if (this.smallMode)
this.shrink();
else this.enlarge();
var layout = [];
var totalCells = this.rowsAllowed * 5;
for (var x = 0; x < totalCells; x++){
layout.push({trap: {}, occupiedBy: {}});
}
this.layout = layout;
playerSpireTraps.Fire.locked = false;
playerSpireTraps.Frost.locked = false;
this.initialized = true;
this.drawSpire();
this.drawInfo();
document.getElementById('playerSpireTab').style.display = 'table-cell';
},
get maxEnemies(){
var max = 1 + Math.ceil(this.rowsAllowed * 2.5);
return max;
},
get killPercent(){
var total = this.escapees + this.enemiesKilled;
if (total == 0) return "0%";
return prettify((this.enemiesKilled / total) * 100) + "%"
},
get difficultyMod(){
var mod = this.difficulty;
if (this.tutorialStep >= 4) this.addRow();
if (mod < 1) mod = 1;
return mod;
},
getNextRowCost: function(){
var costs = [ //Spire I: 20. II: 200. III: 2k. IV: 20k. V: 200k
-1, 6, 14, 20, 60, 200, 400, 800, 1600, 2500, 5500, 10e3, 25e3, 55e3, 100e3, 150e3, 200e3, 1e6, 2e6, 4e6
];
if (this.rowsAllowed >= 20) return -1;
return costs[this.rowsAllowed];
},
saveLayout: function(slot){
var saveLayout = [];
for (var x = 0; x < this.layout.length; x++){
var toAdd = this.layout[x].trap.name ? this.layout[x].trap.name : "";
saveLayout.push(toAdd);
}
this['savedLayout' + slot] = saveLayout;
var noteElem = document.getElementById('spireLayoutNoteInput');
if (noteElem){
var note = noteElem.value;
if (!note) {
this['layout' + slot + 'Note'] = "";
}
if (note.length > 250) note = note.substring(0, 250);
this['layout' + slot + 'Note'] = htmlEncode(note)
}
},
loadLayout: function(slot){
if (slot <= 0 || slot > 3) return false;
var savedLayout = this["savedLayout" + slot];
if ((this.runestones + this.getCurrentLayoutPrice()) < this.getSavedLayoutPrice(slot)) return false;
this.resetTraps();
for (var x = 0; x < savedLayout.length; x++){
if (!savedLayout[x]) continue;
this.buildTrap(x, savedLayout[x]);
}
return true;
},
getSavedLayoutPrice: function(slot){
var layoutCost = 0;
var tempTraps = {};
var savedLayout = this['savedLayout' + slot];
for (var x = 0; x < savedLayout.length; x++){
if (!savedLayout[x]) continue;
if (!tempTraps[savedLayout[x]]) tempTraps[savedLayout[x]] = 0;
layoutCost += this.getTrapCost(savedLayout[x], false, tempTraps[savedLayout[x]]);
tempTraps[savedLayout[x]]++;
}
return layoutCost;
},
getCurrentLayoutPrice: function(){
var price = 0;
var tempTraps = {};
for (var item in playerSpireTraps){
tempTraps[item] = 0;
}
for (var x = 0; x < this.layout.length; x++){
var cell = this.layout[x];
if (cell.trap.name && tempTraps[item] >= 0){
price += this.getTrapCost(cell.trap.name, false, tempTraps[cell.trap.name]);
tempTraps[cell.trap.name]++;
}
}
return price;
},
presetTooltip: function(slot){
var title = "Trap Layout " + slot;
var text = "<b>This saved layout contains:</b><br/><br/>";
var traps = {};
var layout = this["savedLayout" + slot];
var hasTraps = false;
for (var item in playerSpireTraps){
traps[item] = 0;
}
for (var x = 0; x < layout.length; x++){
if (!layout[x]) continue;
hasTraps = true;
traps[layout[x]]++;
}
var cost = this.getSavedLayoutPrice(slot);
var curCost = this.getCurrentLayoutPrice();
for (var item in traps){
if (traps[item] == 0) continue;
var color = playerSpireTraps[item].color;
text += "<span class='playerSpireTooltipTrapName' style='background-color: " + color + "'>" + item + " x" + traps[item] + "</span> ";
}
text += "<br/><br/>";
text += "Total Cost: " + prettify(cost) + " Rs<br/>Value of Current Traps: " + prettify(curCost) + " Rs<br/>";
var dif = (curCost - cost);
if (dif < 0) text += "Remaining Cost: " + prettify(Math.abs(dif));
else text += "Refund: " + prettify(dif);
text += " Rs";
if (!hasTraps) text = "This layout is currently empty. You can save your current setup to this layout, and load it later!";
else if (this['layout' + slot + 'Note'].length) text += "<br/><br/><b>You wanted to remind yourself:</b><br/>" + this['layout' + slot + 'Note'];
text += "<br/>";
var noLoad = false;
if (dif < 0 && this.runestones < Math.abs(dif)){
text += "<span class='red'>You cannot afford to load this Trap layout.</span>";
noLoad = true;
}
else if (layout.length > this.layout.length){
text += "<span class='red'>You don't have enough Floors available in your Spire to load this layout.</span>";
noLoad = true;
}
text += "<br/><br/><div class='spirePresetBtns'><span onclick='tooltip(\"confirm\", null, \"update\", \"Are you sure you want to save your current Spire layout to Preset " + slot + "? This will overwrite your currently saved layout.<br/><br/>If you want, you can also type a note to your future self below!<br/><br/><input maxlength=\\\"250\\\" style=\\\"width: 100%\\\" id=\\\"spireLayoutNoteInput\\\"/><br/>\", \"playerSpire.saveLayout(" + slot + ")\", \"Save to Layout " + slot + "?\")'>Save Current Layout Here</span>";
if (hasTraps && layout.length <= this.layout.length && !noLoad)
text += "<span onclick='tooltip(\"confirm\", null, \"update\", \"Are you sure you want to load layout " + slot + "? This will remove all Traps and Towers currently placed in your Spire!\", \"playerSpire.loadLayout(" + slot + ")\", \"Load Layout " + slot + "?\")'>Load This Layout</span>";
text += "</div>";
tooltip(title, 'customText', 'lock', text, "", "center");
},
settingsTooltip: function(){
var text = "<div id='spireSettingsTooltip'>";
text += "<b style='margin-bottom: 1vw'>Floating Combat Text</b>";
text += "<span class='spireOption'>Make Static:" + buildNiceCheckbox('spirefctStatic', '', this.settings.fctStatic) + "</span>";
text += "<span class='spireOption'>Trap Damage: " + buildNiceCheckbox('spirefctTrap', '', this.settings.fctTrap) + "</span>";
if (!playerSpireTraps.Poison.locked)
text += "<span class='spireOption'>Poison Tick: " + buildNiceCheckbox('spirefctPoison', '', this.settings.fctPoison) + "</span>";
text += "<span class='spireOption'>Runestones: " + buildNiceCheckbox('spirefctRs', '', this.settings.fctRs) + "</span>";
text += "<b style='margin-top: 0; margin-bottom: 1vw'>Visual Settings</b>";
text += "<span class='spireOption'>Trap Icons: " + buildNiceCheckbox('spiretrapIcons', '', this.settings.trapIcons) + "</span>";
text += "<span class='spireOption'>Enemy Icons: " + buildNiceCheckbox('spireenemyIcons', '', this.settings.enemyIcons) + "</span>";
text += "<span class='spireOption'>Chill Effect: " + buildNiceCheckbox('spirechillGradient', '', this.settings.chillGradient) + "</span>";
if (!playerSpireTraps.Lightning.locked)
text += "<span class='spireOption'>Shock Effect: " + buildNiceCheckbox('spireshockEffect', '', this.settings.shockEffect) + "</span>";
text += "<span class='spireOption'>Health as %: " + buildNiceCheckbox('spirepercentHealth', '', this.settings.percentHealth) + "</span>";
text += "<span class='spireOption'>Faded Enemies: " + buildNiceCheckbox('spireenemyFade', '', this.settings.enemyFade) + "</span>";
text += "</div>";
tooltip("Spire Settings", 'customText', 'lock', text, "<span class='btn btn-info' onclick='playerSpire.saveSettings()'>Save</span><span class='btn btn-danger' onclick='cancelTooltip()'>Cancel</span>", "hi", "hi");
},
saveSettings: function(){
for (var item in this.settings){
var elem = document.getElementById('spire' + item);
if (elem){
this.settings[item] = readNiceCheckbox(elem);
}
}
this.drawSpire();
this.drawInfo();
cancelTooltip();
},
rewardRunestones: function(amt){
this.runestones += amt;
this.lootAvg.accumulator += amt;
this.updateRunestones();
},
getRsPs: function() {
if (!this.lootAvg.lastAvg.length) return 0;
var avg = 0;
for (var x = 0; x < this.lootAvg.lastAvg.length; x++){
avg += this.lootAvg.lastAvg[x];
}
avg /= this.lootAvg.lastAvg.length;
return (avg > 0.01) ? avg : 0;
},
updateRsPs: function(){
var elem = document.getElementById('RsPs');
if (elem)
elem.innerHTML = prettify(this.getRsPs());
},
curateAvgs: function() {
this.lootAvg.counter++;
if (this.lootAvg.counter < 10) return;
this.lootAvg.counter = 0;
var alpha = 0.05;
this.lootAvg.average = this.lootAvg.average * (1 - alpha) + this.lootAvg.accumulator * alpha / 10;
this.lootAvg.accumulator = 0;
if (this.lootAvg.lastAvg && this.lootAvg.lastAvg.length >= 20) this.lootAvg.lastAvg.splice(0, 1);
this.lootAvg.lastAvg.push(Math.floor(this.lootAvg.average * 100) / 100);
this.updateRsPs();
if (game.stats.tdKills.value + game.stats.tdKills.valueTotal >= 500e3) giveSingleAchieve("Stoned");
},
addRow: function(force){
var cost = this.getNextRowCost();
if (cost == -1) return;
if (!force && this.spirestones < cost) return;
if (!force && this.difficulty < (100 * (this.rowsAllowed + 1))) return;
this.rowsAllowed++;
if (this.rowsAllowed == 10) giveSingleAchieve("Defender");
if (this.rowsAllowed == 20) giveSingleAchieve("Power Tower");
this.spirestones -= cost;
if (this.spirestones < 0) this.spirestones = 0;
for (var x = 0; x < 5; x++){
this.layout.push({occupiedBy: {}, trap: {}})
}
this.drawSpire();
this.drawInfo();
},
getUpgradesHtml: function(){
var html = "";
var cheapestTrap = -1;
if (this.tutorialStep < 4) return "";
for (var trapItem in playerSpireTraps){
var trap = playerSpireTraps[trapItem];
if (trap.locked) continue;
if (!trap.upgrades || trap.upgrades.length < trap.level) continue;
var nextUpgrade = trap.upgrades[trap.level - 1];
if ((nextUpgrade.cost > this.runestones || game.global.highestLevelCleared + 1 < nextUpgrade.unlockAt) && this.smallMode) continue;
var trapText = trap.isTower ? " Tower " : " Trap ";
var style = (nextUpgrade.cost > this.runestones || (game.global.highestLevelCleared + 1 < nextUpgrade.unlockAt)) ? "grey" : trap.color;
var upgradeClass;
var text;
if (this.smallMode){
upgradeClass = 'spireTrapBoxSmall';
text = trapItem + " " + romanNumeral(trap.level + 1);
}
else{
upgradeClass = 'playerSpireUpgrade spireTrapBox';
text = trapItem + trapText + romanNumeral(trap.level + 1)
}
html += "<div onmouseover='playerSpire.upgradeTooltip(\"" + trapItem + "\", event)' onmouseout='tooltip(\"hide\")' onclick='playerSpire.buyUpgrade(\"" + trapItem + "\")' style='background-color: " + style + "' class='" + upgradeClass + "'>" + text + "</div>";
if (this.runestones < nextUpgrade.cost && (cheapestTrap == -1 || nextUpgrade.cost < cheapestTrap)) cheapestTrap = nextUpgrade.cost;
}
if (this.smallMode && html.length) html = "<hr/>" + html;
this.nextUpgrade = cheapestTrap;
return html;
},
resetUpgrades: function(){
for (var trap in playerSpireTraps){
var trapObj = playerSpireTraps[trap];
trapObj.level = 1;
}
this.runestones += this.spentOnUpgrades;
this.spentOnUpgrades = 0;
this.drawInfo();
},
redrawUpgrades: function(){
var elem = document.getElementById('playerSpireUpgradesArea');
if (elem == null){
this.drawInfo();
return;
}
elem.innerHTML = this.getUpgradesHtml();
},
checkRedrawUpgrades: function(){
//only needed if drawInfo isn't being called, basically just for killedEnemy()
if (this.nextUpgrade != -1 && this.runestones >= this.nextUpgrade) this.redrawUpgrades();
},
checkUpdateTrapColors: function(){
if (this.nextTrap != -1 && this.runestones >= this.nextTrap) this.updateTrapColors();
},
updateTrapColors: function(){
var cheapestTrap = -1;
for (var item in playerSpireTraps){
var trap = playerSpireTraps[item];
if (trap.locked) continue;
var cost = this.getTrapCost(item);
var color = (this.runestones >= cost) ? trap.color : "grey";
var elem = document.getElementById(item + "TrapBox");
if (elem) elem.style.backgroundColor = color;
if (this.runestones < cost && (cheapestTrap == -1 || cost < cheapestTrap)) cheapestTrap = cost;
}
this.nextTrap = cheapestTrap;
},
buyUpgrade: function(trapName, confirmed){
var trapObj = playerSpireTraps[trapName];
if (!trapObj.upgrades || trapObj.upgrades.length < trapObj.level) return 0;
var upgrade = trapObj.upgrades[trapObj.level - 1];
if (this.runestones < upgrade.cost) return 1;
if (game.global.highestLevelCleared + 1 < upgrade.unlockAt) return 2;
if (!confirmed){
var trapText = trapName + ((trapObj.isTower) ? " Tower" : " Trap");
var tipText = "Are you sure you want to upgrade your " + trapText + "? This upgrade is non-refundable!<br/><br/><i>\"" + upgrade.description + "\"</i><br/><br/><b>Cost: " + prettify(upgrade.cost) + " Rs</b>";
tooltip("confirm", null, "update", tipText, "playerSpire.buyUpgrade('" + trapName + "', true)", "Upgrade " + trapText + "?");
return;
}
this.runestones -= upgrade.cost;
this.spentOnUpgrades += upgrade.cost;
if (this.runestones + this.getCurrentLayoutPrice() < 200) this.runestones = 200 - this.getCurrentLayoutPrice();
trapObj.level++;
this.drawInfo();
this.drawSpire();
return true;
},
rewardSpirestones: function(spireNumber){
var reward = Math.floor(Math.pow(10, spireNumber - 1) * 20);
this.spirestones += reward;
if (this.tutorialStep >= 4) this.addRow();
this.updateSpirestoneText();
return reward;
},
giveSpirestones: function(count){
this.spirestones += count;
if (this.tutorialStep >= 4) this.addRow();
this.updateSpirestoneText();
},
updateSpirestoneText: function() {
var elem = document.getElementById('spirestoneBox');
if (elem) elem.innerHTML = this.getSpirestoneHtml();
},
getSpirestoneHtml: function() {
var text = ((this.smallMode) ? "Ss: " : "Spirestones: ") + prettify(this.spirestones);
var nextCost = this.getNextRowCost();
if (nextCost == -1 || this.tutorialStep < 3) return text;
text += " / " + prettify(nextCost) + "</span>"
return text;
},
canSeal: function(){
return (playerSpireTraps.Strength.owned >= 10 && playerSpireTraps.Knowledge.owned >= 10 && playerSpireTraps.Condenser.owned >= 10);
},
seal: function(){
this.sealed = true;
this.clearEnemies();
playerSpireTraps.Knowledge.owned = 11;
playerSpireTraps.Strength.owned = 11;
playerSpireTraps.Condenser.owned = 11;
document.getElementById('playerSpireTab').style.display = 'none';
},
unseal: function(){
playerSpireTraps.Knowledge.owned = 10;
playerSpireTraps.Strength.owned = 10;
playerSpireTraps.Condenser.owned = 10;
this.sealed = false;
document.getElementById('playerSpireTab').style.display = 'table-cell';
this.drawInfo();
},
togglePause: function(){
this.paused = !this.paused;
this.drawInfo();
this.updateTabColor();
},
infoTooltip: function(what, event){
var tooltipText = "";
switch(what){
case "Runestones":
var curCost = this.getCurrentLayoutPrice();
var upgradeCost = this.spentOnUpgrades;
var remaining = this.runestones;
tooltipText = "Runestones (Rs) are earned by killing Bad Guys in your Spire, and the amount of Runestones gained is directly proportional to the Max Health of the slain Bad Guy.<br/><br/>You have found " + prettify(curCost + upgradeCost + remaining) + " total Runestones.<br/><br/>" + prettify(upgradeCost) + " Runestones have been spent on Upgrades.<br/><br/>" + prettify(curCost) + " Runestones have been spent on Traps/Towers in your current layout.";
if (game.heirlooms.Core.runestones.currentBonus > 0) tooltipText += "<br/><br/>You are earning " + prettify(game.heirlooms.Core.runestones.currentBonus) + "% more Runestones from all sources thanks to your Spire Core!";
break;
case "Threat":
tooltipText = "Threat rises as you kill Bad Guys in your Spire, and falls as they escape. Threat is an average of kills/escapes over some time and may not always rise immediately after a kill or fall immediately after an escape, but will always stay near what your Spire can handle.<br/><br/>More Threat means Healthier Bad Guys, which means more Runestones. Threat is also required for adding additional Floors to your Spire, increasing by 100 Threat required per Floor.<br/><br/>The highest Threat your Spire has ever reached is: <b>" + prettify(Math.floor(this.peakThreat)) + "</b><br/><br/>Displayed As: <b>Current Threat</b> / <b>Threat Required for Next Floor</b>";
break;
case "Enemies":
tooltipText = "The amount of enemies currently allowed in your Spire.<br/><br/>Your Spire can hold 1 Bad Guy, plus an additional 2.5 Bad Guys for each Floor in your Spire (rounded up).";
if (playerSpireTraps.Frost.level >= 7 && playerSpireTraps.Frost.owned) tooltipText += "<br/><br/>You have an additional " + playerSpireTraps.Frost.owned + " Maximum Enemies allowed in your Spire, thanks to Frost IV.";
tooltipText += "<br/><br/>Displayed As: <b>Current Enemies in Spire</b> / <b>Maximum Enemies Allowed in Spire</b>"
break;
case "Spirestones":
tooltipText = "Spirestones (Ss) can only be earned by recycling Spire Cores found from Spires in the World, and can be used to add Floors to your Spire or upgrade other Cores.<br/><br/>Displayed As: <b>Current Spirestones</b> / <b>Spirestones Required for Next Floor</b>"
break;
default:
break;
}
tooltip(what, 'customText', event, tooltipText, "");
tooltipUpdateFunction = function(){playerSpire.infoTooltip(what, event)};
},
selectScreenReadInput: function(){
var input = document.getElementById('spireScreenReadInput');
input.focus();
input.select();
},
getCellNum: function(col, row){
var col = parseInt(col);
if (isNumberBad(col) || col > 5 || col < 1){
return "Column (the first number) must be between 1 and 5";
return -1;
}
var row = parseInt(row);
if (isNumberBad(row) || row > this.rowsAllowed){
return "Row (the second number) must be between 1 and " + this.rowsAllowed;
return -1;
}
var cell = ((row - 1) * 5) + col - 1;
return cell;
},
screenReadCommand: function(){
var input = document.getElementById('spireScreenReadInput');
if (!input) return;
var output = document.getElementById('screenReaderTooltip');
if (!output) return;
var val = input.value;
if (val != 'r') this.lastCommand = val;
var split = val.toLowerCase().split(' ');
input.value = "";
this.selectScreenReadInput();
if (split[0] == "help"){
output.innerHTML = "This is a tower defense minigame where the goal is to stop enemies from scaling your spire. You currently have " + this.rowsAllowed + " rows in your Spire, and each row has 5 columns. Your threat increases as you kill enemies, and decreases as enemies reach the top of your Spire. Killing enemies also rewards you with Runestones, which can be used to buy more traps and upgrades. You can also read some additional details about the spire and get your current quest at the heading labeled 'Spire Defense Story/Quest'. Type 'Commands' for a list of the different commands you can use to control your spire!";
return;
}
if (split[0] == "commands"){
output.innerHTML = "Type 'Build X column row' to build a trap. For example, type 'Build Frost 1 1' and then 'Build Fire 2 1' to complete your first quest. You can also type 'Build Fire 2 1 3 1 4 1' to build traps on the 2nd, 3rd and 4th columns of the first row. Type 'Sell Column Row' to sell a trap, for example 'Sell 1 1' will sell the bottom left trap. You can also type multiple pairs of columns and rows with the sell command to sell multiple traps at once just like with build, or you can type 'Sell all' if you want to sell all of your traps. Type 'Traps' for a list of all purchaseable traps and their costs. Type 'Info X' where X is the name of a trap to get the price and description of that trap. Type 'Upgrades' for a list of all purchaseable upgrades and their costs. Type 'Upgrade X' to purchase an upgrade for Trap type X. Type 'Read X' to read the traps on row X, or type 'Read Enemies X' to read what enemies are currently on row X and what their health percents are. Finally you can type 'Shift Up' or 'Shift Down' followed by a Column and Row number to shift the trap on that cell and any other traps ahead or behind it up or down. For example, if you type 'Shift up 1 1' when you have a Frost trap on 1 1 and a Fire trap on 2 1, your Frost trap will be shifted to 2 1 and your Fire trap will be shifted to 3 1."
return;
}
//traps
//upgrades
//upgrade x
if (split[0] == "r"){
if (this.lastCommand) input.value = this.lastCommand;
this.screenReadCommand();
return;
}
if (split[0] == "build"){
var trapName = split[1];
var outputText = "";
trapName = trapName[0].toUpperCase() + trapName.substring(1);
if (!playerSpireTraps[trapName]){
output.innerHTML = "Trap " + trapName + " does not exist";
return;
}
if (playerSpireTraps[trapName].locked) return;
var loops = Math.floor((split.length - 2) / 2);
for (var x = 0; x < loops; x++){
var next = 2 + (x * 2);
if (split.length < (next + 2)) break;
var col = split[next];
var row = split[(next + 1)];
var cell = this.getCellNum(col, row);
if (isNaN(cell)){
outputText += cell + ". ";
continue;
}
var built = this.buildTrap(cell, trapName);
if (built === true) outputText += trapName + " built at " + col + ' ' + row;
else if (built === false) outputText += "Cannot afford " + trapName;
else if (built === 1) outputText += trapName + " already exists at " + col + ' ' + row;
else outputText += "Build failed at " + col + " " + row;
outputText += ". ";
}
output.innerHTML = outputText;
this.selectScreenReadInput();
return;
}
if (split[0] == "shift"){
var cell = this.getCellNum(split[2], split[3]);
if (isNaN(cell)){
output.innerHTML = cell;
return;
}
var command = "shift";
if (split[1] == "up") command += "Up";
else if (split[1] == "down") command += "Down";
else return;
if (!this.layout[cell] || !this.layout[cell].trap){
output.innerHTML = "There is no trap at " + split[2] + " " + split[3] + " to shift!";
return;
}
this.buildTrap(cell, command);
this.selectScreenReadInput();
return;
}
if (split[0] == "sell"){
if (split[1] == "all"){
this.resetTraps();
output.innerHTML = "All traps sold!";
return;
}
var outputText = "";
var loops = Math.floor((split.length - 1) / 2);
for (var x = 0; x < loops; x++){
var next = 1 + (x * 2);
if (split.length < (next + 2)) break;
var col = split[next];
var row = split[(next + 1)];
var cell = this.getCellNum(col, row);
if (isNaN(cell)) {
outputText += cell + ". ";
continue;
}
if (!this.layout[cell] || !this.layout[cell].trap){
outputText += "There is no trap at " + col + " " + row + ". ";
continue;
}
outputText += "Sold " + this.layout[cell].trap.name + " at " + col + ' ' + row + ". ";
this.sellTrap(cell);
}
output.innerHTML = outputText;
this.selectScreenReadInput();
return;
}
if (split[0] == "traps"){
var text = "";
for (var item in playerSpireTraps){
var trap = playerSpireTraps[item];
if (trap.locked) continue;
text += item + " " + ((trap.isTower) ? "Tower" : "Trap") + " ";
text += "Next costs " + prettify(this.getTrapCost(item)) + " Runestones. ";
}
output.innerHTML = text;
return;
}
if (split[0] == "upgrades"){
if (this.tutorialStep < 4) {
output.innerHTML = "No upgrades available yet, check your quest!";
return;
}
var text = "Upgrades: ";
for (var trapItem in playerSpireTraps){
var trap = playerSpireTraps[trapItem];
if (trap.locked) continue;
if (!trap.upgrades || trap.upgrades.length < trap.level) continue;
var nextUpgrade = trap.upgrades[trap.level - 1];
var canAfford = (nextUpgrade.cost <= this.runestones);
var enoughZones = (game.global.highestLevelCleared + 1 >= nextUpgrade.unlockAt);
text += trapItem + " " + (trap.level + 1) + " costs " + prettify(nextUpgrade.cost) + " Runestones. ";
if (!enoughZones) text += " Requires reaching Zone " + nextUpgrade.unlockAt + ". ";
else if (canAfford) text += "Can buy now! ";
text += nextUpgrade.description + ". ";
}
output.innerHTML = text;
return;
}
if (split[0] == "upgrade"){
if (this.tutorialStep < 4) {
output.innerHTML = "No upgrades available yet, check your quest!";
return;
}
var trapName = split[1].toLowerCase();
trapName = trapName[0].toUpperCase() + trapName.substring(1);
if (!playerSpireTraps[trapName]){
output.innerHTML = "Trap " + trapName + " does not exist";
return;
}
var result = this.buyUpgrade(trapName, true);
if (result === 0) output.innerHTML = "No upgrades available for " + trapName;
else if (result === 1) output.innerHTML = "Not enough runestones for upgrade";
else if (result === 2) output.innerHTML = "You haven't reached a high enough Zone for this upgrade";
else if (result == true) output.innerHTML = "Upgrade purchased!";
this.selectScreenReadInput();
return;
}
if (split[0] == "info"){
var text = "";
var trapName = split[1].toLowerCase();
trapName = trapName[0].toUpperCase() + trapName.substring(1);
if (!playerSpireTraps[trapName]){
output.innerHTML = "Trap " + trapName + " does not exist";
return;
}
if (playerSpireTraps[trapName].locked) return;
var trap = playerSpireTraps[trapName];
text += trapName + " " + ((trap.isTower) ? "Tower" : "Trap") + " ";
text += "Next costs " + prettify(this.getTrapCost(trapName)) + " Runestones. ";
text += trap.description.split("<br/>")[0] + " ";
output.innerHTML = text;
return;
}
if (split[0] == "read"){
if (split [1] == "enemies"){
var row = parseInt(split[2]);
if (isNumberBad(row) || row > this.rowsAllowed){
output.innerHTML = "Row must be between 1 and " + this.rowsAllowed;
return;
}
var start = (row - 1) * 5;
var end = start + 5;
var cellNo = 0;
var text = "Enemies on row " + row + ": ";
for (var x = start; x < end; x++){
cellNo++;
var cell = this.layout[x];
if (cell.occupiedBy.name){
text += "Col " + cellNo + " has " + prettify(cell.occupiedBy.health) + " health which is " + Math.floor((cell.occupiedBy.health / cell.occupiedBy.maxHealth) * 100) + "%. ";
}
}
output.innerHTML = text;
return;
}
var row = parseInt(split[1]);
if (isNumberBad(row) || row > this.rowsAllowed){
output.innerHTML = "Row must be between 1 and " + this.rowsAllowed;
return;
}
var start = (row - 1) * 5;
var end = start + 5;
var cellNo = 0;
var text = "Traps on row " + row + ": ";
for (var x = start; x < end; x++){
cellNo++;
var cell = this.layout[x];
if (cell.trap.name){
text += "Col " + cellNo + " has " + cell.trap.name + ". ";
}
else text += "Col " + cellNo + " is empty. "
}
output.innerHTML = text;
return;
}
output.innerHTML = split[0] + " is an unknown command.";
this.selectScreenReadInput();
},
drawInfo: function(){
if (!this.popupOpen) return;
if (this.sealed){
document.getElementById('playerSpireInfoPanel').innerHTML = "<div style='text-align: center; font-weight: bold'>The Spire is Sealed, but you are still earning bonuses from having 11 of each Tower.<br/><br/>You can unseal the Spire if you want to, but will lose your 11th towers.<br/><br/><div onclick='playerSpire.unseal()' id='unsealSpireBtn' class='spireControlBox'>Unseal Spire</div></div><span id='playerSpireCloseBtn' class='icomoon icon-close' onclick='playerSpire.closePopup()'></span>"
return;
}
if (this.smallMode){
this.drawSmallInfo();
return;
}
var elem = document.getElementById('playerSpireInfoPanel');
var infoHtml = "";
infoHtml += "<div id='playerSpireInfoTop'>";
if (usingScreenReader) infoHtml += "<h1>Spire Defense - Type Help in the input below, then press enter</h1><br/><input id='spireScreenReadInput'/><br/>"
infoHtml += "<span onmouseover='playerSpire.infoTooltip(\"Runestones\", event)' onmouseout='tooltip(\"hide\")'>Runestones: <span id='playerSpireRunestones'>" + prettify(this.runestones) + "</span><br/>Runestones per Second: <span id='RsPs'>" + prettify(this.getRsPs()) + "</span></span>";
infoHtml += "<br/><span onmouseover='playerSpire.infoTooltip(\"Enemies\", event)' onmouseout='tooltip(\"hide\")'>Enemies: <span id='playerSpireCurrentEnemies'>" + this.currentEnemies + "</span> / <span id='playerSpireMaxEnemies'>" + this.maxEnemies + "</span></span>";
infoHtml += "<br/><span onmouseover='playerSpire.infoTooltip(\"Spirestones\", event)' onmouseout='tooltip(\"hide\")' id='spirestoneBox'>" + this.getSpirestoneHtml() + "</span><br/><span onmouseover='playerSpire.infoTooltip(\"Threat\", event)' onmouseout='tooltip(\"hide\")' id='playerSpireDifficulty'>" + this.getDifficultyHtml() + "</span></div>";
infoHtml += "<div id='spireTrapsWindow'>";
infoHtml += "<div onclick='playerSpire.shrink()' id='shrinkSpireBox' class='spireControlBox'>Shrink Window</div>";
infoHtml += "<div onclick='playerSpire.settingsTooltip()' id='spireSettingsBox' class='spireControlBox'>Settings</div>"
infoHtml += "<div onclick='tooltip(\"confirm\", null, \"update\", \"Are you sure you want to sell all Traps and Towers? You will get back 100% of Runestones spent on them.<br/><br/>" + ((this.paused) ? "" : "<b>Protip:</b> Pause your Spire before selling your defenses if you want to avoid leaking!") + "\", \"playerSpire.resetTraps()\", \"Sell All?\")' class='spireControlBox'>Sell All</div>";
infoHtml += "<div onclick='playerSpire.togglePause()' id='pauseSpireBtn' class='spireControlBox spirePaused" + ((this.paused) ? "Yes'>Unpause" : "'>Pause Spire") + "</div>";
infoHtml += "<div class='spireControlBoxDbl'><div onclick='playerSpire.presetTooltip(1)'>Layout 1</div><div onclick='playerSpire.presetTooltip(2)'>Layout 2</div></div>"
infoHtml += "<div onclick='playerSpire.selectTrap(\"shiftUp\")' onmouseout='tooltip(\"hide\")' onmouseover='playerSpire.trapTooltip(\"shiftUp\", event)' id='sellTrapBox' class='spireControlBox" + ((this.selectedTrap == "shiftUp") ? " selected" : "") + "'>Shift Up</div>";
infoHtml += "<div onclick='playerSpire.selectTrap(\"shiftDown\")' onmouseout='tooltip(\"hide\")' onmouseover='playerSpire.trapTooltip(\"shiftDown\", event)' id='sellTrapBox' class='spireControlBox" + ((this.selectedTrap == "shiftDown") ? " selected" : "") + "'>Shift Down</div>";
// infoHtml += "<div onclick='playerSpire.resetUpgrades()' class='spireControlBox'>Reset Upgrades</div>";
// infoHtml += "<div onclick='tooltip(\"confirm\", null, \"update\", \"Are you sure you want to reset EVERYTHING? This includes Floors, upgrades, and runestones!\", \"playerSpire.init()\", \"Reset Spire?\")' class='spireControlBox'>Reset EVERYTHING</div>";
// infoHtml += "<div onclick='playerSpire.clearEnemies()' class='spireControlBox'>Clear Enemies</div>";
infoHtml += "<br/><hr/>"
infoHtml += "<div onclick='playerSpire.selectTrap(\"sell\")' onmouseout='tooltip(\"hide\")' onmouseover='playerSpire.trapTooltip(\"sell\", event)' style='padding-top: 1.35vw' id='sellTrapBox' class='spireTrapBox" + ((this.selectedTrap == "sell") ? " selected" : "") + "'>Sell a Trap/Tower</div>";
var cheapestTrap = -1;
for (var item in playerSpireTraps){
var trap = playerSpireTraps[item];
if (trap.locked) continue;
var trapText = trap.isTower ? "Tower" : "Trap";
trapText += " " + romanNumeral(trap.level);
var trapIcon = "";
if (this.settings.trapIcons) trapIcon = "<span class='icomoon icon-" + trap.icon + "'></span> ";
var cost = this.getTrapCost(item);
var color = (this.runestones >= cost) ? trap.color : "grey";
var costText = prettify(this.getTrapCost(item)) + " Rs";
if (trap.isTower && trap.owned >= 10) {
costText = "Max Level"
color = "grey";
}
infoHtml += "<div style='background-color: " + color + "' onmouseout='tooltip(\"hide\")' onmouseover='playerSpire.trapTooltip(\"" + item + "\", event)' onclick='playerSpire.selectTrap(\"" + item + "\")' id='" + item + "TrapBox' class='spireTrapBox" + ((item == this.selectedTrap) ? " selected" : "") + "'>" + trapIcon + item + " " + trapText + "<br/>" + costText + "</div>"
if (this.runestones < cost && (cheapestTrap == -1 || cost < cheapestTrap)) cheapestTrap = cost;
}
this.nextTrap = cheapestTrap;
infoHtml += "</div><hr/>"; //spireTrapsWindow
infoHtml += "<span id='playerSpireCloseBtn' class='icomoon icon-close' onclick='playerSpire.closePopup()'></span>";
infoHtml += "<div id='playerSpireUpgradesArea'>";
infoHtml += this.getUpgradesHtml();
if (this.canSeal()){
infoHtml += "<div id='spireSealInfo' style='font-weight: bold; text-align: center;'>You now have 10 of each Tower and have successfully reinforced every floor of this Spire. Your Trimps would be incredibly proud of you if they could process such strong emotions, for this was no small feat! Your Scientists can now construct one more of each Tower for free, but doing so will seal the Spire. If you choose to Seal the Spire, you'll earn World bonuses as if you had 11 of each Tower, but enemies will no longer spawn in the Spire.<br/>NOTE: Sealing the Spire will remove the tab used to access this window, but a Setting will be added under Other should you want to unseal it for any reason.<br/><div onclick='playerSpire.seal()' id='sealSpireBtn' class='spireControlBox'>Seal Spire</div></div>"
}
infoHtml += "</div>"; //playerSpireUpgradesArea
elem.innerHTML = infoHtml;
if (usingScreenReader) this.selectScreenReadInput();
},
drawSmallInfo: function(){
var elem = document.getElementById('playerSpireSmallPanel');
var html = "<div id='playerSpireInfoTopSm'>";
html += "<span onmouseover='playerSpire.infoTooltip(\"Runestones\", event)' onmouseout='tooltip(\"hide\")'>Rs: <span id='playerSpireRunestones'>" + prettify(this.runestones) + "</span><br/>";
html += "Rs/S: <span id='RsPs'>" + prettify(this.getRsPs()) + "</span></span><br/>"
html += "<span onmouseover='playerSpire.infoTooltip(\"Enemies\", event)' onmouseout='tooltip(\"hide\")'>E: <span id='playerSpireCurrentEnemies'>" + this.currentEnemies + "</span> / <span id='playerSpireMaxEnemies'>" + this.maxEnemies + "</span></span><br/>";
html += "<span onmouseover='playerSpire.infoTooltip(\"Spirestones\", event)' onmouseout='tooltip(\"hide\")' id='spirestoneBox'>" + this.getSpirestoneHtml() + "</span><br/>"
html += "<span onmouseover='playerSpire.infoTooltip(\"Threat\", event)' onmouseout='tooltip(\"hide\")' id='playerSpireDifficulty'>" + this.getDifficultyHtml() + "</span><br/>";
html += "</div>"; //playerSpireInfoTopSm
html += "<div onclick='playerSpire.enlarge()' id='shrinkSpireBox' class='spireControlBoxSmall'>Enlarge</div>";
html += "<hr style='margin: 2%'/>";
html += "<div onclick='playerSpire.selectTrap(\"sell\")' id='sellTrapBox' onmouseout='tooltip(\"hide\")' onmouseover='playerSpire.trapTooltip(\"sell\", event)' class='spireTrapBoxSmall" + ((this.selectedTrap == "sell") ? " selected" : "") + "'>Sell</div>";
var cheapestTrap = -1;
for (var item in playerSpireTraps){
if (playerSpireTraps[item].locked) continue;
var cost = this.getTrapCost(item);
var color = (this.runestones >= cost) ? playerSpireTraps[item].color : "grey";
if (playerSpireTraps[item].isTower && playerSpireTraps[item].owned >= 10) color = "grey";
var trapIcon = "";
if (this.settings.trapIcons) trapIcon = "<span class='icomoon icon-" + playerSpireTraps[item].icon + "'></span> ";
html += "<div style='background-color: " + color + "' onmouseout='tooltip(\"hide\")' onmouseover='playerSpire.trapTooltip(\"" + item + "\", event)' onclick='playerSpire.selectTrap(\"" + item + "\")' id='" + item + "TrapBox' class='spireTrapBoxSmall" + ((item == this.selectedTrap) ? " selected" : "") + "'>" + trapIcon + item + "</div>";
if (this.runestones < cost && (cheapestTrap == -1 || cost < cheapestTrap)) cheapestTrap = cost;
}
html += "<div id='playerSpireUpgradesArea'>" + this.getUpgradesHtml() + "</div>";
this.nextTrap = cheapestTrap;
html += "<span id='playerSpireCloseBtnSm' class='icomoon icon-close' onclick='playerSpire.closePopup()'></span>";
elem.innerHTML = html;
},
resetStats: function(){
this.escapees = 0;
this.enemiesKilled = 0;
this.lootAvg.accumulator = 0;
this.lootAvg.average = 0;
this.updateKills();
this.updateRsPs();
},
resetTraps: function(){
var refund = 0;
for (var x = 0; x < this.layout.length; x++){
var cell = this.layout[x];
if (cell.trap.name){
playerSpireTraps[cell.trap.name].owned--;
refund += this.getTrapCost(cell.trap.name);
}
cell.trap = {};
}
for (var trap in playerSpireTraps){
playerSpireTraps[trap].owned = 0;
}
this.runestones += refund;
this.strengthLocations = [];
this.lightColumns = [0, 0, 0, 0, 0];
this.drawSpire();
this.drawInfo();
},
clearEnemies: function(){
for (var x = 0; x < this.layout.length; x++){
var cell = this.layout[x];
cell.occupiedBy = {};
}
this.drawSpire();
this.resetStats();
this.currentEnemies = 0;
this.drawInfo();
},
shrink: function(){
this.smallMode = true;
document.getElementById('playerSpireInfoPanel').style.display = 'none';
var popoutElem = document.getElementById('playerSpirePopout');
popoutElem.style.left = "2.5%";
document.getElementById('playerSpireSmallPanel').style.display = 'inline-block';
document.getElementById('playerSpireSpirePanel').style.width = "calc(27vw - 4px)";
document.getElementById('floatingCombatText').style.width = "calc(26vw - 4px)";
this.drawSmallInfo();
},
enlarge: function(){
this.smallMode = false;
document.getElementById('playerSpireInfoPanel').style.display = 'inline-block';
var smallElem = document.getElementById('playerSpireSmallPanel');
smallElem.innerHTML = "";
smallElem.style.display = 'none';
document.getElementById('playerSpirePopout').style.left = "5%";
document.getElementById('playerSpireSpirePanel').style.width = "calc(30vw - 4px)";
document.getElementById('floatingCombatText').style.width = "calc(29vw - 4px)";
this.drawInfo();
},
updateTabColor: function(){
var tabClass = (this.paused) ? 'pausedSpire' : 'pausedSpireNo';
swapClass('pausedSpire', tabClass, document.getElementById('playerSpireTab'));
},
closePopup: function() {
this.popupOpen = false;
document.getElementById('playerSpirePopout').style.display = 'none';
this.updateTabColor();
},
openPopup: function(){
this.popupOpen = true;
document.getElementById('playerSpirePopout').style.display = 'block';
this.drawSpire();
this.drawInfo();
},
trapTooltip: function(which, event){
if (which == "sell"){
tooltip("Sell Trap/Tower", 'customText', event, "Sell a Trap or Tower! You'll get back 100% of what you spent on the last Trap or Tower of that type.<br/><br/>(Hotkey 0 or ')")
return;
}
if (which == "shiftUp"){
tooltip("Shift Up", 'customText', event, "Shift your Traps and Towers up one cell!<br/><br/>Click this to select Shift Up Mode, then click a Trap or Tower in your Spire. The Trap/Tower you select and all Traps/Towers after it will shift up one cell until the first empty space is hit.<br/><br/>If there is no empty space, your last Trap/Tower will be sold.")
return;
}
if (which == "shiftDown"){
tooltip("Shift Down", 'customText', event, "Shift your Traps and Towers down one cell!<br/><br/>Click this to select Shift Down Mode, then click a Trap or Tower in your Spire. The Trap/Tower you select and all Traps/Towers before it will shift down one cell until the first empty space is hit.<br/><br/>If there is no empty space, your first Trap/Tower will be sold.")
return;
}
var trapText = playerSpireTraps[which].isTower ? " Tower" : " Trap";
var cost = this.getTrapCost(which);
var costText = (cost > this.runestones) ? "<span style='color: red'>" : "<span style='color: green'>";
costText += prettify(cost) + " Runestones";
if (cost > this.runestones) costText += " (" + calculateTimeToMax(null, this.lootAvg.average, (cost - this.runestones)) + ")";
else{
var costPct = (cost / this.runestones) * 100;
if (costPct < 0.01) costPct = 0;
costText += " (" + prettify(costPct) + "%)";
}
costText += "</span>";
tooltip(which + trapText, 'customText', event, playerSpireTraps[which].description, costText);
tooltipUpdateFunction = function(){playerSpire.trapTooltip(which, event)};
},
upgradeTooltip: function(which, event){
var trap = playerSpireTraps[which];
if (!trap.upgrades || trap.upgrades.length < trap.level) return;
var upgrade = trap.upgrades[trap.level - 1];
var text = upgrade.description;
var title = which + ((trap.isTower) ? " Tower " : " Trap ") + romanNumeral(trap.level + 1);
var cost = "<span style='color: ";
cost += (this.runestones >= upgrade.cost) ? "green" : "red";
cost += "'>" + prettify(upgrade.cost) + " Runestones";
if (upgrade.cost > this.runestones) cost += " (" + calculateTimeToMax(null, this.lootAvg.average, (upgrade.cost - this.runestones)) + ")";
else{
var costPct = (upgrade.cost / this.runestones) * 100;
if (costPct < 0.01) costPct = 0;
cost += " (" + prettify(costPct) + "%)";
}
cost += "</span>";
if (upgrade.unlockAt != -1)
cost += ", <span style='color: " + ((game.global.highestLevelCleared + 1 >= upgrade.unlockAt) ? "green" : "red") + "'>Reach Z" + upgrade.unlockAt + "</span>";
tooltip(title, 'customText', event, text, cost);
tooltipUpdateFunction = function(){playerSpire.upgradeTooltip(which, event)};
},
selectTrap: function(which){
this.selectedTrap = which;
this.drawInfo();
},
drawSpire: function(){
if (!this.popupOpen) return;
if (this.dontDraw) return;
var layout = this.layout;
var layoutHtml = "";
var rowHtml = "";
for (var x = layout.length - 1; x >= 0; x--){
var cellWrapper = "<div onmouseover='playerSpire.checkDragTraps(" + x + ", event)' onmousedown='playerSpire.buildTrap(\"" + x + "\")' id='playerSpireCell" + x + "' class='noselect playerSpireCell'";
cellWrapper += " style='";
cellWrapper += this.getSetTrapBgColor(x);
cellWrapper += "'><span id='playerSpireCell" + x + "enemy'>"
var iconText = "";
if (this.settings.trapIcons){
iconText = "<span id='spireTrapIcon" + x + "' class='spireTrapIcon'>"
if (layout[x].trap.name)
iconText += this.getTrapIcon(x);
iconText += "</span>"
}
rowHtml = cellWrapper + this.getEnemyHtml(x) + "</span>" + iconText + "</div>" + rowHtml;
if (x % 5 == 0){
layoutHtml += rowHtml;
rowHtml = "";
}
}
var tutorialHeight = 84 - (playerSpire.rowsAllowed * 4.5);
if (usingScreenReader) layoutHtml += "<h1>Spire Defense Story/Quest</h1>"
layoutHtml += "<div id='playerSpireTutorial' style='height: " + tutorialHeight + "vh' class='niceScroll'>" + this.updateTutorial(true) + "</div>"
document.getElementById("playerSpireSpireSpirePanel").innerHTML = layoutHtml;
},
updateTutorial: function(textOnly){
var elem = document.getElementById('playerSpireTutorial');
if (!elem || this.tutorialStep >= 8) return "";
var currentStep = this.tutorialStep;
switch(currentStep){
case 0:
if (this.layout[0].trap.name == "Frost" && this.layout[1].trap.name == "Fire"){
this.tutorialStep++;
}
break;
case 1:
if (playerSpireTraps.Frost.owned + playerSpireTraps.Fire.owned >= 5){
this.tutorialStep++;
playerSpireTraps.Strength.locked = false;
this.addRow(true);
}
break;
case 2:
if (this.difficulty >= 300){
this.tutorialStep++;
this.addRow(true);
}