t.protection = protection_char
cmd_GOD_THING_PROTECTION.argtypes = 'int:pos char'
-def cmd_THING_DOOR_CLOSED(game, thing_id):
+def cmd_THING_DOOR_CLOSED(game, thing_id, locked):
t = game.get_thing(thing_id)
if not t:
raise GameError('thing of ID %s not found' % thing_id)
if not t.type_ == 'Door':
raise GameError('thing of ID %s not door' % thing_id)
t.close()
-cmd_THING_DOOR_CLOSED.argtypes = 'int:pos'
+ if locked:
+ t.lock()
+cmd_THING_DOOR_CLOSED.argtypes = 'int:pos bool'
def cmd_THING_MUSICPLAYER_SETTINGS(game, thing_id, playing, index, repeat):
t = game.get_thing(thing_id)
raise GameError('thing of ID %s not a hat' % thing_id)
t.design = design
cmd_THING_HAT_DESIGN.argtypes = 'int:pos string'
+
+def cmd_THING_DOOR_KEY(game, key_id, door_id):
+ key = game.get_thing(key_id)
+ if not key:
+ raise GameError('thing of ID %s not found' % key_id)
+ if key.type_ != 'DoorKey':
+ raise GameError('thing of ID %s not a door key' % key_id)
+ door = game.get_thing(door_id)
+ if not door:
+ raise GameError('thing of ID %s not found' % door_id)
+ if door.type_ != 'Door':
+ raise GameError('thing of ID %s not a door' % key_id)
+ key.door = door
+cmd_THING_DOOR_KEY.argtypes = 'int:pos int:pos'
if hasattr(t, 'installable') and (not t.portable):
write(f, 'THING_INSTALLED %s' % t.id_)
if t.type_ == 'Door' and t.blocks_movement:
- write(f, 'THING_DOOR_CLOSED %s' % t.id_)
+ write(f, 'THING_DOOR_CLOSED %s %s' % (t.id_, int(t.locked)))
elif t.type_ == 'Hat':
write(f, 'THING_HAT_DESIGN %s %s' % (t.id_,
quote(t.design)))
(t.id_, quote(item[0]), item[1]))
elif t.type_ == 'Bottle' and not t.full:
write(f, 'THING_BOTTLE_EMPTY %s' % t.id_)
+ elif t.type_ == 'DoorKey':
+ write(f, 'THING_DOOR_KEY %s %s' % (t.id_, t.door.id_))
write(f, 'SPAWN_POINT %s %s' % (self.spawn_point[0],
self.spawn_point[1]))
def check(self):
action_radius = list(self.thing.game.map_geometry.
get_neighbors_yxyx(self.thing.position).values())
- if len([t for t in self.thing.game.things if
- t.type_ == 'Door' and t.position in action_radius]) == 0:
+ reachable_doors = [t for t in self.thing.game.things if
+ t.type_ == 'Door' and t.position in action_radius]
+ if len(reachable_doors) == 0:
raise PlayError('not standing next to a door to open/close')
+ for door in reachable_doors:
+ if not door.blocks_movement:
+ return
+ if not door.locked:
+ return
+ if self.thing.carrying and self.thing.carrying.type_ == 'DoorKey'\
+ and self.thing.carrying.door == door:
+ return
+ raise PlayError('cannot open locked door without its key')
def do(self):
action_radius = list(self.thing.game.map_geometry.
t.open()
else:
t.close()
+ if self.thing.carrying and\
+ self.thing.carrying.type_ == 'DoorKey' and\
+ self.thing.carrying.door == t:
+ self.thing.send_msg('CHAT "You lock the door."')
+ t.lock()
self.thing.game.record_change(t.position, 'other')
self.thing.game.record_change(t.position, 'fov')
def proceed(self):
for t in [t for t in self.game.things
if t != self and t.position == self.position]:
- return
- self.game.add_thing(self.child_type, self.position)
+ return None
+ return self.game.add_thing(self.child_type, self.position)
class Thing_DoorSpawner(ThingSpawner):
child_type = 'Door'
+ def proceed(self):
+ door = super().proceed()
+ if door:
+ key = self.game.add_thing('DoorKey', self.position)
+ key.door = door
+
+
+
+class Thing_DoorKey(Thing):
+ portable = True
+ symbol_hint = 'k'
+
+
class Thing_Door(ThingInstallable):
symbol_hint = 'D'
blocks_movement = False
+ locked = False
def open(self):
self.blocks_movement = False
self.blocks_light = False
self.blocks_sound = False
+ self.locked = False
del self.thing_char
def close(self):
self.blocks_sound = True
self.thing_char = '#'
+ def lock(self):
+ self.locked = True
+ self.thing_char = 'L'
+
class Thing_Psychedelic(Thing):
cmd_THING_BOTTLE_EMPTY, cmd_PLAYER_FACE,
cmd_GOD_PLAYER_FACE, cmd_GOD_PLAYER_HAT,
cmd_GOD_PLAYERS_HAT_CHARS, cmd_PLAYER_HAT,
- cmd_TERRAIN_TAG)
+ cmd_TERRAIN_TAG, cmd_THING_DOOR_KEY)
from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP,
Task_DROP, Task_FLATTEN_SURROUNDINGS, Task_DOOR,
Task_INTOXICATE, Task_COMMAND, Task_INSTALL,
Thing_BottleSpawner, Thing_BottleDeposit,
Thing_MusicPlayer, Thing_Hat, Thing_HatRemixer,
Thing_Cookie, Thing_CookieSpawner, Thing_Psychedelic,
- Thing_PsychedelicSpawner)
+ Thing_PsychedelicSpawner, Thing_DoorKey)
from plomrogue.config import config
game = Game(config['savefile'])
game.register_command(cmd_GOD_PLAYERS_HAT_CHARS)
game.register_command(cmd_PLAYER_HAT)
game.register_command(cmd_THING_HAT_DESIGN)
+game.register_command(cmd_THING_DOOR_KEY)
game.register_task(Task_WAIT)
game.register_task(Task_MOVE)
game.register_task(Task_WRITE)
game.register_thing_type(Thing_SpawnPoint)
game.register_thing_type(Thing_SpawnPointSpawner)
game.register_thing_type(Thing_Door)
+game.register_thing_type(Thing_DoorKey)
game.register_thing_type(Thing_DoorSpawner)
game.register_thing_type(Thing_Bottle)
game.register_thing_type(Thing_BottleSpawner)