home · contact · privacy
Make doors installable/uninstallable.
[plomrogue2] / plomrogue / tasks.py
index dbe23153f11d7ee842b04bca60ed694bab40f038..a6602cea926822ae8b7a58a4c7c50baad28f6e1b 100644 (file)
@@ -76,7 +76,7 @@ class Task_FLATTEN_SURROUNDINGS(Task):
 
 
 class Task_PICK_UP(Task):
-    argtypes = 'int:nonneg'
+    argtypes = 'int:pos'
 
     def check(self):
         if self.thing.carrying:
@@ -162,6 +162,7 @@ class Task_INTOXICATE(Task):
         self.thing.drunk = 10000
 
 
+
 class Task_COMMAND(Task):
     argtypes = 'string'
 
@@ -177,3 +178,29 @@ class Task_COMMAND(Task):
         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('REPLY ' + quote(reply), c_id)
+
+
+
+class Task_INSTALL(Task):
+
+    def _get_uninstallables(self):
+        return [t for t in self.thing.game.things
+                if t != self.thing
+                and hasattr(t, 'installable') and t.installable
+                and (not t.portable)
+                and t.position == self.thing.position]
+
+    def check(self):
+        if self.thing.carrying:
+            if not hasattr(self.thing.carrying, 'installable')\
+               or not self.thing.carrying.installable:
+                raise PlayError('carried thing not installable')
+        elif len(self._get_uninstallables()) == 0:
+            raise PlayError('nothing to uninstall here')
+
+    def do(self):
+        if self.thing.carrying:
+            self.thing.carrying.install()
+            self.thing.carrying = None
+        else:
+            self._get_uninstallables()[0].uninstall()