-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreens.js
1655 lines (1544 loc) · 75.8 KB
/
screens.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
Game.Screen = {};
// Define our initial start screen
Game.Screen.startScreen = {
enter: function() {console.log("Entered start screen."); },
exit: function() { console.log("Exited start screen."); },
render: function(display) {
// Render our prompt to the screen
display.drawText(1,1, "%c{yellow}Headless Panic");
display.drawText(1,3, "%c{white}Betrayed. Beheaded. Thrown into the ancient cellars below the castle.");
display.drawText(1,4, "%c{white}You pick your head up, put it on your neck, and try to get your bearings.");
display.drawText(1,6, "%c{white}Press %c{yellow}[Enter] %c{white}to start!");
},
handleInput: function(inputType, inputData) {
// When [Enter] is pressed, go to the play screen
if (inputType === 'keydown') {
if (inputData.keyCode === ROT.KEYS.VK_RETURN || inputData.keyCode === ROT.KEYS.VK_SPACE) {
Game.switchScreen(Game.Screen.playScreen);
}
}
}
}
// Define our playing screen
Game.Screen.playScreen = {
_map: null,
_player: null,
_gameEnded: false,
_subScreen: null,
_lastTarget: null,
_altarPosition: {},
alreadyGotList: [],
deathInfo: {
strength: 1,
maxHP: 40,
level: 1,
weapon: 0,
armor: 0
},
turnCount: 0,
turnsOnThisFloorCount: 0,
hasSpawnedDeath: false,
goldCount: 0,
enter: function() {
var width = Game._screenWidth;
var height = Game._screenHeight;
// Create our map from tiles and player
let builder = new Game.Builder(width,height, Game.getLevel())
let tiles = builder.getTiles()
let gasMap = builder.makeEmptyGasMap();
let rooms = builder.getRooms();
let stairs = builder.getStairs();
this._player = new Game.Entity(Game.PlayerTemplate);
//starting player equipment
var startingHead = Game.ItemRepository.create('head', {
name: 'chicken head',
foreground: '#fff'
});
this._player.addItem(startingHead);
this._player.wearHead(startingHead);
var dart = Game.ItemRepository.create('dart');
this._player.addItem(dart);
var dart = Game.ItemRepository.create('dart');
this._player.addItem(dart);
var dart = Game.ItemRepository.create('dart');
this._player.addItem(dart);
var dart = Game.ItemRepository.create('dart');
this._player.addItem(dart);
var dart = Game.ItemRepository.create('dart');
this._player.addItem(dart);
var dart = Game.ItemRepository.create('dart');
this._player.addItem(dart);
var dart = Game.ItemRepository.create('dart');
this._player.addItem(dart);
var dart = Game.ItemRepository.create('dart');
this._player.addItem(dart);
//Create map
this._map = new Game.Map(tiles, this._player, null, stairs, gasMap);
if (Game.getLevel() <= 6){
this._map.putGoldInBoringRooms(rooms);
//this._map.getRidOfBoringRooms(rooms);
//TODO turning this off because it clears rooms after prefabs are generated,
//and it there's an overlap, you might have an orphanned prefab that the player can spawn in.
}
this._map.cleanUpDoors();
// Start the map's engine
this._map.getEngine().start();
},
exit: function() { console.log("Exited play screen."); },
render: function(display) {
if (this._subScreen) {
this._subScreen.render(display);
return;
}
var screenWidth = Game.getScreenWidth();
var screenHeight = Game.getScreenHeight();
// Render the tiles
this.renderTiles(display);
this.renderTelegraphs(display);
// Get the messages in the player's queue and render them
var messages = this._player.getMessages();
var messageY = screenHeight + 4;
for (var i = 0; i < 4; i++) {
// Draw each message, adding the number of lines
if (messages[i] !== undefined){
messageY -= display.drawText(
0,
messageY,
'%c{white}%b{black}' + messages[i]
);
}
}
// Render UI
display.drawText(0, screenHeight, "%c{yellow}I%c{white}nventory %c{yellow}L%c{white}ook %c{yellow}W%c{white}ait %c{yellow}T%c{white}hrow %c{yellow}E%c{white}quip %c{yellow}A%c{white}pply %c{yellow}D%c{white}rop %c{white}e%c{yellow}X%c{white}plore");
var you = '%c{white}%b{black}';
you += "@: You";
display.drawText(screenWidth + 1, 0, you);
var playerHealth = this._player.getHP()/this._player.getMaxHP();
var healthUIColor = (playerHealth > 0.66) ? "%c{white}" : ((playerHealth > 0.33) ? "%c{yellow}" : "%c{red}");
var healthString = "%c{white}%b{black}HP: " + healthUIColor + this._player.getHP() + "/" + this._player.getMaxHP();
var currentHead = this._player.getHead();
if (currentHead !== null){
display.drawText(screenWidth + 1, 2, "%c{white}HEAD: " + "%c{" + currentHead._foreground + "}"+ currentHead.getName());
var numberOfHeadHits = currentHead.getHeadHits();
for (var h = 0; h < numberOfHeadHits; h++){
healthString += " \u2665";
}
} else {
display.drawText(screenWidth + 1, 2, "HEAD: " + "%c{red}NONE");
}
//Finally, draw the health string on the prior line
display.drawText(screenWidth + 1, 1, healthString);
//Draw the effects for the player
var effectsList = this._player.getEffects();
var effectsString = '';
for (effect of effectsList){
var effectsString = effectsString + '%c{' + effect._color + '}' + effect.getName() + ' ';
}
display.drawText(screenWidth + 1, 3, effectsString);
let strengthGap = 0;
let strengthModifier = 0;
let damageType = 'crush';
let strengthValue = this._player.getStrengthValue();
let attackValue = this._player.getAttackValue();
let defenseValue = this._player.getDefenseValue();
let levelName = this.getLevelName();
if (this._player.getWeapon() !== null){
damageType = this._player.getWeapon().getDamageType();
strengthGap = strengthValue - this._player.getWeapon().getStrengthRequirement();
if (strengthGap < 0){
strengthModifier = 4 * strengthGap;
} else if (strengthGap > 0){
strengthModifier = strengthGap;
}
}
const isProtected = this._player.hasEffect('protected');
const isVulnerable = this._player.hasEffect('vulnerable');
if (isVulnerable) {
display.drawText(screenWidth + 1, 5, "%c{white}ARMR: " + "%c{" + Game.Colors.lichColor + "}" + "+" + defenseValue);
} else if (isProtected) {
display.drawText(screenWidth + 1, 5, "%c{white}ARMR: " + "%c{" + Game.Colors.effectDefault + "}" + "+" + defenseValue);
} else {
display.drawText(screenWidth + 1, 5, "%c{white}ARMR: +" + defenseValue);
}
display.drawText(screenWidth + 1, 6, "%c{white}DMG: +" + (attackValue + strengthModifier) + ' ' + damageType);
display.drawText(screenWidth + 1, 7, "%c{white}STRN: " + strengthValue);
display.drawText(screenWidth + 1, 8, "%c{white}LVL: " + levelName );
display.drawText(screenWidth + 1, 9, "%c{white}GOLD: " + Game.Screen.playScreen.goldCount);
},
renderTelegraphs: function(display){
// Draw a line from the start to the cursor.
let entities = this._player.getMap().getEntities();
let aimingEntities = []
for (let key in entities) {
let entity = entities[key];
if (entity._aiming === true){
aimingEntities.push(entity);
}
}
for (aimingEntity of aimingEntities){
let points = Game.Geometry.getLine(aimingEntity.getX(), aimingEntity.getY(), this._player.getX(), this._player.getY());
let foregroundColor = "#333333";
let character = "?";
let map = this._player.getMap();
let visibleCells = {};
this._player.getMap().getFov().compute(this._player.getX(), this._player.getY(), this._player.getSightRadius(),
function(x, y, radius, visibility) {
visibleCells[x + "," + y] = true;
});
// Render yellow along the line.
for (let i = 0, l = points.length; i < l; i++) {
let x = points[i].x
let y = points[i].y
// If the tile is explored, we can give a better tile image
if (map.isExplored(x, y)) {
// If the tile isn't explored, we have to check if we can actually see it before testing if there's an entity or item.
if (visibleCells[x + ',' + y]) {
var items = map.getItemsAt(x, y);
// Check if there's an entity
if (map.getEntityAt(x, y)) {
var entity = map.getEntityAt(x, y);
foregroundColor = entity.getForeground();
character = entity.getChar();
} else if (items) {
// Else if we have items, we want to render the top most item
var item = items[items.length - 1];
foregroundColor = item.getForeground();
character = item.getChar();
} else {
// If there was no entity/item or the tile wasn't visible, then use
// the tile information.
var tile = map.getTile(x, y)
foregroundColor = tile.getForeground();
character = tile.getChar();
}
} else {
//if tile is explored but not visible, check for items, otherwise use tile
var items = map.getItemsAt(x, y);
if (items) {
var item = items[items.length - 1];
foregroundColor = item.getForeground();
character = item.getChar();
// Else get tile info
} else {
var tile = map.getTile(x, y)
foregroundColor = tile.getForeground();
character = tile.getChar();
}
}
} else {
// If the tile is not explored, show no new info to user.
foregroundColor = "#333333";
character = "?";
}
//var tile = this._player.getMap().getTile(x,y)
display.drawText(x, y, '%c{' + foregroundColor + '}%b{#5B2F37}' + character);
}
}
},
handleInput: function(inputType, inputData, invokedManually) {
// If the game is over, enter will bring the user to the losing screen.
if (this._gameEnded) {
if (inputType === 'keydown' && inputData.keyCode === ROT.KEYS.VK_RETURN) {
Game.Screen.playScreen.deathInfo.maxHP = this._player.getMaxHP();
Game.Screen.playScreen.deathInfo.murderer = this._player.murderer;
let strengthGap = 0;
let strengthModifier = 0;
let damageType = 'crush';
let strengthValue = this._player.getStrengthValue();
let attackValue = this._player.getAttackValue();
let defenseValue = this._player.getDefenseValue();
if (this._player.getWeapon() !== null){
damageType = this._player.getWeapon().getDamageType();
strengthGap = strengthValue - this._player.getWeapon().getStrengthRequirement();
if (strengthGap < 0){
strengthModifier = 4 * strengthGap;
} else if (strengthGap > 0){
strengthModifier = strengthGap;
}
}
Game.Screen.playScreen.deathInfo.level = Game.getLevel();
Game.Screen.playScreen.deathInfo.strength = strengthValue;
Game.Screen.playScreen.deathInfo.armor = defenseValue;
Game.Screen.playScreen.deathInfo.weapon = ((attackValue + strengthModifier) + ' ' + damageType);
Game.switchScreen(Game.Screen.loseScreen);
}
// Return to make sure the user can't still play
return;
}
// Handle subscreen input if there is one
if (this._subScreen) {
this._subScreen.handleInput(inputType, inputData);
return;
}
this._player._hasNotMovedThisTurn = true;
if (inputType === 'keydown') {
// Movement
if (inputData.keyCode === ROT.KEYS.VK_LEFT) {
if (!this._player.hasEffect('paralyzed')){
this.move(-1, 0);
this.handleItemPickup();
this.goDownStairs();
this._player.setPathingTarget(null);
} else {
Game.sendMessage(this._player, "You are paralyzed!");
}
} else if (inputData.keyCode === ROT.KEYS.VK_RIGHT) {
if (!this._player.hasEffect('paralyzed')){
this.move(1, 0);
this.handleItemPickup();
this.goDownStairs();
this._player.setPathingTarget(null);
} else {
Game.sendMessage(this._player, "You are paralyzed!");
}
} else if (inputData.keyCode === ROT.KEYS.VK_UP) {
if (!this._player.hasEffect('paralyzed')){
this.move(0, -1);
this.handleItemPickup();
this.goDownStairs();
this._player.setPathingTarget(null);
} else {
Game.sendMessage(this._player, "You are paralyzed!");
}
} else if (inputData.keyCode === ROT.KEYS.VK_DOWN) {
if (!this._player.hasEffect('paralyzed')){
this.move(0, 1);
this.handleItemPickup();
this.goDownStairs();
this._player.setPathingTarget(null);
} else {
Game.sendMessage(this._player, "You are paralyzed!");
}
} else if (inputData.keyCode === ROT.KEYS.VK_I) {
if (this._player.getItems().filter(function(x){return x;}).length === 0) {
// If the player has no items, send a message and don't take a turn
Game.sendMessage(this._player, "You are not carrying anything!");
Game.refresh();
} else {
// Show the inventory
Game.Screen.inventoryScreen.setup(this._player, this._player.getItems());
this.setSubScreen(Game.Screen.inventoryScreen);
}
return;
} else if (inputData.keyCode === ROT.KEYS.VK_D) {
if (this._player.getItems().filter(function(x){return x;}).length === 0) {
// If the player has no items, send a message and don't take a turn
Game.sendMessage(this._player, "You have nothing to drop!");
Game.refresh();
} else {
// Show the drop screen
Game.Screen.dropScreen.setup(this._player, this._player.getItems());
this.setSubScreen(Game.Screen.dropScreen);
}
return;
} else if (inputData.keyCode === ROT.KEYS.VK_A) {
// Show the apply screen
if (Game.Screen.applyScreen.setup(this._player, this._player.getItems())) {
this.setSubScreen(Game.Screen.applyScreen);
} else {
Game.sendMessage(this._player, "You have nothing to apply!");
Game.refresh();
}
return;
} else if (inputData.keyCode === ROT.KEYS.VK_E) {
// Show the equip screen
if (Game.Screen.equipScreen.setup(this._player, this._player.getItems())) {
this.setSubScreen(Game.Screen.equipScreen);
} else {
Game.sendMessage(this._player, "You have nothing to equip!");
Game.refresh();
}
return;
} else if (inputData.keyCode === ROT.KEYS.VK_T) {
// Show the equip screen
if (Game.Screen.throwScreen.setup(this._player, this._player.getItems())) {
this.setSubScreen(Game.Screen.throwScreen);
} else {
Game.sendMessage(this._player, "You have nothing to throw!");
Game.refresh();
}
return;
} else if (inputData.keyCode === ROT.KEYS.VK_L) {
// Setup the look screen.
Game.Screen.lookScreen.setup(this._player, this._player.getX(), this._player.getY());
this.setSubScreen(Game.Screen.lookScreen);
return;
} else if (inputData.keyCode === ROT.KEYS.VK_X) {
let pathingTargets = [];
let player = this._player;
let map = this._map;
let target = {};
let noMoreUnexplored = false;
//let's check to make sure this cell is still unexplored
//this way, we don't have to reach the cell if we've seen it on the way there
if (player.getPathingTarget()){
if(map.isExplored(player.getPathingTarget().x, player.getPathingTarget().y)){
player.setPathingTarget(null);
}
}
// Find an unexplored square
if (player.getPathingTarget() === null){
if (invokedManually === false){
//we've hit our target in an auto-loop. Break out of the recursive function
return;
}
// if we've manually pressed explore and we have no target, find a new target
for (let x = 1; x < map.getWidth() - 1; x++) {
for (let y = 1; y < map.getHeight() - 1; y++) {
if (!map.isExplored(x, y)) {
pathingTargets.push({
x: x,
y: y
});
}
}
}
let sortedPathingTargets = map.sortByDistance(player.getX(), player.getY(), pathingTargets);
//find the closest reachable target
for (sortedTarget of sortedPathingTargets){
//try A*ing there
let path = new ROT.Path.AStar(sortedTarget.x, sortedTarget.y, function(in_x, in_y) {
let tile = map.getTile(in_x, in_y);
return tile.isWalkable() && !tile._isHazard && tile !== Game.Tile.stairsDownTile;
}, {topology: 4});
path.compute(player.getX(), player.getY(), function(x, y) {});
//If we can get there, go to it
if(path._todo.length > 0){
target = {
x: sortedTarget.x,
y: sortedTarget.y
};
break;
}
}
//as long as there's still an unexplored tile we can reach...
if (Object.keys(target).length === 0 && target.constructor === Object){
noMoreUnexplored = true;
} else {
//Make a path to it
player.setPathingTarget(target);
//console.log(target);
}
}
if (!noMoreUnexplored){
let path = new ROT.Path.AStar(player.getPathingTarget().x, player.getPathingTarget().y, function(x, y) {
let tile = map.getTile(x, y);
return tile.isWalkable() && !tile._isHazard && tile !== Game.Tile.stairsDownTile;
}, {topology: 4});
//console.log(path);
// Once we've gotten the path, we want to move to the second cell that is passed in the callback (the first is the entity's starting point)
let count = 0;
let handleItemPickupContext = this.handleItemPickup.bind(Game.Screen.playScreen);
let goDownStairsContext = this.goDownStairs.bind(Game.Screen.playScreen);
path.compute(player.getX(), player.getY(), function(x, y) {
if (count == 1) {
if (!player.hasEffect('paralyzed')){
player.tryMove(x, y);
handleItemPickupContext()
goDownStairsContext();
} else {
Game.sendMessage(this._player, "You are paralyzed!");
}
}
count++;
});
if (path._todo.length === 0){
player.setPathingTarget(null);
}
} else {
//if there are no more unexplored, start going to the stairs
let nextToStairs = map.getWalkableByStairs()
//console.log(map._stairs);
//console.log(nextToStairs)
let path = new ROT.Path.AStar(nextToStairs[0].x, nextToStairs[0].y, function(x, y) {
let tile = map.getTile(x, y);
return tile.isWalkable() && !tile._isHazard && tile !== Game.Tile.stairsDownTile;
}, {topology: 4});
let count = 0;
let handleItemPickupContext = this.handleItemPickup.bind(Game.Screen.playScreen);
let goDownStairsContext = this.goDownStairs.bind(Game.Screen.playScreen);
path.compute(player.getX(), player.getY(), function(x, y) {
if (count == 1) {
if (!player.hasEffect('paralyzed')){
player.tryMove(x, y);
handleItemPickupContext()
goDownStairsContext();
} else {
Game.sendMessage(this._player, "You are paralyzed!");
}
}
count++;
});
if (path._todo.length !== 0){
player.setPathingTarget(nextToStairs[0]);
}
}
}
// Unlock the engine
this._map.getEngine().unlock();
if (this._player.getPathingTarget()){
let currentHead = this._player.getHead();
if (currentHead !== null && inputData.keyCode === ROT.KEYS.VK_X && !this._map.areHunters()){
let thisReference = this;
let canSeeMonster = false;
this._map.getFov().compute(
this._player.getX(), this._player.getY(),
this._player.getSightRadius(),
function(x, y, radius, visibility) {
let key = x + ',' + y;
if (thisReference._map.getEntities()[key] !== undefined && (!thisReference._map.getEntities()[key].isNotMonster()) && thisReference._map.getEntities()[key].getName() !== 'chicken knight') {
//console.log(thisReference._map.getEntities()[key]);
canSeeMonster = true;
}
}
);
if (!canSeeMonster){
let artificialInputData = {}
artificialInputData.keyCode = ROT.KEYS.VK_X
Game.sleep(30).then(() => { this.handleInput('keydown', artificialInputData, false) });
}
}
}
this.turnCount++;
this.turnsOnThisFloorCount++;
if (this.turnsOnThisFloorCount > (Game._screenWidth * Game._screenHeight * .2605) && this.hasSpawnedDeath === false){
this._map.addEntityAtDistantPosition(Game.EntityRepository.create("death"), this._player.getX(), this._player.getY(), 1);
this.hasSpawnedDeath = true;
Game.sendMessage(this._player, "%c{#F61067}--DEATH COMES FOR WHAT'S HERS--");
}
} else {
// Not a valid key
return;
}
},
setGameEnded: function(gameEnded) {
this._gameEnded = gameEnded;
},
move: function(dX, dY) {
var newX = this._player.getX() + dX;
var newY = this._player.getY() + dY;
this.handleAltarUse(newX,newY);
// Try to move to the new cell
this._player.tryMove(newX, newY);
},
handleAltarUse: function(altarX, altarY) {
let map = this._map;
if (map.getTiles()[altarX][altarY] === Game.Tile.altarTile){
if (Game.Screen.altarScreen.setup(this._player, this._player.getItems())) {
this._altarPosition = {x: altarX, y: altarY};
this.setSubScreen(Game.Screen.altarScreen);
} else {
Game.sendMessage(this._player, "You have nothing to put on the altar.");
}
}
},
setSubScreen: function(subScreen) {
this._subScreen = subScreen;
// Refresh screen on changing the subscreen
Game.refresh();
},
goDownStairs(){
let playerX = this._player.getX();
let playerY = this._player.getY();
let tile = this._map.getTile(playerX, playerY);
let items = this._player.getItems()
let playerHasKey = false;
for (let item of items){
if (item !== undefined && item !== null){
if (item.describe() === 'key'){
playerHasKey = true;
}
}
}
if (tile === Game.Tile.stairsDownTile || tile === Game.Tile.stairsDownTileLocked && playerHasKey){
if (Game.getLevel() === 15){
Game.Screen.playScreen.deathInfo.maxHP = this._player.getMaxHP();
Game.Screen.playScreen.deathInfo.murderer = this._player.murderer;
let strengthGap = 0;
let strengthModifier = 0;
let damageType = 'crush';
let strengthValue = this._player.getStrengthValue();
let attackValue = this._player.getAttackValue();
let defenseValue = this._player.getDefenseValue();
if (this._player.getWeapon() !== null){
damageType = this._player.getWeapon().getDamageType();
strengthGap = strengthValue - this._player.getWeapon().getStrengthRequirement();
if (strengthGap < 0){
strengthModifier = 4 * strengthGap;
} else if (strengthGap > 0){
strengthModifier = strengthGap;
}
}
Game.Screen.playScreen.deathInfo.level = Game.getLevel();
Game.Screen.playScreen.deathInfo.strength = strengthValue;
Game.Screen.playScreen.deathInfo.armor = defenseValue;
Game.Screen.playScreen.deathInfo.weapon = ((attackValue + strengthModifier) + ' ' + damageType);
Game.switchScreen(Game.Screen.winScreen);
Game.refresh();
return;
}
var width = Game._screenWidth;
var height = Game._screenHeight;
// Create our map from tiles and player
Game.incrementLevel();
this.turnsOnThisFloorCount = 0;
this.hasSpawnedDeath = false;
let builder = new Game.Builder(width,height, Game.getLevel())
let tiles = builder.getTiles()
let rooms = builder.getRooms();
let stairs = builder.getStairs();
let gasMap = builder.makeEmptyGasMap();
//pass the current player and the new tiles in
this._map = new Game.Map(tiles, this._player, this._player.getItems(), stairs, gasMap);
if (Game.getLevel() <= 6){
this._map.putGoldInBoringRooms(rooms);
//this._map.getRidOfBoringRooms(rooms);
//TODO turning this off because it clears rooms after prefabs are generated,
//and it there's an overlap, you might have an orphanned prefab that the player can spawn in.
}
if (Game.getLevel() <= 6 && Game.getLevel() > 3){
this._map.deleteHalfOfDoors();
}
this._map.cleanUpDoors();
// Start the map's engine
this._map.getEngine().start();
if (playerHasKey){
Game.sendMessage(this._player, "%c{#61AEEE}You use the key on the trapdoor.");
Game.sendMessage(this._player, "%c{#61AEEE}You go down the stairs. They crumble to dust behind you.");
for (let i = 0; i < items.length; i ++){
if (items[i] !== undefined && items[i] !== null){
if (items[i].describe() === 'key'){
items[i] = null;
}
}
}
} else {
Game.sendMessage(this._player, "%c{#61AEEE}You go down the stairs. They crumble to dust behind you.");
}
}
},
handleItemPickup(){
var items = this._map.getItemsAt(this._player.getX(), this._player.getY());
if (!items) {
return;
} else if (items.length === 1) {
// If only one item, try to pick it up
var item = items[0];
if (this._player.pickupItems([0])) {
if (item.getName() === 'key'){
Game.sendMessage(this._player, "%%c{#61AEEE}You pick up %s.", [item.describeA()]);
} else {
Game.sendMessage(this._player, "You pick up %s.", [item.describeA()]);
}
} else {
Game.sendMessage(this._player, "Your inventory is full! Nothing was picked up.");
}
} else {
if (this._player.getFilledItems() != 20){
// Show the pickup screen if there are any items
Game.Screen.pickupScreen.setup(this._player, items);
this.setSubScreen(Game.Screen.pickupScreen);
return;
} else {
Game.sendMessage(this._player, "Your inventory is full! Nothing was picked up.");
}
}
},
renderTiles(display){
var visibleCells = {}
// Store this._map to prevent losing it in callbacks
var map = this._map;
//Find all visible cells
this._map.getFov().compute(
this._player.getX(), this._player.getY(),
this._player.getSightRadius(),
function(x, y, radius, visibility) {
visibleCells[x + "," + y] = true;
// Mark cell as explored
map.setExplored(x, y, true);
});
var screenWidth = Game.getScreenWidth();
// Render the explored map cells
var j = 0;
for (var x = 0; x < this._map.getWidth(); x++) {
for (var y = 0; y < this._map.getHeight(); y++) {
if (map.isExplored(x, y)) {
// Fetch the glyph for the tile and render it to the screen
let glyph = this._map.getTile(x, y);
let foreground = glyph.getForeground();
let tile = this._map.getTile(x, y);
let background = tile.getBackground();
// If we are at a cell that is in the field of vision, we need
// to check if there are items or entities.
if (visibleCells[x + ',' + y]) {
// Check for items first to draw over the floor
let items = map.getItemsAt(x, y);
let tile = map.getTile(x,y);
let gas = map.getGas(x,y)
//If we have stairs, we want to render them in the sidebar
if (!this._player.hasEffect('blind')){
if ( tile === Game.Tile.stairsDownTile) {
display.drawText(screenWidth + 1, 11 + j , '%c{' + tile._foreground + '}' + tile._char + ': ' + 'stairs down');
j+=1;
}
if ( tile === Game.Tile.stairsDownTileLocked) {
display.drawText(screenWidth + 1, 11 + j , '%c{' + tile._foreground + '}' + tile._char + ': ' + 'locked stairs down');
j+=1;
}
if (tile === Game.Tile.altarTile) {
display.drawText(screenWidth + 1, 11 + j , '%c{' + tile._foreground + '}' + tile._char + ': ' + 'wand altar');
j+=1;
}
// If we have items, we want to render the top most item
if (items) {
glyph = items[items.length - 1];
let strSuffix = '';
if (glyph.hasMixin('Equippable')){
strSuffix = (glyph.getStrengthRequirement() > 1 ? ' [' + glyph.getStrengthRequirement() + ']' : '');
}
display.drawText(screenWidth + 1, 11 + j , '%c{' + glyph._foreground + '}' + glyph._char + ': ' + glyph._name + strSuffix);
j++;
// Update the foreground color in case our glyph changed
foreground = glyph.getForeground();
}
//If we have gasses, we want to render them over the background
if (gas !== null) {
foreground = gas.getForeground()
background = gas.getBackground()
}
}
} else {
let items = map.getItemsAt(x, y);
// If we have items, we want to render the top most item
if (items) {
glyph = items[items.length - 1];
foreground = items[items.length - 1].getForeground();
}
// Since the tile was previously explored but is not visible,
// we want to change the foreground color to dark gray.
foreground = ROT.Color.toHex(ROT.Color.multiply(ROT.Color.fromString(foreground),[80,80,130]));
background = ROT.Color.toHex(ROT.Color.multiply(ROT.Color.fromString(background),[80,80,130]));
}
if (!this._player.hasEffect('blind')){
display.draw(x, y, glyph.getChar(), foreground, background);
}
}
}
}
// Render the entities
if (!this._player.hasEffect('blind') || this._player.hasEffect('detecting')){
let entities = this._map.getEntities();
let visibleEntities = [];
let currentHead = this._player.getHead();
for (let key in entities) {
let entity = entities[key];
let tile = this._map.getTile(entity.getX(), entity.getY());
let gas = this._map.getGas(entity.getX(), entity.getY());
let background = gas !== null ? gas.getBackground() : tile.getBackground();
if (visibleCells[entity.getX() + ',' + entity.getY()] || (this._player.hasEffect('detecting') && entity.isNotMonster() == false)) {
if(entity.hasMixin('PlayerActor')){
if (currentHead === null){
display.draw(entity.getX(), entity.getY(), entity.getChar(), '#F61067', background);
} else if (entity.hasEffect('invisible')) {
display.draw(entity.getX(), entity.getY(), entity.getChar(), Game.Colors.invisibleColor, background);
} else {
display.draw(entity.getX(), entity.getY(), entity.getChar(), entity.getForeground(), background);
}
} else if (!entity.isNotMonster()) {
display.draw(entity.getX(), entity.getY(), entity.getChar(), entity.getForeground(), background);
} else if (!this._player.hasEffect('blind')) {
//if you're detecting but you're blind, don't draw barrels
display.draw(entity.getX(), entity.getY(), entity.getChar(), entity.getForeground(), entity.getBackground());
}
if (!entity.hasMixin('PlayerActor') && entity.isNotMonster() === false){
visibleEntities.push(entity);
}
}
}
for (var i=0; i < visibleEntities.length; i++){
var visibleEntity = visibleEntities[i]
let isDestructible = visibleEntity.hasMixin('Destructible');
if (isDestructible){
display.drawText(screenWidth + 1, 11 + 2*i + j , '%c{' + visibleEntity.getForeground() + '}' + visibleEntity.getChar() + ': ' + visibleEntity.getName() + '%c{' + visibleEntity.getForeground() + '} ' + visibleEntity.getHP() + '/' + visibleEntity.getMaxHP());
} else {
display.drawText(screenWidth + 1, 11 + 2*i + j , '%c{' + visibleEntity.getForeground() + '}' + visibleEntity.getChar() + ': ' + visibleEntity.getName() + '%c{' + visibleEntity.getForeground() + '} ');
}
var effectsList = visibleEntity.hasMixin('Affectible') ? visibleEntity.getEffects() : [];
var effectsString = '';
for (effect of effectsList){
var effectsString = effectsString + '%c{' + effect._color + '}' + effect.getName() + ' ';
}
display.drawText(screenWidth + 1, 12 + 2*i + j, effectsString);
}
}
},
getLevelName(){
if (Game.getLevel() < 4){
return "Cellars " + Game.getLevel();
} else if (Game.getLevel() < 7){
return "Sewers " + (Game.getLevel() - 3);
} else if (Game.getLevel() < 10) {
return "Caverns " + (Game.getLevel() - 6);
} else if (Game.getLevel() < 13) {
return "Catacombs " + (Game.getLevel() - 9);
} else {
return "Underworld " + (Game.getLevel() - 12);
}
}
}
// Define our winning screen
Game.Screen.winScreen = {
enter: function() { console.log("Entered win screen."); },
exit: function() { console.log("Exited win screen."); },
render: function(display) {
gtag('event', 'death_stats', {'strength': Game.Screen.playScreen.deathInfo.strength, 'hp': Game.Screen.playScreen.deathInfo.maxHP, 'defense': Game.Screen.playScreen.deathInfo.armor, 'damage': Game.Screen.playScreen.deathInfo.weapon, 'level': Game.Screen.playScreen.deathInfo.level, 'turns': Game.Screen.playScreen.turnCount, 'murderer': 'survived'});
// Render our prompt to the screen
display.drawText(2, 1, "%c{yellow}Death owes you a debt for defeating the Lich!");
display.drawText(2, 3, "She no longer haunts you. You are free.");
display.drawText(2, 5, "STRN: " + Game.Screen.playScreen.deathInfo.strength);
display.drawText(2, 6, "MAX HP: " + Game.Screen.playScreen.deathInfo.maxHP);
display.drawText(2, 7, "DMG: " + Game.Screen.playScreen.deathInfo.weapon);
display.drawText(2, 8, "ARMR: " + Game.Screen.playScreen.deathInfo.armor);
display.drawText(2, 9, "TURNS: " + Game.Screen.playScreen.turnCount);
display.drawText(2, 10, "GOLD: " + Game.Screen.playScreen.goldCount);
display.drawText(2, 12, "(Thank you for playing Headless Panic)");
},
handleInput: function(inputType, inputData) {
// Nothing to do here
}
}
// Define our winning screen
Game.Screen.loseScreen = {
enter: function() { console.log("Entered lose screen."); },
exit: function() { console.log("Exited lose screen."); },
render: function(display) {
// Render our prompt to the screen
display.drawText(2, 1, "You were killed on LVL " + Game.Screen.playScreen.deathInfo.level + " of 15 by " + Game.Screen.playScreen.deathInfo.murderer + '.');
display.drawText(2, 3, "STRN: " + Game.Screen.playScreen.deathInfo.strength);
display.drawText(2, 4, "MAX HP: " + Game.Screen.playScreen.deathInfo.maxHP);
display.drawText(2, 5, "DMG: " + Game.Screen.playScreen.deathInfo.weapon);
display.drawText(2, 6, "ARMR: " + Game.Screen.playScreen.deathInfo.armor);
display.drawText(2, 7, "TURNS: " + Game.Screen.playScreen.turnCount);
display.drawText(2, 9, Game.Screen.loseScreen.chooseHint());
display.drawText(2, 11, "%c{yellow}Refresh your browser tab to restart.");
// Sends an event that passes 'death stats'
gtag('event', 'death_stats', {'strength': Game.Screen.playScreen.deathInfo.strength, 'hp': Game.Screen.playScreen.deathInfo.maxHP, 'defense': Game.Screen.playScreen.deathInfo.armor, 'damage': Game.Screen.playScreen.deathInfo.weapon, 'level': Game.Screen.playScreen.deathInfo.level, 'turns': Game.Screen.playScreen.turnCount, 'murderer': Game.Screen.playScreen.deathInfo.murderer});
},
handleInput: function(inputType, inputData) {
// Nothing to do here
},
chooseHint: function(){
var hintList = [
"Avoiding fights is as good as winning them, especially if an enemy doesn't have a head to drop.",
"Wielding a weapon with insufficient strength greatly reduces chance to hit and max hit.",
"Weapons and armor with Strength requirements show the required Strength level in brackets.",
"Wielding a weapon with excess strength increases chance to hit and max hit.",
"Wearing an enemy's head gives you one of their powers.",
"Enemy heads with powers will have a desciption when you look at them on the ground or you select them in the inventory.",
"The further you throw a weapon, the less likely it is to hit an enemy.",
"Press X to eXplore automatically. It's not as smart as manual control, but it's easier on your fingers.",
"Press L to Look at new monsters to learn something about them.",
"The only way to raise your Strength (STR) is by drinking a Strength Potion.",
"Weapons and armor have a Strength requirement. If you don't meet this requirement, the weapons and armor will perform MUCH worse.",
"Weapons and armor have a Strength requirement. If you exceed this requirement, the performance of these items will scale with your strength.",
"Weapons each have a damage type (crush, slash, or stab). Certain enemies are resistant to or vulnerable to certain damage types.",
"Keep trying! Knowledge of monsters and items will drastically improve your chances of survival.",
"Damage of a type that monsters are vulnerable or resistant to will be blue and red respectively in the newsfeed.",
"Strength Potions, Life Potions, and Altars are the most important items for tackling the dungeon.",
"Wand Altars recharge your wands and boost the number of max charges.",
"Life Potions increase your max HP by 20% and fully refill your health. Sometimes it's better to use it during a fight than before a fight."
];
return hintList[Math.floor(Math.random() * hintList.length)];
}
}
Game.Screen.ItemListScreen = function(template) {
// Set up based on the template
this._caption = template['caption'];
this._okFunction = template['ok'];
// By default, we use the identity function
this._isAcceptableFunction = template['isAcceptable'] || function(x) {
return x;
}
// Whether the user can select items at all.
this._canSelectItem = template['canSelect'];
// Whether the user can select multiple items.
this._canSelectMultipleItems = template['canSelectMultipleItems'];
};
Game.Screen.ItemListScreen.prototype.setup = function(player, items) {
this._player = player;
// Should be called before switching to the screen.
var count = 0;
// Iterate over each item, keeping only the aceptable ones and counting the number of acceptable items.
var that = this;
this._items = items.map(function(item) {
// Transform the item into null if it's not acceptable
if (that._isAcceptableFunction(item)) {
count++;
return item;
} else {
return null;
}
});
// Clean set of selected indices
this._selectedIndices = {};
return count;
};
Game.Screen.ItemListScreen.prototype.render = function(display) {
let letters = 'abcdefghijklmnopqrstuvwxyz';
// Render the caption in the top row
display.drawText(0, 0, this._caption);
let row = 0;
let itemSortList = [];
for (let i = 0; i < this._items.length; i++) {
// If we have an item, we want to render it.
let isWearable = false;
let isWieldable = false;
let isHeadible = false;
let isUsable = false;
let isEdible = false;
if (this._items[i]) {
// Get the letter matching the item's index
let letter = letters.substring(i, i + 1);
// If we have selected an item, show a +, else show a dash between
// the letter and the item's name.
let selectionState = (this._canSelectItem && this._canSelectMultipleItems &&
this._selectedIndices[i]) ? '+' : '-';
// Render at the correct row and add 2.
// Check if the item is worn or wielded
let glyph = this._items[i].getChar()
let foreground = this._items[i].getForeground();
let prefix = '%c{white}';
let suffix = '';
if (this._items[i] === this._player.getArmor()) {
prefix = '%c{#61AEEE}';
suffix = ' (wearing)';
} else if (this._items[i] === this._player.getWeapon()) {
prefix = '%c{#61AEEE}';
suffix = ' (in hand)';
} else if (this._items[i] === this._player.getHead()) {
prefix = '%c{#61AEEE}';
suffix = ' (on neck)';
}
if (this._items[i].hasMixin('Throwable') && this._items[i].isStackable()) {
suffix += ' (x' + this._items[i].getStackQuantity() + ')';
}
if (this._items[i].hasMixin('Usable')) {
isUsable = true;
suffix += ' (' + this._items[i].getUses() + '/' + this._items[i].getMaxUses() + ')';
}
if (this._items[i].hasMixin('Edible')) {
isEdible = true;
}
if (this._items[i].hasMixin('Equippable')) {
isWearable = this._items[i].isWearable();
isWieldable = this._items[i].isWieldable();
isHeadible = this._items[i].isHeadible();
let strengthReq = this._items[i].getStrengthRequirement()
if (strengthReq > 1){
suffix += ' [' + strengthReq + ']';
}
}