forked from OpenPrograms/Kenny-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadventure.lua
More file actions
1363 lines (1241 loc) · 30.6 KB
/
adventure.lua
File metadata and controls
1363 lines (1241 loc) · 30.6 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
local component = require("component")
local event = require("event")
local fs = require("filesystem")
local keyboard = require("keyboard")
local shell = require("shell")
local term = require("term")
local text = require("text")
local unicode = require("unicode")
local sides = require("sides")
local colors=require("colors")
local gpu = component.gpu
local tBiomes = {
"in a forest",
"in a pine forest",
"knee deep in a swamp",
"in a mountain range",
"in a desert",
"in a grassy plain",
"in frozen tundra",
--"in the ocean",
}
function isAdvanced()
return (gpu.getDepth() > 1)
end
local function hasTrees( _nBiome )
return _nBiome <= 3
end
local function hasStone( _nBiome )
return _nBiome == 4
end
local function hasRivers( _nBiome )
return _nBiome ~= 3 and _nBiome ~= 5
end
local items = {
["no tea"] = {
droppable = false,
desc = "Pull yourself together man.",
},
["a pig"] = {
heavy = true,
creature = true,
drops = { "some pork" },
aliases = { "pig" },
desc = "The pig has a square nose.",
},
["a cow"] = {
heavy = true,
creature = true,
aliases = { "cow" },
desc = "The cow stares at you blankly.",
},
["a sheep"] = {
heavy = true,
creature = true,
hitDrops = { "some wool" },
aliases = { "sheep" },
desc = "The sheep is fluffy.",
},
["a chicken"] = {
heavy = true,
creature = true,
drops = { "some chicken" },
aliases = { "chicken" },
desc = "The chicken looks delicious.",
},
["a creeper"] = {
heavy = true,
creature = true,
monster = true,
aliases = { "creeper" },
desc = "The creeper needs a hug.",
},
["a skeleton"] = {
heavy = true,
creature = true,
monster = true,
aliases = { "skeleton" },
nocturnal = true,
desc = "The head bone's connected to the neck bone, the neck bones connected to the chest bone, the chest bones connected to the arm bone, the arm bones connected to the bow, and the bow is pointed at you.",
},
["a zombie"] = {
heavy = true,
creature = true,
monster = true,
aliases = { "zombie" },
nocturnal = true,
desc = "All he wants to do is eat your brains.",
},
["a spider"] = {
heavy = true,
creature = true,
monster = true,
aliases = { "spider" },
desc = "Dozens of eyes stare back at you.",
},
["a cave entrance"] = {
heavy = true,
aliases = { "cave entance", "cave", "entrance" },
desc = "The entrance to the cave is dark, but it looks like you can climb down.",
},
["an exit to the surface"] = {
heavy = true,
aliases = { "exit to the surface", "exit", "opening" },
desc = "You can just see the sky through the opening.",
},
["a river"] = {
heavy = true,
aliases = { "river" },
desc = "The river flows majestically towards the horizon.",
},
["some wood"] = {
aliases = { "wood" },
material = true,
desc = "You could easilly craft this wood into planks.",
},
["some planks"] = {
aliases = { "planks", "wooden planks", "wood planks" },
desc = "You could easilly craft these planks into sticks.",
},
["some sticks"] = {
aliases = { "sticks", "wooden sticks", "wood sticks" },
desc = "A perfect handle for torches or a pickaxe.",
},
["a crafting table"] = {
aliases = { "crafting table", "craft table", "work bench", "workbench", "crafting bench", "table", },
desc = "It's a crafting table. I shouldn't tell you this, but these don't actually do anything in this game, you can craft tools whenever you like.",
},
["a furnace"] = {
aliases = { "furnace" },
desc = "It's a furnace. Between you and me, these don't actually do anything in this game.",
},
["a wooden pickaxe"] = {
aliases = { "pickaxe", "pick", "wooden pick", "wooden pickaxe", "wood pick", "wood pickaxe" },
tool = true,
toolLevel = 1,
toolType = "pick",
desc = "The pickaxe looks good for breaking stone and coal.",
},
["a stone pickaxe"] = {
aliases = { "pickaxe", "pick", "stone pick", "stone pickaxe" },
tool = true,
toolLevel = 2,
toolType = "pick",
desc = "The pickaxe looks good for breaking iron.",
},
["an iron pickaxe"] = {
aliases = { "pickaxe", "pick", "iron pick", "iron pickaxe" },
tool = true,
toolLevel = 3,
toolType = "pick",
desc = "The pickaxe looks strong enough to break diamond.",
},
["a diamond pickaxe"] = {
aliases = { "pickaxe", "pick", "diamond pick", "diamond pickaxe" },
tool = true,
toolLevel = 4,
toolType = "pick",
desc = "Best. Pickaxe. Ever.",
},
["a wooden sword"] = {
aliases = { "sword", "wooden sword", "wood sword" },
tool = true,
toolLevel = 1,
toolType = "sword",
desc = "Flimsy, but better than nothing.",
},
["a stone sword"] = {
aliases = { "sword", "stone sword" },
tool = true,
toolLevel = 2,
toolType = "sword",
desc = "A pretty good sword.",
},
["an iron sword"] = {
aliases = { "sword", "iron sword" },
tool = true,
toolLevel = 3,
toolType = "sword",
desc = "This sword can slay any enemy.",
},
["a diamond sword"] = {
aliases = { "sword", "diamond sword" },
tool = true,
toolLevel = 4,
toolType = "sword",
desc = "Best. Sword. Ever.",
},
["a wooden shovel"] = {
aliases = { "shovel", "wooden shovel", "wood shovel" },
tool = true,
toolLevel = 1,
toolType = "shovel",
desc = "Good for digging holes.",
},
["a stone shovel"] = {
aliases = { "shovel", "stone shovel" },
tool = true,
toolLevel = 2,
toolType = "shovel",
desc = "Good for digging holes.",
},
["an iron shovel"] = {
aliases = { "shovel", "iron shovel" },
tool = true,
toolLevel = 3,
toolType = "shovel",
desc = "Good for digging holes.",
},
["a diamond shovel"] = {
aliases = { "shovel", "diamond shovel" },
tool = true,
toolLevel = 4,
toolType = "shovel",
desc = "Good for digging holes.",
},
["some coal"] = {
aliases = { "coal" },
ore = true,
toolLevel = 1,
toolType = "pick",
desc = "That coal looks useful for building torches, if only you had a pickaxe to mine it.",
},
["some dirt"] = {
aliases = { "dirt" },
material = true,
desc = "Why not build a mudhut?",
},
["some stone"] = {
aliases = { "stone", "cobblestone" },
material = true,
ore = true,
infinite = true,
toolLevel = 1,
toolType = "pick",
desc = "Stone is useful for building things, and making stone pickaxes.",
},
["some iron"] = {
aliases = { "iron" },
material = true,
ore = true,
toolLevel = 2,
toolType = "pick",
desc = "That iron looks mighty strong, you'll need a stone pickaxe to mine it.",
},
["some diamond"] = {
aliases = { "diamond", "diamonds" },
material = true,
ore = true,
toolLevel = 3,
toolType = "pick",
desc = "Sparkly, rare, and impossible to mine without an iron pickaxe.",
},
["some torches"] = {
aliases = { "torches", "torch" },
desc = "These won't run out for a while.",
},
["a torch"] = {
aliases = { "torch" },
desc = "Fire, fire, burn so bright, won't you light my cave tonight?",
},
["some wool"] = {
aliases = { "wool" },
material = true,
desc = "Soft and good for building.",
},
["some pork"] = {
aliases = { "pork", "porkchops" },
food = true,
desc = "Delicious and nutricious.",
},
["some chicken"] = {
aliases = { "chicken" },
food = true,
desc = "Finger licking good.",
},
}
local tAnimals = {
"a pig", "a cow", "a sheep", "a chicken",
}
local tMonsters = {
"a creeper", "a skeleton", "a zombie", "a spider"
}
local tRecipes = {
["some planks"] = { "some wood" },
["some sticks"] = { "some planks" },
["some sticks"] = { "some planks" },
["a crafting table"] = { "some planks" },
["a furnace"] = { "some stone" },
["some torches"] = { "some sticks", "some coal" },
["a wooden pickaxe"] = { "some planks", "some sticks" },
["a stone pickaxe"] = { "some stone", "some sticks" },
["an iron pickaxe"] = { "some iron", "some sticks" },
["a diamond pickaxe"] = { "some diamond", "some sticks" },
["a wooden sword"] = { "some planks", "some sticks" },
["a stone sword"] = { "some stone", "some sticks" },
["an iron sword"] = { "some iron", "some sticks" },
["a diamond sword"] = { "some diamond", "some sticks" },
["a wooden shovel"] = { "some planks", "some sticks" },
["a stone shovel"] = { "some stone", "some sticks" },
["an iron shovel"] = { "some iron", "some sticks" },
["a diamond shovel"] = { "some diamond", "some sticks" },
}
local tGoWest = {
"(life is peaceful there)",
"(lots of open air)",
"(to begin life anew)",
"(this is what we'll do)",
"(sun in winter time)",
"(we will do just fine)",
"(where the skies are blue)",
"(this and more we'll do)",
}
local nGoWest = 0
local bRunning = true
local tMap = { { {}, }, }
local x,y,z = 0,0,0
local inventory = {
["no tea"] = items["no tea"],
}
local nTurn = 0
local nTimeInRoom = 0
local bInjured = false
local tDayCycle = {
"It is daytime.",
"It is daytime.",
"It is daytime.",
"It is daytime.",
"It is daytime.",
"It is daytime.",
"It is daytime.",
"It is daytime.",
"The sun is setting.",
"It is night.",
"It is night.",
"It is night.",
"It is night.",
"It is night.",
"The sun is rising.",
}
local function getTimeOfDay()
return math.fmod( math.floor(nTurn/3), #tDayCycle ) + 1
end
local function isSunny()
return (getTimeOfDay() < 10)
end
local function getRoom( x, y, z, dontCreate )
tMap[x] = tMap[x] or {}
tMap[x][y] = tMap[x][y] or {}
if not tMap[x][y][z] and dontCreate ~= true then
local room = {
items = {},
exits = {},
nMonsters = 0,
}
tMap[x][y][z] = room
if y == 0 then
-- Room is above ground
-- Pick biome
room.nBiome = math.random( 1, #tBiomes )
room.trees = hasTrees( room.nBiome )
-- Add animals
if math.random(1,3) == 1 then
for n = 1,math.random(1,2) do
local sAnimal = tAnimals[ math.random( 1, #tAnimals ) ]
room.items[ sAnimal ] = items[ sAnimal ]
end
end
-- Add surface ore
if math.random(1,5) == 1 or hasStone( room.nBiome ) then
room.items[ "some stone" ] = items[ "some stone" ]
end
if math.random(1,8) == 1 then
room.items[ "some coal" ] = items[ "some coal" ]
end
if math.random(1,8) == 1 and hasRivers( room.nBiome ) then
room.items[ "a river" ] = items[ "a river" ]
end
-- Add exits
room.exits = {
["north"] = true,
["south"] = true,
["east"] = true,
["west"] = true,
}
if math.random(1,8) == 1 then
room.exits["down"] = true
room.items["a cave entrance"] = items["a cave entrance"]
end
else
-- Room is underground
-- Add exits
local function tryExit( sDir, sOpp, x, y, z )
local adj = getRoom( x, y, z, true )
if adj then
if adj.exits[sOpp] then
room.exits[sDir] = true
end
else
if math.random(1,3) == 1 then
room.exits[sDir] = true
end
end
end
if y == -1 then
local above = getRoom( x, y + 1, z )
if above.exits["down"] then
room.exits["up"] = true
room.items["an exit to the surface"] = items["an exit to the surface"]
end
else
tryExit( "up", "down", x, y + 1, z )
end
if y > -3 then
tryExit( "down", "up", x, y - 1, z )
end
tryExit( "east", "west", x - 1, y, z )
tryExit( "west", "east", x + 1, y, z )
tryExit( "north", "south", x, y, z + 1 )
tryExit( "south", "north", x, y, z - 1 )
-- Add ores
room.items[ "some stone" ] = items[ "some stone" ]
if math.random(1,3) == 1 then
room.items[ "some coal" ] = items[ "some coal" ]
end
if math.random(1,8) == 1 then
room.items[ "some iron" ] = items[ "some iron" ]
end
if y == -3 and math.random(1,15) == 1 then
room.items[ "some diamond" ] = items[ "some diamond" ]
end
-- Turn out the lights
room.dark = true
end
end
return tMap[x][y][z]
end
local function itemize( t )
local item = next( t )
if item == nil then
return "nothing"
end
local text = ""
while item do
text = text .. item
local nextItem = next( t, item )
if nextItem ~= nil then
local nextNextItem = next( t, nextItem )
if nextNextItem == nil then
text = text .. " and "
else
text = text .. ", "
end
end
item = nextItem
end
return text
end
function findItem( _tList, _sQuery )
for sItem, tItem in pairs( _tList ) do
if sItem == _sQuery then
return sItem
end
if tItem.aliases ~= nil then
for n, sAlias in pairs( tItem.aliases ) do
if sAlias == _sQuery then
return sItem
end
end
end
end
return nil
end
local tMatches = {
["wait"] = {
"wait",
},
["look"] = {
"look at the ([%a ]+)",
"look at ([%a ]+)",
"look",
"inspect ([%a ]+)",
"inspect the ([%a ]+)",
"inspect",
},
["inventory"] = {
"check self",
"check inventory",
"inventory",
"i",
},
["go"] = {
"go (%a+)",
"travel (%a+)",
"walk (%a+)",
"run (%a+)",
"go",
},
["dig"] = {
"dig (%a+) using ([%a ]+)",
"dig (%a+) with ([%a ]+)",
"dig (%a+)",
"dig",
},
["take"] = {
"pick up the ([%a ]+)",
"pick up ([%a ]+)",
"pickup ([%a ]+)",
"take the ([%a ]+)",
"take ([%a ]+)",
"take",
},
["drop"] = {
"put down the ([%a ]+)",
"put down ([%a ]+)",
"drop the ([%a ]+)",
"drop ([%a ]+)",
"drop",
},
["place"] = {
"place the ([%a ]+)",
"place ([%a ]+)",
"place",
},
["cbreak"] = {
"punch the ([%a ]+)",
"punch ([%a ]+)",
"punch",
"break the ([%a ]+) with the ([%a ]+)",
"break ([%a ]+) with ([%a ]+) ",
"break the ([%a ]+)",
"break ([%a ]+)",
"break",
},
["mine"] = {
"mine the ([%a ]+) with the ([%a ]+)",
"mine ([%a ]+) with ([%a ]+)",
"mine ([%a ]+)",
"mine",
},
["attack"] = {
"attack the ([%a ]+) with the ([%a ]+)",
"attack ([%a ]+) with ([%a ]+)",
"attack ([%a ]+)",
"attack",
"kill the ([%a ]+) with the ([%a ]+)",
"kill ([%a ]+) with ([%a ]+)",
"kill ([%a ]+)",
"kill",
"hit the ([%a ]+) with the ([%a ]+)",
"hit ([%a ]+) with ([%a ]+)",
"hit ([%a ]+)",
"hit",
},
["craft"] = {
"craft a ([%a ]+)",
"craft some ([%a ]+)",
"craft ([%a ]+)",
"craft",
"make a ([%a ]+)",
"make some ([%a ]+)",
"make ([%a ]+)",
"make",
},
["build"] = {
"build ([%a ]+) out of ([%a ]+)",
"build ([%a ]+) from ([%a ]+)",
"build ([%a ]+)",
"build",
},
["eat"] = {
"eat a ([%a ]+)",
"eat the ([%a ]+)",
"eat ([%a ]+)",
"eat",
},
["help"] = {
"help me",
"help",
},
["exit"] = {
"exit",
"quit",
"goodbye",
"good bye",
"bye",
"farewell",
},
}
local commands = {}
function doCommand( text )
if text == "" then
commands[ "noinput" ]()
return
end
for sCommand, t in pairs( tMatches ) do
for n, sMatch in pairs( t ) do
local tCaptures = { string.match( text, "^" .. sMatch .. "$" ) }
if #tCaptures ~= 0 then
local fnCommand = commands[ sCommand ]
if #tCaptures == 1 and tCaptures[1] == sMatch then
fnCommand()
else
fnCommand( table.unpack( tCaptures ) )
end
return
end
end
end
commands[ "badinput" ]()
end
function commands.wait()
print( "Time passes..." )
end
function commands.look( _sTarget )
local room = getRoom( x,y,z )
if room.dark then
print( "It is pitch dark." )
return
end
if _sTarget == nil then
-- Look at the world
if y == 0 then
io.write( "You are standing " .. tBiomes[room.nBiome] .. ". " )
print( tDayCycle[ getTimeOfDay() ] )
else
io.write( "You are underground. " )
if next( room.exits ) ~= nil then
print( "You can travel "..itemize( room.exits ).."." )
else
print()
end
end
if next( room.items ) ~= nil then
print( "There is " .. itemize( room.items ) .. " here." )
end
if room.trees then
print( "There are trees here." )
end
else
-- Look at stuff
if room.trees and (_sTarget == "tree" or _sTarget == "trees") then
print( "The trees look easy to break." )
elseif _sTarget == "self" or _sTarget == "myself" then
print( "Very handsome." )
else
local tItem = nil
local sItem = findItem( room.items, _sTarget )
if sItem then
tItem = room.items[sItem]
else
sItem = findItem( inventory, _sTarget )
if sItem then
tItem = inventory[sItem]
end
end
if tItem then
print( tItem.desc or ("You see nothing special about "..sItem..".") )
else
print( "You don't see any ".._sTarget.." here." )
end
end
end
end
function commands.go( _sDir )
local room = getRoom( x,y,z )
if _sDir == nil then
print( "Go where?" )
return
end
if nGoWest ~= nil then
if _sDir == "west" then
nGoWest = nGoWest + 1
if nGoWest > #tGoWest then
nGoWest = 1
end
print( tGoWest[ nGoWest ] )
else
if nGoWest > 0 or nTurn > 6 then
nGoWest = nil
end
end
end
if room.exits[_sDir] == nil then
print( "You can't go that way." )
return
end
if _sDir == "north" then
z = z + 1
elseif _sDir == "south" then
z = z - 1
elseif _sDir == "east" then
x = x - 1
elseif _sDir == "west" then
x = x + 1
elseif _sDir == "up" then
y = y + 1
elseif _sDir == "down" then
y = y - 1
else
print( "I don't understand that direction." )
return
end
nTimeInRoom = 0
doCommand( "look" )
end
function commands.dig( _sDir, _sTool )
local room = getRoom( x,y,z )
if _sDir == nil then
print( "Dig where?" )
return
end
local sTool = nil
local tTool = nil
if _sTool ~= nil then
sTool = findItem( inventory, _sTool )
if not sTool then
print( "You're not carrying a ".._sTool.."." )
return
end
tTool = inventory[ sTool ]
end
local room = getRoom( x, y, z )
local bActuallyDigging = (room.exits[ _sDir ] ~= true)
if bActuallyDigging then
if sTool == nil or tTool.toolType ~= "pick" then
print( "You need to use a pickaxe to dig through stone." )
return
end
end
if _sDir == "north" then
room.exits["north"] = true
z = z + 1
getRoom( x, y, z ).exits["south"] = true
elseif _sDir == "south" then
room.exits["south"] = true
z = z - 1
getRoom( x, y, z ).exits["north"] = true
elseif _sDir == "east" then
room.exits["east"] = true
x = x - 1
getRoom( x, y, z ).exits["west"] = true
elseif _sDir == "west" then
room.exits["west"] = true
x = x + 1
getRoom( x, y, z ).exits["east"] = true
elseif _sDir == "up" then
if y == 0 then
print( "You can't dig that way." )
return
end
room.exits["up"] = true
if y == -1 then
room.items[ "an exit to the surface" ] = items[ "an exit to the surface" ]
end
y = y + 1
room = getRoom( x, y, z )
room.exits["down"] = true
if y == 0 then
room.items[ "a cave entrance" ] = items[ "a cave entrance" ]
end
elseif _sDir == "down" then
if y <= -3 then
print( "You hit bedrock." )
return
end
room.exits["down"] = true
if y == 0 then
room.items[ "a cave entrance" ] = items[ "a cave entrance" ]
end
y = y - 1
room = getRoom( x, y, z )
room.exits["up"] = true
if y == -1 then
room.items[ "an exit to the surface" ] = items[ "an exit to the surface" ]
end
else
print( "I don't understand that direction." )
return
end
--
if bActuallyDigging then
if _sDir == "down" and y == -1 or
_sDir == "up" and y == 0 then
inventory[ "some dirt" ] = items[ "some dirt" ]
inventory[ "some stone" ] = items[ "some stone" ]
print( "You dig ".._sDir.." using "..sTool.." and collect some dirt and stone." )
else
inventory[ "some stone" ] = items[ "some stone" ]
print( "You dig ".._sDir.." using "..sTool.." and collect some stone." )
end
end
nTimeInRoom = 0
doCommand( "look" )
end
function commands.inventory()
print( "You are carrying " .. itemize( inventory ) .. "." )
end
function commands.drop( _sItem )
if _sItem == nil then
print( "Drop what?" )
return
end
local room = getRoom( x,y,z )
local sItem = findItem( inventory, _sItem )
if sItem then
local tItem = inventory[ sItem ]
if tItem.droppable == false then
print( "You can't drop that." )
else
room.items[ sItem ] = tItem
inventory[ sItem ] = nil
print( "Dropped." )
end
else
print( "You don't have a ".._sItem.."." )
end
end
function commands.place( _sItem )
if _sItem == nil then
print( "Place what?" )
return
end
if _sItem == "torch" or _sItem == "a torch" then
local room = getRoom( x,y,z )
if inventory["some torches"] or inventory["a torch"] then
inventory["a torch"] = nil
room.items["a torch"] = items["a torch"]
if room.dark then
print( "The cave lights up under the torchflame." )
room.dark = false
elseif y == 0 and not isSunny() then
print( "The night gets a little brighter." )
else
print( "Placed." )
end
else
print( "You don't have torches." )
end
return
end
commands.drop( _sItem )
end
function commands.take( _sItem )
if _sItem == nil then
print( "Take what?" )
return
end
local room = getRoom( x,y,z )
local sItem = findItem( room.items, _sItem )
if sItem then
local tItem = room.items[ sItem ]
if tItem.heavy == true then
print( "You can't carry "..sItem.."." )
elseif tItem.ore == true then
print( "You need to mine this ore." )
else
if tItem.infinite ~= true then
room.items[ sItem ] = nil
end
inventory[ sItem ] = tItem
if inventory["some torches"] and inventory["a torch"] then
inventory["a torch"] = nil
end
if sItem == "a torch" and y < 0 then
room.dark = true
print( "The cave plunges into darkness." )
else
print( "Taken." )
end
end
else
print( "You don't see a ".._sItem.." here." )
end
end
function commands.mine( _sItem, _sTool )
if _sItem == nil then
print( "Mine what?" )
return
end
if _sTool == nil then
print( "Mine ".._sItem.." with what?" )
return
end
commands.cbreak( _sItem, _sTool )
end
function commands.attack( _sItem, _sTool )
if _sItem == nil then
print( "Attack what?" )
return
end
commands.cbreak( _sItem, _sTool )
end
function commands.cbreak( _sItem, _sTool )
if _sItem == nil then
print( "Break what?" )
return
end
local sTool = nil
if _sTool ~= nil then
sTool = findItem( inventory, _sTool )
if sTool == nil then
print( "You're not carrying a ".._sTool.."." )
return
end
end
local room = getRoom( x,y,z )
if _sItem == "tree" or _sItem == "trees" or _sItem == "a tree" then
print( "The tree breaks into blocks of wood, which you pick up." )
inventory[ "some wood" ] = items[ "some wood" ]
return
elseif _sItem == "self" or _sItem == "myself" then
if isAdvanced() then
gpu.setForeground( 0xFF0000 )
end
print( "You have died." )
print( "Score: &e0" )
gpu.setForeground( oxFFFFFF )
bRunning = false
return