-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
1777 lines (1663 loc) · 76.5 KB
/
app.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
"use strict";
// TESTING VARIABLES
var nightToSimulate = 1;
var secondLength = 1000; // How long we want a real life 'second' to be in milliseconds. Used to speed up testing.
var defaultCamera = '1A';
var autoStartGame = false;
var Freddy = {
name: 'Freddy',
currentPosition: '1A',
movementOpportunityInterval: 3.02,
aiLevels: [null, 0, 0, 1, Math.ceil(Math.random() * 2), 3, 4, 20],
// Freddy randomly starts at 1 or 2 on night 4
currentAIlevel: 0,
currentCountdown: 0,
pronouns: ['he', 'his'],
subPosition: -1,
stats: {
successfulMovementChecks: 0,
failedMovementChecks: 0,
officeAttempts: 0
}
};
var Bonnie = {
name: 'Bonnie',
currentPosition: '1A',
movementOpportunityInterval: 4.97,
aiLevels: [null, 0, 3, 0, 2, 5, 10, 20],
currentAIlevel: 0,
currentCountdown: 0,
pronouns: ['he', 'his'],
subPosition: -1,
stats: {
successfulMovementChecks: 0,
failedMovementChecks: 0,
officeAttempts: 0
}
};
var Chica = {
name: 'Chica',
currentPosition: '1A',
movementOpportunityInterval: 4.98,
aiLevels: [null, 0, 1, 5, 4, 7, 12, 20],
currentAIlevel: 0,
currentCountdown: 0,
pronouns: ['she', 'her'],
subPosition: -1,
stats: {
successfulMovementChecks: 0,
failedMovementChecks: 0,
officeAttempts: 0
}
};
var Foxy = {
name: 'Foxy',
currentPosition: '1C',
currentAIlevel: 0,
subPosition: 0,
movementOpportunityInterval: 5.01,
aiLevels: [null, 0, 1, 2, 6, 5, 16, 20],
currentCountdown: 0,
pronouns: ['he', 'his'],
stats: {
successfulMovementChecks: 0,
failedMovementChecks: 0,
officeAttempts: 0
}
};
var cameraNames = {
'1A': 'Show stage',
'1B': 'Dining area',
'1C': 'Pirate cove',
'2A': 'West hall',
'2B': 'W. hall corner',
'3': 'Supply closet',
'4A': 'East hall',
'4B': 'E. hall corner',
'5': 'Backstage',
'6': 'Kitchen',
'7': 'Restrooms'
};
var paths = {
assets: 'assets',
cameras: 'assets/cameras',
animatronics: 'assets/animatronics',
office: 'assets/office',
audio: 'assets/sounds'
};
/* Time related variables */
var currentFrame = 0;
var currentSecond = -1; // We start at 1 as 12AM is 89 real seconds long whereas all the others are 90 seconds
var framesPerSecond = 60;
var gameSpeed = 1;
/* Time related page elements */
var framesDisplay = document.querySelector('#frames');
var secondsDisplay = document.querySelector('#real-time');
var inGameHourDisplay = document.querySelector('#in-game-time');
// General page elements
var simulator = document.querySelector('#simulator');
var sidebar = document.querySelector('#sidebar');
var officeDisplay = document.querySelector('#office-overlay img');
// Camera related page elements
var cameraArea = document.querySelector('#camera-display');
var cameraButton = document.querySelector('button#cameras');
var cameraStatusText = document.querySelector('#camera-status');
var cameraScreen = document.querySelector('img#camera-screen');
// Power related page elements
var powerDisplay = document.querySelector('#power');
/* Player choosable variables */
var user = {
camerasOn: false,
currentCamera: defaultCamera,
leftDoorIsClosed: false,
rightDoorIsClosed: false,
leftLightIsOn: false,
rightLightIsOn: false,
camerasToggled: 0,
camerasLookedAt: 0,
leftDoorToggled: 0,
rightDoorToggled: 0,
power: 100,
// power: 1,
audioOn: false,
gameMode: false // false for ai simulator, true for playable game with stuff hidden
};
// ========================================================================== //
// TIMER BASED FUNCTIONS
// These are split off separately as they each need to update at
// different rates.
// ========================================================================== //
// We are running at 60fps
var updateFrames = function updateFrames() {
currentFrame++;
framesDisplay.textContent = "".concat(currentFrame, " frames at ").concat(framesPerSecond * gameSpeed, "fps");
};
var updateTime = function updateTime() {
currentSecond++;
// REAL TIME
var realMinutes = Math.floor(currentSecond / 60);
var realRemainingSeconds = currentSecond % 60;
secondsDisplay.textContent = "\n ".concat(realMinutes, " : ").concat(String(realRemainingSeconds).padStart(2, '0'), "\n ");
// IN GAME TIME
var gameTime = calculateInGameTime();
inGameHourDisplay.innerHTML = "\n <span class=\"in-game-hour\">".concat(gameTime.hour, "</span>\n <span class=\"in-game-minutes\">").concat(String(gameTime.minute).padStart(2, '0'), "</span>\n <span class=\"am-marker\">AM</span>\n ");
updateFrames();
// 2AM
if (currentSecond === 179) {
increaseAILevel(Bonnie);
}
// 3AM
if (currentSecond === 268) {
increaseAILevel(Bonnie);
increaseAILevel(Chica);
increaseAILevel(Foxy);
}
// 4AM
if (currentSecond === 357) {
increaseAILevel(Bonnie);
}
// 6AM - end game
if (currentSecond === 535) {
gameOver('6AM');
}
};
// Modifier is how much to offset the time by.
// This is used in the calculations in calculateRemainingPower() to figure out
// what time you will run out of power based on current usage.
var calculateInGameTime = function calculateInGameTime() {
var modifier = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
var inGameMinutes = Math.floor((currentSecond + modifier) * 0.6741573033707866) > 0 ? Math.floor((currentSecond + modifier) * 0.6741573033707866) : 0;
return {
hour: String(Math.floor(inGameMinutes / 60) > 0 ? Math.floor(inGameMinutes / 60) : 12),
minute: String(inGameMinutes % 60).padStart(2, '0')
};
};
// ========================================================================== //
// ANIMATRONIC BASED FUNCTIONS
// ========================================================================== //
var generateAnimatronics = function generateAnimatronics() {
[Bonnie, Foxy, Freddy, Chica].forEach(function (animatronic) {
var _animatronic$aiLevels, _animatronic$subPosit;
// Initialise their starting AI level
animatronic.currentAIlevel = (_animatronic$aiLevels = animatronic.aiLevels[nightToSimulate]) !== null && _animatronic$aiLevels !== void 0 ? _animatronic$aiLevels : 1;
// Create the icons
var icon = document.createElement('span');
icon.classList.add('animatronic');
icon.setAttribute('id', animatronic.name);
icon.setAttribute('position', animatronic.currentPosition);
icon.setAttribute('sub-position', (_animatronic$subPosit = animatronic.subPosition.toString()) !== null && _animatronic$subPosit !== void 0 ? _animatronic$subPosit : 'none');
simulator.appendChild(icon);
// Create the report
var animatronicReport = document.createElement('div');
animatronicReport.classList.add('animatronic-report');
animatronicReport.setAttribute('for', animatronic.name);
animatronicReport.innerHTML = "\n <div class=\"animatronic-icon\"></div>\n <div class=\"animatronic-name\">".concat(animatronic.name, "</div>\n <div class=\"starting-ai-level\">Starting AI:<span>").concat(animatronic.currentAIlevel, "</span></div>\n <div class=\"current-ai-level\">Current AI level: <span>").concat(animatronic.currentAIlevel, "</span></div>\n <div class=\"report-item-container\"></div>\n ");
document.querySelector('#animatronic-report').appendChild(animatronicReport);
if (animatronic === Freddy) {
var _animatronicReport$qu;
(_animatronicReport$qu = animatronicReport.querySelector('.animatronic-icon')) === null || _animatronicReport$qu === void 0 || _animatronicReport$qu.addEventListener('click', function () {
playAudio('freddy-nose');
});
}
});
};
var makeMovementCheck = function makeMovementCheck(animatronic) {
var comparisonNumber = Math.ceil(Math.random() * 20);
var canMove = animatronic.currentAIlevel >= comparisonNumber;
if (canMove) {
animatronic.stats.successfulMovementChecks++;
} else {
animatronic.stats.failedMovementChecks++;
}
return {
animatronicName: animatronic.name,
canMove: canMove,
scoreToBeat: comparisonNumber,
aiLevel: animatronic.currentAIlevel
};
};
var increaseAILevel = function increaseAILevel(animatronic) {
if (animatronic.currentAIlevel < 20) {
animatronic.currentAIlevel++;
addReport(animatronic, 'increase AI level');
var aiReport = document.querySelector(".animatronic-report[for=\"".concat(animatronic.name, "\"] .current-ai-level span"));
if (aiReport) {
aiReport.innerHTML = animatronic.currentAIlevel.toString();
}
}
};
/* ========================================================================== //
DEVELOPER NOTE
/* ========================================================================== //
Some of the if statements for the animatronics are quite lengthly.
I originally wrote these with nested if statements, but it got out of hand
quite quickly trying to keep track of which combinations of factors were
going on with each one.
The if statements below all seem to have a lot of factors, many of which are
shared, but this makes it much easier to keep track of exactly what
the animatronics should be doing for any given statement.
// ========================================================================== //
// FOXY
// ========================================================================== */
var moveFoxy = function moveFoxy() {
var movementCheck = makeMovementCheck(Foxy);
if (Foxy.currentAIlevel === 0) {
addReport(Foxy, 'AI level 0');
} else if (user.camerasOn && Foxy.currentPosition === '1C') {
// Foxy will fail all movement checks while the cameras are on
addReport(Foxy, 'camera auto fail');
// If Foxy fails a movement check while at 1C, he will not be able to make any more movement checks for a random amount of time between 0.83 and 16.67 seconds
} else if (!movementCheck.canMove && Foxy.currentPosition === '1C') {
addReport(Foxy, 'foxy failed pirate cove movement check', movementCheck);
} else if (movementCheck.canMove && Foxy.currentPosition === '1C' && Foxy.subPosition < 2) {
// Foxy needs to make 3 successful movement checks before he is able to leave 1C
moveAnimatronic(Foxy, {
start: '1C',
end: '1C',
sub: Foxy.subPosition + 1
}, false);
addReport(Foxy, 'foxy successful pirate cove movement check', movementCheck);
} else if (movementCheck.canMove && Foxy.currentPosition === '1C' && Foxy.subPosition === 2 || Foxy.currentPosition === '2A') {
// Once Foxy has made 3 successful movement checks, he can leave Pirate Cove
if (Foxy.currentPosition === '1C') {
// This if statement isn't necessary in normal play, but is necessary during testing when his starting position isn't 1C
moveAnimatronic(Foxy, {
start: '1C',
end: '2A',
sub: -1
});
addReport(Foxy, 'foxy leaving pirate cove', movementCheck);
}
// Once he has left Pirate Cove, he will attempt to attack in 25 seconds or 1.87 seconds after the player looks at cam 2A, whichever comes first
clearInterval(foxyInterval);
Foxy.currentCountdown = 25;
window.addEventListener('cam-on-2A', attemptFoxyJumpscare);
foxyInterval = window.setInterval(function () {
Foxy.currentCountdown--;
if (Foxy.currentCountdown === 0) {
attemptFoxyJumpscare();
}
}, secondLength);
}
};
var attemptFoxyJumpscare = function attemptFoxyJumpscare(e) {
clearInterval(foxyInterval);
Foxy.stats.officeAttempts++;
var performFoxyJumpscareCheck = function performFoxyJumpscareCheck() {
var restartSubPosition = Math.floor(Math.random() * 2);
if (user.leftDoorIsClosed) {
// If Foxy bashes on your door, you lose 1% power, plus an additional 5% for every time after that (e.g. 7% the second time, 13% the third etc)
// We do -1 as the attempts get incremented before this function is called.
var powerDrainage = 1 + (Foxy.stats.officeAttempts - 1) * 5;
user.power -= powerDrainage;
addReport(Foxy, 'foxy left door closed', null, {
restartSubPosition: restartSubPosition,
powerDrainage: powerDrainage
});
moveAnimatronic(Foxy, {
start: '2A',
end: '1C',
sub: restartSubPosition
}, false);
foxyInterval = window.setInterval(moveFoxy, secondLength * Foxy.movementOpportunityInterval);
playAudio('foxy-door-bash');
updatePowerDisplay();
} else {
gameOverFoxy();
}
};
// If this is happening as a result of looking at cam 4A, we need to wait 1.87 seconds before he attempts to attack
// If this is happening as a result of him waiting 25 seconds (in which case there will be no event parameter here) he will attempt to attack immediately.
if (e) {
addReport(Foxy, 'foxy coming down hall');
var foxyIcon = document.querySelector('.animatronic#Foxy');
if (foxyIcon) {
foxyIcon.style.animation = "foxyHallAnimation ".concat(1.87 * secondLength / 1000, "s linear backwards");
}
playAudio('foxy-run');
foxyJumpscareCountdown = window.setTimeout(performFoxyJumpscareCheck, secondLength * 1.87);
} else {
performFoxyJumpscareCheck();
}
};
// When the cameras come down Foxy will be unable to make any more movement checks for a random amount of time between 0.83 and 16.67 seconds
// I am assuming the countdown doesn't renew if another cameras-off event happens during his cooldown.
var pauseFoxy = function pauseFoxy() {
if (Foxy.currentPosition === '1C') {
var cooldownInSeconds = Math.random() * (16.67 - 0.83) + 0.83;
Foxy.currentCountdown = cooldownInSeconds * secondLength;
addReport(Foxy, 'foxy paused', null, cooldownInSeconds);
clearInterval(foxyInterval);
foxyCooldown = window.setInterval(function () {
Foxy.currentCountdown--;
if (Foxy.currentCountdown <= 0) {
foxyInterval = window.setInterval(moveFoxy, secondLength * Foxy.movementOpportunityInterval);
clearInterval(foxyCooldown);
}
}, 1);
}
};
// ========================================================================== //
// FREDDY
// ========================================================================== //
// Once Freddy is in the office he has a 25% chance of getting you every 1 second while the cameras are down
var makeFreddyJumpscareCheck = function makeFreddyJumpscareCheck() {
clearInterval(freddyInterval);
freddyInterval = window.setInterval(function () {
var comparisonNumber = Math.random();
var jumpscare = {
canMove: comparisonNumber > 0.75
};
if (jumpscare.canMove && !user.camerasOn) {
gameOverFreddy();
} else {
// Freddy is in your office but failed his movement check and was unable to jumpscare you.
addReport(Freddy, 'freddy office failed movement check', {
animatronicName: 'Freddy',
canMove: true,
scoreToBeat: 0.75 * 100,
aiLevel: Math.floor(comparisonNumber * 100)
});
}
}, secondLength);
};
// Freddy always follows a set path, and waits a certain amount of time before actually moving.
var moveFreddy = function moveFreddy() {
var movementCheck = makeMovementCheck(Freddy);
if (Freddy.currentAIlevel === 0) {
addReport(Freddy, 'AI level 0');
} else if (Freddy.currentPosition === '1A' && Bonnie.currentPosition === '1A' && Chica.currentPosition === '1A') {
// Freddy cannot move from the stage if Bonnie and/or Chica are also on the stage
addReport(Freddy, 'freddy bonnie and chica on stage');
} else if (Freddy.currentPosition === '1A' && Bonnie.currentPosition === '1A' && Chica.currentPosition !== '1A') {
addReport(Freddy, 'freddy and bonnie on stage');
} else if (Freddy.currentPosition === '1A' && Bonnie.currentPosition !== '1A' && Chica.currentPosition === '1A') {
addReport(Freddy, 'freddy and chica on stage');
} else if (user.camerasOn && Freddy.currentPosition !== '4B') {
// CAMERAS ON, HE'S NOT AT 4B
// Freddy will automatically fail all movement checks while the cameras are up
addReport(Freddy, 'camera auto fail');
// CAMERAS ON, HE'S AT 4B, USER IS LOOKING AT 4B. DOORS DON'T MATTER HERE
// Freddy will fail all movement checks while both he and the camera are at 4B. Other cameras no longer count while Freddy is at 4B.
} else if (user.camerasOn && user.currentCamera === '4B') {
addReport(Freddy, 'freddy and camera at 4B');
// ✓ CAMERAS ON ✓ HE'S AT 4B ✓ USER IS NOT LOOKING AT 4B ✓ HE WANTS TO ENTER THE OFFICE X THE RIGHT DOOR IS CLOSED
} else if (user.camerasOn && Freddy.currentPosition === '4B' && user.currentCamera !== '4B' && user.rightDoorIsClosed && movementCheck.canMove) {
// Freddy can't get you when the right door is closed even if you're not looking at 4B
addReport(Freddy, 'right door closed', null, '4A');
Freddy.currentPosition = '4A';
moveAnimatronic(Freddy, {
start: '4B',
end: '4A'
});
Freddy.stats.officeAttempts++;
playAudio('freddy-move');
// CAMERAS ON, HE'S AT 4B, USER IS NOT LOOKING AT 4B BUT HE'S FAILED HIS MOVEMENT CHECK
} else if (user.camerasOn && Freddy.currentPosition === '4B' && user.currentCamera !== '4B' && !user.rightDoorIsClosed && !movementCheck.canMove) {
// Freddy could have entered the office but he failed his movement check. He will continue to wait at Cam 4B
addReport(Freddy, 'enter office failed movement check', movementCheck);
Freddy.stats.failedMovementChecks++;
} else if (!user.camerasOn && Freddy.currentPosition === '4B' && movementCheck.canMove) {
addReport(Freddy, 'enter office cameras off');
Freddy.stats.officeAttempts++;
// THE CAMERAS ARE ON, HE'S AT 4B, THE RIGHT DOOR IS OPEN, HE CAN GET INTO THE OFFICE!!!!!
} else if (user.camerasOn && Freddy.currentPosition === '4B' && !user.rightDoorIsClosed) {
addReport(Freddy, 'in the office');
moveAnimatronic(Freddy, {
start: '4B',
end: 'office'
}, false);
playAudio('freddy-move');
Freddy.stats.officeAttempts++;
} else if (Freddy.currentPosition === 'office') {
makeFreddyJumpscareCheck();
} else if (movementCheck.canMove) {
var waitingTime = 1000 - Freddy.currentAIlevel * 100; // How many FRAMES to wait before moving
waitingTime = waitingTime >= 0 ? waitingTime : 0;
var currentPosition = Freddy.currentPosition;
var endingPosition = currentPosition;
// Freddy always follows a set path
switch (Freddy.currentPosition) {
case '1A':
// Show stage
endingPosition = '1B';
break;
case '1B':
// Dining area
endingPosition = '7';
break;
case '7':
// Restrooms
endingPosition = '6';
break;
case '6':
// Kitchen
endingPosition = '4A';
break;
case '4A':
// East hall
endingPosition = '4B';
break;
}
// Round to a reasonable number of decimal points for the report, only if it's not an integer.
var formattedWaitingTime = Number.isInteger(waitingTime / 60) ? waitingTime / 60 : (waitingTime / 60).toFixed(2);
addReport(Freddy, 'freddy successful movement check', movementCheck, {
formattedWaitingTime: formattedWaitingTime,
currentPosition: currentPosition,
endingPosition: endingPosition
});
clearInterval(freddyInterval);
// Freddy waits a certain amount of time between passing his movement check and actually moving.
// The amount of time is dependent on his AI level.
Freddy.currentCountdown = waitingTime / framesPerSecond * secondLength;
// Freddy will not move while the cameras are up.
// If his countdown expires while the cameras are up, he will wait until the cameras are down to move.
freddyCountdown = window.setInterval(function () {
Freddy.currentCountdown--;
if (Freddy.currentCountdown <= 0 && !user.camerasOn) {
moveAnimatronic(Freddy, {
start: currentPosition,
end: endingPosition
});
freddyInterval = window.setInterval(moveFreddy, secondLength * Freddy.movementOpportunityInterval);
playAudio('freddy-move');
clearInterval(freddyCountdown);
} else if (Freddy.currentCountdown <= 0 && user.camerasOn) {
addReport(Freddy, 'waiting for cameras down');
}
}, secondLength / framesPerSecond);
} else {
addReport(Freddy, 'failed movement check', movementCheck);
}
};
// ========================================================================== //
// BONNIE AND CHICA
// Bonnie and Chica share much of the same logic with only minor differences.
// ========================================================================== //
var moveBonnieOrChica = function moveBonnieOrChica(animatronic) {
// Figure out which set of details we need to use depending on whether it's Bonnie or Chica we're dealing with
var name = animatronic.name;
var newPosition = name === 'Bonnie' ? calculateNewBonniePosition() : calculateNewChicaPosition();
var hallCorner = name === 'Bonnie' ? '2B' : '4B';
var doorClosed = name === 'Bonnie' ? user.leftDoorIsClosed : user.rightDoorIsClosed;
var doorClosedMessage = name === 'Bonnie' ? 'left door closed' : 'right door closed';
var movementCheck = makeMovementCheck(animatronic);
if (animatronic.currentAIlevel === 0) {
addReport(animatronic, 'AI level 0');
// They can move, aren't in their hall corner
} else if (movementCheck.canMove && animatronic.currentPosition !== hallCorner) {
moveAnimatronic(animatronic, {
start: animatronic.currentPosition,
end: newPosition
}, true, movementCheck);
if (animatronic.name === 'Chica' && newPosition === '6') {
playAudio('oven');
}
// If they're at their hall corner but aren't in your doorway yet, move them into the doorway
} else if (movementCheck.canMove && animatronic.currentPosition === hallCorner && animatronic.subPosition === -1) {
moveAnimatronic(animatronic, {
start: hallCorner,
end: hallCorner,
sub: 1
}, false);
addReport(animatronic, 'in the doorway', movementCheck);
// Passed a movement check, is already in the doorway and the door is not closed, they can get into your office!
} else if (movementCheck.canMove && animatronic.currentPosition === hallCorner && animatronic.subPosition !== -1 && !doorClosed) {
moveAnimatronic(animatronic, {
start: hallCorner,
end: 'office',
sub: -1
}, false);
addReport(animatronic, 'enter office bonnie or chica', movementCheck);
animatronic.stats.officeAttempts++;
if (name === 'Bonnie') {
clearInterval(bonnieInterval);
bonnieInterval = window.setInterval(function () {
if (Math.random() * 3 > 2) {
playAudio('breath');
clearInterval(bonnieInterval);
}
});
} else {
clearInterval(chicaInterval);
chicaInterval = window.setInterval(function () {
if (Math.random() * 3 > 2) {
playAudio('breath');
clearInterval(chicaInterval);
}
});
}
// Disable the doors and lights once the animatronic is in the office
disableOfficeButtons();
// They will jumpscare you in 30 seconds or when you next bring the cameras down - whichever comes first.
if (name === 'Bonnie') {
bonnieJumpscareCountdown = window.setTimeout(gameOverBonnie, secondLength * 30);
window.addEventListener('cameras-off', gameOverBonnie);
} else {
chicaJumpscareCountdown = window.setTimeout(gameOverChica, secondLength * 30);
window.addEventListener('cameras-off', gameOverChica);
}
// He meets all the critera to enter the office but the door is closed. He will return to the dining area
} else if (movementCheck.canMove && animatronic.currentPosition === hallCorner && animatronic.subPosition !== -1 && doorClosed) {
moveAnimatronic(animatronic, {
start: hallCorner,
end: '1B',
sub: -1
}, false);
addReport(animatronic, doorClosedMessage, movementCheck, '1B');
// The conditions were right to enter the office but they failed their movement check
} else if (!movementCheck.canMove && animatronic.currentPosition === hallCorner && animatronic.subPosition !== -1 && !user.leftDoorIsClosed) {
addReport(animatronic, 'enter office failed movement check doorway', movementCheck);
// Failed a bog standard movement check with no other fancy conditions
} else if (!movementCheck.canMove) {
addReport(animatronic, 'failed movement check', movementCheck);
} else {
addReport(animatronic, 'debug');
}
};
// Bonnie does not have to chose adjacent rooms. He can pick at random from a list of approved locations.
var calculateNewBonniePosition = function calculateNewBonniePosition() {
var possibleLocations = ['1B', '3', '5', '2A', '2B'];
var choice = Math.floor(Math.random() * possibleLocations.length);
return possibleLocations[choice];
};
// Chica can only choose cameras adjacent to where she already is.
var calculateNewChicaPosition = function calculateNewChicaPosition() {
var randomChoice = Math.round(Math.random());
var newPosition = '';
var choices;
switch (Chica.currentPosition) {
case '1A':
newPosition = '1B';
break;
case '1B':
choices = ['4A', '6', '7'];
newPosition = choices[Math.floor(Math.random() * choices.length)];
break;
case '6':
choices = ['1B', '7'];
newPosition = choices[Math.floor(Math.random() * choices.length)];
playAudio('oven');
case '7':
choices = ['1B', '6'];
newPosition = choices[Math.floor(Math.random() * choices.length)];
break;
case '4A':
newPosition = randomChoice === 0 ? '1B' : '4B';
break;
}
return newPosition;
};
var moveAnimatronic = function moveAnimatronic(animatronic, position) {
var _position$sub, _document$querySelect, _document$querySelect2, _position$sub$toStrin, _position$sub2;
var logThis = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var movementCheck = arguments.length > 3 ? arguments[3] : undefined;
animatronic.currentPosition = position.end;
animatronic.subPosition = (_position$sub = position.sub) !== null && _position$sub !== void 0 ? _position$sub : -1;
if (logThis) {
addReport(animatronic, 'has moved', movementCheck, {
currentPosition: position.start,
endPosition: position.end
});
}
// Update the cameras if you're looking at their start or end position
if (user.camerasOn && (user.currentCamera === position.start || user.currentCamera === position.end)) {
cameraArea.classList.add('updating');
playAudio('animatronic-camera-move');
}
window.setTimeout(function () {
cameraScreen.src = getCameraImage(user.currentCamera);
cameraArea.classList.remove('updating');
}, secondLength * 5);
(_document$querySelect = document.querySelector(".animatronic#".concat(animatronic.name))) === null || _document$querySelect === void 0 || _document$querySelect.setAttribute('position', position.end);
(_document$querySelect2 = document.querySelector(".animatronic#".concat(animatronic.name))) === null || _document$querySelect2 === void 0 || _document$querySelect2.setAttribute('sub-position', (_position$sub$toStrin = (_position$sub2 = position.sub) === null || _position$sub2 === void 0 ? void 0 : _position$sub2.toString()) !== null && _position$sub$toStrin !== void 0 ? _position$sub$toStrin : 'none');
};
// ========================================================================== //
// REPORTING
// ========================================================================== //
// Foxy is leaving Pirate cove
var pluralise = function pluralise(number, word) {
var plural = number > 1 ? 's' : '';
return word + plural;
};
var capitalise = function capitalise(word) {
return word.charAt(0).toUpperCase() + word.slice(1);
};
var addReport = function addReport(animatronic, reason) {
var movementCheck = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var additionalInfo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
// Figuring out what the message actually should be
var message = '';
var type = 'info';
var preventDuplicates = false;
var stats = movementCheck ? "<div class=\"report-extra-info\">Score to beat: ".concat(Math.ceil(movementCheck.scoreToBeat), " ").concat(animatronic.name, "'s AI level: ").concat(movementCheck.aiLevel, "</div>") : '';
switch (reason) {
case 'debug':
message = "Something happened";
break;
case 'power outage - freddy not arrived':
message = 'Your power has run out. Freddy has a 20% chance of arriving at your office every 5 seconds, up to a maximum of 20 seconds.';
type = 'death-zone';
break;
case 'power outage - freddy has arrived':
message = 'Freddy has arrived at your office. His song has a 20% chance of ending every 5 seconds, up to a maxmimum of 20 seconds';
type = 'death-zone';
break;
case 'power outage - freddy is waiting to jumpscare':
message = "Now Freddy's song has ended, he has a 20% chance of jumpscaring you every 2 seconds";
type = 'death-zone';
break;
case 'power outage - freddy failed to arrive':
message = "Freddy failed his check to arrive at the office. He will try up to ".concat(additionalInfo, " more ").concat(pluralise(additionalInfo, 'time'), "<div class=\"report-extra-info\">20% chance every 5 seconds</div>");
break;
case "power outage - freddy's song didn't end":
message = "Freddy failed his check to end his song. He will continue for up to ".concat(additionalInfo, " more ").concat(pluralise(additionalInfo, 'second'), "<div class=\"report-extra-info\">20% chance every 5 seconds</div>");
break;
case "power outage - freddy didn't jumpscare":
message = "Freddy failed his check to jumpscare you.<div class=\"report-extra-info\">20% chance every 2 seconds</div>";
break;
case 'AI level 0':
message = "".concat(animatronic.name, "'s AI level is 0 and is unable to move.");
if (animatronic === Bonnie) {
message += "<div class=\"report-extra-info\">His AI level will increase at 2AM</div>";
} else if (animatronic === Chica || animatronic === Foxy) {
message += "<div class=\"report-extra-info\">".concat(capitalise(animatronic.pronouns[1]), " AI level will increase at 3AM</div>");
}
preventDuplicates = true;
break;
case 'in the doorway':
var side = animatronic.name === 'Bonnie' ? 'left' : 'right';
message = "".concat(animatronic.name, " is in your ").concat(side, " doorway!");
type = 'alert';
break;
case 'increase AI level':
message = "".concat(animatronic.name, "'s AI level has increased by 1 to ").concat(animatronic.currentAIlevel);
break;
case 'increase AI level max':
message = "".concat(animatronic.name, " could have increased their AI level but they are already at 20");
case 'camera auto fail':
message = "".concat(animatronic.name, " will automatically fail all movement checks while the cameras are on");
preventDuplicates = true;
break;
case 'failed movement check':
message = "".concat(animatronic.name, " has failed ").concat(animatronic.pronouns[1], " movement check and will remain at cam ").concat(animatronic.currentPosition, " (").concat(cameraNames[animatronic.currentPosition], ") ").concat(stats);
type = 'good';
break;
case 'freddy and camera at 4B':
message = "Freddy will fail all movement checks while both he and the camera are at 4B. Other cameras no longer count while Freddy is at 4B.";
preventDuplicates = true;
break;
case 'right door closed':
message = "".concat(animatronic.name, " was ready to enter your office but the right door was closed. ").concat(capitalise(animatronic.pronouns[0]), " will return to cam ").concat(additionalInfo, " (").concat(cameraNames[additionalInfo], ")");
type = 'good';
break;
case 'left door closed':
message = "".concat(animatronic.name, " was ready to enter your office but the left door was closed.\n ").concat(capitalise(animatronic.pronouns[0]), " will return to cam ").concat(additionalInfo, " (").concat(cameraNames[additionalInfo], ")");
type = 'good';
break;
case 'enter office bonnie or chica':
message = "".concat(animatronic.name.toUpperCase(), " HAS ENTERED THE OFFICE\n <div class=\"report-extra-info\">").concat(capitalise(animatronic.pronouns[0]), " will jumpscare you in 30 seconds or the next time the camera goes down - whichever comes first</div>");
type = 'death-zone';
preventDuplicates = true;
break;
case 'freddy office failed movement check':
message = "Freddy is in your office but failed his movement check and was unable to jumpscare you. \n <div class=\"report-extra-info\">\n Score to beat: ".concat(movementCheck === null || movementCheck === void 0 ? void 0 : movementCheck.scoreToBeat, "/100 Freddy's score: ").concat(movementCheck === null || movementCheck === void 0 ? void 0 : movementCheck.aiLevel, "\n </div>");
type = 'death-zone';
break;
case 'enter office failed movement check':
message = "".concat(animatronic.name, " could have entered the office but ").concat(animatronic.pronouns[0], " failed ").concat(animatronic.pronouns[1], " movement check. ").concat(capitalise(animatronic.pronouns[0]), " will continue to wait at cam ").concat(animatronic.currentPosition, " (").concat(cameraNames[animatronic.currentPosition], ") ").concat(stats);
type = 'alert';
break;
case 'enter office failed movement check doorway':
var doorSide = animatronic.currentPosition === '2B' ? 'left' : 'right';
message = "".concat(animatronic.name, " could have entered the office but ").concat(animatronic.pronouns[0], " failed ").concat(animatronic.pronouns[1], " movement check.\n ").concat(capitalise(animatronic.pronouns[0]), " will continue to wait in the ").concat(doorSide, " doorway ").concat(stats);
type = 'alert';
break;
case 'enter office cameras off':
message = "".concat(animatronic.name, " passed ").concat(animatronic.pronouns[1], " movement check to enter the office but couldn't because the cameras were off.\n ").concat(capitalise(animatronic.pronouns[0]), " will continue to wait at cam ").concat(animatronic.currentPosition, " (").concat(cameraNames[animatronic.currentPosition], ") ").concat(stats);
type = 'warning';
break;
case 'in the office':
message = "".concat(animatronic.name.toUpperCase(), " HAS ENTERED THE OFFICE");
type = 'death-zone';
preventDuplicates = true;
break;
case 'waiting for cameras down':
message = "".concat(animatronic.name, " is ready to move but is waiting for the cameras to go down");
preventDuplicates = true;
break;
case 'freddy successful movement check':
message = "Freddy will move from\n ".concat(additionalInfo.currentPosition, " (").concat(cameraNames[additionalInfo.currentPosition], ")\n to ").concat(additionalInfo.endingPosition, " (").concat(cameraNames[additionalInfo.endingPosition], ")\n in ").concat(additionalInfo.formattedWaitingTime, " seconds\n ").concat(stats);
type = 'bad';
break;
case 'freddy and bonnie on stage':
message = 'Freddy is unable to leave the stage while Bonnie is still there';
preventDuplicates = true;
break;
case 'freddy and chica on stage':
message = 'Freddy is unable to leave the stage while Chica is still there';
preventDuplicates = true;
break;
case 'freddy bonnie and chica on stage':
message = 'Freddy is unable to leave the stage while Bonnie and Chica are still there';
preventDuplicates = true;
break;
case 'has moved':
message = "".concat(animatronic.name, " has moved from cam ").concat(additionalInfo.currentPosition, " (").concat(cameraNames[additionalInfo.currentPosition], ") to cam ").concat(additionalInfo.endPosition, " (").concat(cameraNames[additionalInfo.endPosition], ")");
if (movementCheck) {
message += "<div class=\"report-extra-info\">\n Score to beat: ".concat(movementCheck === null || movementCheck === void 0 ? void 0 : movementCheck.scoreToBeat, " ").concat(animatronic.name, "'s score: ").concat(movementCheck === null || movementCheck === void 0 ? void 0 : movementCheck.aiLevel, "\n </div>");
}
type = 'bad';
break;
case 'foxy successful pirate cove movement check':
var stepsRemaining = 3 - Foxy.subPosition;
message = "Foxy has made a successful movement check. He is ".concat(stepsRemaining, " ").concat(pluralise(stepsRemaining, 'step'), " away from leaving Pirate Cove ").concat(stats);
type = stepsRemaining === 1 ? 'warning' : 'bad';
break;
case 'foxy paused':
message = "The cameras have just been turned off. Foxy will be unable to make movement checks for ".concat(additionalInfo.toFixed(2), " seconds <div class=\"report-extra-info\">Random number between 0.83 and 16.67</div>");
break;
case 'foxy failed pirate cove movement check':
var stepsRemainingB = 3 - Foxy.subPosition;
message = "Foxy has failed his movement check. He is still ".concat(stepsRemainingB, " ").concat(pluralise(stepsRemainingB, 'step'), " away from leaving 1C (").concat(cameraNames['1C'], ") ").concat(stats);
type = 'good';
break;
case 'foxy leaving pirate cove':
message = "FOXY HAS LEFT ".concat(cameraNames['1C'].toUpperCase(), "\n <div class=\"report-extra-info\">He will attempt to jumpscare you in 25 seconds or when you next look at cam 2A, whichever comes first</div>");
type = 'alert';
break;
case 'foxy left door closed':
message = "Foxy attempted to enter your office but the left door was closed. He has drained ".concat(additionalInfo.powerDrainage, "% of your power and returned to cam 1C (").concat(cameraNames['1C'], ") at step ").concat(additionalInfo.restartSubPosition + 1, "\n <div class=\"report-extra-info\">Restarting step chosen at random from 1 & 2</div>");
type = 'good';
break;
case 'foxy coming down hall':
message = 'FOXY IS COMING DOWN THE HALL. HE WILL ATTEMPT TO JUMPSCARE YOU IN 1.87 SECONDS';
type = 'death-zone';
break;
case 'jumpscare':
message = "".concat(animatronic.name, " successfully jumpscared you");
type = 'death-zone';
break;
}
var reportToAddTo = document.querySelector(".animatronic-report[for=\"".concat(animatronic.name, "\"] .report-item-container"));
var firstReport = reportToAddTo === null || reportToAddTo === void 0 ? void 0 : reportToAddTo.querySelector('.report-item');
if (preventDuplicates && firstReport && firstReport.innerHTML.indexOf(message) > 0) {
return;
// Don't do anything here
} else if (reportToAddTo) {
var _reportToAddTo$innerH;
var InGameTime = calculateInGameTime();
reportToAddTo.innerHTML = "\n\n <div class=\"report-item\" type=\"".concat(type, "\">\n <span class=\"report-time\">").concat(InGameTime.hour, ":").concat(InGameTime.minute, "AM</span>\n <div class=\"report-description\">").concat(message, "</div></div>\n ").concat((_reportToAddTo$innerH = reportToAddTo === null || reportToAddTo === void 0 ? void 0 : reportToAddTo.innerHTML) !== null && _reportToAddTo$innerH !== void 0 ? _reportToAddTo$innerH : '', "\n ");
}
};
// ========================================================================== //
// IMAGES FOR INDIVIDUAL CAMERAS
// I wish it were simple as figuring out which animatronics were at the current
// location and just giving it an image. It isn't.
// Freddy will only show on a cam if he's the only one at his location.
// Foxy will always be the only one to show at his location.
// Some locations and animatronics have more than one image option.
// ========================================================================== //
var getCameraImage = function getCameraImage(cam) {
var camImageSrc = '';
switch (cam) {
case '1A':
camImageSrc = generateCamImage1A();
break;
case '1B':
camImageSrc = generateCamImage1B();
break;
case '1C':
camImageSrc = generateCamImage1C();
break;
case '2A':
camImageSrc = generateCamImage2A();
break;
case '2B':
camImageSrc = generateCamImage2B();
break;
case '3':
camImageSrc = generateCamImage3();
break;
case '4A':
camImageSrc = generateCamImage4A();
break;
case '4B':
camImageSrc = generateCamImage4B();
break;
case '5':
camImageSrc = generateCamImage5();
break;
case '6':
camImageSrc = '6.webp';
break;
case '7':
camImageSrc = generateCamImage7();
break;
}
return "".concat(paths.cameras, "/").concat(camImageSrc);
};
var getLocationInfo = function getLocationInfo(cam) {
var bonnieIsHere = Bonnie.currentPosition === cam;
var chicaIsHere = Chica.currentPosition === cam;
var foxyIsHere = Foxy.currentPosition === cam;
var freddyIsHere = Freddy.currentPosition === cam;
var bonnieIsAlone = bonnieIsHere && !chicaIsHere && !foxyIsHere && !freddyIsHere;
var chicaIsAlone = !bonnieIsHere && chicaIsHere && !foxyIsHere && !freddyIsHere;
// const foxyIsAlone = !bonnieIsHere && !chicaIsHere && foxyIsHere && !freddyIsHere; // Do I ever actually need to know whether Foxy is alone?
var freddyIsAlone = !bonnieIsHere && !chicaIsHere && !foxyIsHere && freddyIsHere;
var isEmpty = !bonnieIsHere && !chicaIsHere && !foxyIsHere && !freddyIsHere;
return {
bonnieIsHere: bonnieIsHere,
chicaIsHere: chicaIsHere,
foxyIsHere: foxyIsHere,
freddyIsHere: freddyIsHere,
bonnieIsAlone: bonnieIsAlone,
chicaIsAlone: chicaIsAlone,
freddyIsAlone: freddyIsAlone,
isEmpty: isEmpty
};
};
// Chance should be the 1 in X number chance it has
var randomise = function randomise(chance) {
return Math.random() < 1 / chance;
};
// Note - Foxy can never be here.
var generateCamImage1A = function generateCamImage1A() {
var info = getLocationInfo('1A');
// Bonnie, Chica and Freddy are all here
if (info.bonnieIsHere && info.chicaIsHere && info.freddyIsHere) {
return "1A-bonnie-chica-freddy.webp";
}
// Chica and Freddy are here
if (!info.bonnieIsHere && info.chicaIsHere && info.freddyIsHere) {
return "1A-chica-freddy.webp";
}
// Bonnie and Freddy are here
if (info.bonnieIsHere && !info.chicaIsHere && info.freddyIsHere) {
return "1A-bonnie-freddy.webp";
}
if (info.freddyIsAlone) {
// UNKNOWN - I can't find info on the chances of Freddy facing right rather than the camera
var randomiser = randomise(8) ? '-2' : '-1';
return "1A-freddy".concat(randomiser, ".webp");
}
// If we've reached this point it must be empty
return "1A-empty.webp";
};
// Freddy will only show if he's alone. Bonnnie will only show if Chica isn't there.
var generateCamImage1B = function generateCamImage1B() {
var info = getLocationInfo('1B');
var randomiser = randomise(3) ? '-2' : '-1';
if (info.chicaIsHere) {
return "1B-chica".concat(randomiser, ".webp");
}
if (info.bonnieIsHere) {
return "1B-bonnie".concat(randomiser, ".webp");
}
if (info.freddyIsAlone) {
return '1B-freddy.webp';
}
return '1B-empty.webp';
};
// Foxy is the only one who can be here. Exactly which image is shown depends
// on how close he is to leaving Pirate Cove.
var generateCamImage1C = function generateCamImage1C() {
var _getLocationInfo = getLocationInfo('1C'),
foxyIsHere = _getLocationInfo.foxyIsHere;
if (foxyIsHere) {
return "1C-foxy-".concat(Foxy.subPosition, ".webp");
}
var emptyRandomiser = randomise(10) ? '-its-me' : '-default';
return "1C-empty".concat(emptyRandomiser, ".webp");
};
var generateCamImage2A = function generateCamImage2A() {
var info = getLocationInfo('2A');
if (info.foxyIsHere) {
return '2A-foxy.webp';
}
if (info.bonnieIsHere) {
return '2A-bonnie.webp';
}
return '2A-empty.webp';
};
// Bonnie is the only one who can be here.
// This code does not currently deal with the unlikely prospect of Golden Freddy
var generateCamImage2B = function generateCamImage2B() {
var info = getLocationInfo('2B');
// There are 3 different options for Bonnie's images, with some being more
// likely than others.
if (info.bonnieIsHere && Bonnie.subPosition === -1) {