예제 #1
0
    def test_try_companion_block__failed(self):
        actor_1, actor_2 = self.get_actors()

        with mock.patch('the_tale.game.actions.battle.strike_without_contact') as strike_without_contact:
            with mock.patch('the_tale.game.actions.battle.strike_with_contact') as strike_with_contact:
                battle.make_turn(actor_1, actor_2, self.hero)

        self.assertEqual(strike_without_contact.call_count+strike_with_contact.call_count, 1)
예제 #2
0
    def check_first_strike(self, actor_1, actor_2, turn, expected_actors):
        with mock.patch('the_tale.game.actions.battle.strike') as strike:
            for i in xrange(100):
                actor_1.context.turn = turn
                actor_2.context.turn = turn
                battle.make_turn(actor_1, actor_2, self.hero)

        self.assertEqual(set(id(call[1]['attacker']) for call in strike.call_args_list), expected_actors)
예제 #3
0
    def test_make_turn__initialize_contexts_on_first_turn(self):
        actor_1, actor_2 = self.get_actors()

        with mock.patch('the_tale.game.actions.battle.strike') as strike:
            with mock.patch('the_tale.game.actions.battle.Actor.update_context') as update_context:
                battle.make_turn(actor_1, actor_2, self.hero)

        self.assertEqual(strike.call_count, 1)
        self.assertEqual(update_context.call_args_list, [mock.call(actor_2), mock.call(actor_1)])
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
예제 #5
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
예제 #6
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)