def change_settings(user_input): """ Show or change game settings. Args: user_input: Get input from game_action function. Usage: > settings > settings hud on > options hud hints off """ settings_printout = f"""\n -------------------- SETTINGS -------------------- {on_off(rimuru.textcrawl)}\ttextcrawl <on/off>\t-- Enable or disable text crawl effect. {on_off(rimuru.show_actions)}\thud/interface <on/off>\t-- Show available actions player can take. {on_off(rimuru.show_art)}\tart/ascii <on/off>\t-- Show ASCII art. {on_off(rimuru.show_hints)}\thints/clues <on/off>\t-- Show game hints, highly recommended for first timers. {on_off(rimuru.hardcore)}\thardcore <on/off>\t-- Hides playable actions, tutorial, and hints. Usage: /settings COMMAND(S) on/off Example: '/settings textcrawl off', '/options hud hints off """ new_value = None # Tries to extract game settings and on/off section from user_input. try: split_input = user_input.split() # Checks if player wants to enable/disable a setting. if get_any(split_input[-1], off_subs): new_value = False elif get_any(split_input[-1], on_subs): new_value = True # User can change multiple game settings with one go. settings_input = ''.join(user_input[:-1]) except: new_value = None # If not detected game settings with usable on/off data from user_input. if not user_input or new_value is None: print(settings_printout) return if 'textcrawl' in settings_input: rimuru.textcrawl = new_value if 'hardcore' in settings_input: rimuru.hardcore = new_value # strict_match is false so user can change multiple game settings in one go. if get_any(settings_input, ['hud', 'interface'], strict_match=False): rimuru.show_actions = new_value if get_any(settings_input, ['art', 'ascii'], strict_match=False): rimuru.show_art = new_value if get_any(settings_input, ['hints', 'clues'], strict_match=False): rimuru.show_hints = new_value print(settings_printout)
def set_targets(targets): """ Adds inputted targets to targeted_mobs list from user input. Separates user inputted targets by ',' then checks to see if mob is in active_mobs list. If so, adds to setTargets list. Args: targets str: String of target(s) to add to targeted_mobs (list) Usage: > target tempest serpent, giant bat """ targets = targets.lower() # Clears currently targeted. if get_any(targets, ['reset', 'clear']): rimuru.targeted_mobs.clear() # Target all nearby targetable mobs. elif 'all' in targets: rimuru.targeted_mobs = rimuru.active_mobs[:] else: for target in targets.split(','): # Only able to target mobs in active_mobs list. for mob in rimuru.active_mobs: if mob[0].name.lower() == target.strip().lower(): mob_list_adder(mob, rimuru.targeted_mobs)
def show_info(self, game_object): """ Shows info page. Args: game_object str: skill/item/mob/etc. Usage: > info predator > info hipokte grass > info tempest serpent > info gobta """ # Need this so player can get the info page on itself. if get_any(game_object, ['me', 'self', 'player', self.name]): print(self.info_page) return True if game_object := self.get_object(game_object, mimic_pool=True, sub_pool=True): # Some skills or objects have special info pages, I couldn't get @property method working... if hasattr(game_object, 'show_info_page'): print(game_object.show_info_page(self)) else: print(game_object.info_page)
def show_help(arg): """Shows help page.""" if get_any(arg, ['rank', 'level', 'ranking', 'showrank', 'showlevel'], strict_match=False): show_rank_chart() return print("""\n -------------------- HELP -------------------- Usage: Command Required_Parameter [Optional_Parameter] -- Description Commands: inv -- Show inventory. stats [TARGET] -- Show skills and resistances. E.g. 'stats tempest serpent' info TARGET -- Show info on skill/item/mob. E.g. 'info great sage' target TARGET(S) -- Target mob. E.g. 'target tempest serpent', 'target tempest serpent, black spider' - target all -- Target all nearby targetable mobs. - target reset -- Clear targeted. attack SKILL/ITEM -- Attack targeted mob(s) with skill/item. E.g. 'attack water blade' use SKILL/ITEM -- Use a skill. E.g. 'use sense heat source' craft ITEM [amount] -- Craft items. E.g. 'craft full potion', 'craft full potion 5' Note: Some items are crafted in batches, suggest reading the item's info page for the recipe and more. mimic TARGET -- Mimics appearance and attributes of analysed mob. E.g. 'mimic tempest serpent' - mimics -- Shows available mimicries. - mimic reset -- Resets mimic (Back to slime). eat -- Predate target(s). Can only eat mobs that are targeted_mobs and also dead. can also use 'predate'. nearby -- Shows nearby mobs if acquired [Magic Sense] skill. Same as 'use magic sense'. subordinates/subs -- Show subordinates you have named. reputations/rep -- Show factions/characters standing with player. /log [LINES] -- Shows x dialogue line history. E.g. '/log', '/log 10', '/log game 15' - /log game [LINES] -- Shows x game event history log (skill/item acquisitions, hints, etc). /help -- Show this help page. - /help rank -- Show game level, rank, risk chart. /settings -- Shows or change game settings. E.g. '/settings', '/settings hud off', '/options hud hints on' /reset -- Deletes player save and restarts game. /exit -- Exits after save. Game Dialogue: Message -- Indented messages are inner thoughts. ~ Message ~ -- Telepathy, thought communication. * Message * -- Story context. < Message > -- Game info, acquisition, game help, etc. << Message >> -- Great Sage (Raphael, Ciel). <<< Message >>> -- Voice of the World. """)
def actions(level=None): """ Updates player's location, Shows HUD, takes user input and runs corresponding actions. Args: level obj: Current story progress class object. Usage: > inv > stats > attack tempest serpent with water blade """ global successful_attack # Updates player's location. rimuru.update_location(get_class_var(level, '__location')) # Get's playable actions from parsing inputted class subclasses. playable_actions = [] for action in dir(level): # Gets subclass functions. if action_playable(action) is False: continue if '__' in action: continue # Filters out unwanted variables and functions. # Hides any action with 'x_' in name, unless action_playable() return True. if 'x_' in action[:3] and action_playable(action) is not True: continue playable_actions.append(action) game_hud(playable_actions) # ========== Debug Mode # Runs first available action that will progress the storyline. if rimuru.fast_mode is True: for action in playable_actions: if action[0] == '_': user_input = action.replace('_', ' ').strip() else: user_input = input("\n> ").strip().lower() if 'hfunc' in user_input: actions(level) # So user can't so easily activate 'hfunc' actions. # Removes anything that's not alpha-numeric, easier for making __subs. user_input = ''.join(i for i in user_input if i.isalnum() or ' ') # Separates user input into command and command arguments. split_user_input = user_input.split(' ') command, parameters = split_user_input[0], ' '.join(split_user_input[1:]) user = rimuru # [correspond_game_function, [optional_parameters], ['user_input_to_match_to'] game_actions = [ [rimuru.show_info, ['info']], [rimuru.show_inventory, ['inv']], [rimuru.show_attributes, ['stats']], [set_targets, ['target']], [rimuru.attack, [parameters], ['attack']], [rimuru.use, [parameters, user], ['use']], [rimuru.craft_item, ['craft']], [rimuru.remove_inventory, ['remove']], [rimuru.eat_targets, ['eat', 'predate']], [rimuru.use_mimic, ['mimic']], [rimuru.show_mimics, ['mimics', 'mimicries']], [rimuru.use, ['magic sense'], ['nearby']], [rimuru.get_location, ['location']], [rimuru.show_subordinates, ['subs', 'subordinates']], [rimuru.show_reputations, ['rep', 'reps', 'reputations', 'standings']], [show_help, ['/help']], [change_settings, ['/settings', '/options']], [show_history, ['/history', '/log']], [restart, ['/restart']], [save_reset, ['/reset']], [game_exit, ['/exit']], ] # Passes in user inputted arguments as parameters and runs corresponding action. for action in game_actions: if 'attack' in command: # Used for check_attack_success(). successful_attack = rimuru.attack(parameters) break # If action needs custom parameters passed in. if len(action) == 3 and command in action[2]: action[0](*action[1]) # Run matched corresponding game function and pass rest of user input as parameter. if command in action[1]: action[0](parameters) for action in playable_actions: # Currently need two evals to find __subs for action. try: action_subs = eval(f"level.{action}.{action}__subs") except: action_subs = [] try: action_subs = eval(f"level.{action}._{action}__subs") except: pass # Able to activate a hfunc or _hfunc action without needing to add redundant item to __subs. # E.g. 'hfunc_attack' action you would've needed to add __subs = ['attack'], if not for this line. if 'hfunc' in action: action_subs.append(' '.join([i for i in action.split('_') if i][1:])) # Usually used for when you want an action to be used only once. if 'ACTIONBLOCKED' in action_subs: continue # Adds action's class name to subs list, so you don't have to add it yourself. action_subs = set_action_subs(action, action_subs) # play game action if matching from player input. if get_any(user_input, action_subs, strict_match=False): # If level class has __accept_params variable, pass in parameters parsed from player input. if get_class_var(level, '__accept_params'): eval(f"level.{action}(parameters)") else: eval(f"level.{action}()") # So you can check if action has been played using game.conditions('action_name') function. rimuru.add_action_played(action_subs[-1]) actions(level)