From: Christian Heller Date: Thu, 3 Dec 2020 04:39:16 +0000 (+0100) Subject: Turn Consumable into Bottle that may be full or empty. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/%7B%7Bdb.prefix%7D%7D/processes?a=commitdiff_plain;h=018bb0242ebd2b7e9fde170fae830376dea55e16;p=plomrogue2 Turn Consumable into Bottle that may be full or empty. --- diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 0638cb8..dea4b63 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -305,3 +305,12 @@ def cmd_THING_MUSICPLAYER_PLAYLIST_ITEM(game, thing_id, title, length): raise GameError('thing of ID %s not music player' % thing_id) t.playlist += [(title, length)] cmd_THING_MUSICPLAYER_PLAYLIST_ITEM.argtypes = 'int:pos string int:pos' + +def cmd_THING_BOTTLE_EMPTY(game, thing_id): + t = game.get_thing(thing_id) + if not t: + raise GameError('thing of ID %s not found' % thing_id) + if not t.type_ == 'Bottle': + raise GameError('thing of ID %s not bottle' % thing_id) + t.full = False +cmd_THING_BOTTLE_EMPTY.argtypes = 'int:pos' diff --git a/plomrogue/game.py b/plomrogue/game.py index ba25eca..453ee30 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -354,12 +354,14 @@ class Game(GameBase): write(f, 'GOD_THING_NAME %s %s' % (t.id_, quote(t.name))) if t.type_ == 'Door' and t.blocking: write(f, 'THING_DOOR_CLOSED %s' % t.id_) - if t.type_ == 'MusicPlayer': + elif t.type_ == 'MusicPlayer': write(f, 'THING_MUSICPLAYER_SETTINGS %s %s %s %s' % (t.id_, int(t.playing), t.playlist_index, int(t.repeat))) for item in t.playlist: write(f, 'THING_MUSICPLAYER_PLAYLIST_ITEM %s %s %s' % (t.id_, quote(item[0]), item[1])) + elif t.type_ == 'Bottle' and not t.full: + write(f, 'THING_BOTTLE_EMPTY %s' % t.id_) write(f, 'SPAWN_POINT %s %s' % (self.spawn_point[0], self.spawn_point[1])) diff --git a/plomrogue/tasks.py b/plomrogue/tasks.py index 0bc0d9c..eca9400 100644 --- a/plomrogue/tasks.py +++ b/plomrogue/tasks.py @@ -128,13 +128,14 @@ class Task_INTOXICATE(Task): def check(self): if self.thing.carrying is None: - raise PlayError('nothing to consume') - if self.thing.carrying.type_ != 'Consumable': - raise PlayError('cannot consume non-consumable') + raise PlayError('carrying nothing to drink from') + if self.thing.carrying.type_ != 'Bottle': + raise PlayError('cannot drink from non-bottle') + if not self.thing.carrying.full: + raise PlayError('bottle is empty') def do(self): - self.thing.game.things.remove(self.thing.carrying) - self.thing.carrying = None + self.thing.carrying.full = False for c_id in self.thing.game.sessions: if self.thing.game.sessions[c_id]['thing_id'] == self.thing.id_: self.thing.game.io.send('RANDOM_COLORS', c_id) diff --git a/plomrogue/things.py b/plomrogue/things.py index 15216ef..67a3807 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -141,14 +141,15 @@ class Thing_Door(Thing): -class Thing_Consumable(Thing): +class Thing_Bottle(Thing): symbol_hint = 'B' portable = True + full = True -class Thing_ConsumableSpawner(ThingSpawner): - child_type = 'Consumable' +class Thing_BottleSpawner(ThingSpawner): + child_type = 'Bottle' diff --git a/rogue_chat.py b/rogue_chat.py index 076fd92..cb3080d 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -11,14 +11,15 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN cmd_GOD_THING_PROTECTION, cmd_THING_PROTECTION, cmd_SET_MAP_CONTROL_PASSWORD, cmd_SPAWN_POINT, cmd_THING_MUSICPLAYER_SETTINGS, - cmd_THING_MUSICPLAYER_PLAYLIST_ITEM) + cmd_THING_MUSICPLAYER_PLAYLIST_ITEM, + cmd_THING_BOTTLE_EMPTY) from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP, Task_DROP, Task_FLATTEN_SURROUNDINGS, Task_DOOR, Task_INTOXICATE, Task_COMMAND) from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner, Thing_SpawnPoint, Thing_SpawnPointSpawner, - Thing_Door, Thing_DoorSpawner, Thing_Consumable, - Thing_ConsumableSpawner, Thing_MusicPlayer) + Thing_Door, Thing_DoorSpawner, Thing_Bottle, + Thing_BottleSpawner, Thing_MusicPlayer) from plomrogue.config import config game = Game(config['savefile']) @@ -53,6 +54,7 @@ game.register_command(cmd_BECOME_ADMIN) game.register_command(cmd_SPAWN_POINT) game.register_command(cmd_THING_MUSICPLAYER_SETTINGS) game.register_command(cmd_THING_MUSICPLAYER_PLAYLIST_ITEM) +game.register_command(cmd_THING_BOTTLE_EMPTY) game.register_task(Task_WAIT) game.register_task(Task_MOVE) game.register_task(Task_WRITE) @@ -69,8 +71,8 @@ game.register_thing_type(Thing_SpawnPoint) game.register_thing_type(Thing_SpawnPointSpawner) game.register_thing_type(Thing_Door) game.register_thing_type(Thing_DoorSpawner) -game.register_thing_type(Thing_Consumable) -game.register_thing_type(Thing_ConsumableSpawner) +game.register_thing_type(Thing_Bottle) +game.register_thing_type(Thing_BottleSpawner) game.register_thing_type(Thing_MusicPlayer) game.read_savefile() game.io.start_loop()