def choice_clicked(self, choice): clickable.unregister_all() if choice.set: setattr(World, choice.set, choice.value) if choice.morale_bonus: hero.active_hero.morale += choice.morale_bonus if hero.active_hero.morale > 100: hero.active_hero.morale = 100 if choice.next == "end_act1": if World.next_dungeon == "ogre": World.finding = "shield" if choice.next == "end_act2": if World.next_dungeon == "fire": World.finding = "sword" else: World.finding = "armor" if "end_act" in choice.next: import game event.fire("dungeon.setup", World.next_dungeon) game.mode = "dungeon" else: self.load_option(choice.next)
def box_clicked(self, box, x, y): clickable.unregister_all() self.pending_attack_type = box.attack_type self.pending_attack_powerful = box.attack_powerful self.show_dialog("you", box.choice['text'], "boss_attack", 0)
def dismiss_dialog(self, dialog, x, y): clickable.unregister_all() self.action_window.children = [self.action_window.title, self.action_overlay] self.action_overlay.start("fade_out", anim_speed=256) self.next_state = None self.after_animation_state = dialog.next_state self.state_delay = dialog.state_delay
def __init__(self): clickable.unregister_all() hero.stat_display.set_mode("adventure") self.root = pytality.buffer.Buffer(height=main.screen_height, width=main.screen_width - main.sidebar_width) self.frame_l = data.load_buffer("frame-l.ans", width=80, crop=False) self.frame_r = data.load_buffer("frame-r.ans", width=49, crop=True) self.frame_r.x = 80 self.i = 0
def victory_setup(): global active_text pytality.term.clear() clickable.unregister_all() active_text = pytality.buffer.PlainText( "The hero is too demoralized to continue fighting. You lose.", y=main.screen_height / 2 + 10, center_to=main.screen_width, fg=pytality.colors.LIGHTRED, children=[data.load_buffer("grave.ans", width=42, x=(main.screen_width - 42) / 2, y=-15, crop=True)], )
def victory_setup(): global active_text pytality.term.clear() clickable.unregister_all() active_text = pytality.buffer.PlainText( "The final boss has been defeated. The world is saved. You win.", y=main.screen_height / 2 + 10, center_to=main.screen_width, fg=pytality.colors.LIGHTGREEN, children=[data.load_buffer("earf.ans", width=40, x=(main.screen_width - 40) / 2, y=-30, crop=True)], )
def start_act(self): clickable.unregister_all() sound.play_music("Relax.mp3") if World.act == 1: self.load_option("burn_1") elif World.act == 2: self.load_option("fetch_1") else: self.load_option("final_1") World.act += 1
def tick(self): self.i += 1 if self.i % 15 == 0: # safety margin self.root.dirty = True self.stat_display.tick(self) # animation tickers self.hero_sprite.tick() self.boss_sprite.tick() self.action_overlay.tick(self.action_overlay) if self.state_delay: self.state_delay -= 1 if self.after_animation_state and not self.action_overlay.animation: self.next_state = self.after_animation_state self.after_animation_state = None self.state_delay = 0 if self.state_delay is not None and self.state_delay <= 0: self.state_delay = None if self.next_state == "hero_talk": if self.pending_attack_type: if self.pending_attack_type == "phys": self.message_log.add("The boss strikes!") damage = monsters.combat(self.boss_attack, hero.active_hero.defense * hero.active_hero.morale_multiplier(), powerful=self.pending_attack_powerful, durable=False) self.message_log.add("%s damage!" % damage) hero.active_hero.hp -= damage else: self.message_log.add("The boss uses magic!") damage= monsters.combat(self.boss_attack, hero.active_hero.m_defense * hero.active_hero.morale_multiplier(), powerful=self.pending_attack_powerful, durable=False) self.message_log.add("%s damage!" % damage) hero.active_hero.hp -= damage self.pending_attack_type = None if hero.active_hero.hp <= 0: self.message_log.add("The hero is defeated!") clickable.unregister_all() hero.active_hero.hp = 0 self.hero_sprite.animate("fade_out", anim_speed=3, restrict=True) self.next_state = "hero_defeated" self.state_delay = len(self.hero_sprite.overlay.empty_cells) / 3 + 5 elif not self.real_boss: hero.active_hero.morale += 5 if self.pending_attack_powerful: hero.active_hero.morale += 10 if hero.active_hero.morale > 100: hero.active_hero.morale = 100 if hero.active_hero.hp > 0: choice = random.choice(exchanges) self.show_dialog("hero", choice['hero'], "hero_attack", 0) self.next_choice = choice elif self.next_state == "hero_attack": self.hero_sprite.animate("flash") self.next_state = "hero_attack_2" self.state_delay = 6 elif self.next_state == "hero_attack_2": self.boss_sprite.animate("flash", color=pytality.colors.LIGHTRED) self.next_state = "boss_choose" self.state_delay = 15 elif self.next_state == "boss_choose": self.message_log.add("The hero strikes!") damage = monsters.combat(hero.active_hero.attack * hero.active_hero.morale_multiplier(), self.boss_defense, powerful=False, durable=False) self.message_log.add("%s damage!" % damage) self.boss_hp -= damage if self.boss_hp <= 0: self.message_log.add("The boss is defeated!") clickable.unregister_all() hero.active_hero.level_up(self.message_log) hero.active_hero.level_up(self.message_log) self.boss_hp = 0 self.boss_sprite.animate("fade_out", anim_speed=12, restrict=True) self.next_state = "boss_defeated" self.state_delay = len(self.boss_sprite.overlay.empty_cells) / 12 + 5 else: self.offer_choices(self.next_choice['choices']) elif self.next_state == "boss_attack": self.boss_sprite.animate("flash") self.next_state = "boss_attack_2" self.state_delay = 6 elif self.next_state == "boss_attack_2": self.hero_sprite.animate("flash", color=pytality.colors.LIGHTRED) self.next_state = "hero_talk" self.state_delay = 15 elif self.next_state == "boss_defeated": import game if self.real_boss: game.mode = "victory" event.fire("victory.setup") else: game.mode = "adventure" hero.active_hero.in_combat = False adventure.active_adventure.start_act() elif self.next_state == "hero_defeated": import game game.mode = "defeat" event.fire("defeat.setup")
def __init__(self, dungeon, final_boss): sidebar_width = 26 bottom_height = 17 self.message_log = dungeon.message_log self.stat_display = dungeon.stat_display self.stat_display.set_mode("battle") clickable.unregister_all() self.battle_window = pytality.buffer.Buffer( x=sidebar_width, y=0, height=main.screen_height - bottom_height, width=main.screen_width - (sidebar_width * 2) ) self.action_window = ActionWindow( width=main.screen_width - sidebar_width * 2, height=bottom_height, x=sidebar_width, y=main.screen_height - bottom_height, border_fg=pytality.colors.LIGHTGREY, battle=self, ) self.action_overlay = overlay.Overlay( width=self.action_window.width, height=self.action_window.height - 1, x=0, y=0 ) self.real_boss = final_boss if self.real_boss: self.boss_sprite = BattleSprite(file_names=["finalboss.ans"], width=61, height=48, x=self.battle_window.width - 61, y=0, crop=True) self.boss_portrait = data.load_buffer("finalbossport.ans", width=16, crop=True) sound.play_music("The_Final_Threat.mp3") else: self.boss_sprite = BattleSprite(file_names=["you2.ans", "you2alt.ans"], width=34, height=31, x=self.battle_window.width - 40, y=14, crop=True) self.boss_portrait = data.load_buffer("youport.ans", width=16, crop=True) sound.play_music("OHC_Changeling_Rumble.mp3") act = (adventure.World.act - 1) self.boss_attack = 6 + (7 * act) self.boss_defense = 4 + (7 * act) self.boss_hp = self.boss_max_hp = 50 + (20 * act) self.hero_sprite = BattleSprite(file_names=[hero.active_hero.get_boss_file()], width=18, height=15, x=10, y=30) self.hero_portrait = data.load_buffer("heroportrait.ans", width=16, crop=True) self.battle_window.children = [self.boss_sprite, self.hero_sprite] self.fullscreen_flash = pytality.buffer.Buffer( x=sidebar_width, height=main.screen_height, width=main.screen_width - (sidebar_width * 2) ) self.root = pytality.buffer.Buffer(height=0, width=0, children=[ self.message_log, self.stat_display, self.battle_window, self.action_window ]) self.i = 0 self.flashed = False self.message_log.add("\n <LIGHTRED>BOSS BATTLE!") self.next_state = "hero_talk" self.after_animation_state = None self.state_delay = 5 self.pending_attack_type = None self.pending_attack_powerful = False