def setUp(self): super(BattlePvE1x1ActionTest, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.storage = LogicStorage() self.storage.load_account_data(AccountPrototype.get_by_id(account_id)) self.hero = self.storage.accounts_to_heroes[account_id] self.hero._model.level = 6 self.hero.health = self.hero.max_health # do half of tests with companion if random.random() < 0.5: companion_record = companions_storage.companions.enabled_companions( ).next() companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.hero.companion.health = 1 self.action_idl = self.hero.actions.current_action with mock.patch( 'the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 0): self.action_battle = ActionBattlePvE1x1Prototype.create( hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero))
def test_lighting(self): current_time = TimePrototype.get_current_time() action_battle = actions_prototypes.ActionBattlePvE1x1Prototype.create( hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) current_time.increment_turn() self.storage.process_turn() old_mob_health = action_battle.mob.health old_percents = action_battle.percents self.assertTrue(HELP_CHOICES.LIGHTING in action_battle.help_choices) with mock.patch( 'the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.LIGHTING): with self.check_delta(lambda: self.hero.statistics.help_count, 1): self.assertEqual(self.ability.use(**self.use_attributes), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertTrue(old_mob_health > action_battle.mob.health) self.assertEqual(self.hero.actions.current_action.percents, action_battle.percents) self.assertTrue(old_percents < action_battle.percents)
def test_action_full_serialization(self): mob = mobs_storage.create_mob_for_hero(self.hero) account_2 = self.accounts_factory.create_account() self.storage.load_account_data(account_2) hero_2 = self.storage.accounts_to_heroes[account_2.id] meta_action = meta_actions.ArenaPvP1x1.create(self.storage, self.hero, hero_2) default_action = TestAction( hero=self.hero, bundle_id=self.bundle_id, state=TestAction.STATE.UNINITIALIZED, created_at_turn=666, context=TestAction.CONTEXT_MANAGER(), description='description', place_id=2, mob=mob, data={'xxx': 'yyy'}, break_at=0.75, length=777, destination_x=20, destination_y=30, percents_barier=77, extra_probability=0.6, mob_context=TestAction.CONTEXT_MANAGER(), textgen_id='textgen_id', back=True, info_link='/bla-bla', meta_action=meta_action, replane_required=True) self.assertEqual(default_action.serialize(), {'bundle_id': self.bundle_id, 'state': TestAction.STATE.UNINITIALIZED, 'context': TestAction.CONTEXT_MANAGER().serialize(), 'mob_context': TestAction.CONTEXT_MANAGER().serialize(), 'mob': mob.serialize(), 'length': 777, 'back': True, 'textgen_id': 'textgen_id', 'extra_probability': 0.6, 'percents_barier': 77, 'destination_x': 20, 'destination_y': 30, 'percents': 0.0, 'description': 'description', 'type': TestAction.TYPE.value, 'created_at_turn': 666, 'place_id': 2, 'data': {'xxx': 'yyy'}, 'info_link': '/bla-bla', 'break_at': 0.75, 'meta_action': meta_action.serialize(), 'replane_required': True}) deserialized_action = TestAction.deserialize(default_action.serialize()) deserialized_action.hero = self.hero self.assertEqual(default_action, deserialized_action)
def test_action_full_serialization(self): mob = mobs_storage.create_mob_for_hero(self.hero) account_2 = self.accounts_factory.create_account() self.storage.load_account_data(account_2) hero_2 = self.storage.accounts_to_heroes[account_2.id] meta_action = meta_actions.ArenaPvP1x1.create(self.storage, self.hero, hero_2) default_action = TestAction( hero=self.hero, bundle_id=self.bundle_id, state=TestAction.STATE.UNINITIALIZED, created_at_turn=666, context=TestAction.CONTEXT_MANAGER(), description=u'description', place_id=2, mob=mob, data={'xxx': 'yyy'}, break_at=0.75, length=777, destination_x=20, destination_y=30, percents_barier=77, extra_probability=0.6, mob_context=TestAction.CONTEXT_MANAGER(), textgen_id='textgen_id', back=True, info_link='/bla-bla', meta_action=meta_action, replane_required=True) self.assertEqual(default_action.serialize(), {'bundle_id': self.bundle_id, 'state': TestAction.STATE.UNINITIALIZED, 'context': TestAction.CONTEXT_MANAGER().serialize(), 'mob_context': TestAction.CONTEXT_MANAGER().serialize(), 'mob': mob.serialize(), 'length': 777, 'back': True, 'textgen_id': 'textgen_id', 'extra_probability': 0.6, 'percents_barier': 77, 'destination_x': 20, 'destination_y': 30, 'percents': 0.0, 'description': u'description', 'type': TestAction.TYPE.value, 'created_at_turn': 666, 'place_id': 2, 'data': {'xxx': 'yyy'}, 'info_link': '/bla-bla', 'break_at': 0.75, 'meta_action': meta_action.serialize(), 'replane_required': True}) deserialized_action = TestAction.deserialize(default_action.serialize()) deserialized_action.hero = self.hero self.assertEqual(default_action, deserialized_action)
def test_lighting_when_mob_killed(self): current_time = TimePrototype.get_current_time() action_battle = actions_prototypes.ActionBattlePvE1x1Prototype.create( hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) current_time.increment_turn() self.storage.process_turn() action_battle.mob.health = 0 self.assertFalse(HELP_CHOICES.LIGHTING in action_battle.help_choices)
def test_peacefull_battle(self): self.hero.actions.pop_action() with self.check_delta(lambda: self.hero.statistics.pve_kills, 0): action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) self.assertEqual(action_battle.percents, 1.0) self.assertEqual(action_battle.state, self.action_battle.STATE.PROCESSED) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action, self.action_idl)
def test_experience_for_kill(self): mob = mobs_storage.create_mob_for_hero(self.hero) mob.health = 0 with self.check_delta(lambda: self.hero.statistics.pve_kills, 1): with mock.patch('the_tale.game.heroes.objects.Hero.add_experience') as add_experience: with mock.patch('the_tale.game.actions.prototypes.ActionBattlePvE1x1Prototype.process_artifact_breaking') as process_artifact_breaking: action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mob) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(add_experience.call_args_list, [mock.call(c.EXP_FOR_KILL)]) self.assertEqual(process_artifact_breaking.call_count, 1) self.assertEqual(action_battle.state, self.action_battle.STATE.PROCESSED)
def test_use(self): from the_tale.game.actions.prototypes import ActionBattlePvE1x1Prototype from the_tale.game.mobs.storage import mobs_storage with mock.patch('the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 0): ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) self.assertTrue(self.hero.actions.current_action.TYPE.is_BATTLE_PVE_1X1) self.assertTrue(self.hero.actions.current_action.mob.health > 0) self.assertTrue(self.hero.actions.current_action.percents < 1) result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero)) self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertTrue(self.hero.actions.current_action.mob.health <= 0) self.assertEqual(self.hero.actions.current_action.percents, 1)
def test_use(self): from the_tale.game.actions.prototypes import ActionBattlePvE1x1Prototype from the_tale.game.mobs.storage import mobs_storage with mock.patch( 'the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 0): ActionBattlePvE1x1Prototype.create( hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) self.assertTrue( self.hero.actions.current_action.TYPE.is_BATTLE_PVE_1X1) self.assertTrue(self.hero.actions.current_action.mob.health > 0) self.assertTrue(self.hero.actions.current_action.percents < 1) result, step, postsave_actions = self.card.use( **self.use_attributes(storage=self.storage, hero=self.hero)) self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertTrue(self.hero.actions.current_action.mob.health <= 0) self.assertEqual(self.hero.actions.current_action.percents, 1)
def setUp(self): super(BattlePvE1x1ActionTest, self).setUp() create_test_map() account = self.accounts_factory.create_account() self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.hero.level = 6 self.hero.health = self.hero.max_health # do half of tests with companion if random.random() < 0.5: companion_record = next(companions_storage.companions.enabled_companions()) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.hero.companion.health = 1 self.action_idl = self.hero.actions.current_action with mock.patch('the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 0): self.action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero))
def test_lighting_when_mob_killed(self): current_time = TimePrototype.get_current_time() action_battle = actions_prototypes.ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) current_time.increment_turn() self.storage.process_turn() action_battle.mob.health = 0 self.assertFalse(HELP_CHOICES.LIGHTING in action_battle.help_choices)
def test_lighting(self): current_time = TimePrototype.get_current_time() action_battle = actions_prototypes.ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) current_time.increment_turn() self.storage.process_turn() old_mob_health = action_battle.mob.health old_percents = action_battle.percents self.assertTrue(HELP_CHOICES.LIGHTING in action_battle.help_choices) with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.LIGHTING): with self.check_delta(lambda: self.hero.statistics.help_count, 1): self.assertEqual(self.ability.use(**self.use_attributes), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertTrue(old_mob_health > action_battle.mob.health) self.assertEqual(self.hero.actions.current_action.percents, action_battle.percents) self.assertTrue(old_percents < action_battle.percents)