From: Christian Heller Date: Wed, 16 Dec 2020 22:26:44 +0000 (+0100) Subject: Add crates. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/processes?a=commitdiff_plain;h=509d9ca8e54529b5d728b1635df4ba4bbb0bcc23;p=plomrogue2 Add crates. --- diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 074cc34..c86aebe 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -396,3 +396,17 @@ def cmd_THING_DOOR_KEY(game, key_id, door_id): 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' diff --git a/plomrogue/game.py b/plomrogue/game.py index 0c84e04..b394c5d 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -561,9 +561,14 @@ class Game(GameBase): 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 diff --git a/plomrogue/tasks.py b/plomrogue/tasks.py index 14ea820..9594505 100644 --- a/plomrogue/tasks.py +++ b/plomrogue/tasks.py @@ -75,6 +75,9 @@ class Task_MOVE(Task): 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 @@ -139,6 +142,11 @@ class Task_PICK_UP(Task): 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') @@ -150,42 +158,43 @@ class Task_DROP(Task): 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') diff --git a/plomrogue/things.py b/plomrogue/things.py index a0db94a..2519798 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -456,6 +456,28 @@ class Thing_CookieSpawner(Thing): +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 diff --git a/rogue_chat.py b/rogue_chat.py index a3654b0..cc6421f 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -15,7 +15,8 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN 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, @@ -26,7 +27,8 @@ from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner, 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']) @@ -71,6 +73,7 @@ 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_command(cmd_THING_CRATE_ITEM) game.register_task(Task_WAIT) game.register_task(Task_MOVE) game.register_task(Task_WRITE) @@ -101,6 +104,8 @@ game.register_thing_type(Thing_Cookie) 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']: