-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1456 lines (1405 loc) · 64.9 KB
/
index.html
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
<!--todo: cookies for saving game-->
<!--todo: ui cleanup-->
<!--stop for the night backgrounds-->
<!--slots with item images-->
<!--stats-->
<!--monster images-->
<!--tooltip with more info-->
<!--todo: adventure-->
<!--todo:explorable locations-->
<!--space stations-->
<!--small outposts-->
<!--planet colonies-->
<!--todo:mayhem-->
<!--marooned on planet-->
<!--parts of ship fail-->
<!--todo: needs: food water sleep-->
<!--punish stats when low-->
<!--todo: equipment/items-->
<!--combine magic item ability enhancers-->
<!--add tooltips for more info-->
<!--compare currently equipped-->
<!--todo: merchant-->
<!--quantities for merchant and inventory-->
<!--always carry food/drink/medical-->
<!--sort items by category-->
<!--todo: player stuff-->
<!--todo: add charisma-->
<!--increase amount gained when selling to merchant-->
<!--decrease amount spent when buying from merchant-->
<!--different speaking options?-->
<!--todo: add luck-->
<!--better chance of money items-->
<!--less chance of mob attacks-->
<!--crit percentage-->
<!--levelup sort out bonuses (str,dex,wis)-->
<!--skillups-->
<!--adds buttons for combat or passive stuff-->
<!--point buy/character customization-->
<!--add leaderboards-->
<!--add trophies-->
<!--add stats-->
<!--todo: enemies-->
<!--monster images/pluralization-->
<!--enemy weaknesses/strengths-->
<!--todo: combat-->
<!--todo: ship to ship combat-->
<!--todo: ship upgrades-->
<!--shields-->
<!--weapons-->
<!--todo: magic/int utilization-->
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Space RPG | Version 1.1</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<!-- Place favicon.ico in the root directory -->
<!--<link rel="stylesheet" href="css/main.css">-->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Share+Tech+Mono|Titillium+Web" rel="stylesheet">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<style>
body {
font-family: 'Titillium Web', sans-serif;
background-position: 0 0;
}
.headfootpad {
margin-top:20px;
margin-bottom:30px;
}
.info-label {
padding: 5px 20px;
margin:0 0 5px;
min-height:32px;
}
.btn {
margin:0 0 5px;
width:100%;
}
.redtext {
color:red;
}
.Junk {
color:lightgrey;
}
.Common {
color:darkolivegreen;
}
.Uncommon {
color:aqua;
}
.Rare {
color:deepskyblue;
}
.Epic {
color:blueviolet;
}
.Legendary {
color:hotpink;
}
.merchant-button {
color: dodgerblue;
}
.merchant-button:hover {
color: red;
cursor: pointer;
color:white;
}
.encounter{
display:none;
}
.merchant{
display:none;
font-size:14px;
padding:0;
}
.progress {
margin-bottom:5px;
}
.left {
margin:0 0 15px;
}
.stat {
float:right;
}
.stats {
background-color: white;
opacity:.5;
padding:15px;
-webkit-border-radius:7px;
-moz-border-radius:7px;
border-radius:7px;
}
label {
padding:5px;
color: black;
background-color: white;
opacity:.7;
cursor: pointer;
}
.statrow {
clear:both;
}
#journal {
height:300px;
overflow: hidden;
}
.screen {
overflow:hidden;
background-color: black;
color: greenyellow;
font-family: 'Share Tech Mono', monospace;
-webkit-border-radius:7px;
-moz-border-radius:7px;
border-radius:7px;
font-size:13px;
padding:15px;
border: 2px solid grey;
-webkit-border-radius:7px;
-moz-border-radius:7px;
border-radius:7px;
}
.information,.actions,#target-name-box {
padding:0;
}
#target-name {
color: white;
margin:5px 0;
width:100%;
text-align: center;
font-size:16px;
}
.btn-primary {
background-color: #555555;
border:1px solid grey;
}
.btn-primary:hover {
background-color: darkred;
border:1px solid white;
}
.progress-bar-success {
background-color: limegreen;
}
.progress-bar-warning {
background-color: gold;
}
.progress-bar-danger {
background-color: darkred;
}
.progress-bar-success .bar-label {
color:white;
}
.progress-bar-danger .bar-label {
color:white;
}
.bar-label {
color:black;
}
#target-image, #merchant-image, #merchant-name {
text-align: center;
background-color: transparent;
color:white;
}
#target-image img, #merchant-image img {
width:100%;
border: 2px solid grey;
border-radius: 7px;
}
.actions-encounters {
margin-top:15px;
}
#store-contents {
margin-top:-15px;
}
#quick-info {
color: black;
background-color: white;
opacity: .7;
padding: 7px;
margin-bottom:10px;
}
#death {
position: relative;
}
</style>
</head>
<body>
<!--[if lt IE 8]>
<p class="browserupgrade">Why are you using such an old browser! Stop it!</p>
<![endif]-->
<div class="container headfootpad">
<div class="col-sm-6 col-sm-12 player-stats">
<div class="left">
<div class="bars">
<div class="progress">
<div id="myhp-bar" class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100">
<span class="bar-label">My HP</span>
</div>
</div>
<div class="progress">
<div id="food-bar" class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100">
<span class="bar-label">Food</span>
</div>
</div>
<div class="progress">
<div id="drink-bar" class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100">
<span class="bar-label">Drink</span>
</div>
</div>
<div class="progress">
<div id="sleep-bar" class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100">
<span class="bar-label">Sleep</span>
</div>
</div>
<div class="progress">
<div id="dist-bar" class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="0">
<span class="bar-label">Distance to Destination</span>
</div>
</div>
</div>
<div class="actions-encounters">
<div class="col-sm-6 actions">
<!--only appears on encounter-->
<div class="col-sm-12 row">
<div id="attack" class="btn btn-primary encounter">Attack</div>
</div>
<div class="col-sm-12 row">
<!--only appears on encounter-->
<div id="run" class="btn btn-primary encounter">Run Away</div>
</div>
<!--only appears outside of encounters-->
<div class="col-sm-12 row">
<!--roll die for outcome, gain miles (random)-->
<div id="continue" class="btn btn-primary">Continue On</div>
</div>
<div class="col-sm-12 row">
<!--roll die for outcome, don't gain miles-->
<div id="camp" class="btn btn-primary">Stop for the night</div>
</div>
<div class="col-sm-12 row">
<!--roll die for outcome, gain miles (random)-->
<div id="market" class="btn btn-primary">Market</div>
</div>
<div class="clearfix"></div>
<div class="col-sm-8" id="quick-info">
<div class="statrow">Credits:<div class="stat player-credits">0</div></div>
</div>
</div>
<div class="col-sm-6 row merchant">
<div id="merchant-image" class="img-responsive"></div>
<div id="merchant-name" class="info-label"></div>
</div>
<div class="col-sm-6 row encounter" id="target-name-box">
<!--only appears on encounter-->
<div id="target-image" class="img-responsive"></div>
<div id="target-name" class="info-label"></div><div class="progress encounter">
<div id="targethp-bar" class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100">
<span class="bar-label">Enemy HP</span>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
<div class="merchant col-sm-12">
<div id="store-contents" class="info-label screen"></div>
</div>
</div>
<div class="col-sm-6 information">
<div class="col-sm-12">
<label id="journal-tab" for="journal">Journal</label>
<label id="inventory-tab" for="inventory-contents">Inventory</label>
<label id="equipment-tab" for="equipment-contents">Equipment</label>
<label id="stats-tab" for="equipment-contents">Stats</label>
<div id="journal" class="info-label screen"></div>
</div>
<div class="col-sm-12">
<div id="inventory-contents" class="info-label screen"></div>
</div>
<div class="col-sm-12">
<div id="equipment-contents" class="info-label screen"></div>
</div>
<div class="col-sm-12">
<div id="stats-contents" class="info-label screen">
<div class="clearfix"></div>
<div class="col-xs-6 row">
<div class="statrow">Name:<div id="player-name" class="stat"></div></div>
<div class="statrow">Level:<div id="player-level" class="stat"></div></div>
<div class="statrow">Race:<div id="player-race" class="stat"></div></div>
<div class="statrow">Class:<div id="player-class" class="stat"></div></div>
<div class="statrow">HP:<div id="player-hp" class="stat"></div></div>
<div class="statrow">AC:<div id="player-ac" class="stat"></div></div>
<div class="statrow">Credits:<div class="stat player-credits">0</div></div>
<div class="statrow">Weight:<div id="player-weight" class="stat">0</div></div>
<div class="statrow">Exp:<div id="player-exp" class="stat">0</div></div>
<div class="statrow">Distance Left:<div id="player-dist" class="stat"></div></div>
</div>
<div class="col-xs-6">
<div class="statrow">Weapon:<div id="player-weapon" class="stat"></div></div>
<div class="statrow">Str:<div id="player-str" class="stat"></div></div>
<div class="statrow">Con:<div id="player-con" class="stat"></div></div>
<div class="statrow">Dex:<div id="player-dex" class="stat"></div></div>
<div class="statrow">Int:<div id="player-int" class="stat"></div></div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-89862605-3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-89862605-3');
</script>
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<!--<script src="js/main.js"></script>-->
<script>
// fvar
var char = {};
var target = {};
var inventory = [];
var equipment = [];
var store = [];
const distToDestination = 50001;
var traveled = 1;
var dist = {name:"dist",value:0};
var food = {name:"food",value:100}, drink = {name:"drink",value:100}, sleep = {name:"sleep",value:100};
var myhp = {name:"myhp",value:"100"};
var targethp = {name:"targethp"};
var expRequirements = 100;
var weaponType = ["Ranged","Melee"];
var meleeWeaponSubtype = [
{subtype:"Sword",weight:5,attack:5,speed:5,value:10},
{subtype:"Baton",weight:3,attack:4,speed:4,value:10},
{subtype:"Dagger",weight:2,attack:3,speed:3,value:10}
];
var rangedWeaponSubtype = [
{subtype:"Cannon",weight:10,attack:5,speed:5,value:10},
{subtype:"Rifle",weight:5,attack:4,speed:4,value:10},
{subtype:"Pistol",weight:2,attack:3,speed:3,value:10}
];
var rangedWeaponPower = ["Ionic","Plasma","Pulse"];
var meleeWeaponPower = ["Sonic","Plasma","Beam","Toxic","Super-Heated"];
var apparelSubtype = ["Head","Chest","Hands","Feet","Waist"];
var apparelMaterial = ["Duralumin","Carbon","Moscovium","Neutronium","Polonium","Rhodium","Selenium"];
var headItem = [{name:"Hood",weight:2,value:5},{name:"Circlet",weight:1,value:8}];
var chestItem = [{name:"Robes",weight:10,value:10},{name:"Vest",weight:5,value:5},{name:"Shirt",weight:4,value:5}];
var handsItem = [{name:"Gloves",weight:1,value:3}];
var feetItem = [{name:"Shoes",weight:3,value:5},{name:"Boots",weight:5,value:7}];
var waistItem = [{name:"Sash",weight:1,value:4},{name:"Belt",weight:2,value:2},{name:"Bandolier",weight:-2,value:6}];
var junkCondition = ["Bent","Cracked","Drained","Dented","Old"];
var junkItem = [
{name:"Ionic Battery",weight:3,value:1},
{name:"Ionizing Deozonator",weight:2,value:1},
{name:"Quantum Stabilizer",weight:4,value:1},
{name:"Thermoglasses",weight:3,value:1},
{name:"Heat Sync",weight:4,value:1},
{name:"Fission Decoupler",weight:3,value:1}
];
var foodItem = [
{name:"Akrennian Beetle Sashimi",type:"food",weight:1,value:10},
{name:"Relenian Blood Wine",type:"drink",weight:1,value:4},
{name:"Squild Grubs",type:"food",weight:1,value:8},
{name:"Kep-mok Blood Ticks",type:"food",weight:1,value:12},
{name:"Weemil Moon Juice",type:"drink",weight:1,value:8},
{name:"Dehydrated Water",type:"drink",value:10,weight:2},
{name:"Military Ration",type:"food",value:10,weight:2}
];
var itemItem = [
{name:"Proximity Mine",type:"offensive",value:10,weight:2},
{name:"Med Kit",type:"defensive",value:15,weight:2},
{name:"Med Kit",type:"defensive",value:20,weight:2},
{name:"Poison Gas Bomb",type:"offensive",value:10,weight:2}];
var bonuses = ["HP","AC","STR","DEX","INT"];
// add more monsters (maybe categories with different random weights/chance of a group)
var targets = [
{name:'pirate',type:"humanoid",img:"assets/images/enemies/pirate.jpg"},
{name:'space sludge',type:"monster",img:"assets/images/enemies/slime.jpg"},
{name:'bandit',type:"humanoid",img:"assets/images/enemies/bandit.jpg"},
{name:'cultist',type:"humanoid",img:"assets/images/enemies/cultist.jpg"},
{name:'oclethorpe',type:"monster",img:"assets/images/enemies/oclethorpe.jpg"},
{name:'shazari warrior',type:"humanoid",img:"assets/images/enemies/shazari-warrior.jpg"}
];
var treasureLocations = ["You come across a wrecked ship","You check out a makeshift hut"];
$( document ).ready(function() {
newChar();
// get supplies
typeText("You need to get halfway across the galaxy. Go ahead and buy some supplies. If you have the credits...");
refreshAllNeeds();
// fbuttons
$("#attack").on("click",function(){
if (target.hp <= 0) {
typeText(target.name+" is dead. Continue on.");
} else {
attackAttempt();
}
});
$("#run").on("click",function(){
if(rollDie(3)===1) {
monsterAttack();
typeText("You manage to get away but the enemy was able to get another attack in!");
} else {
typeText("You manage to get away safely without harm.");
}
hideMerchant();
food.value -= 1;
drink.value -= 1;
sleep.value -= 1;
refreshAllNeeds();
if (food.value <= 0 || drink.value <= 0 || sleep.value <= 0) {
checkNeeds();
} else {
$(".encounter").hide();
$("#continue").show();
$("#camp").show();
}
});
var spaceImages = ["assets/images/spacebg1.jpg"];
$("#continue").on("click",function(){
$(".encounter").hide();
$("body").css("background-image","url("+ randomFromArray(spaceImages) +")");
$("#market").hide();
hideMerchant();
food.value -= 1;
drink.value -= 1;
sleep.value -= 1;
refreshAllNeeds();
if (food.value <= 0 || drink.value <= 0 || sleep.value <= 0) {
checkNeeds();
} else {
refreshInventory();
randomEvent();
refreshBar("dist");
}
});
$("#camp").on("click",function(){
hideMerchant();
$(".encounter").hide();
food.value -= 5;
drink.value -= 5;
if (rollDie(3)==1) {
sleep.value = 50;
typeText("Your sleep is cut short by an attack!");
// force an encounter
randomEvent(5);
} else if (rollDie(3)==2) {
$("body").css("background-image","url('assets/images/bed.jpg')");
sleep.value = 100;
gainHP(.35);
typeText("You sleep through the night waking up refreshed!");
} else {
$("body").css("background-image","url('assets/images/bed.jpg')");
sleep.value = 75;
gainHP(.2);
// make array for random stuff to keep player up
typeText("You are groggy from being kept up most the night by strange noises..");
}
refreshAllNeeds();
if (food.value <= 0 || drink.value <= 0 || sleep.value <= 0) {
checkNeeds();
} else {
refreshInventory();
}
});
$("#market").on("click",function(){
if ($(".merchant").is(":hidden")) {
generateMerchant(rollDie(20,10));
}
});
$("#journal-tab").on("click",function(){
$("#journal").show();
$("#inventory-contents").hide();
$("#equipment-contents").hide();
$("#stats-contents").hide();
$("#journal-tab").css("background-color","cornflowerblue");
$("#inventory-tab").css("background-color","white");
$("#equipment-tab").css("background-color","white");
$("#stats-tab").css("background-color","white");
});
$("#inventory-tab").on("click",function(){
$("#journal").hide();
$("#inventory-contents").show();
$("#equipment-contents").hide();
$("#stats-contents").hide();
$("#journal-tab").css("background-color","white");
$("#inventory-tab").css("background-color","cornflowerblue");
$("#equipment-tab").css("background-color","white");
$("#stats-tab").css("background-color","white");
});
$("#equipment-tab").on("click",function(){
$("#journal").hide();
$("#inventory-contents").hide();
$("#equipment-contents").show();
$("#stats-contents").hide();
$("#journal-tab").css("background-color","white");
$("#inventory-tab").css("background-color","white");
$("#equipment-tab").css("background-color","cornflowerblue");
$("#stats-tab").css("background-color","white");
});
$("#stats-tab").on("click",function(){
$("#journal").hide();
$("#inventory-contents").hide();
$("#equipment-contents").hide();
$("#stats-contents").show();
$("#journal-tab").css("background-color","white");
$("#inventory-tab").css("background-color","white");
$("#equipment-tab").css("background-color","white");
$("#stats-tab").css("background-color","cornflowerblue");
});
});
function gainHP (percent) {
extraHp = Math.ceil(char.hpTotal*percent);
if (char.hp + extraHp >= char.hpTotal) {
char.hp = char.hpTotal;
} else {
char.hp += extraHp;
}
updateMy("hp");
refreshBar(myhp);
}
// fupdate
function updateMy (stat) {
if (stat === "hp") {
updateText("#player-hp",char.hp+"/"+char.hpTotal);
} else if (stat === "weight") {
updateText("#player-weight",char.weight+"/"+char.weightTotal);
} else if (stat === "dist") {
updateText("#player-dist",distToDestination - traveled+" ly");
} else if (stat === "targethp") {
updateText("#target-hp",target.hp);
} else if (stat === "credits") {
updateText(".player-credits",char.credits);
} else if (stat === "weapon") {
updateText("#player-weapon",char.weapon);
} else if (stat === "ac") {
updateText("#player-ac",char.ac);
} else if (stat === "lvl") {
updateText("#player-level",char.lvl);
} else if (stat === "exp") {
updateText("#player-exp",char.exp+"/"+expRequirements);
} else if (stat === "str") {
updateText("#player-str",char.str);
} else if (stat === "dex") {
updateText("#player-dex",char.dex);
} else if (stat === "con") {
updateText("#player-con",char.con);
} else if (stat === "int") {
updateText("#player-int",char.int);
} else if (stat === "name") {
updateText("#player-name",char.name);
} else if (stat === "race") {
updateText("#player-race",char.race);
} else if (stat === "class") {
updateText("#player-class",char.class);
}
}
function printTreasure(obj) {
typeText("You found <span class="+obj.rarity+">"+obj.name+"</span>");
}
function hideMerchant() {
$(".merchant").hide();
store = [];
}
var firstNames = ["Meetho","Lorsab","Gilhar","Blathan","Korl","Flin","Jorb","Grol","Poltan"];
var lastNames = ["Lufor","Olimdet","Blorio","Flaaso","Wriven","Jorkan","Writho","Slo","Fivin","Slipe"];
var merchantImages = ["assets/images/store/merchants/store1.jpg"];
function generateMerchant(howManyItems) {
store = [];
$("#merchant-name").text(randomFromArray(firstNames)+" "+randomFromArray(lastNames));
$("#merchant-image").html("<img src='assets/images/store/merchants/merchant1.jpg'>");
$("#store-contents").text("");
$(".merchant").show();
for (i = 0; i < howManyItems; i++) {
thisThing = generateItem();
store.push(thisThing);
}
store.push({name:"Med Kit",type:"defensive",value:10,weight:2});
store.push({name:"Dehydrated Water",type:"drink",value:10,weight:2});
store.push({name:"Military Ration",type:"food",value:10,weight:2});
refreshInventory();
refreshStore();
}
function buyItem(index) {
obj = store[index];
if (char.credits >= obj.value) {
if (char.weight + obj.weight > char.weightTotal) {
typeText("You can't possibly carry any more!");
} else {
char.credits -= obj.value;
char.weight += obj.weight;
inventory.push(obj);
typeText("You bought "+obj.name+" for "+obj.value+" credits.");
updateMy("credits");
updateMy("weight");
if (obj.name === "Med Kit" || obj.name === "Dehydrated Water" || obj.name === "Military Ration") {
} else {
store.splice(index, 1);
}
refreshInventory();
refreshStore();
}
} else {
typeText("You don't have enough credits!");
}
}
//fnewchar
function newChar() {
$("#inventory-contents").hide();
$("#equipment-contents").hide();
$("#stats-contents").hide();
$("#camp").hide();
$("#journal-tab").css("background-color","cornflowerblue");
$("#market").show();
// var playerName = prompt("Please enter your name", "Sven");
$("body").css("background-image",randomFromArray(randomFromArray(stations).img));
var playerName = randomFromArray(firstNames)+" "+randomFromArray(lastNames);
races = ["Human","Lothean","Balamin"];
classes = ["Smuggler","Monk","Soldier"];
char["race"] = randomFromArray(races);
char["class"] = randomFromArray(classes);
updateMy("race");
updateMy("class");
updateMy("dist");
char["name"] = playerName;
char["lvl"] = 1;
refreshBar(myhp);
statsRollMax = 18;
statsRollMin = 6;
char["str"] = rollDie(statsRollMax,statsRollMin);
char["con"] = rollDie(statsRollMax,statsRollMin);
char["int"] = rollDie(statsRollMax,statsRollMin);
char["dex"] = rollDie(statsRollMax,statsRollMin);
char["strmod"] = generateModifier(char.str);
char["conmod"] = generateModifier(char.con);
char["intmod"] = generateModifier(char.int);
char["dexmod"] = generateModifier(char.dex);
char["ac"] = rollDie(18,12);
hp = rollDie(30,20);
char["hp"] = hp;
char["hpTotal"] = hp;
myhp["value"] = char.hp/char.hpTotal*100;
char["weight"] = 0;
char["weightTotal"] = char.str*10;
char["weapon"] = char.str;
char["exp"] = 0;
char["credits"] = rollDie(50,30);
updateMy("name");
updateMy("hp");
updateMy("ac");
updateMy("lvl");
updateMy("str");
updateMy("con");
updateMy("dex");
updateMy("int");
updateMy("exp");
updateMy("credits");
updateMy("weapon");
for (i = 0; i < rollDie(10)-1; i++) {
item = generateItem("Junk");
inventory.push(item);
char.weight += item.weight;
}
// save
for (i = 0; i < 3; i++) {
freeFood = randomFromArray(foodItem);
freeItem = randomFromArray(itemItem);
inventory.push(freeFood);
inventory.push(freeItem);
char.weight += freeFood.weight;
char.weight += freeItem.weight;
}
updateMy("weight");
refreshInventory();
refreshEquipment();
}
function generateModifier (stat) {
return Math.floor(stat/2)-5;
}
//frfneeds
function refreshAllNeeds() {
refreshBar(food);
refreshBar(drink);
refreshBar(sleep);
}
//fbar
function refreshBar(barType) {
bar = "#"+barType.name+"-bar";
$(bar).css("width",barType.value+"%");
if (barType.name !== "dist") {
if (barType.value > 50) {
$(bar).removeClass("progress-bar-warning").removeClass("progress-bar-danger").addClass("progress-bar-success");
} else if (barType.value <= 50 && barType.value > 20) {
$(bar).removeClass("progress-bar-success").removeClass("progress-bar-danger").addClass("progress-bar-warning");
} else if (barType.value <= 20 && barType.value > 0) {
$(bar).removeClass("progress-bar-success").removeClass("progress-bar-warning").addClass("progress-bar-danger");
}
}
}
function refreshEquipment() {
if (equipment.length === 0) {
updateText("#equipment-contents","You have no items equipped.");
} else {
updateText("#equipment-contents","");
$.each(equipment, function(i, value) {
if (value.slot === "Weapon" || value.type === "Apparel") {
if (value.slot === "Weapon") {
bonus = "Attack: "+value.attack;
} else {
bonus = "AC: "+value.ac;
}
typeText("<span class="+value.rarity+">"+value.name+" </span> | "+bonus+" Weight: "+value.weight+" Cost: "+value.value+" <br/><span class='merchant-button' onclick='unequipItem("+i+")'>Unequip</span>","#equipment-contents");
} else {
typeText("<span class="+value.rarity+">"+value.name+" </span> | Weight: "+value.weight+" Cost: "+value.value+" <br/><span class='merchant-button' onclick='unequipItem("+i+")'>Unequip</span>","#equipment-contents");
}
});
}
}
function equipItem(i) {
if (i > -1) {
slotsUsed = [];
item = inventory[i];
$.each(equipment, function(i, value) {
slotsUsed.push(value.slot);
});
result = $.inArray(item.slot, slotsUsed);
if (result === -1) {
typeText("You equip "+item.name+".");
equipment.push(item);
if (item.slot === "Weapon") {
char.weapon = item.attack+char.str;
updateMy("weapon");
} else if (item.type === "Apparel") {
char.ac += item.ac;
updateMy("ac");
}
inventory.splice(i, 1);
// loop through equiped items, if slot is taken ask to replace. swap item to inventory
// can only sell/destroy items in inventory
// add unequip button in equipment section
// possibly show avatar with highlighted items/rarity
// add all appropriate stats/weight after equipping
if (item.str) {
char.str += item.str;
}
} else {
typeText("You already have an item in that slot!");
}
}
refreshInventory();
refreshEquipment();
}
function unequipItem(i) {
if (i > -1) {
item = equipment[i];
console.log(equipment[i]);
typeText("You unequipped "+item.name+".");
inventory.push(item);
if (item.slot === "Weapon") {
char.weapon = char.str;
updateMy("weapon");
} else if (item.type === "Apparel") {
char.ac -= item.ac;
updateMy("ac");
}
equipment.splice(i, 1);
}
refreshInventory();
refreshEquipment();
}
function refreshInventory() {
if ($(".merchant").is(":visible")) {
updateText("#inventory-contents","");
$.each(inventory, function(i, value) {
if (value.type === "Ranged" || value.type === "Melee" || value.type === "Apparel") {
if (value.slot === "Weapon") {
// add dmg/bonuses
bonus = "Attack: "+value.attack;
} else {
bonus = "AC: "+value.ac;
// add ac/bonuses
}
typeText("<span class="+value.rarity+">"+value.name+"</span> | "+bonus+" Weight: "+value.weight+" Value: "+value.value+" <br/><span class='merchant-button' onclick='sellItem("+i+")'>Sell</span>"+" <span class='merchant-button' onclick='equipItem("+i+")'>Equip</span>","#inventory-contents");
} else if (value.type === "food" || value.type === "drink" || value.type === "defensive" || value.type === "offensive") {
typeText("<span class="+value.rarity+">"+value.name+"</span> | Weight: "+value.weight+" Value: "+value.value+" <br/><span class='merchant-button' onclick='sellItem("+i+")'>Sell</span>"+" <span class='merchant-button' onclick='useItem("+i+")'>Use</span>","#inventory-contents");
} else {
typeText("<span class="+value.rarity+">"+value.name+"</span> | Weight: "+value.weight+" Value: "+value.value+" <br/><span class='merchant-button' onclick='sellItem("+i+")'>Sell</span>","#inventory-contents");
}
});
} else {
updateText("#inventory-contents","");
$.each(inventory, function(i, value) {
if (value.type === "Ranged" || value.type === "Melee" || value.type === "Apparel") {
if (value.slot === "Weapon") {
// add dmg/bonuses
bonus = "Attack: "+value.attack;
} else {
bonus = "AC: "+value.ac;
// add ac/bonuses
}
typeText("<span class="+value.rarity+">"+value.name+"</span> | "+bonus+" Weight: "+value.weight+" Value: "+value.value+" <br/><span class='merchant-button' onclick='tossItem("+i+")'>Destroy</span>"+" <span class='merchant-button' onclick='equipItem("+i+")'>Equip</span>","#inventory-contents");
} else if (value.type === "food" || value.type === "drink" || value.type === "defensive" || value.type === "offensive") {
typeText("<span class="+value.rarity+">"+value.name+"</span> | Weight: "+value.weight+" Value: "+value.value+" <br/><span class='merchant-button' onclick='tossItem("+i+")'>Destroy</span>"+" <span class='merchant-button' onclick='useItem("+i+")'>Use</span>","#inventory-contents");
} else {
typeText("<span class="+value.rarity+">"+value.name+"</span> | Weight: "+value.weight+" Value: "+value.value+" <br/><span class='merchant-button' onclick='tossItem("+i+")'>Destroy</span>","#inventory-contents");
}
});
}
}
function refreshStore() {
updateText("#store-contents","");
$.each(store, function(i, value) {
if (value.slot === "Weapon" || value.type === "Apparel") {
if (value.slot === "Weapon") {
// add dmg/bonuses
bonus = "Attack: "+value.attack;
} else {
bonus = "AC: "+value.ac;
// add ac/bonuses
}
typeText("<span class="+value.rarity+">"+value.name+" </span> | "+bonus+" Weight: "+value.weight+" Cost: "+value.value+" <span class='merchant-button' onclick='buyItem("+i+")'>Buy</span>","#store-contents");
} else {
typeText("<span class="+value.rarity+">"+value.name+" </span> | Weight: "+value.weight+" Cost: "+value.value+" <span class='merchant-button' onclick='buyItem("+i+")'>Buy</span>","#store-contents");
}
});
}
function useItem(i) {
item = inventory[i];
if (item.type === "food") {
foodEffectiveness = 3;
if (food.value === 100) {
typeText("You are not hungry.");
} else if (food.value + item.value*foodEffectiveness > 100) {
food.value = 100;
removeFromInventory();
} else {
food.value += item.value*foodEffectiveness;
removeFromInventory();
}
} else if (item.type === "drink") {
drinkEffectiveness = 3;
if (drink.value === 100) {
typeText("You are not thirsty.");
} else if (drink.value + item.value*drinkEffectiveness > 100) {
drink.value = 100;
removeFromInventory();
} else {
drink.value += item.value*drinkEffectiveness;
removeFromInventory();
}
} else if (item.type === "defensive") {
// char.hp/char.hpTotal*100;
if (char.hp/char.hpTotal === 1) {
typeText("You are already full health!");
} else if ((char.hp + item.value)/char.hpTotal > 1) {
char.hp = char.hpTotal;
myhp.value = 100;
typeText("You are healed to full health!");
removeFromInventory();
updateMy("hp");
refreshBar(myhp);
} else {
char.hp += item.value;
typeText("You are healed for "+item.value+" health!");
myhp.value = char.hp/char.hpTotal*100;
removeFromInventory();
updateMy("hp");
refreshBar(myhp);
}
} else if (item.type === "offensive") {
if (target.hp) {
damageRoll = rollDie(item.value,Math.ceil(item.value/2));
if (target.hp - item.value <= 0) {
targetKilled(item.value);
} else {
targetDamaged(item.value);
setTimeout(function(){ monsterAttack(); }, 500);
}
removeFromInventory();
} else {
typeText("There is nothing to use that on.");
}
}
function removeFromInventory() {
char.weight -= item.weight;
updateMy("weight");
inventory.splice(i, 1);
refreshInventory();
}
refreshAllNeeds();
}
function sellItem(i) {
if (i > -1) {
item = inventory[i];
sellPriceWeight = .75;
sellPrice = Math.ceil(item.value*sellPriceWeight);
typeText("You sold "+item.name+" for "+sellPrice+" credits.");
store.push(item);
inventory.splice(i, 1);
char.credits += sellPrice;
char.weight -= item.weight;
updateMy("credits");
updateMy("weight");
}
refreshInventory();
refreshStore();
}
function tossItem(i) {
if (i > -1) {
inventory.splice(i, 1);
char.weight -= item.weight;
updateMy("weight");
}
refreshInventory();
}
function travel (distance) {
typeText("You traveled "+distance+" light years.");
traveled += distance;
dist.value = Math.floor(traveled/distToDestination*100);
$("#dist-bar").css("width",dist.value+"%");
}