From: Christian Heller Date: Wed, 9 Dec 2020 00:12:26 +0000 (+0100) Subject: Disallow picking up thing already carried by other player. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/foo.html?a=commitdiff_plain;h=497f9b478cdaf0ad1825d95d612caab33ba7c403;p=plomrogue2 Disallow picking up thing already carried by other player. --- diff --git a/plomrogue/tasks.py b/plomrogue/tasks.py index c7b35bd..9447cc6 100644 --- a/plomrogue/tasks.py +++ b/plomrogue/tasks.py @@ -95,6 +95,8 @@ class Task_PICK_UP(Task): raise PlayError('cannot pick up oneself') elif to_pick_up.type_ == 'Player': raise PlayError('cannot pick up player') + elif to_pick_up.carried: + raise PlayError('thing already carried by a player') elif to_pick_up.position not in reach: raise PlayError('thing not in reach') elif not to_pick_up.portable: @@ -104,6 +106,7 @@ class Task_PICK_UP(Task): to_pick_up = self.thing.game.get_thing(self.args[0]) to_pick_up.position = self.thing.position[:] self.thing.carrying = to_pick_up + to_pick_up.carried = True @@ -119,20 +122,20 @@ class Task_DROP(Task): raise PlayError('cannot drop full bottle into bottle deposit') def do(self): - if self.thing.carrying.type_ == 'Bottle' and not self.thing.carrying.full: + dropped = self.thing.uncarry() + if 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 == self.thing.position]: t.accept() - self.thing.game.remove_thing(self.thing.carrying) + self.thing.game.remove_thing(dropped) break - elif self.thing.carrying.type_ == 'Hat': + elif dropped.type_ == 'Hat': for t in [t for t in self.thing.game.things if t.type_ == 'HatRemixer' and t.position == self.thing.position]: - t.accept(self.thing.carrying) + t.accept(dropped) break - self.thing.carrying = None @@ -207,8 +210,8 @@ class Task_INSTALL(Task): def do(self): if self.thing.carrying: - self.thing.carrying.install() - self.thing.carrying = None + t = self.thing.uncarry() + t.install() self.thing.send_msg('CHAT "You install the thing you carry."') else: self._get_uninstallables()[0].uninstall() diff --git a/plomrogue/things.py b/plomrogue/things.py index 18cdf4c..4f802db 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -22,6 +22,7 @@ class Thing(ThingBase): portable = False protection = '.' commandable = False + carried = False def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -436,3 +437,9 @@ class Thing_Player(ThingAnimate): if self.game.sessions[c_id]['thing_id'] == self.id_: self.game.io.send(msg, c_id) break + + def uncarry(self): + t = self.carrying + t.carried = False + self.carrying = None + return t