home · contact · privacy
Make doors installable/uninstallable.
authorChristian Heller <c.heller@plomlompom.de>
Mon, 7 Dec 2020 01:27:00 +0000 (02:27 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Mon, 7 Dec 2020 01:27:00 +0000 (02:27 +0100)
plomrogue/tasks.py
plomrogue/things.py
rogue_chat.html
rogue_chat.py
rogue_chat_curses.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()
index 895f5ce98938515e84670aa89b05694b01c6fbac..d348e8400df1239d0105995f1193689dd132cd09 100644 (file)
@@ -128,17 +128,22 @@ class Thing_Door(Thing):
     symbol_hint = 'D'
     blocking = False
     portable = True
+    installable = True
 
     def open(self):
         self.blocking = False
-        self.portable = True
         del self.thing_char
 
     def close(self):
         self.blocking = True
-        self.portable = False
         self.thing_char = '#'
 
+    def install(self):
+        self.portable = False
+
+    def uninstall(self):
+        self.portable = True
+
 
 
 class Thing_Bottle(Thing):
index 0c0cb307c65366d9ff1d6ec0de0c45f55230bf6f..41cf365c0a5f88fe71dad7977a1e1e6aa12f4d03 100644 (file)
@@ -57,6 +57,7 @@ keyboard input/control: <span id="keyboard_control"></span>
       <button id="consume"></button>
       <button id="switch_to_command_thing"></button>
       <button id="teleport"></button>
+      <button id="install"></button>
     </td>
   </tr>
   <tr>
@@ -99,6 +100,7 @@ keyboard input/control: <span id="keyboard_control"></span>
 <li>drop thing: <input id="key_drop_thing" type="text" value="u" />
 <li>open/close: <input id="key_door" type="text" value="D" />
 <li>consume: <input id="key_consume" type="text" value="C" />
+<li>install: <input id="key_install" type="text" value="I" />
 <li><input id="key_switch_to_take_thing" type="text" value="z" />
 <li><input id="key_switch_to_chat" type="text" value="t" />
 <li><input id="key_switch_to_play" type="text" value="p" />
@@ -236,6 +238,7 @@ let key_descriptions = {
     'drop_thing': 'drop thing',
     'door': 'open/close',
     'consume': 'consume',
+    'install': 'install',
     'toggle_map_mode': 'toggle map view',
     'toggle_tile_draw': 'toggle protection character drawing',
     'hex_move_upleft': 'up-left',
@@ -664,6 +667,7 @@ let tui = {
       'drop_thing': 'DROP',
       'move': 'MOVE',
       'door': 'DOOR',
+      'install': 'INSTALL',
       'command': 'COMMAND',
       'consume': 'INTOXICATE',
   },
@@ -674,7 +678,7 @@ let tui = {
       this.mode_play.available_modes = ["chat", "study", "edit", "admin_enter",
                                         "command_thing", "take_thing"]
       this.mode_play.available_actions = ["move", "drop_thing",
-                                          "teleport", "door", "consume"];
+                                          "teleport", "door", "consume", "install"];
       this.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
       this.mode_study.available_actions = ["toggle_map_mode", "move_explorer"];
       this.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
@@ -1512,6 +1516,8 @@ tui.inputEl.addEventListener('keydown', (event) => {
               server.send(["TASK:INTOXICATE"]);
           } else if (event.key === tui.keys.door && tui.task_action_on('door')) {
               server.send(["TASK:DOOR"]);
+          } else if (event.key === tui.keys.install && tui.task_action_on('install')) {
+              server.send(["TASK:INSTALL"]);
           } else if (event.key in tui.movement_keys && tui.task_action_on('move')) {
               server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
           } else if (event.key === tui.keys.teleport) {
@@ -1631,6 +1637,9 @@ document.getElementById("door").onclick = function() {
 document.getElementById("consume").onclick = function() {
     server.send(['TASK:INTOXICATE']);
 };
+document.getElementById("install").onclick = function() {
+    server.send(['TASK:INSTALL']);
+};
 document.getElementById("teleport").onclick = function() {
     game.teleport();
 };
index 8dea1766ba8aef9ae82bbd56db03b4c81b267798..37edc7ad2ff43ff78a396116fb2c9785bfd257f4 100755 (executable)
@@ -15,7 +15,7 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN
                                 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)
+                             Task_INTOXICATE, Task_COMMAND, Task_INSTALL)
 from plomrogue.things import (Thing_Player, Thing_Item, Thing_ItemSpawner,
                               Thing_SpawnPoint, Thing_SpawnPointSpawner,
                               Thing_Door, Thing_DoorSpawner, Thing_Bottle,
@@ -64,6 +64,7 @@ game.register_task(Task_DROP)
 game.register_task(Task_DOOR)
 game.register_task(Task_INTOXICATE)
 game.register_task(Task_COMMAND)
+game.register_task(Task_INSTALL)
 game.register_thing_type(Thing_Player)
 game.register_thing_type(Thing_Item)
 game.register_thing_type(Thing_ItemSpawner)
index 6a30f746f8cdc86e7fc787dfc676c1f3955a59e1..c539062bcfe19db3e5d2fef294d7c220c2222eb9 100755 (executable)
@@ -432,7 +432,8 @@ class TUI:
         self.mode_play.available_modes = ["chat", "study", "edit", "admin_enter",
                                           "command_thing", "take_thing"]
         self.mode_play.available_actions = ["move", "drop_thing",
-                                            "teleport", "door", "consume"]
+                                            "teleport", "door", "consume",
+                                            "install"]
         self.mode_study.available_modes = ["chat", "play", "admin_enter", "edit"]
         self.mode_study.available_actions = ["toggle_map_mode", "move_explorer"]
         self.mode_admin.available_modes = ["admin_thing_protect", "control_pw_type",
@@ -479,6 +480,7 @@ class TUI:
             'teleport': 'p',
             'consume': 'C',
             'door': 'D',
+            'install': 'I',
             'help': 'h',
             'toggle_map_mode': 'L',
             'toggle_tile_draw': 'm',
@@ -950,6 +952,7 @@ class TUI:
             'drop_thing': 'drop thing',
             'toggle_map_mode': 'toggle map view',
             'toggle_tile_draw': 'toggle protection character drawing',
+            'install': 'install',
             'door': 'open/close',
             'consume': 'consume',
         }
@@ -959,6 +962,7 @@ class TUI:
             'take_thing': 'PICK_UP',
             'drop_thing': 'DROP',
             'door': 'DOOR',
+            'install': 'INSTALL',
             'move': 'MOVE',
             'command': 'COMMAND',
             'consume': 'INTOXICATE',
@@ -1131,6 +1135,8 @@ class TUI:
                     self.send('TASK:DOOR')
                 elif key == self.keys['consume'] and task_action_on('consume'):
                     self.send('TASK:INTOXICATE')
+                elif key == self.keys['install'] and task_action_on('install'):
+                    self.send('TASK:INSTALL')
                 elif key == self.keys['teleport']:
                     player = self.game.get_thing(self.game.player_id)
                     if player.position in self.game.portals: