Repository navigation
Expand file tree
/
Copy pathadv.js
More file actions
1549 lines (1309 loc) · 48.3 KB
/
Copy pathadv.js
File metadata and controls
1549 lines (1309 loc) · 48.3 KB
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
const attackBtn = document.getElementById('attackBtn');
const defendBtn = document.getElementById('defendBtn');
const filterArmorBtn = document.getElementById('filterArmorBtn');
const filterBtn = document.getElementById('filterBtn');
const logBox = document.getElementById('actionContent');
const specialMoveBtn = document.getElementById('specialMoveBtn');
const parryBtn = document.getElementById('parryBtn');
const lockPickButton = document.getElementById('lockPickButton');
let selectedArmor = null;
let selectedWeapon = null;
let currentEnemy = null;
let enemyAttacked = null;
let enemyDefended = null;
let canUseSpecialMove = false;
let canUseParryMove = false;
let specialMoveBtnClicked = null;
let parryBtnClicked = false;
let defendBtnClicked = null;
let isBattleInProgress = false;
console.log(isBattleInProgress);
specialMoveBtn.addEventListener('click', () => {
if (canUseSpecialMove) {
specialMoveBtnClicked = true;
player1.attackWithSpecialMove(currentEnemy);
} else {
console.log('Cannot perform special move under these conditions!');
}
});
attackBtn.addEventListener('click', () => {
defendBtnClicked = false;
if (isBattleInProgress) {
enemyTurn(defendBtnClicked);
} else {
console.log('Cannot attack outside of battle!');
}
});
defendBtn.addEventListener('click', () => {
defendBtnClicked = true;
if (isBattleInProgress) {
enemyTurn(defendBtnClicked);
} else {
console.log('Cannot defend outside of battle!');
}
});
filterBtn.addEventListener('click', () => {
selectedWeapon = player1.cycleWeapons(selectedWeapon);
updateCycleButton();
});
filterArmorBtn.addEventListener('click', () => {
selectedArmor = player1.cycleArmor(selectedArmor);
updateArmorCycleButton();
});
lockPickButton.addEventListener('click', () => {
click();
});
//COPY PARRY FUNCTIOn
parryBtn.addEventListener('click', () => {
if (canUseParryMove) {
parryBtnClicked = true;
player1.parryAction(currentEnemy);
} else {
console.log('Cannot perform parry!');
}
});
function updateCycleButton() {
filterBtn.textContent = selectedWeapon ? selectedWeapon.itemName : 'Cycle Weapons';
}
function updateArmorCycleButton() {
filterArmorBtn.textContent = selectedArmor ? selectedArmor.armorName : 'Cycle Armor';
}
/*function resetGame(){
player1.health = 100;
currentEnemy.health = currentEnemy.maxHealth;
updateEnemyHealthBar(currentEnemy.maxHealth);
updateHealthBar(100);
showTextNode(1);
player1.inventory = [];
selectedArmor = null;
selectedWeapon = null;
currentEnemy = null;
enemyAttacked = null;
enemyDefended = null;
canUseSpecialMove = false;
canUseParryMove = false;
player1.displayInventory();
console.log('You have been defeated and the game has reset');
}*/
class Player {
constructor(playerName, health) {
this.playerName = playerName;
this.health = health;
this.inventory = [];
}
addItem(item) {
this.inventory.push(item);
console.log(`${item.itemName} has been added to ${this.playerName}'s inventory`);
}
addArmor(armor) {
this.inventory.push(armor);
console.log(`${armor.armorName} has been added to ${this.playerName}'s inventory`);
}
displayInventory() {
const inventoryContainer = document.getElementById('inventoryContainer');
inventoryContainer.innerHTML = '';
const inventoryHeader = document.createElement('h2');
inventoryHeader.textContent = `${this.playerName}'s Inventory:`;
inventoryContainer.appendChild(inventoryHeader);
const itemList = document.createElement('ul');
this.inventory.forEach(item => {
const listItem = document.createElement('li');
if (item instanceof Weapon) {
listItem.textContent = item.itemName;
} else if (item instanceof Armor) {
listItem.textContent = item.armorName;
} else if (item instanceof Item){
listItem.textContent = item.itemName;
}
itemList.appendChild(listItem);
});
inventoryContainer.appendChild(itemList);
}
/*displayStats() {
console.log(`${this.playerName}'s inventory:`);
this.inventory.forEach(item => console.log(item.itemName));
console.log(`Health: ${this.health}`);
}*/
takeDamage(damage) {
this.health -= damage;
if (this.health <= 0) {
console.log(`${this.playerName} has been defeated!`);
location.reload();
}
updateHealthBar(this.health);
}
negateDmg(totalDamage) {
console.log(totalDamage);
console.log(selectedArmor.def);
const equippedArmor = selectedArmor;
if (equippedArmor) {
const negatedAmount = Math.min(totalDamage, equippedArmor.def);
console.log(`${this.playerName} negates ${negatedAmount} damage using ${equippedArmor.armorName}!`);
let trueDamage = totalDamage - negatedAmount;
player1.takeDamage(totalDamage - negatedAmount);
console.log(this.playerName + ' takes ' + trueDamage + ' in damage.')
} else {
console.log('No armor equipped. Taking full damage!');
player1.takeDamage(totalDamage);
}
updateHealthBar(this.health);
}
attackWithSpecialMove(currentEnemy) {
console.log('Begin special move!')
if (selectedWeapon.durability > 0) {
console.log(`${this.playerName} performs a special attack on ${currentEnemy.enemyName} with ${selectedWeapon.itemName} for ` + selectedWeapon.specialDmg);
console.log(currentEnemy.name);
console.log(selectedWeapon.specialDmg);
currentEnemy.takeDamage(selectedWeapon.specialDmg);
selectedWeapon.durability -= 7;
console.log(selectedWeapon.itemName + ' has lost 7 durability. It now has ' + selectedWeapon.durability + ' durability!')
console.log('Special has been used!')
canUseSpecialMove = false;
if (currentEnemy.health <= 0) {
console.log(`${currentEnemy.enemyName} has been defeated by special move! Brutality!`);
}
} else {
console.log(selectedWeapon.itemName + ' is broken! Please choose another weapon')
}
}
attackWithSelectedWeapon(enemy) {
const weaponForAttack = selectedWeapon;
if (!weaponForAttack) {
console.log('No weapon selected. Cannot attack.');
return;
}
// Perform attack
if (weaponForAttack.durability > 0) {
console.log(`${this.playerName} attacks ${enemy.enemyName} with ${weaponForAttack.itemName} for ` + weaponForAttack.dmg);
enemy.takeDamage(weaponForAttack.dmg);
weaponForAttack.durability -= 5;
console.log(weaponForAttack.itemName + ' has lost 5 durability. It now has ' + weaponForAttack.durability + ' durability!')
if (enemy.health <= 0) {
console.log(`${enemy.enemyName} has been defeated!`);
}
} else {
console.log(weaponForAttack.itemName + ' is broken! Please choose another weapon')
}
}
defendWithSelectedArmor(enemy, enemyAttacked) {
if (enemyAttacked = true) {
if (defendBtnClicked) {
const armorForDefend = selectedArmor;
if (!armorForDefend) {
console.log('No armor selected. Cannot defend.');
return;
}
if (armorForDefend.durability > 0) {
const baseDamage = Math.floor(Math.random() * 5) + 1;
const totalDamage = baseDamage + enemy.enemydmg;
this.negateDmg(totalDamage);
armorForDefend.durability -= 10;
console.log(`${armorForDefend.armorName} has lost 10 durability. It now has ${armorForDefend.durability} durability.`);
if (totalDamage > armorForDefend.def) {
updateHealthBar(this.health);
} else {
console.log(`${this.playerName} takes 0 damage after defending!`);
}
} else {
console.log(`${armorForDefend.armorName} is broken! Please choose another armor.`);
}
}
}
if (enemyAttacked = false) {
console.log('Enemy has missed!')
}
}
cycleWeapons(currentWeapon) {
const weapons = this.inventory.filter(item => item instanceof Weapon);
if (!weapons || weapons.length === 0) return null;
let currentIndex = -1;
if (currentWeapon) {
currentIndex = weapons.findIndex(item => item === currentWeapon);
}
let nextIndex = (currentIndex + 1) % weapons.length;
return weapons[nextIndex];
}
cycleArmor(currentArmor) {
const armor = this.inventory.filter(item => item instanceof Armor);
if (!armor || armor.length === 0) return null;
let currentIndex = -1;
if (currentArmor) {
currentIndex = armor.findIndex(item => item === currentArmor);
}
let nextIndex = (currentIndex + 1) % armor.length;
return armor[nextIndex];
}
parryAction(currentEnemy)
{
console.log('Begin parry move!');
this.health += 30;
console.log('You gain 30 health!');
console.log(currentEnemy.enemyName);
currentEnemy.takeDamage(5);
console.log('You parry ' + currentEnemy.enemyName + ' for 5 damage!');
updateEnemyHealthBar();
canUseParryMove = false;
}
healPlayer()
{
player1.health += 50;
console.log("You heal for 50");
updateHealthBar(this.health);
console.log(this.health);
}
}
class Enemy {
constructor(enemyName, health, enemydmg, healthBarId, maxHealth, percentChanceToAttack, enemyDefense, percentChanceToDefend, totalDamage) {
this.enemyName = enemyName;
this.health = health;
this.enemydmg = enemydmg;
this.healthBarId = healthBarId;
this.maxHealth = maxHealth;
this.percentChanceToAttack = percentChanceToAttack;
this.enemyDefense = enemyDefense;
this.percentChanceToDefend = percentChanceToDefend;
this.totalDamage = totalDamage;
}
attackPlayer(player, isDefending) {
if (!isDefending) {
const baseDamage = Math.floor(Math.random() * 5) + 1;
const totalDamage = baseDamage + this.enemydmg;
console.log(`${this.enemyName} attacks ${player.playerName} with ${totalDamage} damage!`);
player.takeDamage(totalDamage);
} else {
const baseDamageForNegation = Math.floor(Math.random() * 5) + 1;
const totalDamage = baseDamageForNegation + this.enemydmg;
player.negateDmg(totalDamage);
}
}
takeDamage(dmg) {
this.health -= dmg;
if (this.health <= 0) {
console.log(`${this.enemyName} has been defeated!`);
}
updateEnemyHealthBar(this.health, this);
}
negateDmg() {
console.log('Enemy Negates Damage!');
const negatedAmountEnemy = selectedWeapon.dmg - this.enemyDefense;
console.log(`${this.enemyName} negates ${negatedAmountEnemy} damage!`);
let trueDamageEnemy = selectedWeapon.dmg - negatedAmountEnemy;
this.health -= trueDamageEnemy;
console.log(this.enemyName + ' takes ' + trueDamageEnemy + ' in damage.');
console.log('Enemy Health: ' + this.health);
updateEnemyHealthBar(this.health, this);
}
}
class Weapon {
constructor(itemName, dmg, durability, specialDmg) {
this.itemName = itemName;
this.dmg = dmg;
this.durability = durability;
this.specialDmg = specialDmg;
}
}
class Item {
constructor(itemName, value){
this.itemName = itemName;
this.value = value;
}
}
class Armor {
constructor(armorName, def, durability) {
this.armorName = armorName;
this.def = def;
this.durability = durability;
}
}
function updateHealthBar(health) {
const healthBarFill = document.getElementById('healthBarFill');
const maxHealth = 100;
const percentage = (health / maxHealth) * 100;
healthBarFill.style.width = `${percentage}%`;
}
// Function to update enemy's health bar
function updateEnemyHealthBar(health, currentEnemy) {
const enemyHealthBarFill = document.getElementById('enemyHealthBarFill');
const maxHealth = currentEnemy.maxHealth;
const percentage = (health / maxHealth) * 100;
enemyHealthBarFill.style.width = `${percentage}%`;
}
const player1 = new Player('Paladin', 100);
const skeleton = new Enemy('Skeleton', 90, 15, 'skeletonHealthBarFill', 90, 0.8, 5, 0.2);
const darkMage = new Enemy('Dark Mage', 80, 20, 'darkMageHealthBarFill', 80, 0.8, 7, 0.2);
const gremlin = new Enemy('Horice the Gremlin', 90, 15, 'horiceHealthBarFill', 90, 0.8, 5, 0.2);
const goblin = new Enemy('Godrey the Goblin', 80, 20, 'godreyHealthBarFill', 80, 0.8, 7, 0.2);
const bigGoblin = new Enemy('Giant Goblin', 90, 15, 'bigGoblinHealthBarFill', 90, 0.8, 5, 0.2);
const mimic = new Enemy('Golden Mimic', 80, 20, 'mimicHealthBarFill', 80, 0.8, 7, 0.2);
const arcaneMage = new Enemy('Jester the Arcane', 90, 15, 'arcaneHealthBarFill', 90, 0.8, 5, 0.2);
const ghoul = new Enemy('Ghoul', 80, 20, 'ghoulHealthBarFill', 80, 0.8, 7, 0.2);
const woodSword1 = new Weapon('Wood Sword', 15, 40, 40);
const woodMace1 = new Weapon('Wood Mace', 8, 60, 45);
const woodWhip1 = new Weapon('Wood Whip', 20, 30, 15);
const ironSword = new Weapon('Iron Sword', 20, 40, 23);
const ironHammer = new Weapon('Iron hammer', 15, 60, 20);
const darkWand = new Weapon('Dark Wand', 10, 30, 50);
const woodArmor1 = new Armor('Wood Armor', 5, 100);
const woodArmor2 = new Armor('Dark Wood Armor', 7, 100);
const woodArmor3 = new Armor('Light Wood Armor', 7, 100);
const boneArmor = new Armor('Bone Armor', 10, 120);
const darkRobe = new Armor('Dark Robe', 10, 120);
const arcaneRobe = new Armor('Arcane Robe', 15, 120);
const goblinChainmail = new Armor('Goblin Chainmail', 20, 120);
const strangePotion = new Item('Healing Elixir', 50);
const scroll = new Item('Ancient Scroll', 100);
const coins = new Item('Bag of Coins', 100);
const treasure = new Item('Dungeon Treasure', 500);
const map = new Item('Dungeon Map', 100);
const textElement = document.getElementById('text')
const optionButtonsElement = document.getElementById('option-buttons')
function showTextNode(textNodeIndex) {
const textNode = textNodes.find(textNode => textNode.id === textNodeIndex);
textElement.innerText = textNode.text;
while (optionButtonsElement.firstChild) {
optionButtonsElement.removeChild(optionButtonsElement.firstChild);
}
textNode.options.forEach(option => {
if (showOption(option)) {
const button = document.createElement('button');
button.innerText = option.text;
button.classList.add('btn');
button.addEventListener('click', () => selectOption(option));
optionButtonsElement.appendChild(button);
}
});
}
function showOption(option) {
return true;
}
function selectOption(option) {
const nextTextNodeId = option.nextText;
if (nextTextNodeId === -1) {
return;
}
showTextNode(nextTextNodeId);
handleGameLogic(option);
}
function handleGameLogic(option) {
switch (option.action) {
case 'takeSword':
player1.addItem(woodSword1);
player1.displayInventory();
break;
case 'takeIronHammer':
player1.addItem(ironHammer);
player1.displayInventory();
break;
case 'takeMace':
player1.addItem(woodMace1);
player1.displayInventory();
break;
case 'takeWhip':
player1.addItem(woodWhip1);
player1.displayInventory();
break;
case 'takeDarkWand':
player1.addItem(darkWand);
player1.displayInventory();
break;
case 'takeIronSword':
player1.addItem(ironSword);
player1.displayInventory();
break;
case 'takeArmor':
player1.addArmor(woodArmor1);
player1.displayInventory();
break;
case 'takeDarkRobe':
player1.addItem(darkRobe);
player1.displayInventory();
break;
case 'takeArcaneRobe':
player1.addItem(arcaneRobe);
player1.displayInventory();
break;
case 'takeGoblinChainmail':
player1.addItem(goblinChainmail);
player1.displayInventory();
break;
case 'takeBoneArmor':
player1.addItem(boneArmor);
player1.displayInventory();
break;
case 'takePotion':
player1.addItem(strangePotion);
player1.displayInventory();
break;
case 'takeMap':
player1.addItem(map);
player1.displayInventory();
break;
case 'takeAmulet':
player1.addItem(magicAmulet);
player1.displayInventory();
break;
case 'takeScrollAndCoins':
player1.addItem(scrol1);
player1.addItem(coins);
player1.displayInventory();
break;
case 'takeTreasure':
player1.addItem(treasure);
player1.displayInventory();
break;
case 'battleSkeleton':
console.log('You choose to battle the skeleton.');
console.log('Get ready for the fight!');
startSkeletonBattle();
break;
case 'battleDarkMage':
console.log('You choose to battle the Dark Mage.');
console.log('Get ready for the fight!');
startDarkMageBattle();
break;
case 'battleArcaneMage':
console.log('Get ready for the fight with the Arcane Mage!');
startArcaneMageBattle();
break;
case 'battleBeast':
console.log('Get ready for the fight with the Beast of the Dungeon!');
startBeastBattle();
break;
case 'wearAmulet':
player1.equipAmulet(magicAmulet);
player1.displayStatus();
break;
case 'openBox':
console.log('You opened the box. A burst of light fills the room and you gain a magical boost.');
player1.gainMagicBoost();
player1.displayStatus();
break;
case 'pickLock':
console.log('You attempt to pick the lock.');
attemptLockPicking();
break;
case 'escapeDungeon':
console.log('You find the door leading out of the dungeon and escape!');
endGameWithVictory();
break;
case 'crossBridge':
console.log('You carefully cross the rickety bridge.');
crossRicketyBridge();
break;
case 'touchCrystals':
console.log('You touch the glowing crystals and feel a surge of energy.');
gainCrystalEnergy();
break;
case 'lookForTraps':
console.log('You carefully examine the door for traps.');
findTrapsOnDoor();
break;
case 'investigateArtifacts':
console.log('You investigate the ancient artifacts.');
findArtifacts();
break;
case 'enterHiddenPassage':
console.log('You enter the hidden passage.');
exploreHiddenPassage();
break;
case 'openGate':
console.log('You try to open the large gate.');
tryToOpenGate();
break;
case 'findSecretDoor':
console.log('You find the secret door behind the tapestry.');
discoverSecretDoor();
break;
case 'readDiary':
console.log('You read the old diary.');
readOldDiary();
break;
case 'lookInMirror':
console.log('You look into the dusty mirror.');
gazeIntoMirror();
break;
default:
console.log('No action defined for this option.');
break;
}
}
function updateEnemyHealthVisibility() {
var enemyHealthContainer = document.getElementById('enemyHealthContainer');
if (isBattleInProgress) {
enemyHealthContainer.classList.remove('hidden');
} else {
enemyHealthContainer.classList.add('hidden');
}
}
function startSkeletonBattle() {
console.log('Prepare for battle with the skeleton!');
const skeletonNameText = document.getElementById('enemyHealthBarName');
skeletonNameText.textContent = 'SKELETON HEALTH';
isBattleInProgress = true;
currentEnemy = skeleton;
updateEnemyHealthVisibility();
}
function endSkeletonBattle() {
isBattleInProgress = false;
if (player1.health <= 0) {
console.log('You have been defeated by the skeleton. Game over!');
resetGame();
} else {
console.log('You have defeated the skeleton!');
showTextNode(3011);
}
updateEnemyHealthVisibility();
player1.healPlayer();
}
function startArcaneMageBattle() {
console.log('Prepare for battle with the Arcane Mage!');
const arcaneMageNameText = document.getElementById('enemyHealthBarName');
arcaneMageNameText.textContent = 'ARCANE MAGE HEALTH';
isBattleInProgress = true;
currentEnemy = arcaneMage;
updateEnemyHealthBar(arcaneMage.maxHealth, arcaneMage);
updateEnemyHealthVisibility();
}
function endArcaneMageBattle() {
isBattleInProgress = false;
if (player1.health <= 0) {
console.log('You have been defeated by the Arcane Mage. Game over!');
resetGame();
} else {
console.log('You have defeated the Arcane Mage!');
showTextNode(301211111);
}
updateEnemyHealthVisibility();
player1.healPlayer();
}
function startDarkMageBattle() {
console.log('Prepare for battle with the Dark Mage!');
const darkMageNameText = document.getElementById('enemyHealthBarName');
darkMageNameText.textContent = 'DARK MAGE HEALTH';
isBattleInProgress = true;
currentEnemy = darkMage;
updateEnemyHealthVisibility();
}
function endDarkMageBattle() {
isBattleInProgress = false;
if (player1.health <= 0) {
console.log('You have been defeated by the Dark Mage. Game over!');
resetGame();
} else {
console.log('You have defeated the Dark Mage!');
showTextNode(3012);
}
updateEnemyHealthVisibility();
player1.healPlayer();
}
function enemyTurn(defendBtnClicked) {
console.log("Enemy's turn begins...");
if (!isBattleInProgress) return;
const randomChanceToAttack = Math.random();
const randomChanceToDefend = Math.random();
//console.log('enemy has a ' + currentEnemy.percentChanceToAttack + ' to attack you!');
//console.log('enemy has a ' + currentEnemy.percentChanceToDefend + ' to defend against you!');
// check if the player is still alive and if the enemy has attacked in this turn
if (player1.health > 0 && currentEnemy.health > 0) {
// Check if the player defended
//ATTACK CHANCES
if (randomChanceToAttack < currentEnemy.percentChanceToAttack) {
enemyAttacked = true;
//console.log('Enemy Attacked: ' + enemyAttacked);
}
if (randomChanceToAttack > currentEnemy.percentChanceToAttack) {
enemyAttacked = false;
//console.log('Enemy Attacked: ' + enemyAttacked);
}
//DEFEND CHANCES
if (randomChanceToDefend < currentEnemy.percentChanceToDefend) {
enemyDefended = true;
//console.log('Enemy Defended: ' + enemyDefended);
}
if (randomChanceToDefend > currentEnemy.percentChanceToDefend) {
enemyDefended = false;
//console.log('Enemy Defended: ' + enemyDefended);
}
// IF ATTACKING AND ENEMY DOESNT DEFEND (U ATTACK HIM)
if (!defendBtnClicked && !enemyDefended) {
player1.attackWithSelectedWeapon(currentEnemy);
}
// IF ATTACKING AND ENEMY DOES DEFEND
if (!defendBtnClicked && enemyDefended) {
currentEnemy.negateDmg(player1);
enemyAttacked = false;
// how enemy defends
}
//IF DEFENDING AND ENEMY ATTACKS (U NEGATE DAMAGE)
if (defendBtnClicked, enemyAttacked) {
player1.defendWithSelectedArmor(currentEnemy, defendBtnClicked, enemyAttacked);
}
// IF ATTACKING AND ENEMY ATTACKS
if (!defendBtnClicked && enemyAttacked)//pass in percent chance to attack
{
currentEnemy.attackPlayer(player1);
// how enemy attacks
}
/* if (!defendBtnClicked && !enemyAttacked && !enemyDefended){
console.log('Enemy missed its attack and defense! Its big damage time!');
window.alert('Special Attack Ready!');
} */
if (!enemyAttacked && !enemyDefended) {
console.log('Enemy missed its attack and defense! Special move is available!');
canUseSpecialMove = true;
window.alert('SPECIAL ATTACK READY!');
}
if (defendBtnClicked && enemyAttacked && enemyDefended){
console.log('Enemy hit its attack and defense! Parry move is available!');
canUseParryMove = true;
window.alert('PARRY READY!');
}
/* if (defendBtnClicked && !enemyAttacked && !enemyDefended){
console.log('Enemy missed its attack and defense!')
} */
}
if (currentEnemy.health <= 0) {
if (currentEnemy === skeleton) {
endSkeletonBattle();
} else if (currentEnemy === darkMage) {
endDarkMageBattle();
} else if (currentEnemy === arcaneMage){
endArcaneMageBattle();
}
}
}
const textNodes =
[
{
id: 1,
text: 'You wake on the floor of a dungeon. Its dark and you can feel 4 distint objects around you.',
options: [
{
text: 'pick up sword',
action: 'takeSword',
nextText: 2
},
{
text: 'pick up mace',
action: 'takeMace',
nextText: 2
},
{
text: 'pick up whip',
action: 'takeWhip',
nextText: 2
},
{
text: 'pick up armor',
action: 'takeArmor',
nextText: 2
},
]
},
{
id: 2,
text: 'As you feel around the walls you find two different hallways that lead deeper into the depths of the dungeon',
options: [
{
text: 'go to the left passage',
nextText: 301
},
{
text: 'go to the right passage',
nextText: 4
},
{
text: 'look for another way out',
nextText: 3
},
]
},
{
id: 301,
text: 'do u battle the skeleton or the dark mage',
options: [
{
text: 'skeleton',
action: 'battleSkeleton',
nextText: 1000
},
{
text: 'dark mage',
action: 'battleDarkMage',
nextText: 1000
},
]
},
{
id: 3011,
text: 'the skeleton begins to fall to peices and dropps to the ground.',
options: [
{
text: 'NEXT',
action: 'takeBoneArmor',
nextText: 30121
},
]
},
{
id: 3012,
text: 'the mage dissapears in dust after its defeat',
options: [
{
text: 'NEXT',
action: 'takeDarkRobe',
nextText: 30121
},
]
},
{
id: 30121,
text: 'You continue on down the halls of the dungeon looking for a way out...',
options: [
{
text: 'NEXT',
nextText: 301211
},
]
},
{
id: 301211,
text: 'You come across a two way split off of the hallways. The path to the left has a demonic presence. The path to the right looks long forgotten.',
options: [
{
text: 'Be brave. Go left.',
nextText: 3012111
},
{
text: 'Be smart. Go right.',
nextText: 3012112
},
]
},