def active_context(ctx): """Context manager to set the current command context.""" prev_ctx = adventurelib.current_context adventurelib.set_context(ctx) try: yield finally: adventurelib.set_context(prev_ctx)
def __set_raw_status(self): raw_stati = [] for ctx in self.ACTIVE: raw_stati.append(ctx.status) if raw_stati: set_context('.'.join(raw_stati)) else: set_context(None)
def on_enter(self): super().on_enter() if self._event is None: self._event = _AltarEvent() # TODO: Use add_event here and elsewhere; # omit _maybe_append_event from Room.add_event. self._event.room = self G.add_event(self._event, "post") adventurelib.set_context("altar")
def go(direction): global current_room room = current_room.exit(direction) if room: current_room = room a.say('You go %s.' % direction) look() if room == magic_forest: a.set_context('magic_aura') else: a.set_context('default')
def _restart(unused_actor): # Creates the player character and ensures game will restart upon death. _G.player = actor.create_actor( health=10, psyche=10, strength=10, stamina=10, will=10, wisdom=10, insanity=0, name="player", ) _G.player.log_stats = True _G.player.upon_death(_restart) # Removes all events from global queue. _G.clear_queues() # Resets just_died flag. _G.add_event(_ResetDiedFlag(), "pre") # Creates a small dungeon. level = floor.Floor.generate("cathedral", number_rooms=config["num_rooms"]) # Places a monster in a random room. level.random_room().add_character(npcs.fish_man()) # Places an NPC in a random room. level.random_room().add_character(npcs.mad_librarian()) # Places a cool NPC in a random room. level.random_room().add_character(npcs.smokes_man()) # Places the player. level.random_room().add_character(_G.player) # Starts it up. _get_random_start() adventurelib.set_context("start_game") adventurelib.set_context(None) with _poll_events(poll_before=True, poll_after=True): commands.enter_room(_G.player.current_room)
def start_battle(): global battle_over battle_over = False new_context = 'attacking.' + character_enemy.name set_context(new_context) if character_enemy.name is cookies_name: print_delayed('\n\nFINAL COMBATANT', 3) print_delayed( 'Linda\'s nemesis, the greatest and most terrible foe she will ever face...', 2) print_delayed( 'More dangerous than all previous combatants put together...', 2) print_delayed('The one...', 1) print_delayed('The only...', 1) print_delayed('STORE-BOUGHT CHOCOLATE CHIP COOKIES!!!!!', 3) print_delayed('(ooh, the horror!)', 1) else: print_delayed('\n\nNext combatant:', 3) print_delayed(f'{character_enemy.name}!!!', next_attack_delay)
def go(direction): global current_room room = current_room.exit(direction) if room: current_room = room current_room.visited = 1 say('You go %s.' % direction) look() if room == door_room: set_context('final_door') elif room == shop_room: set_context('shop') elif room == starting_room: set_context('starting_room') elif room == grue_room: set_context('grue_room') else: set_context('default') else: say("You can't currently go %s." % direction) look()
def end_battle(losing_character): ''' This function is called when a fight ends. It handles the cases where the enemy lost, and where Mom lost ''' global num_turns_in_battle global character_enemy global current_character_enemy_index global battle_over if losing_character is character_mom: print_delayed(game_over, standard_delay) sys.exit() # First, print out character defeat info if losing_character is dict_enemies[ tilly_name] and num_turns_in_battle == 10: print_delayed( 'Because Tilly escaped defeat, Linda did not gain any points', standard_delay) else: global score score += increment_score(num_turns_in_battle) print_delayed(f'Your current score: {score}', standard_delay) if character_enemy == dict_enemies[cookies_name]: print_end_game_text() sys.exit() # Set the next enemy Mom will face, and reset her damage boost and active effect. Set context to 'break' to enable # break actions num_turns_in_battle = 1 current_character_enemy_index += 1 character_enemy = dict_enemies[enemy_order[current_character_enemy_index]] set_context('break') character_mom.damage_boost = 1.0 character_mom.active_effect = dict_effects[Effects.NONE] battle_over = True print_delayed('\n\nLinda went to the hooga zone', standard_delay)
def clear(cls): cls.ACTIVE = [] set_context(None)
"INT - Inteligence allows you to craft better items or trick your enemies in combat." ) print( "MIND - Each point in Mind increases your total mana by {} and your concentration(chance to succesfully cast a spell) by 1" .format(cfg.MP_per_lvl)) print("FORCE - Makes most of your spells more powerfull.") return print( "Use \"show SOMETHING\" command to learn information about the game elements." ) print("As SOMETHING you can type:") print("spells - to get complete information about the spells you control.") print("stats - shows your stats and what they mean.") set_context("combat") @when('cast SPELL', context="combat") def casting(spell): if spell in player.spells: if spell in spells_logic.spells: spells_logic.spells[spell].cast_spell(player, player) else: print("Invalid casting instructions.") #set_context("combat") start(help=False)
def main(): set_context('attacking.Greg') print_start_of_game_text() start()
def on_exit(self): super().on_exit() adventurelib.set_context(None)
# make the notebook to store letters class Notebook(Item): letters_found = Bag() notebook = Notebook('Notebook', 'book', 'notes') # initialize the players inventory inventory = Bag() inventory.gold = 0 inventory.add(notebook) #set starting context set_context('starting_room') #create master list for testing purposes master_item_list = Bag({ wand, compass, map, ball, notebook, }) for letter in letter_bank: master_item_list.add(letter) # action functions @when('north', direction='north')