def process_battle(hero_1, hero_2):

    hero_1_context = contexts.BattleContext()
    hero_2_context = contexts.BattleContext()

    while hero_1.health > 0 and hero_2.health > 0:
        battle.make_turn(battle.Actor(hero_1, hero_1_context),
                         battle.Actor(hero_2, hero_2_context), MESSENGER)

    return hero_1.health > 0
예제 #2
0
파일: battle.py 프로젝트: serhii73/the-tale
def try_companion_strike(attacker, defender, messenger):

    if not attacker.has_companion:
        return False

    if attacker.companion.is_dead:
        return False

    if random.random() > c.COMPANIONS_BATTLE_STRIKE_PROBABILITY:
        return False

    abilities = attacker.companion.modify_attribute(
        heroes_relations.MODIFIERS.ADDITIONAL_ABILITIES,
        heroes_relations.MODIFIERS.ADDITIONAL_ABILITIES.default())
    battle_abilities = [
        ability for ability in abilities
        if ability.TYPE.is_BATTLE and ability.ACTIVATION_TYPE.is_ACTIVE
    ]

    if not battle_abilities:
        return False

    ability = random_value_by_priority([(ability, ability.priority)
                                        for ability in battle_abilities])

    companion_actor = CompanionActor(attacker, contexts.BattleContext())

    _strike(ability, companion_actor, defender, messenger)

    return True