forked from Trimps/Trimps.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playerSpire.js
2118 lines (2087 loc) · 103 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,
settings: {
fctTrap: true,
fctPoison: true,
fctRs: true,
fctStatic: false,
chillGradient: true,
enemyIcons: true,
trapIcons: true,
shockEffect: true,
percentHealth: 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,
}
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 += "</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 >= 1e6) 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;
var upgrade = trapObj.upgrades[trapObj.level - 1];
if (this.runestones < upgrade.cost) return;
if (game.global.highestLevelCleared + 1 < upgrade.unlockAt) return;
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();
},
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)};
},
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'>";
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;
},
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);
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);
}
break;
case 3:
if (this.difficulty >= 400 && this.spirestones >= 20){
this.tutorialStep++;
this.addRow();
}
break;
case 4:
if (playerSpireTraps.Frost.level >= 2){
this.tutorialStep++;
}
break;
case 5:
if (playerSpireTraps.Poison.locked && game.global.spiresCompleted >= 2) {
playerSpireTraps.Poison.locked = false;
playerSpireTraps.Condenser.locked = false;
this.drawInfo();
}
if (this.rowsAllowed >= 6 && game.global.spiresCompleted >= 2){
this.tutorialStep++;
}
break;
case 6:
if (playerSpireTraps.Lightning.locked && game.global.spiresCompleted >= 3) {
playerSpireTraps.Lightning.locked = false;
playerSpireTraps.Knowledge.locked = false;
this.drawInfo();
}
if (this.rowsAllowed >= 11 && game.global.spiresCompleted >= 3){
this.tutorialStep++;
}
break;
case 7:
if (this.rowsAllowed >= 13){
this.tutorialStep++;
}
break;
default:
break;
}
if (currentStep != this.tutorialStep){
this.drawInfo();
this.drawSpire();
}
var tutorialSteps = [
"<p>Welcome to your Spire! You've killed Druopitee and stolen some Spirestones: ancient construction materials that duplicate themselves across dimensions, traditionally used to create powerful Spires. Druopitee thought that he was the only one who could build tall buildings, but you're on a mission to prove him wrong!</p><p>You were able to finish constructing the first Floor of your very own Spire with the Spirestones you found, and you still have a few left over to try to make it even taller. You had your Trimps build a wall around the entire town, making your new Spire the only entrance and exit point. You feel super safe for a few seconds, and your Trimps are super stoked on their new fortress.</p><p>After those few seconds are up, you see that the Spire is attracting a decent amount of unwanted attention from jealous enemies, who seem to take your Spire as a challenge.</p><p>Luckily, your Scientists have managed to come up with a few Trap designs that can hopefully stop the flow of enemies into your town.</p><p class='spireQuest'>Try placing a Frost Trap in the leftmost cell of your Spire, and a Fire Trap directly to the right of it.</p>",
"<p>Perfect, everything seems to be working just as your Scientists explained. The Frost Trap slows the enemies down, and the Fire Trap finishes them off.</p><p>Unfortunately, it seems like each enemy you kill in here makes your Spire a more important target, causing stronger and stronger enemies to come through.</p><p>Fortunately though, your Magical Spire Traps convert Bad Guys into a new type of resource whenever they kill one, which your Scientists call 'Runestones'. Even more fortunately, larger enemies with more Max Health convert into larger amounts of Runestones! As your Spire's Threat increases, so will your Runestones per second, and so will your Spire's defenses (if you're doing your job).</p><p style='text-decoration: underline'>You don't have to stay here while Runestones build up, you can go back to leading your Trimps while your Traps do some work. The enchanted Spirestones copy your progress to all possible dimensions, so you won't even lose your Traps if you Portal!</p><p class='spireQuest'>Keep an eye on your Runestones, and add more Traps whenever you can. Try to fill this entire Floor with Traps!</p>",
"<p>You're a natural Spiarchitect! Your Scientists have finally finished adding the second Floor of your Spire, and the added height seems to be attracting even more enemies. Cool, more Runestones for you! You're starting to really like the idea of enemies constantly climbing to their demise in the teeth of your Traps.</p><p>While you're appreciating your deadly handiwork, a small group of Scientists runs up to you and shares some new research. They say that the Runestones can also be used to create mini-towers that broadcast their energy to all Trimps in the World. Wasting no time, they hand you the schematics for the Strength Tower, which increases the effect of all Fire Traps on its Floor, and grants all of your Trimps an attack bonus.</p><p class='spireQuest'>Continue placing more Traps and Towers to fill out your Spire, and raise your Threat level to 300.</p>",
"<p>Beautiful. It seems like you're getting the hang of this!</p><p>You've finished constructing the third Floor of your Spire, but it seems as if you've used up your entire intial supply of Spirestones. You'll need to clear a Spire and crush its Core to earn more! Note that you'll find considerably better Cores worth more Spirestones from more difficult Spires.</p><p class='spireQuest'>Collect 20 Spirestones and raise your Spire's Threat to 400 to build your fourth Floor.</p>",
"<p>It's getting huge! However, the Traps are getting more expensive as you place more and more of them. At this rate you'll never be able to afford enough Strength Towers to make a huge impact on your Trimps.</p><p>You consult with your Scientists, who tell you that they can create upgrades for your Traps, but that they need to study corpses of high level enemies in order to exploit their weaknesses.</p><p class='spireQuest'>Raise your Highest Zone Reached to Z230, and upgrade your Frost Trap.</p>",
"<p>Wow, look at that thing slow!</p><p>You seem to have a pretty decent understanding of how to manage your Spire, and I believe you can handle it on your own for a while. Continue to raise your HZE to unlock more upgrades, collect Spirestones to add more Floors and enemies, and tweak your Trap layout every once in a while to make sure you're getting as many Runestones as you can, you'll definitely need them later.</p><p>Your Scientists let you know that they can possibly forge a new Trap and Tower, but they need to study a Core from a higher level Spire first.</p><p class='spireQuest'>Complete Spire II to unlock Poison Trap and Condenser Tower! Once you have your new Traps, raise your Spire's Threat to 600 and build your sixth Floor.<br/><br/>Remember that you have to satisfy both the Threat and Spirestone requirements to add a new Floor!</p>",
"<p>You've got a new Trap and Tower, your Spire is still growing, and your power is growing with it! Your Trimps are slightly annoyed that they have to clean up the occasional Bad Guy that makes it through the Spire and into the town, but they can handle it. They all agree that life in general is just more fun when there's a giant Spire grinding Bad Guys at the entrance to their town.</p><p>While you're feeling comfortable maintaining your Spire's defenses with the tools you have, you still feel like there's something missing. Your Scientists say that they could perhaps create one more Trap and Tower, but again they'll need to study a Core from an even higher Spire.</p><p class='spireQuest'>Clear Spire III to unlock the Lightning Trap and Knowledge Tower, then raise your Spire's Threat to 1100 and build your eleventh Floor.</p>",
"<p>And that's about all there is to teach you! The rest of the management of your Spire is left in your more-than-capable hands.</p><p>Raise your HZE, clear Spires, buy upgrades, build Floors, and come up with the perfect layout for your Spire.</p><p class='spireQuest'>I'll hang out and make sure everything's OK until you reach Threat level 1300 and build your thirteenth Floor, and then you'll be on your own.</p>"
];
var text = (this.tutorialStep < 8) ? tutorialSteps[this.tutorialStep] : "";
if (textOnly) return text;
elem.innerHTML = text;
},
getSetTrapBgColor: function(cellNumber, elem){
//Elem is optional, will set on the element instead of getting html
var trap = this.layout[cellNumber].trap;
var bgColor = trap.name ? playerSpireTraps[trap.name].color : "#000";
var layout = this.layout;
var dblPoisonColor = "";
if (playerSpireTraps.Poison.level >= 3 && trap.name == "Poison"){
var dblPoisonCount = 0;
if (cellNumber > 0 && this.layout[cellNumber - 1].trap.name == "Poison") dblPoisonCount++;
if (cellNumber + 1 < this.layout.length && this.layout[cellNumber + 1].trap.name == "Poison") dblPoisonCount++;
var barColor = "#012b13";
if (dblPoisonCount > 0){
dblPoisonColor = "linear-gradient(" + barColor + " 20%, " + bgColor + " 20%";
if (dblPoisonCount == 2) dblPoisonColor += ", " + bgColor + " 30%, " + barColor + " 30%, " + barColor + " 50%, " + bgColor + " 50%";
dblPoisonColor += ")";
}
}
var secondGradient = "";
var lightStacks = (playerSpireTraps.Lightning.level >= 4) ? this.lightColumns[this.getColFromCell(cellNumber)] : 0;
if (lightStacks && (trap.name == "Poison" || trap.name == "Fire")){
var pct = (100 - (lightStacks * 2)) + "%";
secondGradient = "linear-gradient(to right, rgba(0,0,0,0) " + pct + ", " + playerSpireTraps.Lightning.color + " " + pct + ")";
}
if ((!trap.name || trap.name == "Fire") && this.strengthLocations.indexOf(this.getRowFromCell(cellNumber)) != -1){
var setting = (trap.name) ? "linear-gradient(#7F0505, #630202 75%, #684112 75%)" : "linear-gradient(#000 75%, #684112 75%)";
if (secondGradient) setting = secondGradient + ", " + setting;
if (elem) elem.style.backgroundImage = setting;
else return "background-image: " + setting;
}
else if (playerSpireTraps.Frost.level >= 4 && (!trap.name || trap.name == "Poison") && layout.length > cellNumber + 1 && playerSpire.layout[cellNumber + 1].trap.name && playerSpire.layout[cellNumber + 1].trap.name == "Frost"){
var setting = "linear-gradient(";
if (dblPoisonColor) setting = dblPoisonColor.substring(0, dblPoisonColor.length - 1) + ", ";
setting += bgColor + " 73%, " + playerSpireTraps.Frost.color + " 73%)";
if (secondGradient) setting = secondGradient + ", " + setting;
if (elem) elem.style.backgroundImage = setting;
else return "background-image: " + setting;
}
else if (dblPoisonColor){
if (secondGradient) dblPoisonColor = secondGradient + ", " + dblPoisonColor;
if (elem) elem.style.backgroundImage = dblPoisonColor;
else return "background-image: " + dblPoisonColor;
}
else if (secondGradient){
secondGradient = secondGradient.replace("rgba(0,0,0,0)", bgColor);
if (elem) elem.style.backgroundImage = secondGradient;
else return "background-image: " + secondGradient;
}
else if (elem){
elem.style.backgroundColor = bgColor;
elem.style.backgroundImage = "none";
}
else return "background-color: " + bgColor;
},
getEnemyHtml: function(cellNumber){
var cell = this.layout[cellNumber];
var color = "";
var iconColor = "#000";
if (cell.occupiedBy.dead){
color = "#350e0d";
}
else if (!cell.occupiedBy.name) return "";
else {
var healthPct = Math.ceil(cell.occupiedBy.health / cell.occupiedBy.maxHealth * 100);
color = "#009681";
iconColor = "#42f1d9";
if (healthPct <= 20){
color = "#541411";
iconColor = "#ec352c";
}
else if (healthPct <= 50){
color = "#861d18";
iconColor = "#ff584f";
}
else if (healthPct < 75){
color = "#b55b1b";
iconColor = "#fb9b57"
}
}
var cellHtml = "<span ";
var cellClass = "playerSpireEnemy";
if (cell.occupiedBy.slowedFor && this.settings.chillGradient){
var pct = cell.occupiedBy.slowedFor * 10;
var freezeColor = cell.occupiedBy.slowMod == 1 ? playerSpireTraps.Frost.color : playerSpireTraps.Knowledge.color;
var gradient = freezeColor + " 0%, ";
var lastPct = 0;
if (pct > 100) pct = 100;
var bars = Math.floor(pct / 10);
var borderColor = cell.occupiedBy.slowMod == 1 ? "#0470CE" : "#7e4fd4";
for (var x = 0; x < bars; x++){
//if (x != 0) gradient += freezeColor + " " + lastPct + "%, ";
lastPct += 10;
gradient += borderColor + " " + (lastPct) + "%";
if (x != 9) gradient += ", " + freezeColor + " " + (lastPct) + "%, "
}
if (bars != 10) gradient += color + " " + lastPct + "%";
cellHtml += "style='background-image: linear-gradient(to right, " + gradient + ");";
}
else cellHtml += "style='background-color: " + color + ";";
if (this.settings.shockEffect && cell.occupiedBy.shockTurns != null && cell.occupiedBy.shockTurns >= 0) cellClass += " shocked"
var innerText = (cell.occupiedBy.dead) ? "<span class='icomoon icon-skeletor'></span>" : ((this.settings.percentHealth) ? prettify((cell.occupiedBy.health / cell.occupiedBy.maxHealth) * 100) + "%" : prettify(cell.occupiedBy.health));
innerText = "<span class='playerSpireEnemyText'>" + innerText + "</span>";
if (cell.occupiedBy.name && this.settings.enemyIcons){
innerText += "<span class='icomoon icon-" + cell.occupiedBy.name + " spireUniqueIcon' style='color: " + iconColor + "'></span>"
}
cellHtml += "' class='" + cellClass + "'>" + innerText + "</span>";
return cellHtml;
},
checkDragTraps: function(cell, event){
if (event.buttons) this.buildTrap(cell);
},
drawSpireCell: function(cellNumber){
if (!this.popupOpen) return;
var elem = document.getElementById('playerSpireCell' + cellNumber);
if (!elem) return;
this.drawTrapIcon(cellNumber);
this.getSetTrapBgColor(cellNumber, elem);
this.drawEnemy(cellNumber);
},
getTrapIcon: function(cellNumber){
var trap = this.layout[cellNumber].trap;
if (!trap.name) return "";
var trapIcon = "icomoon icon-" + playerSpireTraps[trap.name].icon;
return "<span class='" + trapIcon + "'></span>";
},
drawTrapIcon: function(cellNumber){
if (!this.settings.trapIcons) return;
var elem = document.getElementById('spireTrapIcon' + cellNumber);
if (!elem) return;
elem.innerHTML = this.getTrapIcon(cellNumber);
},
drawEnemy: function(cellNumber){
if (!this.popupOpen) return;
var elem = document.getElementById('playerSpireCell' + cellNumber + 'enemy');
if (!elem) return;
elem.innerHTML = this.getEnemyHtml(cellNumber);
},
getThreatChange: function(isKill, enemy, location){
var base = 2;
if (!isKill){
var healthPct = Math.ceil((enemy.health / enemy.maxHealth) / 0.15);
base *= healthPct;
}
else{
if (this.killedSinceLeak > 100) base *= 2;
if (this.killedSinceLeak > 250) base *= 2;
if (this.difficultyHidden > 300){
var row = this.getRowFromCell(location);
row = (this.rowsAllowed - row + 1) / this.rowsAllowed;
base *= row;
}
else base *= 0.5;
}
var enemyMod = 1 / (this.currentEnemies / 5);
if (enemyMod > 1) enemyMod = 1;
base *= enemyMod;
//console.log(((isKill) ? "kill" : "leak"), prettify(enemy.health / enemy.maxHealth * 100), location, base);
return base;
},
enemyEscaped: function(enemy, location, catchingUp){
this.currentEnemies--;
this.updateEnemyCount();
this.escapees++;
this.killedSinceLeak = 0;
if (enemy.toxicity > 0 && playerSpireTraps.Poison.level >= 6){
var toxReward = enemy.toxicity * 0.1;
toxReward = calcHeirloomBonus("Core", "runestones", toxReward);
this.rewardRunestones(toxReward);
if (!catchingUp && this.settings.fctRs)
TDFloatingText.spawnFloatingText(location, playerSpireTraps.Poison.color, -0.05, 3.5, "+ " + prettify(toxReward) + " Rs");
}
this.difficultyHidden -= this.getThreatChange(false, enemy, location);
if (this.difficultyHidden < 1) this.difficultyHidden = 1;
if (this.difficultyHidden < this.difficulty)
this.difficulty += ((this.difficultyHidden - this.difficulty) / 10);
if (this.difficulty < 1) this.difficulty = 1;
this.updateKills();
},
getRsReward: function(enemy, rsBonus){
var reward = Math.ceil(enemy.maxHealth / 600);
if (enemy.threat){
reward += enemy.threat / 20;
reward *= Math.pow(1.00116, enemy.threat);
}
if (rsBonus > 0){