X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=rogue_chat_curses.py;h=5046de199ce0f7c6db4f31bd176eded30235d002;hb=af8fcb03dfec27571cf6c79127a326caa2348bba;hp=2d51ce8a7b4b7d07fa7fed786975abead99af7c5;hpb=d524cfceadd9338a18759e8a7ea1db659cd6cbb5;p=plomrogue2 diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index 2d51ce8..5046de1 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -267,11 +267,12 @@ def cmd_MAP_CONTROL(game, content): cmd_MAP_CONTROL.argtypes = 'string' def cmd_GAME_STATE_COMPLETE(game): - if game.tui.mode.name == 'post_login_wait': - game.tui.switch_mode('play') game.turn_complete = True game.tui.do_refresh = True game.tui.info_cached = None + game.player = game.get_thing(game.player_id) + if game.tui.mode.name == 'post_login_wait': + game.tui.switch_mode('play') cmd_GAME_STATE_COMPLETE.argtypes = '' def cmd_PORTAL(game, position, msg): @@ -376,6 +377,7 @@ class Game(GameBase): self.annotations = {} self.portals = {} self.terrains = {} + self.player = None def get_string_options(self, string_option_type): if string_option_type == 'map_geometry': @@ -463,7 +465,7 @@ class TUI: "command_thing", "take_thing", "drop_thing"] self.mode_play.available_actions = ["move", "teleport", "door", "consume", - "install", "wear"] + "install", "wear", "spin"] 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", @@ -473,10 +475,11 @@ class TUI: self.mode_control_tile_draw.available_modes = ["admin_enter"] self.mode_control_tile_draw.available_actions = ["move_explorer", "toggle_tile_draw"] - self.mode_edit.available_modes = ["write", "annotate", "portal", "name_thing", - "password", "chat", "study", "play", - "admin_enter", "enter_face"] - self.mode_edit.available_actions = ["move", "flatten", "toggle_map_mode"] + self.mode_edit.available_modes = ["write", "annotate", "portal", + "name_thing", "enter_face", "password", + "chat", "study", "play", "admin_enter"] + self.mode_edit.available_actions = ["move", "flatten", "install", + "toggle_map_mode"] self.mode = None self.host = host self.game = Game() @@ -513,6 +516,7 @@ class TUI: 'door': 'D', 'install': 'I', 'wear': 'W', + 'spin': 'S', 'help': 'h', 'toggle_map_mode': 'L', 'toggle_tile_draw': 'm', @@ -625,34 +629,34 @@ class TUI: self.map_mode = 'terrain only' def switch_mode(self, mode_name): + + def fail(msg, return_mode='play'): + self.log_msg('? ' + msg) + self.flash = True + self.switch_mode(return_mode) + 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 == 'drop_thing' and\ - not (hasattr(player, 'carrying' or player.carrying)): - self.log_msg('? not carrying anything droppable') - self.flash = True - self.switch_mode('play') - return + (not self.game.player.carrying or + not self.game.player.carrying.commandable): + return fail('not carrying anything commandable') + if mode_name == 'take_thing' and self.game.player.carrying: + return fail('already carrying something') + if mode_name == 'drop_thing' and not self.game.player.carrying: + return fail('not carrying anything droppable') if mode_name == 'admin_enter' and self.is_admin: mode_name = 'admin' elif mode_name in {'name_thing', 'admin_thing_protect'}: thing = None - for t in [t for t in self.game.things if t.position == player.position - and t.id_ != player.id_]: + for t in [t for t in self.game.things + if t.position == self.game.player.position + and t.id_ != self.game.player.id_]: thing = t break if not thing: - self.flash = True - self.log_msg('? not standing over thing') - return + return fail('not standing over thing', 'edit') else: self.thing_selected = thing self.mode = getattr(self, 'mode_' + mode_name) @@ -662,8 +666,8 @@ class TUI: elif self.mode.name != 'edit': self.map_mode = 'terrain + things' if self.mode.shows_info or self.mode.name == 'control_tile_draw': - player = self.game.get_thing(self.game.player_id) - self.explorer = YX(player.position.y, player.position.x) + self.explorer = YX(self.game.player.position.y, + self.game.player.position.x) if self.mode.is_single_char_entry: self.show_help = True if len(self.mode.intro_msg) > 0: @@ -675,26 +679,22 @@ class TUI: self.log_msg('@ enter username') elif self.mode.name == 'take_thing': self.log_msg('Portable things in reach for pick-up:') - player = self.game.get_thing(self.game.player_id) - select_range = [player.position, - player.position + YX(0,-1), - player.position + YX(0, 1), - player.position + YX(-1, 0), - player.position + YX(1, 0)] + select_range = [self.game.player.position, + self.game.player.position + YX(0,-1), + self.game.player.position + YX(0, 1), + self.game.player.position + YX(-1, 0), + self.game.player.position + YX(1, 0)] if type(self.game.map_geometry) == MapGeometryHex: - if player.position.y % 2: - select_range += [player.position + YX(-1, 1), - player.position + YX(1, 1)] + if self.game.player.position.y % 2: + select_range += [self.game.player.position + YX(-1, 1), + self.game.player.position + YX(1, 1)] else: - select_range += [player.position + YX(-1, -1), - player.position + YX(1, -1)] + select_range += [self.game.player.position + YX(-1, -1), + self.game.player.position + YX(1, -1)] self.selectables = [t.id_ for t in self.game.things if t.portable and t.position in select_range] if len(self.selectables) == 0: - self.log_msg('none') - self.flash = True - self.switch_mode('play') - return + return fail('nothing to pick-up') else: for i in range(len(self.selectables)): t = self.game.get_thing(self.selectables[i]) @@ -924,11 +924,11 @@ class TUI: draw_thing(t, used_positions) for t in [t for t in self.game.things if t.type_ == 'Player']: draw_thing(t, used_positions) - player = self.game.get_thing(self.game.player_id) if self.mode.shows_info or self.mode.name == 'control_tile_draw': map_lines_split[self.explorer.y][self.explorer.x] = '??' elif self.map_mode != 'terrain + things': - map_lines_split[player.position.y][player.position.x] = '??' + map_lines_split[self.game.player.position.y]\ + [self.game.player.position.x] = '??' self.map_lines = [] if type(self.game.map_geometry) == MapGeometryHex: indent = 0 @@ -940,7 +940,7 @@ class TUI: self.map_lines += [''.join(line)] window_center = YX(int(self.size.y / 2), int(self.window_width / 2)) - center = player.position + center = self.game.player.position if self.mode.shows_info or self.mode.name == 'control_tile_draw': center = self.explorer center = YX(center.y, center.x * 2) @@ -1030,6 +1030,7 @@ class TUI: 'wear': '(un-)wear', 'door': 'open/close', 'consume': 'consume', + 'spin': 'spin', } action_tasks = { @@ -1042,6 +1043,7 @@ class TUI: 'move': 'MOVE', 'command': 'COMMAND', 'consume': 'INTOXICATE', + 'spin': 'SPIN', } curses.curs_set(False) # hide cursor @@ -1083,15 +1085,21 @@ class TUI: self.do_refresh = True except curses.error: continue + keycode = None + if len(key) == 1: + keycode = ord(key) self.show_help = False if key == 'KEY_RESIZE': reset_screen_size() elif self.mode.has_input_prompt and key == 'KEY_BACKSPACE': self.input_ = self.input_[:-1] - elif self.mode.has_input_prompt and key == '\n' and self.input_ == ''\ - and self.mode.name in {'chat', 'command_thing', 'take_thing', - 'drop_thing', 'admin_enter'}: - if self.mode.name != 'chat': + elif (((not self.mode.is_intro) and keycode == 27) # Escape + or (self.mode.has_input_prompt and key == '\n' + and self.input_ == ''\ + and self.mode.name in {'chat', 'command_thing', + 'take_thing', 'drop_thing', + 'admin_enter'})): + if self.mode.name not in {'chat', 'play', 'study', 'edit'}: self.log_msg('@ aborted') self.switch_mode('play') elif self.mode.has_input_prompt and key == '\n' and self.input_ == '/help': @@ -1208,14 +1216,13 @@ 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['wear'] and task_action_on('wear'): self.send('TASK:WEAR') + elif key == self.keys['spin'] and task_action_on('spin'): + self.send('TASK:SPIN') elif key == self.keys['teleport']: - player = self.game.get_thing(self.game.player_id) - if player.position in self.game.portals: - self.host = self.game.portals[player.position] + if self.game.player.position in self.game.portals: + self.host = self.game.portals[self.game.player.position] self.reconnect() else: self.flash = True @@ -1242,6 +1249,8 @@ class TUI: continue elif key == self.keys['flatten'] and task_action_on('flatten'): self.send('TASK:FLATTEN_SURROUNDINGS ' + quote(self.password)) + elif key == self.keys['install'] and task_action_on('install'): + self.send('TASK:INSTALL %s' % quote(self.password)) elif key == self.keys['toggle_map_mode']: self.toggle_map_mode() elif key in self.movement_keys and task_action_on('move'):