home · contact · privacy
Disallow picking up thing already carried by other player.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 9 Dec 2020 00:12:26 +0000 (01:12 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 9 Dec 2020 00:12:26 +0000 (01:12 +0100)
plomrogue/tasks.py
plomrogue/things.py

index c7b35bd00b76bfa6ee0f3695f098c5e71b758fa3..9447cc6eecb2b8eb9135ec702a3426bdf8ad451e 100644 (file)
@@ -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()
index 18cdf4c78069e9273e411c38223f4baae080a38f..4f802db6e25a9f340a9da02074b219d80502b0ab 100644 (file)
@@ -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