raise GameError('thing of ID %s not a door' % key_id)
key.door = door
cmd_THING_DOOR_KEY.argtypes = 'int:pos int:pos'
+
+def cmd_THING_CRATE_ITEM(game, crate_id, item_id):
+ crate = game.get_thing(crate_id)
+ if not crate:
+ raise GameError('thing of ID %s not found' % crate_id)
+ if crate.type_ != 'Crate':
+ raise GameError('thing of ID %s not a crate' % crate_id)
+ item = game.get_thing(item_id)
+ if not item:
+ raise GameError('thing of ID %s not found' % item_id)
+ if item.type_ == 'Crate':
+ raise GameError('thing of ID %s is a crate' % item_id)
+ crate.accept(item)
+cmd_THING_CRATE_ITEM.argtypes = 'int:pos int:pos'
write(f, 'THING_BOTTLE_EMPTY %s' % t.id_)
elif t.type_ == 'DoorKey':
write(f, 'THING_DOOR_KEY %s %s' % (t.id_, t.door.id_))
+ elif t.type_ == 'Crate':
+ for item in t.content:
+ write(f, 'THING_CRATE_ITEM %s %s' % (t.id_, item.id_))
write(f, 'SPAWN_POINT %s %s' % (self.spawn_point[0],
self.spawn_point[1]))
+
+
def get_map(self, big_yx, type_='normal'):
if type_ == 'normal':
maps = self.maps
self.thing.game.record_change(self.thing.position, 'fov')
if self.thing.carrying:
self.thing.carrying.position = self.thing.position
+ if self.thing.carrying.type_ == 'Crate':
+ for t in self.thing.carrying.content:
+ t.position = self.thing.position
to_pick_up.position = self.thing.position[:]
self.thing.carrying = to_pick_up
to_pick_up.carried = True
+ for t in [t for t in self.thing.game.things
+ if t.type_ == 'Crate' and to_pick_up in t.content]:
+ t.remove_from_crate(to_pick_up)
+ self.thing.send_msg('CHAT "You take the item out of the crate."')
+ break
self.thing.game.record_change(self.thing.position, 'other')
if not self.thing.carrying:
raise PlayError('nothing to drop')
target_position = self._get_move_target()
- if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
- for t in [t for t in self.thing.game.things
- if t.type_ == 'BottleDeposit'
- and t.position == target_position]:
- raise PlayError('cannot drop full bottle into bottle deposit')
- for t in [t for t in self.thing.game.things
- if t.type_ == 'CookieSpawner'
- and t.position == target_position]:
- if not self.thing.carrying.cookable:
+ targets = [t for t in self.thing.game.things
+ if t.position == target_position
+ and not t == self.thing.carrying]
+ for target in targets:
+ if target.type_ == 'CookieSpawner' and\
+ not self.thing.carrying.cookable:
raise PlayError('cannot cook items of this type')
- break
+ elif target.type_ == 'BottleDeposit':
+ if not self.thing.carrying.type_ == 'Bottle':
+ raise PlayError('cannot only put bottle into bottle deposit')
+ if self.thing.carrying.full:
+ raise PlayError('cannot drop full '
+ 'bottle into bottle deposit')
+ elif target.type_ == 'Crate' and\
+ self.thing.carrying.type_ == 'Crate':
+ raise PlayError('cannot put crate into crate')
def do(self):
target_position = self._get_move_target()
dropped = self.thing.uncarry()
dropped.position = target_position
- over_cookie_spawner = None
- for t in [t for t in self.thing.game.things
- if t.type_ == 'CookieSpawner'
- and t.position == dropped.position]:
- over_cookie_spawner = t
- break
- if over_cookie_spawner:
- over_cookie_spawner.accept(dropped)
- self.thing.game.remove_thing(dropped)
- elif dropped.type_ == 'Bottle' and not dropped.full:
- for t in [t for t in self.thing.game.things
- if t.type_ == 'BottleDeposit'
- and t.position == dropped.position]:
- t.accept()
+ targets = [t for t in self.thing.game.things
+ if t.position == dropped.position and not t == dropped]
+ for target in targets:
+ if target.type_ == 'CookieSpawner':
+ target.accept(dropped)
self.thing.game.remove_thing(dropped)
break
- elif dropped.type_ == 'Hat':
- for t in [t for t in self.thing.game.things
- if t.type_ == 'HatRemixer'
- and t.position == dropped.position]:
+ elif target.type_ == 'BottleDeposit':
+ target.accept()
+ self.thing.game.remove_thing(dropped)
+ break
+ elif target.type_ == 'Crate':
+ target.accept(dropped)
+ self.thing.send_msg('CHAT "You put the item into the crate."')
+ break
+ elif target.type_ == 'HatRemixer':
t.accept(dropped)
break
self.thing.game.record_change(self.thing.position, 'other')
+class Thing_Crate(Thing):
+ portable = True
+ symbol_hint = 'C'
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.content = []
+
+ def accept(self, thing):
+ self.content += [thing]
+
+ def remove_from_crate(self, thing):
+ self.content.remove(thing)
+
+
+
+class Thing_CrateSpawner(ThingSpawner):
+ child_type = 'Crate'
+ symbol_hint = 'C'
+
+
+
class ThingAnimate(Thing):
weariness = 0
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_THING_DOOR_KEY)
+ cmd_TERRAIN_TAG, cmd_THING_DOOR_KEY,
+ cmd_THING_CRATE_ITEM)
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_DoorKey)
+ Thing_PsychedelicSpawner, Thing_DoorKey,
+ Thing_Crate, Thing_CrateSpawner)
from plomrogue.config import config
game = Game(config['savefile'])
game.register_command(cmd_PLAYER_HAT)
game.register_command(cmd_THING_HAT_DESIGN)
game.register_command(cmd_THING_DOOR_KEY)
+game.register_command(cmd_THING_CRATE_ITEM)
game.register_task(Task_WAIT)
game.register_task(Task_MOVE)
game.register_task(Task_WRITE)
game.register_thing_type(Thing_CookieSpawner)
game.register_thing_type(Thing_Psychedelic)
game.register_thing_type(Thing_PsychedelicSpawner)
+game.register_thing_type(Thing_Crate)
+game.register_thing_type(Thing_CrateSpawner)
game.read_savefile()
game.io.start_loop()
for port in config['servers']: