From: Christian Heller Date: Wed, 9 Dec 2020 00:44:39 +0000 (+0100) Subject: Don't enter command_thing mode when not carrying anything commandable. X-Git-Url: https://plomlompom.com/repos/%27%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28escapeHTML%28span%5B2%5D%29%29;%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20chunks.push%28%27?a=commitdiff_plain;h=ba09978e0179406218f052ed29690f1f7c508920;p=plomrogue2 Don't enter command_thing mode when not carrying anything commandable. --- diff --git a/plomrogue/game.py b/plomrogue/game.py index b0233b3..143248f 100755 --- a/plomrogue/game.py +++ b/plomrogue/game.py @@ -267,9 +267,9 @@ class Game(GameBase): self.io.send('MAP_CONTROL %s' % quote(player.visible_control), c_id) for t in [t for t in self.things if player.fov_test(*t.position)]: target_yx = player.fov_stencil.target_yx(*t.position) - self.io.send('THING %s %s %s %s %s' % (target_yx, t.type_, - quote(t.protection), - t.id_, int(t.portable)), + self.io.send('THING %s %s %s %s %s %s' + % (target_yx, t.type_, quote(t.protection), t.id_, + int(t.portable), int(t.commandable)), c_id) if hasattr(t, 'name'): self.io.send('THING_NAME %s %s' % (t.id_, quote(t.name)), c_id) @@ -283,7 +283,8 @@ class Game(GameBase): self.io.send('THING_CHAR %s %s' % (t.id_, quote(t.thing_char)), c_id) if hasattr(t, 'carrying') and t.carrying: - self.io.send('THING_CARRYING %s' % (t.id_), c_id) + self.io.send('THING_CARRYING %s %s' % (t.id_, t.carrying.id_), + c_id) if hasattr(t, 'installable') and not t.portable: self.io.send('THING_INSTALLED %s' % (t.id_), c_id) for big_yx in self.portals: diff --git a/rogue_chat.html b/rogue_chat.html index 1b501b5..2e37e7f 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -485,6 +485,7 @@ let server = { t.type_ = tokens[2]; t.protection = tokens[3]; t.portable = parseInt(tokens[5]); + t.commandable = parseInt(tokens[6]); } else if (tokens[0] === 'THING_NAME') { let t = game.get_thing(tokens[1], false); t.name_ = tokens[2]; @@ -506,7 +507,7 @@ let server = { game.thing_types[tokens[1]] = tokens[2] } else if (tokens[0] === 'THING_CARRYING') { let t = game.get_thing(tokens[1], false); - t.carrying = true; + t.carrying = t = game.get_thing(tokens[2], false); } else if (tokens[0] === 'THING_INSTALLED') { let t = game.get_thing(tokens[1], false); t.installed = true; @@ -756,17 +757,24 @@ let tui = { tui.log_msg('@ finished tile protection drawing.') } this.tile_draw = false; + const player = game.things[game.player_id]; + if (mode_name == 'command_thing' && (!player.carrying || !player.carrying.commandable)) { + this.log_msg('? not carrying anything commandable'); + terminal.blink_screen(); + this.switch_mode('play'); + return; + }; if (mode_name == 'admin_enter' && this.is_admin) { mode_name = 'admin'; } else if (['name_thing', 'admin_thing_protect'].includes(mode_name)) { - let player_position = game.things[game.player_id].position; let thing_id = null; for (let t_id in game.things) { if (t_id == game.player_id) { continue; } let t = game.things[t_id]; - if (player_position[0] == t.position[0] && player_position[1] == t.position[1]) { + if (player.position[0] == t.position[0] + && player.position[1] == t.position[1]) { thing_id = t_id; break; } @@ -1459,10 +1467,8 @@ tui.inputEl.addEventListener('keydown', (event) => { tui.inputEl.value = ""; tui.switch_mode('edit'); } else if (tui.mode.name == 'command_thing' && event.key == 'Enter') { - if (tui.task_action_on('command')) { - server.send(['TASK:COMMAND', tui.inputEl.value]); - tui.inputEl.value = ""; - } + server.send(['TASK:COMMAND', tui.inputEl.value]); + tui.inputEl.value = ""; } else if (tui.mode.name == 'take_thing' && event.key == 'Enter') { const i = parseInt(tui.inputEl.value); if (isNaN(i) || i < 0 || i >= tui.selectables.length) { diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index aeb955e..15f59bf 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -199,7 +199,7 @@ def cmd_PLAYER_ID(game, player_id): game.player_id = player_id cmd_PLAYER_ID.argtypes = 'int:nonneg' -def cmd_THING(game, yx, thing_type, protection, thing_id, portable): +def cmd_THING(game, yx, thing_type, protection, thing_id, portable, commandable): t = game.get_thing(thing_id) if not t: t = ThingBase(game, thing_id) @@ -208,7 +208,8 @@ def cmd_THING(game, yx, thing_type, protection, thing_id, portable): t.type_ = thing_type t.protection = protection t.portable = portable -cmd_THING.argtypes = 'yx_tuple:nonneg string:thing_type char int:nonneg bool' + t.commandable = commandable +cmd_THING.argtypes = 'yx_tuple:nonneg string:thing_type char int:nonneg bool bool' def cmd_THING_NAME(game, thing_id, name): t = game.get_thing(thing_id) @@ -309,9 +310,9 @@ def cmd_THING_INSTALLED(game, thing_id): game.get_thing(thing_id).installed = True cmd_THING_INSTALLED.argtypes = 'int:pos' -def cmd_THING_CARRYING(game, thing_id): - game.get_thing(thing_id).carrying = True -cmd_THING_CARRYING.argtypes = 'int:pos' +def cmd_THING_CARRYING(game, thing_id, carried_id): + game.get_thing(thing_id).carrying = game.get_thing(carried_id) +cmd_THING_CARRYING.argtypes = 'int:pos int:pos' def cmd_TERRAIN(game, terrain_char, terrain_desc): game.terrains[terrain_char] = terrain_desc @@ -620,10 +621,16 @@ class TUI: if self.mode and self.mode.name == 'control_tile_draw': self.log_msg('@ finished tile protection drawing.') self.tile_draw = False + player = self.game.get_thing(self.game.player_id) + if mode_name == 'command_thing' and\ + (not hasattr(player, 'carrying') or not player.carrying.commandable): + self.log_msg('? not carrying anything commandable') + self.flash = True + self.switch_mode('play') + return if mode_name == 'admin_enter' and self.is_admin: mode_name = 'admin' elif mode_name in {'name_thing', 'admin_thing_protect'}: - player = self.game.get_thing(self.game.player_id) thing = None for t in [t for t in self.game.things if t.position == player.position and t.id_ != player.id_]: @@ -1090,9 +1097,8 @@ class TUI: self.input_ = '' self.switch_mode('play') elif self.mode.name == 'command_thing' and key == '\n': - if task_action_on('command'): - self.send('TASK:COMMAND ' + quote(self.input_)) - self.input_ = "" + self.send('TASK:COMMAND ' + quote(self.input_)) + self.input_ = "" elif self.mode.name == 'control_pw_pw' and key == '\n': if self.input_ == '': self.log_msg('@ aborted')