-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextBasedDNDGame.js
More file actions
1148 lines (985 loc) · 42.5 KB
/
TextBasedDNDGame.js
File metadata and controls
1148 lines (985 loc) · 42.5 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
(function() {
var DamageCurseScroll, PoisonScroll, Scroll,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
this.Item = (function() {
function Item() {}
Item.prototype.use = function() {};
return Item;
})();
this.Die = (function() {
function Die(numberOfDice, numberOfSides, constant) {
this.numberOfDice = numberOfDice;
this.numberOfSides = numberOfSides;
this.constant = constant;
}
Die.prototype.roll = function() {
var i, sum, _i, _ref;
sum = this.constant;
for (i = _i = 1, _ref = this.numberOfDice; 1 <= _ref ? _i <= _ref : _i >= _ref; i = 1 <= _ref ? ++_i : --_i) {
sum += Math.random() * this.numberOfSides;
}
return Math.floor(Math.max(sum, 0));
};
Die.prototype.toString = function() {
return this.numberOfDice + "d" + this.numberOfSides + "+" + this.constant;
};
return Die;
})();
/*
Weapon class
*/
this.Weapon = (function(_super) {
__extends(Weapon, _super);
function Weapon(die, name, price) {
this.die = die;
this.name = name;
this.price = price;
}
Weapon.prototype.roll = function() {
return this.die.roll();
};
Weapon.prototype.toString = function() {
return this.name.toString() + ": " + this.die.toString() + " (" + this.price.toString() + "gp)";
};
return Weapon;
})(Item);
/*
Monster class
All monsters should be instances of this class.
Make a monster with "new Monster(<parameters in here>)"
*/
this.Monster = (function() {
function Monster(name, hp, weapon, gp, xp) {
this.hp = hp;
this.weapon = weapon;
this.gp = gp;
this.xp = xp;
this.name = randomAdjective() + " " + name;
}
Monster.prototype.roll = function() {
return this.weapon.roll();
};
Monster.prototype.hit = function(damage) {
return this.hp -= damage;
};
Monster.prototype.isDead = function() {
return this.hp <= 0;
};
Monster.prototype.toString = function() {
return this.name;
};
return Monster;
})();
/*
Potions
*/
this.Potion = (function(_super) {
__extends(Potion, _super);
function Potion() {}
return Potion;
})(Item);
this.HealthPotion = (function(_super) {
__extends(HealthPotion, _super);
function HealthPotion() {}
/*
Drinks the potion
*/
HealthPotion.prototype.use = function() {
var index;
hp += 10;
index = inventory.indexOf(this);
return inventory.splice(index, 1);
};
HealthPotion.prototype.toString = function() {
return "Health Potion";
};
return HealthPotion;
})(Potion);
this.EvasionPotion = (function(_super) {
__extends(EvasionPotion, _super);
function EvasionPotion() {}
/*
Drinks the potion
Temporarially boosts the player's Evasion
*/
EvasionPotion.prototype.use = function() {};
EvasionPotion.prototype.toString = function() {
return "Evasion Potion";
};
return EvasionPotion;
})(Potion);
this.BlockPotion = (function(_super) {
__extends(BlockPotion, _super);
function BlockPotion() {}
/*
Drinks the potion
Temporarially boosts the player's block
*/
BlockPotion.prototype.use = function() {};
BlockPotion.prototype.toString = function() {
return "Block Potion";
};
return BlockPotion;
})(Potion);
/*
Scrolls
*/
Scroll = (function(_super) {
__extends(Scroll, _super);
function Scroll() {}
return Scroll;
})(Item);
DamageCurseScroll = (function(_super) {
__extends(DamageCurseScroll, _super);
function DamageCurseScroll() {}
DamageCurseScroll.prototype.use = function() {
return enemies[0].damage = 0;
};
DamageCurseScroll.prototype.toString = function() {
return "Damage-curse scroll";
};
return DamageCurseScroll;
})(Scroll);
PoisonScroll = (function(_super) {
__extends(PoisonScroll, _super);
function PoisonScroll() {}
PoisonScroll.prototype.use = function() {};
return PoisonScroll;
})(Scroll);
}).call(this);
/*
this file is full of Named Weapons
*/
/*
Blacksmith
*/
(function() {
this.smallDagger = new Weapon(new Die(3, 6, +3), "Dagger of awesome", 200);
this.daggerofshadow = new Weapon(new Die(3, 7, +2), "Dagger of Shadow", 500);
this.daggerofdeath = new Weapon(new Die(3, 8, +3), "Dagger of Death", 600);
this.swordofthefeather = new Weapon(new Die(3, 8, -3), "Sword of the feather", 300);
this.supersword = new Weapon(new Die(6, 6, -6), "Super Sword", 600);
this.swordofthesun = new Weapon(new Die(5, 9, -5), "Sword of the Sun", 750);
/*
Fletcher
*/
this.longbowoffire = new Weapon(new Die(5, 4, -5), "Long Bow of Fire", 400);
this.powerfulllongbow = new Weapon(new Die(6, 4, 0), "powerfull longbow", 400);
}).call(this);
(function() {
var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
this.print = function(text) {
return ($(".game")).append(text);
};
this.println = function(text) {
print(text);
return print("<br>");
};
this.setState = function(newState) {
this.state = newState;
return run();
};
this.loadState = function() {
return returnToState;
};
this.button = function(newState, text) {
return println("<button onclick=\"setState('" + newState + "')\">\n" + text + "\n</button>");
};
this.dropDown = function(options) {
var option, result, _i, _len;
result = "<select>";
for (_i = 0, _len = options.length; _i < _len; _i++) {
option = options[_i];
result += "<option>";
result += option;
result += "</option>";
}
result += "</select>";
return result;
};
this.prob = function(probability) {
return Math.random() <= probability;
};
this.inBounds = function(x, y) {
return x >= 0 && y >= 0 && x < 4 && y < 4;
};
this.randomAdjective = function() {
return ["Mean", "Nasty", "Terrible", "Ugly"][Math.floor(Math.random() * 4)];
};
this.showMap = function() {
if (inBounds(this.locY + 1, this.locX) && this.map[this.locY + 1][this.locX]) {
button(this.map[this.locY + 1][this.locX], "Head south to the " + this.map[this.locY + 1][this.locX]);
}
if (inBounds(this.locY - 1, this.locX) && this.map[this.locY - 1][this.locX]) {
button(this.map[this.locY - 1][this.locX], "Head north to the " + this.map[this.locY - 1][this.locX]);
}
if (inBounds(this.locY, this.locX + 1) && this.map[this.locY][this.locX + 1]) {
button(this.map[this.locY][this.locX + 1], "Head east to the " + this.map[this.locY][this.locX + 1]);
}
if (inBounds(this.locY, this.locX - 1) && this.map[this.locY][this.locX - 1]) {
return button(this.map[this.locY][this.locX - 1], "head west to the " + this.map[this.locY][this.locX - 1]);
}
};
this.visited = function(state) {
return __indexOf.call(this.statesEntered, state) >= 0;
};
this.printstat = function(string) {
($(".stats")).append("<br>");
return ($(".stats")).append(string);
};
this.useInventoryItemN = function(n) {
this.inventory[n].use();
return console.log("TEST");
};
this.convertAlignmentNumberToWord = function(number) {
if (number === -1) {
return "Hate";
} else if (number === 0) {
return "neautral";
} else if (number === 1) {
return "Love";
} else if (number < -0.5) {
return "Strongly Dislike";
} else if (number < 0) {
return "Dislike";
} else if (number > 0.5) {
return "Strongly Like";
} else if (number > 0) {
return "Like";
} else {
return "ERROR, COMPUTER BLOWING UP IN 5... 4... 3... 2... 1... BOOOOOOOOOOOOOOOOOOM (EXPLOSION NOISES)";
}
};
this.refresh = function() {
var enemy, index, item, _i, _j, _len, _len1, _ref, _ref1;
($(".stats")).html("");
_ref = this.enemies;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
enemy = _ref[_i];
printstat("");
printstat("Enemy stats:");
printstat("HP: " + enemy.hp);
}
printstat("");
printstat("Your stats:");
printstat("HP: " + this.hp);
printstat("MP: " + this.mp);
printstat("GP: " + this.gp);
printstat("XP: " + this.xp);
printstat("");
printstat("Your allignments:");
printstat("Zealon: " + (convertAlignmentNumberToWord(this.zealonAlignment)));
printstat("Scilo: " + (convertAlignmentNumberToWord(this.sciloAlignment)));
printstat("Ajurite: " + (convertAlignmentNumberToWord(this.ajuriteAlignment)));
printstat("Weapon:");
printstat("" + this.weapon);
($(".inventory")).html("");
($(".inventory")).append("Inventory");
($(".inventory")).append("<br>");
($(".inventory")).append("-------------");
($(".inventory")).append("<br>");
index = 0;
_ref1 = this.inventory;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
item = _ref1[_j];
($(".inventory")).append("<br>");
($(".inventory")).append("<button onclick=\"useInventoryItemN(" + index + ")\">\n" + index + "\n" + (item.toString()) + "\n</button>");
index++;
}
return setTimeout(refresh, 1000);
};
}).call(this);
(function() {
this.goblin = function() {
return new Monster("Goblin", smallHP.roll(), smallDamage, smallDrop.roll(), 10);
};
this.dwarfBeserker = function() {
return new Monster("Dwarf Beserker", smallHP.roll(), mediumDamage, mediumDrop.roll(), 30);
};
this.horseMan = function() {
return new Monster("Horse Man", smallHP.roll(), mediumDamage, mediumDrop.roll(), 30);
};
this.paladin = function() {
return new Monster("Ajurite Paladin", largeHP.roll(), largeDamage, largeDrop.roll(), 100);
};
this.zombie = function() {
return new Monster("Zombie", mediumHP.roll(), mediumDamage, mediumDrop.roll(), 40);
};
this.largeZombie = function() {
return new Monster("Terrible Zombie", largeHP.roll(), mediumDamage, mediumDrop.roll(), 40);
};
this.corruptedOrc = function() {
return new Monster("Corrupted Orc", mediumHP.roll(), mediumDamage, mediumDrop.roll(), 30);
};
this.spider = function() {
return new Monster("Spider", smallHP.roll(), mediumDamage, mediumDrop.roll(), 25);
};
this.animatedCactus = function() {
return new Monster("Animated Cactus", mediumHP.roll(), smallDamage, smallDrop.roll(), 20);
};
this.riverMonster = function() {
return new Monster("River Monster", largeHP.roll(), mediumDamage, largeDrop.roll(), 50);
};
}).call(this);
(function() {
this.townStatesRun = function() {
var cost, upgradeBlockXPCost, upgradeEvadeXPCost;
upgradeEvadeXPCost = this.evade * 1000 + 100;
upgradeBlockXPCost = this.block * 100 + 10;
if (this.state === "inTown") {
println("You are in the town of Zemboria");
println("What do you want to do?");
button("town of Zemboria", "Leave town");
button("shops", "Look at the shops");
button("people", "Talk to people");
return button("Trainer", "Go to the Trainer");
} else if (this.state === "Trainer") {
println("Trainer: I can upgrade your block or evade.");
button("upgrade block", "Upgrade Block to " + (block + 1) + " (" + upgradeBlockXPCost + " xp)");
button("upgrade evade", "Upgrade Evade to " + (this.evade + .1) + " (" + upgradeEvadeXPCost + " xp)");
return button("inTown", "Back to town square");
} else if (this.state === "upgrade evade") {
if (this.xp >= upgradeEvadeXPCost) {
this.xp -= upgradeEvadeXPCost;
this.evade += 0.1;
println("You train and train and you finally get stronger");
} else {
println("I aint gonna train you if you arent going to pay me my price.");
}
return setState("Trainer");
} else if (this.state === "upgrade block") {
if (this.xp >= this.block * 100) {
this.xp -= this.block * 100;
this.block += 1;
println("You train and train and you finally get more agile");
} else {
println("I aint gonna train you if you arent going to pay me my price.");
}
return setState("Trainer");
} else if (this.state === "shops") {
println("The shops are small but friendly");
button("blacksmith", "Visit John the Blacksmith");
button("fletcher", "Visit Ken the Fletcher");
button("mage", "Visit Almerond the Mage");
return button("inTown", "Done shopping");
} else if (this.state === "town of Zemboria") {
println("Which way do you want to go?");
button("inTown", "Enter the town");
return showMap();
} else if (this.state === "blacksmith") {
println("John: Hello there, what can i do for you?");
button("daggers", "I'd like to look at your daggers.");
button("swords", "I'd like to take a look at your swords.");
return button("shops", "Leave the Blacksmith");
} else if (this.state === "daggers") {
println("Here's what I've got");
this.returnToState = this.state;
button(smallDagger, smallDagger);
button(daggerofshadow, daggerofshadow);
button(daggerofdeath, daggerofdeath);
button("aboutDaggers", "Can you tell me more about daggers?");
return button("blacksmith", "I guess I'm not interested in daggers");
} else if (this.state === "aboutDaggers") {
println("Daggers are small and fast. Some daggers will let you strike twice per turn, some daggers are poisoned.");
return button("daggers", "Thanks.");
} else if (this.state === "swords") {
println("These are the swords I've got.");
this.returnToState = this.state;
button(swordofthefeather, swordofthefeather);
button(supersword, supersword);
button(swordofthesun, swordofthesun);
button("aboutSwords", "Can you tell me more about swords?");
return button("blacksmith", "I'm not really interested in swords");
} else if (this.state === "aboutSwords") {
println("Swords are powerful and balanced. They tend to do more damage than daggers, but are more expensive.");
return button("swords", "Thanks.");
} else if (this.state === "fletcher") {
println("Ken: Hello there me matey. What can I do for you on this fine day?");
button("crossbows", "Might i have a look at your crossbows.");
button("longBows", "i'll take a look at your long bows.");
return button("shops", "Leave the Fletcher");
} else if (this.state === "crossbows") {
return println("Here's what I've got in the way of crossbows.");
} else if (this.state === "mage") {
println("You see a musty old shop with magical stuff everywhere. All over the shelves of the shop you see Hydra heads, slamander tails, frog tongue and other such magical things.");
println("You hear a booming voice: What do you want youngster? I was just taking a magicians nap!");
if (!visited("mage")) {
println("You may call me Almerond.");
}
button("potions", "May I look at your potion selection?");
button("staffs", "What staffs do you have?");
button("scrolls", "What in the way of scrolls do you have?");
button("heal", "Heal 10 hp (100 gp)");
button("enchant", "Enchant Weapon (500 gp)");
return button("shops", "I'm sorry for intruding, Almerond. Thank you.");
} else if (this.state === "enchant") {
cost = 500;
if (this.gp >= cost) {
this.weapon.die.numberOfDice += 1;
this.gp -= cost;
println("Your weapon has been enchanted.");
} else {
println("What you trying to do, scamp.");
}
return setState("mage");
} else if (this.state === "heal") {
cost = 100;
if (this.gp >= cost) {
println("You pay " + cost + " gp");
this.hp += 10;
this.gp -= cost;
} else {
println("you trying to cheat me boy.");
}
return setState("mage");
} else if (this.state === "potions") {
println("Potions will give you momentary advantages over enemies but they only last for a single battle.");
button("Health Potion buying", "Buy Health potion (30 gp)");
return button("mage", "Thanks!");
} else if (this.state === "staffs") {
println("Staffs are what make the mage, if you watched lord of the rings you would know that.");
return setState("mage");
} else if (this.state === "scrolls") {
println("Scrolls are powerfull spells that can decimate your enemy.");
button("damage-curse scroll buying", "Buy a damage-curse scroll");
return button("mage", "Thanks!");
} else if (this.state === "Health Potion buying") {
if (gp >= 30) {
gp -= 30;
inventory.push(new HealthPotion());
} else {
println("You trying to cheat me scamp!!!");
}
return setState("mage");
} else if (this.state === "damage-curse scroll buying") {
if (gp >= 50) {
gp -= 50;
inventory.push(new DamageCurseScroll());
} else {
println("You aint got the dough, bro.");
}
return setState("mage");
} else if (this.state === "people") {
if (prob(.25)) {
return setState("Dungeon guy");
} else if (prob(.50)) {
return setState("mayor");
} else {
println("No one is out and about.");
return setState("inTown");
}
} else if (this.state === "Dungeon guy") {
if (visited("Dungeon guy win")) {
return println("Thank you so much i cant ever thank you enough");
} else {
if ((visited("Dungeon guy")) && (visited("Zealon Dungeon"))) {
return setState("Dungeon guy win");
} else {
println("Howdy, stranger. My name is Alastor. Let me tell you my story.");
println("My family's heirloom, a great horn that my great great great grandfather used in the great guild wars, one day dissapeared. I raised a hue and cry and paid the best trackers around to find the people that stole it. They eventually tracked them down to the Zealon Dungeon. I tried to hire people to kill them and get my horn back but everyone was to scared to venture into the Zealon Dungeon. So I wish for you to go in there, kill them and get me my horn back. I'll reward you 1000 gold for retrieving the horn.");
return button("inTown", "I'll see what I can do.");
}
}
} else if (this.state === "Dungeon guy win") {
this.gp += 1000;
println("thank you so much i cant ever thank you enough!!! Heres 1000 gp for getting my heirloom.");
return button("inTown", "My pleasure.");
} else if (this.state === "mayor") {
if (visited("mayor win")) {
return println("Thanks");
} else {
return println("Ever since the great guild wars that ravaged this land long ago, The land has been infested with every sort of nasty mosnter. The goblins are the worst though, They raid the villages of alavar. They are a menace to everyone. So i wish for you to go and raid them. I will pay you 500 gold (kill 5 goblins).");
}
} else if (this.state === smallDagger.toString()) {
if (this.gp >= smallDagger.price) {
this.gp -= smallDagger.price;
this.weapon = smallDagger;
println("Congratulations on buying the Dagger of awesome. You look at it and see that its awesome");
} else {
println("Take your hands off that dagger. You aint got the money to pay for that beauty.");
}
return setState(loadState());
} else if (this.state === swordofthefeather.toString()) {
if (this.gp >= swordofthefeather.price) {
this.gp -= swordofthefeather.price;
this.weapon = swordofthefeather;
println("You pick up the sword and it is incredibly light. It feels wonderful in your hands.");
} else {
println("Get out of here cheapskate.");
}
return setState(loadState());
} else if (this.state === supersword.toString()) {
if (this.gp >= supersword.price) {
this.gp -= supersword.price;
this.weapon = supersword;
println("You pick up the sword and suddenly you feel like super man. You feel like you can do anything.");
} else {
println("Get out of here cheapskate.");
}
return setState(loadState());
} else if (this.state === swordofthesun.toString()) {
if (this.gp >= swordofthesun.price) {
this.gp -= swordofthesun.price;
this.weapon = swordofthesun;
println("You pick up the sword and it glows with an angelic light.");
} else {
println("Dont come back here Hobo.");
}
return setState(loadState());
} else if (this.state === daggerofshadow.toString()) {
if (this.gp >= daggerofshadow.price) {
this.gp -= daggerofshadow.price;
this.weapon = daggerofshadow;
println("you can barely see the dagger its so cloaked by Shadow. it is cold to the touch.");
} else {
println("Set your hands of that dagger.");
}
return setState(loadState());
} else if (this.state === daggerofdeath.toString()) {
if (this.gp >= daggerofdeath.price) {
this.gp -= daggerofdeath.price;
this.weapon = daggerofdeath;
println("This dagger has the stench of Death. it had perpetual blood on its edge. No matter how much you wipe it never comes of.");
} else {
println("Stop touching that beauty, poor guy. You can't afford it.");
}
return setState(loadState());
} else if (this.state === powerfulllongbow.toString()) {
if (this.gp >= powerfulllongbow.price) {
this.gp -= powerfulllongbow.price;
this.weapon = powerfulllongbow;
println("You heft the beautiful long bow and then throw it over your shoulder.");
} else {
println("You aint got the money te pay for that beauty, so go away.");
}
return setState(loadState());
} else if (this.state === longbowoffire) {
if (this.gp >= longbowoffire.price) {
this.gp -= longbowoffire.price;
this.weapon = longbowoffire;
println("There are beautiful carvings of fire and in the darkness those engravings flicker like fire. (he says reverantly)");
} else {
println("Get your hands of that ye scurvy scallywag, that one of my best bows. Unless yev actually got te gold for it.");
}
return setState(loadState());
}
};
}).call(this);
(function() {
this.mapStatesRun = function() {
var damage;
if (this.state === "forest") {
println("The forest is dark and spooky");
if (!visited(this.state)) {
println("You find a frog who blesses you (+5 hp)");
this.hp += 5;
} else {
if (prob(.5)) {
"You see a spider scuttling away from you.";
}
}
button("upTree", "Climb a tree");
return showMap();
} else if (this.state === "upTree") {
if (!visited("upTree")) {
println("You see an old monkey at the top of the tree");
println("Murundy: Welcome to the land of the Monkeys, young one.");
println("Murundy: My name is Murundy, and I am a sage among the Monkeys here.");
} else {
println("You and Murundy are in the top of the tree, in the middle of the Monkey's forest.");
}
button("askAboutForests", "What can you tell me about these forests?");
return button("forest", "Climb down the tree");
} else if (this.state === "askAboutForests") {
println("Murundy: The forests have been the land of the Monkeys for over a century. But this last year the Spiders have moved in, driven by some unnatural force.");
button("showSpiderForest", "Would you take me to where the spiders are?");
return button("forest", "Climb down the tree");
} else if (this.state === "showSpiderForest") {
println("Murundy: Certainly. But be prepared for what you are about to see.");
println("Murundy: I'll take you on a path through the branches. Follow me");
button("spiderForestUpTree", "Follow Murundy");
return button("forest", "Climb down the tree");
} else if (this.state === "spiderForestUpTree") {
println("You find yourself in a darker part of the forest, and vast sticky cobwebs are strung hanging between the trees.");
println("Murundy: See the egg-sacks between the root of the trees? These spiders are reproducing out of control. We don't know why.");
button("upTree", "I've seen enough. Please take me back.");
return button("Spider Forest", "Climb down the tree");
} else if (this.state === "Spider Forest") {
println("The trees are tangled with cobwebs and the roots have egg-sacks strung between their roots.");
if (prob(.5)) {
println("A spider clambers down from the trees and lunges at you.");
this.enemies = [spider()];
button("fightYourTurn", "Engage him");
return this.returnToState = this.state;
} else {
println("you get tangled in a cobweb (-2 hp)");
this.hp -= 2;
button("eggSacks", "Investigate egg-sacks");
return showMap();
}
} else if (this.state === "eggSacks") {
println("You see larvae swarming inside of translucent pouches.");
button("breakEggSacks", "Break egg-sack");
return button("Spider Forest", "Done inestigating egg-sacks");
} else if (this.state === "breakEggSacks") {
println("A baby spider crawls on to your hand and tries to bite you with its mandibles.");
this.enemies = [babySpider()];
this.returnToState = this.state;
return button("fightYourTurn", "Fight the Baby Spider");
} else if (this.state === "swamp") {
println("The swamps glurp and gurgle at you");
if (prob(.5)) {
println("A goblin rises out of the black deep");
this.enemies = [goblin()];
button("fightYourTurn", "Engage him");
return this.returnToState = this.state;
} else {
println("Your boots get mucky");
return showMap();
}
} else if (this.state === "deeper swamp") {
println("The swamp is almost unbearebly thick. It smells like mold and like orc.");
if (prob(.5)) {
println("A corrupted orc rises from the muck");
this.enemies = [corruptedOrc()];
button("fightYourTurn", "Engage him");
return this.returnToState = this.state;
} else {
println("The swamp mud mucks up your boots.");
return showMap();
}
} else if (this.state === "marshes") {
println("The marshes are marshy");
return showMap();
} else if (this.state === "desert") {
println("The desert is hot and dry. It continues for great lengths to the south, but yields to foothills to the north. There are serious-looking cacti.");
if (prob(.25)) {
println("You accidentally got a spine in you. (-3 hp)");
this.hp -= 3;
}
return showMap();
} else if (this.state === "wasteland") {
println("The wasteland is the result of a Scilos experiment gone wrong. It's a parched and lifeless desert as far as the eye can see. You are miserably thirsty.");
if (prob(.5)) {
println("A cactus starts to move towards you.");
this.enemies = [animatedCactus()];
button("fightYourTurn", "Engage the Animated Cactus");
return this.returnToState = this.state;
} else {
return showMap();
}
} else if (this.state === "Beara Mountains") {
println("The air is thin and hard to breathe, and you see crevasses stretching far below you.");
if (prob(.5)) {
println("Suddenly, a dwarf beserker charges at you from a cliff above.");
this.enemies = [dwarfBeserker()];
button("fightYourTurn", "Engage the Beserker");
return this.returnToState = this.state;
} else {
return showMap();
}
} else if (this.state === "foothills") {
println("The ground is rough and treacherous, and the going is hard but you eventually make it to a good campground.");
if (prob(.5)) {
println("While you are sleeping a savage horseman attacks you!");
this.enemies = [horseMan()];
button("fightYourTurn", "Engage the Horseman");
return this.returnToState = this.state;
} else {
return showMap();
}
} else if (this.state === "Lake Mysterious") {
println("The lake goes out as far as the eye can see its absolutely enormous.");
println("there is a slight disturbance in the water... you wonder what it is...");
if (prob(.5)) {
println("suddenly an enourmous octopus arises from the water.");
this.enemies = [riverMonster()];
button("fightYourTurn", "Engage the Octopus");
return this.returnToState = this.state;
} else {
return showMap();
}
} else if (this.state === "Zealon Dungeon") {
println("You see cut into the side of a hill the Zealon emblem, a skull inside of a circle made of snakes. Entranced, you walk closer and see that the gaping mouth of the skull leads to a room underground. It's darkeness is impenetrable.");
button("enteranceRoom", "Enter the Zealon Dungeon");
return showMap();
} else if (this.state === "enteranceRoom") {
println("You find yourself in a small room with walls that are coated in dried blood. The walls seem to press in on you. Your compass goes haywire. Your internal instincts are screaming at you to turn back.");
button("entrance corridor", "Go further in to the Dungeon");
return button("Zealon Dungeon", "Exit Dungeon");
} else if (this.state === "entrance corridor") {
println("You walk in to a long narrow corridor. It has strange symbols and markings on the ground. It seems to be a kind of warning");
if (!visited(this.state)) {
if (prob(.5)) {
println("A zombie raises itself out of the dirt.");
this.enemies = [zombie()];
button("fightYourTurn", "Engage the Zombie");
return this.returnToState = this.state;
} else {
println("A spike-trap beneath your feet shoots up and stabs you. You lose 10 hp.");
this.hp -= 10;
button("junctionRoom", "Head deeper into the darkness");
return button("enteranceRoom", "Head back towards the light");
}
} else {
button("junctionRoom", "Head deeper into the darkness");
return button("enteranceRoom", "Head back towards the light");
}
} else if (this.state === "junctionRoom") {
println("You are in a large room with three corridors leading out of it.");
damage = Math.ceil(Math.random() * 3);
println("An ill odor fills the room and your lungs. You lose " + damage + " hp.");
this.hp -= damage;
if (!visited(this.state)) {
println("A giant Zombie raises itself out of the filthy ground. It reaches its long fingers towards you.");
this.enemies = [largeZombie()];
button("fightYourTurn", "Engage the Zombie");
return this.returnToState = this.state;
} else {
button("leftCorridor", "Enter the corridor on the left");
button("rightCorridor", "Enter the corridor on the right");
return button("entrance corridor", "Go back towards the enterance");
}
} else if (this.state === "leftCorridor") {
println("Deeper into the dungeon, you see an open room. A huge, engraved chest sits at the back of the room.");
button("junctionRoom", "Go towards the enterance");
return button("leftRoom", "Go deeper");
} else if (this.state === "leftRoom") {
if (!visited(this.state)) {
println("As you enter the room, the door slams behind you and a towering orc smiles a sister grin at you.");
button("leftRoom fight", "Attack him");
return button("leftRoom talk", "Go up to him");
} else if (!visited("leftRoom fight")) {
button("leftRoom talk", "talk with Chenk again");
button("junctionRoom", "go back to the junction room");
return button("left room trap chest inspect", "go over to the huge engraved chest");
} else {
return println("You walk over to the dead corpse of the orc and see a locket bearing the crest of the ajurite paladins, the most elite group of ajurite knights.");
}
} else if (this.state === "left room trap chest inspect") {
return button("left room trap chest", "open the chest");
} else if (this.state === "leftRoom fight") {
println("You meet the battle with gusto.");
this.enemies = [corruptedOrc()];
setState("fightYourTurn");
return this.returnToState = "leftRoom";
} else if (this.state === "leftRoom talk") {
println("You walk up to the orc");
return button("hello", "Hello");
} else if (this.state === "hello") {
println("Hello my name is Chenk.");
return button("whatGoingOn", "What's going on with this dungeon?");
} else if (this.state === "whatGoingOn") {
println("Chenk: This is a dungeon created by the Zealon for their sinister rites.");
return button("whyareyouhere", "Why are you here? And why havent you attacked me?");
} else if (this.state === "whyareyouhere") {
println("I am here because the Zealon experimented their corruption magic on me but it backfired. Orcs arent all bad you know its just that the Zealon corrupted many of my kind. I cant leave the dungeon because of some strange magic.");
return button("more", "Wow the Zealon are really bad!");
} else if (this.state === "more") {
println("Chenk: The Zealon are bad but its debatable if they are the worst. The Ajurites are also pretty bad. They are good but over-zealous. They will kill hundreds of people just because one person did something bad. Then there are the Scilos. They are a group of mad scientists who are ruthless in the name of science. They do all kinds of experiments on people and animals.");
return button("leftRoom", "Wow. Thank you.");
} else if (this.state === "rightRoom") {
println("");
return button("junctionRoom", "Go towards the enterance");
} else if (this.state === "Plain of Ashard") {
println("A paladin in blazing white armor rides up and greets you as you enter onto the plain. You see the Ajurite symbol of a rising sun on his chestplate.");
if (visited("attackThePaladin")) {
println("Ajurite Paladin: You are not welcome here. Leave at once.");
} else {
println("Ajurite Paladin: The plain of Ashard is the land of the holy Ajurites. All travellers, including yourself, are granted free-passage through this land, providing you strictly adhere to Ajurite law.");
println("Ajurite Paladin: If you have come to the Plain of Ashard to prove your mettle, I'll escourt you to the arena.");
button("arena", "Please take me to the arena.");
}
button("attackTheKnight", "Attack the Ajurite Paladin");
return showMap();
} else if (this.state === "attackTheKnight") {
println("Ajurite Paladin: You raise your weapon against me? The Ajurites will not forgive you till your bones are ashes and those ashes are whiped from the face of the earth. Not a trace of you will remain after I am through with you. (he spits)");
this.enemies = [paladin()];
this.returnToState = "Plain of Ashard";
return setState("fightYourTurn");
} else if (this.state === "arena") {
println("The arena is a palacial, white circular stadium which you hear and smell long before your enter. The stench of human bodies pressed close together and the constant roar of the croud.");
println("Your in the lobby of the arena.");
if (!visited("arenaFight")) {
println("Ajurite Lord: (loudly) Let the next fight begin.");
} else {
println("Ajurite Lord: Ah. Welcome back. Will you do battle again?");
}
button("Plain of Ashard", "Leave the Arena");
return button("arenaFight", "Challenge an opponent");
} else if (this.state === "arenaFight") {
println("Ajurite Lord: So you'd like to try your strength in the pit? Whom would you like to challenge?");
button("arenaCorruptedOrc", "Fight a Corrupted Orc");
return button("arenaZombie", "Fight a Zombie");
} else if (this.state === "arenaCorruptedOrc") {
println("You walk out in the center of the dirt field and the croud goes silent. A grate is raised on the opposite side of the field, and a hulking orc emerges.");
this.enemies = [corruptedOrc()];
this.returnToState = "arena";
return setState("fightYourTurn");
} else if (this.state === "arenaZombie") {
println("You walk out in the center of the dirt field and the croud goes silent. A grate is raised on the opposite side of the field, and a sickening zombie emerges.");
this.enemies = [zombie()];
this.returnToState = "arena";
return setState("fightYourTurn");
}
};
}).call(this);
(function() {
var $;
$ = jQuery;
this.run = function() {
var damage, enemy, x, y, _i, _j, _k, _len, _ref;
if (this.turn !== 0) {
println("---");
}
console.log(this.state);
for (x = _i = 0; _i <= 3; x = ++_i) {
for (y = _j = 0; _j <= 3; y = ++_j) {
if (this.map[y][x] === this.state) {
this.locX = x;
this.locY = y;
}
}
}
if (this.state === "start") {
setState("story");
} else if (this.state === "story") {
println("You were born in the town of Zemboria. Your father was an important " + (dropDown(["Nobleman", "Blacksmith", "Merchant"])) + ". One day, when you came home, you found both of your parents brutally killed. You ask the neighbors and they tell you that they were slain by a " + (dropDown(["Holy Justicar", "Spider-dog", "Rampaging Orc"])) + ". You set off on your " + (dropDown(["easy", "medium", "hard"])) + " quest to avenge their death.");
println("");
button("inTown", "I'm ready to begin");
} else if (this.state === "dead") {
println("You have died : (");
println("You find yourself back in the town");
this.xp -= 15;
if (this.xp < 0) {
this.xp = 0;
}
this.gp -= 200;
if (this.gp < 0) {
this.gp = 0;
}
this.hp = 60;
println("Almerond: Stop making me revive you, young whippersnapper. I've charged you 200 gold peices for my trouble, thank you very much. Maybe if you bought some of my high-quality health potions you wouldn't die so much.");
setState("mage");
}
townStatesRun();
mapStatesRun();
if (this.state === "fightYourTurn") {
_ref = this.enemies;
for (_k = 0, _len = _ref.length; _k < _len; _k++) {
enemy = _ref[_k];
button("dealDamageToEnemy", "Attack " + enemy);
}
button("runAway", "Run Away");
} else if (this.state === "dealDamageToEnemy") {
damage = this.weapon.roll();