From: Christian Heller Date: Mon, 7 Dec 2020 01:27:00 +0000 (+0100) Subject: Make doors installable/uninstallable. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/do_todos?a=commitdiff_plain;h=35714a1e0616ada0be5929d5fb8100047e46cdd2;p=plomrogue2 Make doors installable/uninstallable. --- diff --git a/plomrogue/tasks.py b/plomrogue/tasks.py index dbe2315..a6602ce 100644 --- a/plomrogue/tasks.py +++ b/plomrogue/tasks.py @@ -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() diff --git a/plomrogue/things.py b/plomrogue/things.py index 895f5ce..d348e84 100644 --- a/plomrogue/things.py +++ b/plomrogue/things.py @@ -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): diff --git a/rogue_chat.html b/rogue_chat.html index 0c0cb30..41cf365 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -57,6 +57,7 @@ keyboard input/control: + @@ -99,6 +100,7 @@ keyboard input/control:
  • drop thing:
  • open/close:
  • consume: +
  • install:
  • @@ -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(); }; diff --git a/rogue_chat.py b/rogue_chat.py index 8dea176..37edc7a 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -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) diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 6a30f74..c539062 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -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: