-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·2047 lines (1887 loc) · 72.1 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
<!DOCTYPE html>
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-177414002-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-177414002-1');
</script>
<meta charset="UTF-8"/>
<!--
👶 Baby Merchant 👶
A text trading game (and sin against best practices) by J.R. Willett (https://www.linkedin.com/in/jrwillett/)
Inspired by:
A Dark Room http://adarkroom.doublespeakgames.com/
Universal Paperclip https://www.decisionproblem.com/paperclips/
Candy Box 2 https://candybox2.github.io/candybox/
Taipan! https://en.wikipedia.org/wiki/Taipan
Desert Trader, specifically the Apple IIGS version: https://www.reddit.com/r/tipofmytongue/comments/hh2exu/tomtgamelate_80s_to_early_90s_pc_game_about/
Galactic Conquest (https://www.galcon.com/classic/history.html), specifically the 1991 version for the Apple IIGS by David Hallwas, which the internet has forgotten
Goals I'd like to implement:
* Each level adds a new gameplay wrinkle
* Health, Battles, Upgradeable weapons and/or number of weapons
* Weapons should take cargo space
* Borrowing from a money lender
* Banking Deposits
* Owning multiple ships
* Gaining/Losing territory to rivals
* Karma from doing good or bad things affects luck?
* Travel down into massive number of consistently named subworlds
* Maybe to earn karma?
* Buy upgrades with absurd amoumts of currency from higher levels
* Find artifacts based on clues discovered at higher levels
* Trading affects supply/demand? (My trading actions affect prices?)
* Prices trending over time?
* Narration needs more voice/humor
* 'glowing pill' mechanic allows expensive upgrades that restart the game with perks - only shows up when you can afford it
* Booger pill, Gossip pill
TODOs resulting from play testing:
* Bug: repeatedly entering and exiting level 0 to change prices made baby names undefined
* Bug: going to lower levels sometimes gets me stuck where I am too encumbered to go to the boss to go back up (shouldn't be possible)
* Early inventory management is hard to learn. Should make it easier by making slimy boogers
and bloody boogers move prices in opposite directions, so that when one is cheap,
other is expensive
* Eat boogers? This would help with early inventory management frustration, and it could
build HP or have some other benefit
* Would be nice to have better graphical visualization of the destinations and of moving up and down the levels
* Need more play testing!
* Feels awfully repetitive
-->
<title>Baby Merchant</title>
<meta itemprop="description" name="description" property="og:description" content="A minimalist trading game">
<meta itemprop="name" property="og:title" content="Baby Merchant" />
<link rel="apple-touch-icon" sizes="57x57" href="images/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="images/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="images/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="images/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="images/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="images/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="images/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="images/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="images/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
<link rel="manifest" href="images/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="images/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<!-- From https://github.com/davidbau/seedrandom -->
<script src='seedrandom.min.js'>
</script>
<script src='nameGenerator.js'>
</script>
<script src='bigNumbers.js'>
</script>
<script type='text/javascript'>
'use strict';
Math.seedrandom() // Start out truly random
var buttonAction = ''
var basePrice = [1,10,100,1000]
function deepFreeze(object) {
// Retrieve the property names defined on object
var propNames = Object.getOwnPropertyNames(object);
// Freeze properties before freezing self
for (let name of propNames) {
let value = object[name];
if(value && typeof value === "object") {
deepFreeze(value);
}
}
return Object.freeze(object);
}
const levelData = [
{
levelDownMessage: "err",
levelDownImg: "leveldown0.jpeg",
levelUpMessage: "You decide you are ready to roll to other groups of babies",
levelUpImg: "levelup0.jpeg",
levelUpAwesomeness: "You can choose your next destination and revisit places with favorable prices.",
levelDownLabel: "err",
levelUpLabel: "Roll to another group",
discoveryMsg1: "You bump into another ",
discoveryMsg2: " whom you decide should be named ",
discoveryMsg3: ".",
BossDiscoveryMsg1: "You found a ",
BossDiscoveryMsg2: ", larger than the others, who babbles a name which might be \"",
BossDiscoveryMsg3: "\". Here you can buy upgrades in exchange for ",
BossDiscoveryMsg4: ". Perhaps you can trade with the other babies to get some.",
BossBabyImg: "bossBaby0.jpeg",
ArrivalMsg1: "You arrive at ",
ArrivalMsg2: "'s ",
MoveMsg: "Random limb movements propel you.",
MoveHdr: "Thrashing toward the unknown . . . ",
RevisitMsg: "You thrash your limbs with purpose.",
RevisitHdr1: "Thrashing toward ",
RevisitHdr2: "'s ",
VisitHdr1: "Trading at ",
VisitHdr2: " ",
VisitHdr3: "'s ",
tradeableItems: ['crusty boogers (ƀ)', 'slimy boogers', 'bloody boogers', 'shards of glass'],
tradeableItemsSingular: ['crusty booger (ƀ)', 'slimy booger', 'bloody booger', 'shard of glass'],
characterType: 'helpless baby',
locomotionType: 'thrash',
locationLabel: ['spot','spot','spot','spot','spot'],
travelFasterUpgradeMsg: [" reaches into a nearby diaper and liberally applies grease to your back.", " shows you how to thrash about more efficiently."],
travelFasterUpgradeImg: ["backgrease.jpeg", "teachingBaby0.jpeg"],
travelFasterUpgradeDesc: ['Back Grease', 'Super Thrash'],
cargoUpgradeMsg: ' teaches you how to grip 100 more boogers at once.',
cargoUpgradeImg: 'cargograsp.jpeg',
cargoUpgradeDesc: 'Tighter Grip',
levelUpgradeMsg: ' teaches you how to roll over to travel further to reach other groups of babies.',
levelUpgradeDesc: 'Roll Over',
levelUpgradeHeaderMsg: "You learned to roll over!",
levelUpgradeHeaderImg: "rollover.jpeg",
loseMsg: 'As you thrashed your limbs, you accidentally flung away ',
loseImg: 'BabyLossLevel0.jpeg',
foundMsg: 'As you thrashed your limbs, you managed to find ',
foundImg: 'BabyFoundLevel0.jpeg',
exploreMsg: 'You have visited every baby in this group and are starting to get better at thrashing about.',
exploreImg: 'BabyCircuit0.jpeg',
numLocations: 5,
},
{
levelDownMessage: "You lie on your back and prepare to move by thrashing about",
levelDownImg: "leveldown1.jpeg",
levelUpMessage: "You decide you are ready to crawl to other rooms of babies",
levelUpImg: "levelup1.jpeg",
levelUpAwesomeness: "Combat! (Coming soon)",
levelDownLabel: "Enter ",
levelUpLabel: "Crawl to another baby room",
discoveryMsg1: "You roll to another ",
discoveryMsg2: " who babbles a name which might be \"",
discoveryMsg3: "\".",
BossDiscoveryMsg1: "You roll up to a ",
BossDiscoveryMsg2: ", larger than the others, who babbles a name which sounds like \"",
BossDiscoveryMsg3: "\". Here you can buy upgrades in exchange for ",
BossDiscoveryMsg4: ".",
BossBabyImg: "bossBaby1.jpeg",
ArrivalMsg1: "You arrive at ",
ArrivalMsg2: "'s ",
MoveMsg: "You roll awkwardly toward a new group.",
MoveHdr: "Rolling somewhere new . . . ",
RevisitMsg: "You roll determinedly.",
RevisitHdr1: "Rolling toward ",
RevisitHdr2: "'s ",
VisitHdr1: "Trading at ",
VisitHdr2: " ",
VisitHdr3: "'s ",
tradeableItems: ['shards of glass', 'paperclips', 'shiny beads', 'pacifiers'],
tradeableItemsSingular: ['shard of glass', 'paperclip', 'shiny bead', 'pacifier'],
characterType: 'wee baby',
locomotionType: 'roll',
locationLabel: ['doorway','group','group','group','group'],
travelFasterUpgradeMsg: [" reaches into a nearby diaper and liberally applies grease to your tummy.", " shows you how to roll more efficiently."],
travelFasterUpgradeImg: ["tummygrease.jpeg", "teachingBaby1.jpeg"],
travelFasterUpgradeDesc: ['Tummy Grease', 'Mega Roll'],
cargoUpgradeMsg: ' violently stretches your cheeks. They will now hold 100 more items.',
cargoUpgradeImg: 'cargostretch.jpeg',
cargoUpgradeDesc: 'Stretchier Cheeks',
levelUpgradeMsg: ' teaches you how to crawl and thereby reach other rooms.',
levelUpgradeDesc: 'Crawl',
levelUpgradeHeaderMsg: "You learned to crawl!",
levelUpgradeHeaderImg: "crawl.jpeg",
loseMsg: 'While rolling, you choked and accidentally swallowed ',
loseImg: 'BabyLossLevel1.jpeg',
foundMsg: 'While rolling, you managed to find ',
foundImg: 'BabyFoundLevel1.jpeg',
exploreMsg: 'You have visited every group in this room and you notice your rolling skills have improved.',
exploreImg: 'BabyCircuit1.jpeg',
numLocations: 5,
},
{
levelDownMessage: "You lie down, and prepare to move by rolling over",
levelDownImg: "leveldown2.jpeg",
levelUpMessage: "You decide you are ready to ride the elevator to visit other floors full of babies",
levelUpImg: "levelup2.jpeg",
levelUpAwesomeness: "?????? (TBD, coming eventually)",
levelDownLabel: "Enter ",
levelUpLabel: "Use Elevator",
discoveryMsg1: "You crawl to another ",
discoveryMsg2: " who babbles a name which sounds like \"",
discoveryMsg3: "\".",
BossDiscoveryMsg1: "You crawl up to a ",
BossDiscoveryMsg2: ", larger than the others, who babbles that their name is \"",
BossDiscoveryMsg3: "\". Here you can buy upgrades in exchange for ",
BossDiscoveryMsg4: ".",
BossBabyImg: "bossBaby2.jpeg",
ArrivalMsg1: "You arrive at ",
ArrivalMsg2: "'s ",
MoveMsg: "You crawl aimlessly toward a new doorway.",
MoveHdr: "Crawling somwhere new . . . ",
RevisitMsg: "You crawl steadily.",
RevisitHdr1: "Crawling toward ",
RevisitHdr2: "'s ",
VisitHdr1: "Trading at ",
VisitHdr2: " ",
VisitHdr3: "'s ",
tradeableItems: ['pacifiers', 'building blocks', 'toy cars', 'candies'],
tradeableItemsSingular: ['pacifier', 'building block', 'toy car', 'candy'],
characterType: 'lil baby',
locomotionType: 'crawl',
locationLabel: ['elevator','doorway','doorway','doorway','doorway'],
travelFasterUpgradeMsg: [" reaches into a nearby diaper and liberally applies grease to your elbows.", " shows you how to crawl more efficiently."],
travelFasterUpgradeImg: ["elbowgrease.jpeg", "teachingBaby2.jpeg"],
travelFasterUpgradeDesc: ['Elbow Grease', 'Hyper Crawl'],
cargoUpgradeMsg: ' provides you with a roomier diaper.',
cargoUpgradeImg: 'cargodiaper.jpeg',
cargoUpgradeDesc: 'Bigger Diaper',
levelUpgradeMsg: ' teaches you how to push elevator buttons to access other floors.',
levelUpgradeDesc: 'Use Elevator',
levelUpgradeHeaderMsg: "You learned to use the elevator!",
levelUpgradeHeaderImg: "elevator.jpeg",
loseMsg: 'Your diaper loosened while crawling, and you lost ',
loseImg: 'BabyLossLevel2.jpeg',
foundMsg: 'You kept out a sharp eye while crawling and managed to find ',
foundImg: 'BabyFoundLevel2.jpeg',
exploreMsg: 'You have visited every room on this floor and you notice your crawling skills have improved.',
exploreImg: 'BabyCircuit2.jpeg',
numLocations: 5,
},
]
deepFreeze(levelData)
// These are the variables to save between sessions
var gameVersion = "0.1.1"
var gameSeed = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)
var waitingTitleCards = 0
var waitingTitleHeader = []
var waitingTitleFooter = []
var waitingTitleText = []
var waitingTitleButton = []
var waitingTitleImage = []
var lastChar = ' '
var alreadyTyped = ''
var textBelow = ''
var textToType = []
var textToTypeBolded = []
var waitingMessagesToType = 0
var lastLineWasBold = false
var currLevel = 0
var locIndex = 0
var nextLocIndex = 1
var transitMoves = 4
var pickingEnabled = false
var tradingEnabled = false
var storeVisible = false
var upgradesVisible = false
var lastGameHTML = ""
var inv = [0,0,0,0]
var oldInv = []
var oldLocIndex = []
var travelTime = []
var visitedLocation = []
var cargoRoom = 100
var price = []
var locationName = []
var levelSeed = []
var levelChildSeed = []
var maxLevel = 0
var inventoryChanged = false
var showingGossipColors = false
var gossipLocation = 0
// End variables to save betweens sessions
const varsToSave = ['gameVersion', 'gameSeed', 'waitingTitleCards',
'waitingTitleHeader', 'waitingTitleFooter', 'waitingTitleText',
'waitingTitleButton', 'waitingTitleImage', 'lastChar', 'alreadyTyped', 'textBelow',
'textToType', 'textToTypeBolded', 'waitingMessagesToType',
'lastLineWasBold', 'currLevel', 'locIndex', 'nextLocIndex', 'transitMoves',
'pickingEnabled', 'tradingEnabled', 'storeVisible', 'upgradesVisible',
'lastGameHTML', 'inv', 'oldInv', 'oldLocIndex', 'travelTime',
'visitedLocation', 'cargoRoom', 'price', 'locationName', 'levelSeed',
'levelChildSeed', 'maxLevel', 'inventoryChanged', 'showingGossipColors',
'gossipLocation']
deepFreeze(varsToSave)
var PAUSE_MULT = 100 // Pause multiplier
var devMode = false
if(devMode) {
gameSeed = 1
PAUSE_MULT = 1
}
var typingText = false
var needToSave = false
function saveGameState() {
lastGameHTML = document.getElementById('normalGameGoesHere').innerHTML
// console.log("Starting save")
for (const key of varsToSave) {
// console.log("Saving " + key + "=" + JSON.stringify(window[key]))
localStorage.setItem(key, JSON.stringify(window[key]))
}
needToSave = false
// console.log("Save complete")
}
function loadGameState() {
for (const key of varsToSave) {
if(key != 'gameVersion') {
// console.log(key + "=" + localStorage.getItem(key));
var value = localStorage.getItem(key)
if(value != null && value != 'undefined') {
window[key] = JSON.parse(value)
}
}
}
document.getElementById('normalGameGoesHere').innerHTML = lastGameHTML
document.getElementById('buttonIDlocomote').style.display = "block"
document.getElementById('buttonIDlocomote').style.visiblity = "visible"
document.getElementById('buttonIDlocomote').disabled = false
if(currLevel > 0) {
document.getElementById("destinationsAndLabel").style.display = "flex"
document.getElementById('buttonIDpick').style.display = "none"
} else {
document.getElementById('buttonIDpick').style.display = "block"
if(pickingEnabled) {
document.getElementById('buttonIDpick').style.visibility = "visible"
document.getElementById('buttonIDpick').disabled = false
}
}
if(currLevel < maxLevel) {
document.getElementById('buttonIDlevelUp').style.display = "block"
document.getElementById('buttonIDlevelUp').style.visiblity = "visible"
}
if(currLevel > 0) {
document.getElementById('buttonIDlevelDown').style.display = "block"
document.getElementById('buttonIDlevelDown').style.visiblity = "visible"
}
setTimeout('goBaby()', 100)
gtag('event', 'loadGame', {'event_category': 'gameState'})
}
Math.seedrandom(gameSeed) // replaces Math.random with predictable pseudorandom generator
function isPunctuation(charToCheck) {
return(charToCheck == '.' || charToCheck == ',' || charToCheck == '?' || charToCheck == '!' || charToCheck == ':' || charToCheck == ';')
}
function setupTitleCard(text, header, footer, button, imageSRC) {
document.getElementById("titleMainTextGoesHere").innerHTML = text.replace(/\n/g,'<br/>')
document.getElementById("titleHeaderTextGoesHere").innerHTML = header
if(button == "" && footer == "") {
document.getElementById("titleCardFooter").style.display = "none"
} else {
document.getElementById("titleFooterTextGoesHere").innerHTML = footer
document.getElementById("continueButton").innerHTML = button
document.getElementById("titleCardFooter").style.display = "flex"
}
if(imageSRC == "") {
document.getElementById("titleCardImageGoesHere").style.display = "none"
} else {
document.getElementById("titleCardImageGoesHere").style.backgroundImage = "url(" + imageSRC + ")"
document.getElementById("titleCardImageGoesHere").style.display = "flex"
}
document.getElementById("normalGameGoesHere").style.display = "none"
document.getElementById("titleCard").style.display = "flex"
}
function hideTitleCard() {
if(waitingTitleCards > 0) {
setupTitleCard(waitingTitleText[0], waitingTitleHeader[0], waitingTitleFooter[0], waitingTitleButton[0], waitingTitleImage[0])
for(i = 0; i < waitingTitleCards - 1; i++) {
waitingTitleHeader[i] = waitingTitleHeader[i+1]
waitingTitleFooter[i] = waitingTitleFooter[i+1]
waitingTitleText[i] = waitingTitleText[i+1]
waitingTitleButton[i] = waitingTitleButton[i+1]
waitingTitleImage[i] = waitingTitleImage[i+1]
}
waitingTitleCards--
} else {
document.getElementById("titleCard").style.display = "none"
document.getElementById("normalGameGoesHere").style.display = "flex"
}
}
function displayTitleCard(mainText, headerText, footerText, buttonText="OK", imageName="") {
var imageSRC = 'images/cardImages/' + imageName
if(document.getElementById("titleCard").style.display == "flex") {
// Already have a title card displayed, so queue this one up
waitingTitleHeader[waitingTitleCards] = headerText
waitingTitleFooter[waitingTitleCards] = footerText
waitingTitleText[waitingTitleCards] = mainText
waitingTitleButton[waitingTitleCards] = buttonText
waitingTitleImage[waitingTitleCards] = imageSRC
waitingTitleCards++
} else {
setupTitleCard(mainText, headerText, footerText, buttonText, imageSRC)
}
}
function setHeaderText(newText) {
document.getElementById("headerTextGoesHere").innerHTML = newText
document.getElementById("headerGoesHere").style.display = "flex"
}
function setStatusText(newText) {
document.getElementById("headerStatusGoesHere").innerHTML = newText
document.getElementById("headerGoesHere").style.display = "flex"
}
function setInventoryHTML(newHTML) {
document.getElementById("inventoryGoesHere").innerHTML = newHTML
if(newHTML == "")
document.getElementById("inventoryGoesHere").style.display = "none"
else
document.getElementById("inventoryGoesHere").style.display = "flex"
}
function setActionsHTML(newHTML) {
document.getElementById("actionsGoHere").innerHTML = newHTML
document.getElementById("actionsGoHere").style.display = "flex"
document.getElementById("controlsGoHere").style.display = "flex"
}
function setDestinationsHTML(newHTML) {
document.getElementById("destinationsGoHere").innerHTML = newHTML
}
function setOutputHTML(newHTML) {
document.getElementById("outputGoesHere").innerHTML = newHTML
document.getElementById("outputAndGradient").style.visibility = "visible"
}
function typeCharacter(characterToType, bolded) {
if(characterToType == '\n') {
if(lastLineWasBold) {
textBelow = '<br><strong class="outputSpan">' + alreadyTyped + '</strong>' + textBelow
lastLineWasBold = false
} else {
textBelow = '<br><span class="outputSpan">' + alreadyTyped + '</span>' + textBelow
}
alreadyTyped = ''
} else {
alreadyTyped += characterToType
}
if(bolded) {
lastLineWasBold = true
setOutputHTML('<strong class="outputSpan">' + alreadyTyped + '</strong>' + textBelow.substring(0,4000))
} else {
setOutputHTML('<span class="outputSpan">' + alreadyTyped + '</span>' + textBelow.substring(0,4000))
}
}
function typeNextText() {
var thisChar = textToType[0].substring(0,1)
typeCharacter(thisChar, textToTypeBolded[0])
textToType[0] = textToType[0].substring(1,textToType[0].length)
var nextWait = 500
if(textToType[0].length > 0) {
var nextChar = textToType[0].substring(0,1)
nextWait = 25 + Math.random()*50
if(isPunctuation(lastChar) && !isPunctuation(thisChar)) {
// Pause after punctuation
nextWait += 200 + Math.random()*200
} else if(thisChar != '\n' && nextChar == '\n') {
// Pause before linebreak
nextWait += 200 + Math.random()*200
} else if(thisChar ==' ') {
// Slight pause after space
nextWait += 50 + Math.random()*50
}
} else {
waitingMessagesToType--
if(waitingMessagesToType > 0) {
for(i = 0; i < waitingMessagesToType; i++) {
textToType[i] = textToType[i+1]
textToTypeBolded[i] = textToTypeBolded[i+1]
}
} else {
typingText = false
if(needToSave) {
saveGameState()
}
}
}
lastChar = thisChar
if(typingText) {
if(devMode || true) {
nextWait = nextWait / 100
}
setTimeout('typeNextText()', nextWait)
}
}
// If titleCardFooter and/or titleCardHeader is passed, then text will be
// displayed as a title card with a header and footer and text will be bolded
// when user returns from title card
function typeText(whatToType, titleCardHeader = "", titleCardFooter = "", titleCardButton = "OK", titleCardImageName = "") {
//textBelow = '<br><br>' + alreadyTyped + textBelow
//alreadyTyped = ''
var showTitleCard = (titleCardFooter.length > 0 || titleCardHeader.length > 0)
if(showTitleCard) {
titleCardHeader = titleCardHeader.charAt(0).toUpperCase() + titleCardHeader.slice(1)
displayTitleCard(whatToType, titleCardHeader, titleCardFooter, titleCardButton, titleCardImageName)
whatToType = titleCardHeader + " " + whatToType
}
textToType[waitingMessagesToType] = '\n\n' + whatToType
textToTypeBolded[waitingMessagesToType] = showTitleCard
waitingMessagesToType++
if(!typingText) {
typingText = true
typeNextText()
}
}
function setupLevel(index, seed, mainLocationName) {
levelSeed[index] = seed
Math.seedrandom(seed)
levelChildSeed[index] = []
for(var i = 1; i < levelData[index].numLocations; i++) {
levelChildSeed[index][i] = Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)
}
locationName[index] = []
locationName[index][0] = mainLocationName
for(var i = 1; i < levelData[index].numLocations; i++) {
locationName[index][i] = getRandomName()
}
}
function setupLocationRadioButtons() {
var rbHTML = '';
for(var i = 0; i < levelData[currLevel].numLocations; i++) {
rbHTML += '<div class="locChoice">'
rbHTML += '<input class="locRadioButton" type="radio" id="nextLoc' + i + '" name="nextLoc" value="' + i + '"'
rbHTML += ' onclick="updateLocomoteButton()"'
if(i == nextLocIndex) rbHTML += ' checked'
rbHTML +='>'
rbHTML += '<label for="nextLoc' + i + '" '
if(showingGossipColors) {
if(i == gossipLocation) {
rbHTML += "style='color:rgb(0,200,0);' "
}
}
if(i == locIndex) {
rbHTML += 'class="locRadioLabelDisabled">'
} else {
rbHTML += 'class="locRadioLabel">'
}
if(visitedLocation[currLevel][i]) {
rbHTML += locationName[currLevel][i]
} else {
rbHTML += levelData[currLevel].locationLabel[i]
if(i > 0) {
rbHTML += " #" + i
}
}
rbHTML += '</label></div>'
}
setDestinationsHTML(rbHTML)
}
function positiveExclamation() {
var exclamationChoice = ["Good Joss!", "Yay!", "Hooray!", "Incredible!", "Yes!", "Fantastic!", "Lucky you!", "Fabulous!", "Excellent!", "Splendid!"]
return exclamationChoice[Math.floor(Math.random()*exclamationChoice.length)]
}
function negativeExclamation() {
var exclamationChoice = ["Bad Joss!", "Oh no!", "Boo!", "Terrible news!", "No!", "Bummer!", "Bad luck!", "Turnip farts!", "Dagnabbit!", "Poodoo!"]
return exclamationChoice[Math.floor(Math.random()*exclamationChoice.length)]
}
function doButtonAction(actionName) {
buttonAction = actionName
}
function getButtonHTML(actionName, buttonText) {
return '<button class=babyButton id="buttonID' + actionName + '" onclick="doButtonAction(\'' + actionName +'\')">' + buttonText + '</button>'
}
function hasAnything() {
for(var i = 0; i < inv.length; i++) {
if(inv[i] > 0) return true
}
return false
}
function visitedAllLocations() {
for(var i = 0; i < levelData[currLevel].numLocations; i++ ) {
if(!visitedLocation[currLevel][i]) return false
}
return true
}
function getDisplayNumber(num, compact="") {
var modIndex = Math.floor(Math.log10(num)/3) - 1
if(compact != "") {
var mod = ['k','m','b','t','qd','qn','sx','sp','oc','nn','dc']
if(num < 1000 || compact != "super" && num < 2000) {
return num.toLocaleString()
} else if(modIndex < mod.length) {
num /= Math.pow(1000,(modIndex+1))
if(compact == "super") {
return Math.round(num) + mod[modIndex]
} else {
return num.toPrecision(3) + mod[modIndex]
}
} else {
if(compact == "super") {
return num.toExponential(0)
} else {
return num.toExponential(2)
}
}
} else {
modIndex--
if(num < 2000000) {
return num.toLocaleString()
} else if(modIndex < 998) {
num /= Math.pow(1000,(modIndex+2))
return num.toPrecision(4) + " " + numberScaleNameShortScale(modIndex+2)
} else {
return num.toExponential(5)
}
}
}
function calculateFreeSpace() {
var freeSpace = cargoRoom
for(var i = 0; i < inv.length; i++) {
freeSpace -= inv[i]
}
return freeSpace
}
function handleLostAndFound() {
var whaHappen = Math.random()
if(whaHappen < 0.07) {
// Lost something, mebbe
var whichInv = inv.length - 1
while(whichInv > 0 && Math.random() < 0.5) {
whichInv--
}
var amount = Math.floor(Math.random()*inv[whichInv]*0.5)
if(amount > 0) {
inv[whichInv] -= amount
var suggestion = " Perhaps if you learn to travel faster there will be fewer opportunities to lose your cargo."
if(travelTime[currLevel] == 1) {
suggestion = ""
}
if(amount == 1) {
typeText(levelData[currLevel].loseMsg + " " +
amount + " " + levelData[currLevel].tradeableItemsSingular[whichInv] + "!" + suggestion,
levelData[currLevel].tradeableItemsSingular[whichInv] + " lost.",
negativeExclamation(), "OK", levelData[currLevel].loseImg)
} else {
typeText(levelData[currLevel].loseMsg + " " +
amount + " " + levelData[currLevel].tradeableItems[whichInv] + "!" + suggestion,
levelData[currLevel].tradeableItems[whichInv] + " lost.",
negativeExclamation(), "OK", levelData[currLevel].loseImg)
}
}
} else if(whaHappen > 0.975 && hasAnything()) {
var whichInv = 0
while(whichInv < inv.length && Math.random() < 0.1) {
whichInv++
}
var maxAmountFound = calculateFreeSpace() / 2
var amount = Math.floor(Math.random()*maxAmountFound*0.5)
if(amount > 0) {
inv[whichInv] += amount
if(amount == 1) {
typeText(levelData[currLevel].foundMsg + " " +
amount + " " + levelData[currLevel].tradeableItemsSingular[whichInv] + "!",
levelData[currLevel].tradeableItemsSingular[whichInv] + " found.",
positiveExclamation(), "OK", levelData[currLevel].foundImg)
} else {
typeText(levelData[currLevel].foundMsg + " " +
amount + " " + levelData[currLevel].tradeableItems[whichInv] + "!",
levelData[currLevel].tradeableItems[whichInv] + " found.",
positiveExclamation(), "OK", levelData[currLevel].foundImg)
}
}
}
}
function getNetWorth() {
var netWorth = 0
var lvlMultiplier = 1
for(i = 0; i < currLevel; i++) {
netWorth += lvlMultiplier * oldInv[i][0]
for(j = 1; j < 4; j++) {
lvlMultiplier *= 10
netWorth += lvlMultiplier * oldInv[i][j]
}
}
netWorth += lvlMultiplier * inv[0]
for(j = 1; j < 4; j++) {
lvlMultiplier *= 10
netWorth += lvlMultiplier * inv[j]
}
for(i = currLevel + 1; i < levelData.length; i++) {
netWorth += lvlMultiplier * oldInv[i][0]
for(j = 1; j < 4; j++) {
lvlMultiplier *= 10
netWorth += lvlMultiplier * oldInv[i][j]
}
}
return netWorth
}
function sellInv(index, quantity) {
if(inv[index] >= quantity) {
var thisPrice = price[currLevel][locIndex][index]
inv[index] -= quantity
inv[0] += quantity*thisPrice
var sellMsg = "You sell " + getDisplayNumber(quantity) + " "
if(quantity == 1) {
sellMsg += levelData[currLevel].tradeableItemsSingular[index]
} else {
sellMsg += levelData[currLevel].tradeableItems[index]
}
sellMsg += " to get " + getDisplayNumber(quantity*thisPrice) + " "
if(quantity*thisPrice == 1) {
sellMsg += levelData[currLevel].tradeableItemsSingular[0]
} else {
sellMsg += levelData[currLevel].tradeableItems[0]
}
typeText(sellMsg)
inventoryChanged = true
} else {
typeText("You do not have " + levelData[currLevel].tradeableItems[index] + " to sell")
}
}
function buyInv(index, quantity) {
var thisPrice = price[currLevel][locIndex][index]
if(inv[0] >= quantity*thisPrice) {
inv[index] += quantity
inv[0] -= quantity*thisPrice
var buyMsg = "You buy " + getDisplayNumber(quantity) + " "
if(quantity == 1) {
buyMsg += levelData[currLevel].tradeableItemsSingular[index]
} else {
buyMsg += levelData[currLevel].tradeableItems[index]
}
buyMsg += " for " + getDisplayNumber(quantity*thisPrice) + " "
if(quantity*thisPrice == 1) {
buyMsg += levelData[currLevel].tradeableItemsSingular[0]
} else {
buyMsg += levelData[currLevel].tradeableItems[0]
}
typeText(buyMsg)
inventoryChanged = true
} else {
var shortBy = quantity*thisPrice - inv[0]
var errMsg = "You need " + shortBy + " more "
if(shortBy == 1) {
errMsg += levelData[currLevel].tradeableItemsSingular[0]
} else {
errMsg += levelData[currLevel].tradeableItems[0]
}
typeText(errMsg)
}
}
function getGossipText() {
// console.log("Starting to figure out gossip")
var gossipText = "Prices look unfavorable everywhere!"
var msgCount = 0
var thisBuyRatio = 1
var bestBuyRatio = 1
var thisProfit = 0
var bestProfit = 0
var bestBuyIndex = 0
var bestSellIndex = 0
var bestBuyLoc = 0
var expensiveCount = 0
for(var i = 3; i >= 0; i--) {
if(inv[i] > 0) {
// console.log ("Checking selling " + levelData[currLevel].tradeableItems[i])
// Find good places to sell this
if(i > 0) {
// We don't already have a ton of the next less expensive item, so see about buying some
for(var j = 1; j < levelData[currLevel].numLocations; j++) {
for(var k = 0; k < i; k++) {
// console.log (" and buying " + levelData[currLevel].tradeableItems[k] + " at " + locationName[currLevel][j])
thisBuyRatio = price[currLevel][j][i] / (price[currLevel][j][k]*(10 ** (i-k)))
if(thisBuyRatio > 1) {
thisProfit = inv[i]*(thisBuyRatio-1) * (10 ** i)
var actualSpace = cargoRoom - expensiveCount
for(var m = k; m < i; m++) {
actualSpace -= inv[m];
}
var neededSpace = (inv[i])*thisBuyRatio*(10 ** (i-k))+1
// console.log("Needed space: " + neededSpace + ", original profit: " + thisProfit + ", actual space: " + actualSpace)
neededSpace -= actualSpace
var reduceCount = 0
while(neededSpace > 0) {
// Maybe if we don't sell one of them
neededSpace = neededSpace - thisBuyRatio*(10 ** (i-k)) + 1
thisProfit -= (thisBuyRatio-1) * (10 ** i)
reduceCount++
}
// if(reduceCount > 0) {
// console.log("reduced by " + reduceCount)
// }
// console.log("Expected profit: " + thisProfit)
if(thisProfit > bestProfit) {
bestProfit = thisProfit
bestBuyIndex = k
bestSellIndex = i
bestBuyLoc = j
bestBuyRatio = thisBuyRatio
}
}
}
}
}
expensiveCount += inv[i]
if(i < 3) {
// See about buying the more expensive item
for(var j = 1; j < levelData[currLevel].numLocations; j++) {
for(var k = i+1; k <= 3; k++) {
// console.log (" and buying " + levelData[currLevel].tradeableItems[k] + " at " + locationName[currLevel][j])
thisBuyRatio = (price[currLevel][j][i]*(10 ** (k-i))) / price[currLevel][j][k]
if(thisBuyRatio > 1) {
var buyCount = Math.floor(inv[i]*thisBuyRatio/(10 ** (k-i)))
thisProfit = buyCount*(thisBuyRatio-1) * (10 ** k)
// console.log("Expected profit: " + thisProfit)
if(thisProfit > bestProfit) {
bestProfit = thisProfit
bestBuyIndex = k
bestSellIndex = i
bestBuyLoc = j
bestBuyRatio = thisBuyRatio
}
}
}
}
}
}
}
// console.log(price[currLevel])
if(bestProfit > 0) {
var gossipSize = ""
if(bestBuyRatio < 1.1) {
gossipSize = "tolerable"
} else if(bestBuyRatio < 1.2) {
gossipSize = "ok"
} else if(bestBuyRatio < 1.3) {
gossipSize = "good"
} else if(bestBuyRatio < 1.4) {
gossipSize = "very good"
} else if(bestBuyRatio < 1.6) {
gossipSize = "great"
} else {
gossipSize = "fabulous"
}
// console.log(bestBuyLoc, bestProfit, bestBuyIndex, bestSellIndex, bestBuyRatio, gossipSize)
gossipText = locationName[currLevel][bestBuyLoc] + " has " +
gossipSize + " prices for those looking"
if(bestSellIndex > 0) {
gossipText += " to sell " + levelData[currLevel].tradeableItems[bestSellIndex]
}
if(bestBuyIndex > 0) {
gossipText += " to buy " + levelData[currLevel].tradeableItems[bestBuyIndex]
}
gossipLocation = bestBuyLoc
}
return gossipText
}
function buyUpgrade(upgradeType, upgradeAmount, cost) {
if(cost <= inv[3]) {
switch(upgradeType) {
case 'gossip':
if(visitedAllLocations() && !showingGossipColors) {
showingGossipColors = true
inv[3] -= cost
randomizeStore()
typeText('"' + getGossipText() + '"', "Price Rumors: ", "Go Baby!", "OK", "gossip.jpeg")
setupLocationRadioButtons()
inventoryChanged = true
gtag('event', 'gossip', {'event_category': 'upgradeBought', 'value': currLevel})
}
break
case 'travel':
if(travelTime[currLevel] > 1) {
travelTime[currLevel]--
inv[3] -= cost
inventoryChanged = true
if(travelTime[currLevel] > 1 + (visitedAllLocations() ? 0 : 1)) {
typeText(locationName[currLevel][locIndex] + levelData[currLevel].travelFasterUpgradeMsg[0],
"Travel Speed Upgraded.",
"Go Baby!", "OK", levelData[currLevel].travelFasterUpgradeImg[0])
gtag('event', 'travelSpeed', {'event_category': 'upgradeBought', 'event_label': 'intermediate', 'value': currLevel})
} else {
typeText(locationName[currLevel][locIndex] + levelData[currLevel].travelFasterUpgradeMsg[1],
"Travel Speed Upgraded.",
"Go Baby!", "OK", levelData[currLevel].travelFasterUpgradeImg[1])
gtag('event', 'travelSpeed', {'event_category': 'upgradeBought', 'event_label': 'final', 'value': currLevel})
}
}
break
case 'cargo':
cargoRoom += upgradeAmount
inv[3] -= cost
inventoryChanged = true
typeText(locationName[currLevel][locIndex] + levelData[currLevel].cargoUpgradeMsg,
"Cargo space upgraded.",
"More Room!", "OK", levelData[currLevel].cargoUpgradeImg)
gtag('event', 'cargo', {'event_category': 'upgradeBought', 'value': currLevel})
break
case 'level':
if(maxLevel < levelData.length - 1) {
maxLevel++
inv[3] -= cost
inventoryChanged = true
document.getElementById('buttonIDlevelUp').style.visibility = 'visible'
typeText(locationName[currLevel][locIndex] + levelData[currLevel].levelUpgradeMsg +
" You can now advance to level " + (currLevel + 1) + " (\"" + levelData[currLevel].levelUpLabel + "\").",
levelData[currLevel].levelUpgradeHeaderMsg,
"Level " + maxLevel + " Available!", "OK", levelData[currLevel].levelUpgradeHeaderImg)
gtag('event', 'level', {'event_category': 'upgradeBought', 'value': maxLevel})
} else {
typeText("You have completed Baby Merchant! Hopefully more will be written soon.",
"You win!", "Thanks for playing", "OK", "won.jpeg")
gtag('event', 'win', {'event_category': 'gameState', 'value': currLevel})
}
break
}
} else {
typeText("You need more " + levelData[currLevel].tradeableItems[3] + " to purchase this")
}
}
function randomizeStore(initAll=false) {
for(i = 1; i < inv.length; i++) {
for(j = 0; j < levelData[currLevel].numLocations; j++) {
if(initAll) {
price[currLevel][j][i] = basePrice[i]
}
var formerPrice = price[currLevel][j][i]
var newPrice = (formerPrice*2+basePrice[i])/3 // Trend back toward the basePrice
var variancepct = 0.3
if(Math.random() < 0.1) variancepct = 0.5 + Math.random()*0.45 // Sometimes have wild price swings
newPrice = Math.round(newPrice + Math.random()*newPrice*variancepct*2 - newPrice*variancepct)
if(newPrice > formerPrice*1.2 && formerPrice <= basePrice) {
// Prices can sometimes get very high
while(Math.random() < 0.7 && newPrice < basePrice[i]*10) newPrice = Math.round(newPrice*1.2)
}