def create_turn_order_list(self): order = [] for duel in self.input_list: if y_helpers.is_character_KOed( duel['agent'] ) or duel['agent']['statusEffect']['CONFUSED']: continue duel['isHeroAgent'] = True order.append(duel) for enemy in self.enemy_party: if y_helpers.is_character_KOed( enemy) or enemy['statusEffect']['CONFUSED']: continue self.handle_enemy(enemy, order) for element in self.combined_parties: if element['statusEffect']['KO']: continue if element['statusEffect']['POISONED']: self.handle_poison(element, order) if element['statusEffect']['CONFUSED']: self.handle_confused(element, order) order = sorted(order, key=lambda x: y_helpers.get_stat(x['agent']['speed']), reverse=True) return order
def attack(self): turn = self.current_turn message = '' for target in turn['target']: if y_helpers.is_character_KOed(target): defendingParty = self.enemy_party if turn[ 'isHeroAgent'] else self.hero_party target = next((x for x in defendingParty if not y_helpers.is_character_KOed(x)), None) if not target: # maybe could call end of battle screen? return message += self.attack_target(turn['agent'], target) return message
def outcome(self): if self.is_battle_over: ishero_partyDefeated = next( (False for x in self.hero_party if not y_helpers.is_character_KOed(x)), True) return y_helpers.OUTCOME_DEFEAT if ishero_partyDefeated else y_helpers.OUTCOME_VICTORY return y_helpers.OUTCOME_DRAW
def handle_confused(self, element, order): if y_helpers.is_team_KOed(self.combined_parties): return duel = {'agent': element} duel['target'] = [random.choice(self.combined_parties)] while y_helpers.is_character_KOed(duel['target'][0]): duel['target'] = [random.choice(self.combined_parties)] duel['type'] = y_helpers.TYPE_ATTACK order.append(duel)
def animateAgent(self, fight_round, seq): turn = fight_round.current_turn modelAgent = y_helpers.find_by_name(self.animationModels, turn['agent']['name']) if modelAgent: if y_helpers.is_character_KOed(modelAgent.fightObj): return False seq.append(Func(modelAgent.request, turn['type'])) return True
def nextHero(self): if self.heroIndex < len(self.hero_party) - 1: self.heroIndex += 1 if y_helpers.is_character_KOed(self.hero_party[self.heroIndex]): self.nextHero() else: self.request("SelectInput") else: self.heroIndex = 0 self.request("ShowAnimation")
def enemy_choose_target(self, targetType, duel, enemy): if targetType == y_helpers.TARGET_ANOTHER: duel['target'] = [random.choice(self.hero_party)] while y_helpers.is_character_KOed(duel['target'][0]): duel['target'] = [random.choice(self.hero_party)] elif targetType == y_helpers.TARGET_SELF: duel['target'] = [enemy] elif targetType == y_helpers.TARGET_ANOTHER_PARTY: duel['target'] = self.hero_party elif targetType == y_helpers.TARGET_OWN_PARTY: duel['target'] = self.enemy_party
def gain_xp(self, messages): gainedXp = 0 messages.append('The party has won') for enemy in self.enemy_party: gainedXp += enemy['xp'] message = '' for hero in self.hero_party: if y_helpers.is_character_KOed(hero): continue message += '{} gained {} experience points\n'.format( hero['name'], gainedXp) hero['xp'] += gainedXp messages.append(message)
def round_fight(self): turn = self.current_turn if self.is_battle_over: return if y_helpers.is_character_KOed(turn['agent']): return message = '' if turn['type'] == y_helpers.TYPE_ATTACK: message = self.attack() elif turn['type'] == y_helpers.TYPE_MAGIC: message = self.magic() elif turn['type'] == y_helpers.TYPE_POISON: message = self.poison() # this may need to change in the future if the messages don't fit return [message]
def __init__(self, enemy_party): self.COLUMN_HEIGHT = 3 self.enemy_party = enemy_party frame = DirectFrame( frameColor=(0, 0, 0, 0.5), borderWidth=(10, 10), # (Left,Right,Bottom,Top) frameSize=(-2, 2, -1, -0.45)) IMenuHorizontal.__init__(self, self.COLUMN_HEIGHT, frame=frame) self.menuVerticalChoicesList = [] for enemy in self.enemy_party: if y_helpers.is_character_KOed(enemy): continue index = self.enemy_party.index(enemy) self.menuVerticalChoicesList.append({ "event": "Target-{}".format(index), "text": enemy["name"] }) self.createVerticalButtons()
def initAnimation(self): if y_helpers.is_character_KOed(self.fightObj): self.request('KOed') else: self.request('Idle')
def append_attack_message(self, attacker, defender, attackOutcome): message = '\n{} received {} damage from {}\'s attack'.format( defender['name'], (attackOutcome * -1), attacker['name']) if y_helpers.is_character_KOed(defender): message += '\nand collapsed\n' return message
def is_battle_over(self): return next((False for x in self.hero_party if not y_helpers.is_character_KOed(x)), True) or \ next( (False for x in self.enemy_party if not x['statusEffect']['KO']), True)
def findHero(self): while y_helpers.is_character_KOed(self.hero_party[self.heroIndex]): self.heroIndex += 1