-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
1239 lines (1037 loc) · 34.6 KB
/
game.py
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
import os, time, sys, re
import importlib, inspect
from functools import wraps
import pickle
from gmap import *
import iface
import bldgfx
import achieve
import pdb
WIDTH = 60
HEIGHT = 45
scr = iface.CurseScreen()
rend = None
g = None
def debug():
rend.play(False)
pdb.set_trace()
def undebug():
rend.play(True)
pass
def makeSaveName(name):
return "save/"+name+".bld"
def save(g, filename):
with open(makeSaveName(filename), "wb") as f:
pickle.dump(g, f)
def load(g, filename):
with open(makeSaveName(filename), "rb") as f:
return pickle.load(f)
def getSaveNames():
files = os.listdir("save")
saves = []
for name in files:
parts = name.split('.')
if len(parts) > 1 and parts[-1] == 'bld':
saves.append('.'.join(parts[:-1]))
return saves
def extractSaveName(cmd):
"""
Extracts a save file name by returning the first word
after "save" or "load".
"""
parts = cmd.split(' ')
next = False
for p in parts:
if next:
return p
if p == 'save' or p == 'load':
next = True
return None
#Text display functions for saying things
def sayLine(data):
"""
Say some text without adding a newline at the end. Named
to be intuitive.
"""
scr.sayLine(data)
def spell(data, delay=.75):
"""
Spell some text one character at a time with a delay
between characters. For special effects.
"""
scr.spell(data, delay)
def lf(num = 1):
"""
Linefeed. Just adds a newline.
"""
scr.lf(num)
def say(data):
"""
Say some text with a newline at the end. The main
function for saything things.
"""
scr.say(data)
def sayList(items):
"""
Formats and says a list of strings with some spacing.
"""
xpos = 0
string = " "
for item in items:
string += item
xpos += 1
if xpos == 4:
xpos = 0
string += "\n"
else:
string += " "*(15-len(item))
say(string)
def fail(string = None):
"""
For commands that have failed e.g. the player used take
one something that has a take verb but can't be taken
yet. Allows a thing print a different fail message than
the default without
"""
if string == None:
string = g.getString('fail')
say(string)
return False
def _pass():
"""
For when a function handles a command but wants to let
other objects try the command as well. Used with the
base take verb to allow nonunique items in the inventory
to not block identical items in the room.
"""
return "pass"
def confirm(text = None):
"""
Prompt the player for input and return True of False for
y/n. Default is
ARE YOU SURE? Y/N
"""
if text != None:
return g.interface.getConfirm(text)
return g.interface.getConfirm()
def wait(text = None):
"""
Print some text and wait for the player to press a key
to continue. Default is
(CONTINUE)
"""
if text != None:
return g.interface.getPause(text)
return g.interface.getPause()
directions = ["up", "down", "left", "right"]
def getDir(cmd):
"""
Find and return a valid direction in the given command.
"""
for part in cmd.split(' '):
if part in directions:
return part
def getInter(list1, list2):
"""
Return the intersection of two lists.
"""
return [x for x in list1 if x in list2]
def require(matches=[], empty=False, any=False):
"""
A decorator to make a verb function fail if the
command doesn't contain any of the valid objects.
"""
def dec(f):
@wraps(f)
def wrapper(self, cmd):
if self._matchCmd(cmd, matches, empty, any):
return f(self, cmd)
else:
return _pass()
return wrapper
return dec
def inv(f):
"""
A decorator to only calls the function if the object
is in the player's inventory. Useful for use functions.
"""
@wraps(f)
def wrapper(self, cmd):
result = self._reqInv()
if result != True:
return result
return f(self,cmd)
return wrapper
def needItem(name, qty=1):
"""
Decorator to require that the player has at least qty
of the specified item in inv.
"""
def dec(f):
@wraps(f)
def wrapper(self, cmd):
result = g.hasItem(name)
if result >= qty:
return f(self,cmd)
return fail()
return wrapper
return dec
def standing(f):
"""
A decorator to only calls the function if the player is
standing and fails otherwise.
"""
@wraps(f)
def wrapper(self, cmd):
if g.getFlag('sit'):
return fail(g.currRoom.getString("sitFail"))
return f(self,cmd)
return wrapper
class Achievement():
"""
An achievement with a desc and length. Displays as
[DESC]: X/Y
where x is the player's progress and y is the total
possible progress. A single-event achievement will have
length of 0 e.g.
BLACK WINDS ACQUIRED: 0/1
"""
def __init__(self, desc, length = 1):
self.desc = desc.upper()
self.length = length
self.qty = 0
def give(self, qty = 1):
self.qty += qty
if self.qty > self.length:
self.qty = self.length
def getString(self):
return "{desc}: {qty}/{length}".format(**self.__dict__)
class Bld():
"""
Base class for game objects. Handles verbs, descriptive
strings, sprites, and flags.
"""
fancyVerbs = {}
addVerbs = []
rmVerbs = []
defVerbs = []
name = ''
strings = {}
defStrings = {}
defSprite = None
defFlags = {}
flagDec = ''
def __init__(self):
self.sprite = self.defSprite
self.verbs = {}
verblist = list(self.defVerbs)
verblist.extend(self.addVerbs)
self.verbs = {}
verblist = [x for x in verblist if x not in self.rmVerbs]
for v in verblist:
try:
func = getattr(self, v)
except:
print("Plain verb error: {} in Bld {}".format(v, self.name))
else:
self.verbs[v] = v
self.verbs.update(self.fancyVerbs)
def _checkSprite(self):
"""
Called on show and hide to change the sprite if it
needs to change.
"""
pass
def _shortCmd(self, cmd):
"""
Checks to see if a command doesn't have any objects.
"""
if len(cmd.split(' ')) == 1:
return True
return False
def _matchCmd(self, cmd, matches=[], empty = False, any = False):
"""
Checks to see if a command contains one of the words
in matches. Also checks to see if the command has no
objects if empty is True. If any is True, returns
True as long as there is an object.
"""
if any and len(cmd.split(' ')) > 1:
return True
if empty and len(cmd.split(' ')) == 1:
return True
for m in matches:
if m in cmd:
return True
return False
def _show(self):
self._checkSprite()
if self.sprite == None:
return
rend.addSprite(self.sprite)
def _hide(self):
self._checkSprite()
if self.sprite == None:
return
rend.removeSprite(self.sprite)
def _flagName(self, name):
return self.name + self.flagDec + name
def _getVerbs(self):
"""
Returns only the objects valid verbs as a list. Used
in getVerbs.
"""
return self.verbs.keys()
def getVerbs(self):
"""
Should be overridden for anything that needs to give
more than its own verbs e.g. Room and Game.
"""
return self._getVerbs()
def _doCmd(self, cmd):
for v in self.verbs.keys():
if v == cmd.split(' ')[0]:
result = getattr(self, self.verbs[v])(cmd)
if result != "pass":
return True
return False
def getFlag(self, name):
"""
Retrieves the requested flag from the game flag
dictionary. Returns the default from defFlags if
not already set. Returns none if no default.
"""
default = None
if name in self.defFlags.keys():
default = self.defFlags[name]
return g.getFlag(self._flagName(name), default)
def setFlag(self, name, val):
"""
Sets the given flag in the game flag dictionary.
"""
g.setFlag(self._flagName(name), val)
def getString(self, key):
"""
Retrieves the descriptive string from strings or
defStrings, formats it with name and self's
dictionary, and returns the result.
"""
if key in self.strings.keys():
base = self.strings[key]
elif key in self.defStrings.keys():
base = self.defStrings[key]
else:
return None
pattern = "\<\s*flag=`(?P<flag>.*)`\s*`(?P<true>.*)`\s*`(?P<false>.*)`\s*\>"
for match in re.finditer(pattern, base):
flag = match.group('flag').split('=')
val = flag[1]
try:
val = int(val)
except:
pass
rstr = match.string[match.start():match.end()]
if g.getFlag(flag[0]) == val:
base = base.replace(rstr, match.group('true'))
else:
base = base.replace(rstr, match.group('false'))
return base.format(self.name.upper(), **self.__dict__)
class Game(Bld):
"""
Game class handles loading content, setting up screens,
scoring, timekeeping, flags, saving, loading, and the
main game loop.
"""
defFlags = { "subTurn": 0
, "turns": 0
, "score": 0
, "hair": 1
, "sit": False
}
force = ""
done = False
defStrings= { 'fail': 'Hmm...'
}
defVerbs = ["debug", "help", "exit", "hint", "score", "save", "load", "restart"]
fancyVerbs ={ "==>": "_mspa"
, "saves": "showsaves"
}
alarms = {}
def __init__(self):
global g
Bld.__init__(self)
g = self
self.currRoom = None
self.flags = {}
self.rooms = {}
self.items = {}
self.banned = []
self.achievements = {}
self.lastSave = "default"
def __getstate__(self):
return self.currRoom, self.inv, self.flags, self.rooms, self.items, self.lastSave, self.achievements
def __setstate__(self, state):
self.currRoom, self.inv, self.flags, self.rooms, self.items, self.lastSave, self.achievements = state
def initScreens(self, Interface, Screen, Renderer):
"""
Initializes the Interface and Screen objects from
the given classes, then initalizes the renderer
from the given screen. Also sets global variables
for renderer and screen.
"""
global rend, scr
self.interface = Interface(self)
self.screen = Screen()
self.interface.setScreen(self.screen)
self.screen.setWindow(self.interface.cmdwin)
scr = self.screen
rend = Renderer(self.interface)
def commandLoop(self, infile = None):
"""
Runs the game.
"""
self.interface.commandLoop(infile)
def loadModules(self):
"""
Loads rooms from all modules in rooms/*.py. and sets
inventory to the room named 'inv', which must exist.
"""
with open("logs/gameload", "w") as f:
roomFiles = os.listdir('./rooms')
items = []
combos = []
for name in roomFiles:
modName, modExt = os.path.splitext(name)
if modExt == '.py' and modName != '__init__':
f.write("loading module {}\n".format(name))
mod = importlib.import_module("rooms."+modName)
for val in dir(mod):
try:
thing = mod.__dict__[val]
if Room in inspect.getmro(thing):
f.write("Found Room\n")
self._addRoom(thing())
if Item in inspect.getmro(thing):
f.write("Found item\n")
try:
nItem = thing()
items.append(nItem)
self._addItem(nItem)
except Exception as e:
f.write(str(e)+'\n')
elif Combo in inspect.getmro(thing):
try:
nCombo = thing()
combos.append(nCombo)
except Exception as e:
f.write(str(e)+'\n')
except Exception as e:
pass
for item in items:
room = self.rooms[item.loc]
room.items[item.name] = item
item.room = room
f.write("Adding item {} to room {}\n".format(item.name, room.name))
for combo in combos:
room = self.rooms[combo.loc]
room.combos[combo.name] = combo
combo.room = room
f.write("Adding combo {} to room {}\n".format(combo.name, room.name))
self.inv = self.rooms['inv']
for name, desc, qty in achieve.achievements:
self.achievements[name] = Achievement(desc, qty)
def _addRoom(self, room):
if not room.name in self.rooms.keys():
self.rooms[room.name] = room
else:
print("Failed to add duplicate room")
def _addItem(self, item):
if not item.unique:
return
if not item.name in self.items.keys():
self.items[item.name] = item
else:
print("Failed to add duplicate item")
def refreshImg(self):
self.currRoom._show()
def doCmd(self, cmd):
"""
Evaluates the given command and says the fail string
if the command isn't currently valid. Order is:
inv -> room -> game
"""
lf()
self.tickTurn()
if cmd.split(' ')[0] in self.banned:
pass
elif self.inv.doCmd(cmd):
pass
elif self.currRoom.doCmd(cmd):
pass
elif self._doCmd(cmd):
pass
else:
say(self.getString('fail'))
self.refreshImg()
def giveAchievement(self, name, qty = 1):
"""
Gives the player qty progress towards the named
achievement.
"""
self.achievements[name].give(qty)
def getAchievements(self):
"""
Formats and returns a list of strings for the
player's achievements.
"""
strings = [x.getString() for x in self.achievements.values()]
result = []
strings = sorted(strings, key=lambda x: len(x))
return strings
def moveRoom(self, name):
"""
Changes the current room, refreshes rendering info,
and calls exit and enter functions.
"""
if self.currRoom:
self.currRoom._onLeave()
self.banned = []
self.currRoom = self.rooms[name]
self.refreshImg()
self.currRoom._onEnter()
def banVerbs(self, verbs):
"""
Temporarily ban the given verbs from being
recognized. Cleared on moveRoom.
"""
self.banned.extend(verbs)
def moveItem(self, name, newLoc):
"""
Move the named unique item to the given room.
"""
self.items[name]._move(newLoc)
def hasItem(self, name):
"""
Checks to see if an item with the given name is in
the inventory and returns the quantity.
"""
if name in self.inv.items.keys():
return self.inv.items[name].qty
return 0
def getVerbs(self):
"""
Returns a list of all currently valid verbs i.e.
from the game, the current room, and the inventory.
This is for autocompletion support.
"""
verbs = []
verbs.extend(self._getVerbs())
verbs.extend(self.inv.getVerbs())
verbs.extend(self.currRoom.getVerbs())
return verbs
def getFlag(self, name, default = None):
"""
Retrieves the requested flag. If not set, returns
and sets the value from defFlags. If still not set,
returns default.
"""
if name in self.flags.keys():
return self.flags[name]
elif name in self.defFlags.keys():
self.flags[name] = self.defFlags[name]
return self.flags[name]
else:
return default
def setFlag(self, name, val):
self.flags[name] = val
def forceCmd(self, cmd):
"""
Forces the next command to be the given command.
"""
self.force = cmd
def getScore(self):
return self.getFlag("score")
def getTurns(self):
return self.getFlag("turns")
def setTurns(self, val):
self.setFlag("turns", val)
#possibly better to derive the game class?
def getHair(self):
return self.getFlag("hair")
def setAlarm(self, delay, func, *args, **kwargs):
"""
Sets an alarm to call the function func after delay
turns with the given arguments.
"""
turn = self.getTurns()+delay
if not turn in self.alarms.keys():
self.alarms[turn] = []
self.alarms[turn].append((func, args, kwargs))
def tickTurn(self):
"""
Move time forward. In this implementation the turn
count increments every hair commands.
Also call any relevant alarm functions for the next
turn.
"""
turns = self.getTurns()
sub = self.getFlag("subTurn")
hair = self.getHair()
sub += 1
if sub >= hair:
sub = 0
turns += 1
if turns in self.alarms.keys():
for func, args, kwargs in self.alarms[turns]:
func(*args, **kwargs)
self.flags["subTurn"] = sub
self.setTurns(turns)
def addScore(self, val):
"""
Add points to the player's score.
"""
score = self.getFlag("score")
self.flags["score"] = score+val
def _getSaveName(self, cmd):
"""
Gets save name info from save and load commands.
"""
saveName = extractSaveName(cmd)
if saveName == None:
saveName = self.lastSave
self.lastSave = saveName
def _clear(self):
"""
Clear and reload data.
"""
self.__init__()
self.interface.clear()
self.loadModules()
def restart(self, cmd):
"""
Restart the game. Starts in the room named _init.
"""
#TODO: Check unsaved game and confirm if so?
self._clear()
self.moveRoom('_init')
def save(self, cmd):
"""
Save the game using the given save filename
"""
self._getSaveName(cmd)
save(self, self.lastSave)
say("Saved gamed as {}.".format(self.lastSave))
return True
def load(self, cmd):
"""
Load the game from the given save file and update
self from the loaded information.
"""
self._getSaveName(cmd)
loadGame = load(self, self.lastSave)
if loadGame == None:
say("Failed to load game {}.".format(self.lastSave))
return False
self.__dict__.update(loadGame.__dict__)
self.refreshImg()
say("Loaded gamed {}.".format(self.lastSave))
return True
def showsaves(self, cmd):
saves = getSaveNames()
result = []
fmt = "{name:12}{loc:12}{score:12}{time:12}"
result.append(fmt.format( name="name"
, loc ="room"
, score = "score"
, time = "turns"
))
for name in saves:
loadGame = load(self, name)
if loadGame != None:
result.append(fmt.format( name=name
, loc=loadGame.currRoom.name
, score=str(loadGame.getScore())
, time=str(loadGame.getTurns())
))
game.say('\n'.join(result))
return True
def debug(self, cmd):
"""
Debug command. Stops rendering and starts pdb, then
restarts rendering.
"""
rend.play(False)
pdb.set_trace()
rend.play(True)
@require(empty=True)
def score(self, cmd):
"""
Command to display the player's scoring info.
"""
score = self.getScore()
turns = self.getTurns()
hair = self.getHair()
scoreStr = "SCORE: {}".format(score)
scoreStr += " "*(15 - len(scoreStr))
scoreStr += "TURNS: {}".format(turns)
scoreStr += " "*(30 - len(scoreStr))
scoreStr+= "HAIR: {}".format(hair)
say(" "*7 + scoreStr)
return True
def help(self, cmd):
return fail("There is no one here you can help.")
def hint(self, cmd):
return fail("I don't need any hints, but thanks for offering.")
@require(empty = True)
def exit(self, cmd):
self.done = True
return True
def _mspa(self, cmd):
"""
A refrance. Example of fancyVerbs.
"""
return fail("hhhhhhm..")
class Room(Bld):
"""
A Room is a distinct location in the game. It contains
items. The current room catches
commands from the player and handles them or passes
them to items that can. The inventory is a special room
that also catches commands and holds items in the
player's inventory.
Rooms can be entered and exited and will call the
functions _onFirstEnter, _onOtherEnter, and _onLeave.
Rooms presently have some shoddy sit/stand functionality.
Items live in a dictionary as items[name].
"""
name = ""
sitable = False #Can the player sit?
defVerbs = ["look", "sit", "stand"]
defStrings= { "desc": "It is a room?"
, "closer": "You take a closer look."
, "loc": "You are {pos}."
, "sit": "There's nowhere to sit!"
, "sit2": "You are already sitting."
, "stand": "You stand up. You are now standing."
, "stand2": "You are already standing."
, "sitFail": "You can't do that while sitting?"
}
defFlags = {}
flagDec = '~'
def __init__(self):
Bld.__init__(self)
self.items = {}
self.combos = {}
self.defFlags['entered'] = False
def _show(self):
rend.clear()
Bld._show(self)
for item in self.items.values():
item._show()
def _hide(self):
rend.clear()
def _makeItemString(self, obscure = False):
"""
Formats a description of items in the room, exluding
obscure items.
"""
itemStrings = []
for item in self.items.values():
if item.obscure == obscure:
itemStrings.append( item.getGround() )
return ' '.join(itemStrings)
def _onEnter(self):
if self.getFlag('entered'):
self._onOtherEnter()
else:
self.setFlag("entered", True)
self._onFirstEnter()
def _onOtherEnter(self):
"""
Called when the player enters the room any time
other than the first. Runs the look command by
by default.
"""
self.look("look")
def _onFirstEnter(self):
"""
Called the first time the player enters the room.
Defaults to _onOtherEnter().
"""
self._onOtherEnter()
def _onLeave(self):
"""
Called when the player leaves the room. Does nothing
by default.
"""
pass
def getVerbs(self):
verbs = self._getVerbs()
for item in self.items.values():
verbs.extend(item.getVerbs())
return verbs
def doCmd(self, cmd):
"""
Checks commands on items first, then on self.
"""
for combo in self.combos.values():
if combo._checkCmd(cmd):
if combo._doCmd(cmd):
return True
for item in self.items.values():
if item.name.lower() in cmd:
if item._doCmd(cmd):
return True
if self._doCmd(cmd):
return True
return False
@require(["closer"], True)
def look(self, cmd):
"""
Says either the desc string or the closer string,
then says the list of items in the room from
_makeItemString()
"""
if "closer" in cmd:
desc = self.getString('closer')
items = self._makeItemString(True)
else:
desc = self.getString('desc')
items = self._makeItemString()
say(desc)
if items != "":
lf()
say(items)
return True
def sit(self, cmd):
"""
Handles sitting in various directions. Is stupid and
should be reworked.
"""
state = g.getFlag("sit")
if state:
return fail(self.getString("sit2"))
return self.sitDown()
def stand(self, cmd):
"""
Same dead as sit. Blam this piece of crap.
"""
state = g.getFlag("sit")
if not state:
return fail(self.getString("stand2"))
return self.standUp()
def sitDown(self):
if self.sitable:
g.setFlag('sit', True)
say(self.getString("sit"))
return True
return fail(self.getString("sit"))
def standUp(self):
say(self.getString("stand"))
g.setFlag('sit', False)
return True
class Item(Bld):
"""
Items are things that the player can interact with or
that can do stuff. They have got a bunch of true/false
flags for common behaviors.
By default items cannot be picked up or dropped, are not
listed in the room look command, are unique, and exist
when the room is created.
Hidden items are meant to hold information without being
directly interactable, but can also be interactable
without the player having and obvious way to know they
exist, e.g. the Black Wind item in the demo. They will