Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    def process_battle_running(self):
        # apply all changes made by player
        hero_1_effectivenes = self.hero_1.pvp.effectiveness
        hero_2_effectivenes = self.hero_2.pvp.effectiveness

        if self.hero_1.is_bot:
            self.process_bot(bot=self.hero_1, enemy=self.hero_2)

        if self.hero_2.is_bot:
            self.process_bot(bot=self.hero_2, enemy=self.hero_1)

        # modify advantage
        max_effectivenes = float(max(hero_1_effectivenes, hero_2_effectivenes))
        if max_effectivenes < 0.01:
            effectiveness_fraction = 0
        else:
            effectiveness_fraction = (hero_1_effectivenes - hero_2_effectivenes) / max_effectivenes
        advantage_delta = c.PVP_MAX_ADVANTAGE_STEP * effectiveness_fraction

        self.hero_1.pvp.set_advantage(self.hero_1.pvp.advantage + advantage_delta)
        self.hero_1_context.use_pvp_advantage(self.hero_1.pvp.advantage)

        self.hero_2.pvp.set_advantage(self.hero_2.pvp.advantage - advantage_delta)
        self.hero_2_context.use_pvp_advantage(self.hero_2.pvp.advantage)

        # battle step
        if self.hero_1.health > 0 and self.hero_2.health > 0:
            battle.make_turn(battle.Actor(self.hero_1, self.hero_1_context),
                             battle.Actor(self.hero_2, self.hero_2_context ),
                             self)

            if self.hero_1_context.pvp_advantage_used or self.hero_2_context.pvp_advantage_used:
                self.hero_1.pvp.set_advantage(0)
                self.hero_2.pvp.set_advantage(0)

            self.percents = 1.0 - min(self.hero_1.health_percents, self.hero_2.health_percents)

        # update resources, etc
        self.update_hero_pvp_info(self.hero_1)
        self.update_hero_pvp_info(self.hero_2)

        self.hero_1.pvp.store_turn_data()
        self.hero_2.pvp.store_turn_data()

        # check if anyone has killed
        self._check_hero_health(self.hero_1, self.hero_2)
        self._check_hero_health(self.hero_2, self.hero_1)
Ejemplo n.º 3
0
    def test_choose_ability__additional_companion_abilities(self):
        from the_tale.game.heroes.habilities import ABILITIES
        from the_tale.game.companions.abilities import effects as companions_effects
        from the_tale.game.companions.abilities import container as abilities_container
        from the_tale.game.companions import logic as companions_logic
        from the_tale.game.companions import relations as companions_relations

        abilities = [
            ability for ability in companions_effects.ABILITIES.records
            if (isinstance(ability.effect, companions_effects.BaseBattleAbility
                           ) and ability.effect.ABILITY.get_id() != 'hit')
        ]
        companion_ability = random.choice(abilities)

        all_abilities = [
            ability(level=ability.MAX_LEVEL)
            for ability in list(ABILITIES.values())
            if ability.get_id() != companion_ability.effect.ABILITY.get_id()
        ]

        active_abilities = set(ability.get_id()
                               for ability in list(ABILITIES.values())
                               if ability.ACTIVATION_TYPE.is_ACTIVE)

        companion_record = companions_logic.create_random_companion_record(
            'battle',
            abilities=abilities_container.Container(
                start=(companion_ability, )),
            state=companions_relations.STATE.ENABLED)
        self.hero.set_companion(
            companions_logic.create_companion(companion_record))
        self.hero.health = 1  # allow regeneration

        actor = battle.Actor(self.hero, BattleContext())

        chosen_abilities = set()

        # mock abilities modify_attribute instead of hereos, since we test correct work of it
        def modify_attribute(self, modifier, value):
            if modifier.is_ADDITIONAL_ABILITIES:
                return all_abilities
            return value

        with mock.patch(
                'the_tale.game.heroes.habilities.AbilitiesPrototype.modify_attribute',
                modify_attribute):
            for i in range(1000):
                chosen_abilities.add(actor.choose_ability().get_id())

        self.assertEqual(len(active_abilities), len(chosen_abilities) + 1)
        self.assertEqual(
            active_abilities -
            set([companion_ability.effect.ABILITY.get_id()]), chosen_abilities)
Ejemplo n.º 4
0
    def test_process_effects(self):
        actor = battle.Actor(self.hero, BattleContext())

        actor.context.use_damage_queue_fire([p.Damage(50, 50), p.Damage(50, 50)])
        actor.context.use_damage_queue_poison([p.Damage(50, 50), p.Damage(50, 50)])
        actor.context.on_own_turn()

        actor.context.use_incoming_damage_modifier(physic=1.0, magic=0.8)
        actor.process_effects(self.hero)
        self.assertEqual(self.hero.health, self.hero.max_health - 180)

        actor.context.on_own_turn()
        actor.context.use_incoming_damage_modifier(physic=1.2, magic=1.0)
        actor.process_effects(self.hero)
        self.assertEqual(self.hero.health, self.hero.max_health - 180 - 220)
Ejemplo n.º 5
0
    def test_choose_ability__additional_abilities(self):
        from the_tale.game.heroes.habilities import ABILITIES
        all_abilities = [ability(level=ability.MAX_LEVEL) for ability in ABILITIES.values()]

        active_abilities = set(ability.get_id() for ability in all_abilities if ability.activation_type.is_ACTIVE)

        self.hero.health = 1 # allow regeneration

        actor = battle.Actor(self.hero, BattleContext())

        chosen_abilities = set()

        with mock.patch('the_tale.game.heroes.objects.Hero.additional_abilities', all_abilities):
            for i in xrange(1000):
                chosen_abilities.add(actor.choose_ability().get_id())

        self.assertEqual(active_abilities, chosen_abilities)
Ejemplo n.º 6
0
    def test_mob_actor(self):
        mob = mobs_storage.get_random_mob(self.hero)
        mob.health = 10
        mob.abilities.add(RUN_UP_PUSH.get_id())

        actor = battle.Actor(mob, BattleContext())

        self.assertEqual(mob.initiative, actor.initiative)
        self.assertEqual(mob.name, actor.name)
        self.assertEqual(mob.utg_name, actor.utg_name)
        self.assertEqual(mob.basic_damage, actor.basic_damage)
        self.assertEqual(mob.health, actor.health)
        self.assertEqual(mob.max_health, actor.max_health)

        self.assertEqual(actor.change_health(-5), -5)
        self.assertEqual(actor.health, 5)

        self.assertEqual(actor.change_health(-50), -5)
        self.assertEqual(actor.health, 0)

        self.assertEqual(actor.change_health(actor.max_health + 50),
                         actor.max_health)
        self.assertEqual(actor.health, actor.max_health)

        hit_selected = False
        run_up_push_selected = False
        vampire_strike_selected = False
        for i in range(100):
            ability = actor.choose_ability()

            if ability.get_id() == HIT.get_id():
                hit_selected = True
            elif ability.get_id() == RUN_UP_PUSH.get_id():
                run_up_push_selected = True
            elif ability.get_id() == VAMPIRE_STRIKE.get_id():
                vampire_strike_selected = True

        self.assertTrue(hit_selected)
        self.assertTrue(run_up_push_selected)
        self.assertTrue(vampire_strike_selected)

        self.storage._test_save()
Ejemplo n.º 7
0
    def get_actors(self):
        mob = mobs_storage.get_random_mob(self.hero)
        actor_1 = battle.Actor(self.hero, BattleContext())
        actor_2 = battle.Actor(mob, BattleContext())

        return actor_1, actor_2
Ejemplo n.º 8
0
 def test_initiative_change(self):
     actor = battle.Actor(self.hero, BattleContext())
     actor.context.use_initiative([2])
     self.assertEqual(actor.initiative, self.hero.initiative*2)