class FirstStepsActionTest(testcase.TestCase): def setUp(self): super(FirstStepsActionTest, self).setUp() create_test_map() self.account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(self.account) self.hero = self.storage.accounts_to_heroes[self.account.id] self.action_idl = self.hero.actions.current_action with self.check_calls_count( 'the_tale.game.heroes.logic.push_message_to_diary', 1): self.action_first_steps = ActionFirstStepsPrototype.create( hero=self.hero) def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_first_steps.leader, True) self.assertEqual(self.action_first_steps.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_processed(self): current_time = TimePrototype.get_current_time() self.assertEqual(self.hero.journal.messages_number(), 2) with self.check_calls_count( 'the_tale.game.heroes.logic.push_message_to_diary', 0): self.storage.process_turn() current_time.increment_turn() self.assertEqual(self.hero.journal.messages_number(), 3) self.storage.process_turn() current_time.increment_turn() self.assertEqual(self.hero.journal.messages_number(), 4) self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.journal.messages_number(), 5) self.assertTrue(self.hero.actions.current_action.TYPE.is_IDLENESS) self.storage._test_save()
class FirstStepsActionTest(testcase.TestCase): def setUp(self): super(FirstStepsActionTest, self).setUp() create_test_map() self.account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(self.account) self.hero = self.storage.accounts_to_heroes[self.account.id] self.action_idl = self.hero.actions.current_action with self.check_calls_count("the_tale.game.heroes.logic.push_message_to_diary", 1): self.action_first_steps = ActionFirstStepsPrototype.create(hero=self.hero) def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_first_steps.leader, True) self.assertEqual(self.action_first_steps.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_processed(self): current_time = TimePrototype.get_current_time() self.assertEqual(self.hero.journal.messages_number(), 2) with self.check_calls_count("the_tale.game.heroes.logic.push_message_to_diary", 0): self.storage.process_turn() current_time.increment_turn() self.assertEqual(self.hero.journal.messages_number(), 3) self.storage.process_turn() current_time.increment_turn() self.assertEqual(self.hero.journal.messages_number(), 4) self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.journal.messages_number(), 5) self.assertTrue(self.hero.actions.current_action.TYPE.is_IDLENESS) self.storage._test_save()
class DoNothingActionTest(testcase.TestCase): @mock.patch('the_tale.game.actions.prototypes.ActionBase.get_description', lambda self: 'abrakadabra') def setUp(self): super(DoNothingActionTest, self).setUp() create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.action_donothing = ActionDoNothingPrototype.create( hero=self.hero, duration=7, messages_prefix='QUEST_HOMETOWN_JOURNAL_CHATTING', messages_probability=0.3) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_donothing.leader, True) self.assertEqual(self.action_donothing.textgen_id, 'QUEST_HOMETOWN_JOURNAL_CHATTING') self.assertEqual(self.action_donothing.percents_barier, 7) self.assertEqual(self.action_donothing.extra_probability, 0.3) self.assertEqual(self.action_donothing.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_not_ready(self): self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_donothing) self.storage._test_save() def test_full(self): current_time = TimePrototype.get_current_time() for i in range(7): self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertTrue(self.action_donothing.leader) self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertTrue(self.action_idl.leader) self.storage._test_save()
class DoNothingActionTest(testcase.TestCase): @mock.patch('the_tale.game.actions.prototypes.ActionBase.get_description', lambda self: 'abrakadabra') def setUp(self): super(DoNothingActionTest, self).setUp() create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.action_donothing = ActionDoNothingPrototype.create(hero=self.hero, duration=7, messages_prefix='QUEST_HOMETOWN_JOURNAL_CHATTING', messages_probability=0.3) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_donothing.leader, True) self.assertEqual(self.action_donothing.textgen_id, 'QUEST_HOMETOWN_JOURNAL_CHATTING') self.assertEqual(self.action_donothing.percents_barier, 7) self.assertEqual(self.action_donothing.extra_probability, 0.3) self.assertEqual(self.action_donothing.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_not_ready(self): self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_donothing) self.storage._test_save() def test_full(self): current_time = TimePrototype.get_current_time() for i in range(7): self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertTrue(self.action_donothing.leader) self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertTrue(self.action_idl.leader) self.storage._test_save()
class HealCompanionActionTest(UseAbilityTaskMixin, testcase.TestCase): PROCESSOR = Help def setUp(self): super(HealCompanionActionTest, self).setUp() create_test_map() self.account = self.accounts_factory.create_account() self.storage = LogicStorage() self.storage.load_account_data(self.account) self.hero = self.storage.accounts_to_heroes[self.account.id] self.companion_record = companions_storage.companions.enabled_companions( ).next() self.hero.set_companion( companions_logic.create_companion(self.companion_record)) self.action_idl = self.hero.actions.current_action self.hero.companion.healed_at_turn = -1 with self.check_increased(lambda: self.hero.companion.healed_at_turn): self.action_heal_companion = prototypes.ActionHealCompanionPrototype.create( hero=self.hero) def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_heal_companion.leader, True) self.assertEqual(self.action_heal_companion.bundle_id, self.action_heal_companion.bundle_id) self.assertEqual(self.action_heal_companion.percents, 0) self.storage._test_save() def test_processed__no_companion(self): self.hero.remove_companion() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_processed__max_health(self): self.assertEqual(self.hero.companion.health, self.hero.companion.max_health) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_not_ready(self): self.hero.companion.health = 1 self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_heal_companion) self.assertTrue(self.hero.companion.health, 1) self.assertTrue(self.action_heal_companion.percents > 0) self.storage._test_save() def test_ability_heal_companion(self): self.hero.companion.health = 1 with self.check_increased(lambda: self.action_heal_companion.percents): with self.check_increased(lambda: self.hero.companion.health): ability = self.PROCESSOR() with mock.patch( 'the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION): self.assertTrue( ability.use(**self.use_attributes( hero=self.hero, storage=self.storage))) def test_ability_heal_companion__processed_when_healed(self): self.hero.companion.health -= 1 with self.check_increased(lambda: self.action_heal_companion.percents): with self.check_increased(lambda: self.hero.companion.health): ability = self.PROCESSOR() with mock.patch( 'the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION): self.assertTrue( ability.use(**self.use_attributes( hero=self.hero, storage=self.storage))) self.assertTrue(self.action_heal_companion.percents, 1) self.assertEqual(self.action_heal_companion.state, self.action_heal_companion.STATE.PROCESSED) @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.can_companion_exp_per_heal', lambda hero: True) def test_ability_heal_companion__processed_when_healed__exp_per_heal(self): self.hero.companion.health -= 1 with self.check_delta(lambda: self.hero.experience, c.COMPANIONS_EXP_PER_HEAL): with self.check_increased(lambda: self.hero.companion.health): ability = self.PROCESSOR() with mock.patch( 'the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION): self.assertTrue( ability.use(**self.use_attributes( hero=self.hero, storage=self.storage))) self.assertTrue(self.action_heal_companion.percents, 1) self.assertEqual(self.action_heal_companion.state, self.action_heal_companion.STATE.PROCESSED) def test_ability_heal_companion__full_action(self): self.hero.companion.health = 1 current_time = TimePrototype.get_current_time() with self.check_increased(lambda: self.action_heal_companion.percents): with self.check_increased(lambda: self.hero.companion.health): while self.action_heal_companion.state != self.action_heal_companion.STATE.PROCESSED: current_time.increment_turn() ability = self.PROCESSOR() with mock.patch( 'the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION): self.assertTrue( ability.use(**self.use_attributes( hero=self.hero, storage=self.storage))) def test_full(self): self.hero.companion.health = 1 current_time = TimePrototype.get_current_time() with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.can_companion_exp_per_heal', lambda hero: True) def test_full__exp_per_heal(self): self.hero.companion.health = 1 with self.check_delta(lambda: self.hero.experience, c.COMPANIONS_EXP_PER_HEAL): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() @mock.patch('the_tale.common.utils.logic.randint_from_1', lambda v: v) @mock.patch( 'the_tale.game.balance.constants.COMPANIONS_REGEN_ON_HEAL_PER_HEAL', 1.0) @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.can_companion_regenerate', lambda hero: True) def test_full__regeneration(self): self.hero.companion.health = 1 current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.assertEqual( self.hero.companion.health, 1 + c.COMPANIONS_HEALTH_PER_HEAL + c.COMPANIONS_REGEN_ON_HEAL_AMOUNT) self.storage._test_save() @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.companion_heal_probability', 1) @mock.patch('the_tale.common.utils.logic.randint_from_1', lambda v: v) def test_companion_healing_by_hero(self): current_time = TimePrototype.get_current_time() self.hero.companion.health = 1 with self.check_delta( lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL + c.COMPANIONS_REGEN_BY_HERO): self.action_heal_companion.state = self.action_heal_companion.STATE.PROCESSED self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.companion_heal_probability', 0) @mock.patch('the_tale.common.utils.logic.randint_from_1', lambda v: v) def test_companion_healing_by_hero__not_healed(self): current_time = TimePrototype.get_current_time() self.hero.companion.health = 1 with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL): self.action_heal_companion.state = self.action_heal_companion.STATE.PROCESSED self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn()
class MoveNearActionTest(testcase.TestCase): def setUp(self): super(MoveNearActionTest, self).setUp() self.p1, self.p2, self.p3 = create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.hero.position.set_place(self.p1) self.action_move = prototypes.ActionMoveNearPlacePrototype.create(hero=self.hero, place=self.p1, back=False) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_move.leader, True) self.assertEqual(self.action_move.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_get_destination_coordinates(self): self.assertTrue(len(self.p1.nearest_cells) > 3) # two coordinates will be in coordinates set, other will not x_1, y_1 = self.p1.nearest_cells[0] map_info_storage.item.terrain[y_1][x_1] = TERRAIN.WATER_DEEP x_2, y_2 = self.p1.nearest_cells[1] map_info_storage.item.terrain[y_2][x_2] = TERRAIN.WATER_DEEP coordinates = set() for i in range(100): coordinates.add(prototypes.ActionMoveNearPlacePrototype._get_destination_coordinates(back=False, place=self.p1, terrains=(TERRAIN.WATER_DEEP,))) self.assertEqual(coordinates, set([(x_1, y_1), (x_2, y_2)])) def test_get_destination_coordinates__no_terrains(self): self.assertTrue(len(self.p1.nearest_cells) > 3) # two coordinates will be in coordinates set, other will not coordinates = set() for i in range(100): coordinates.add(prototypes.ActionMoveNearPlacePrototype._get_destination_coordinates(back=False, place=self.p1, terrains=(TERRAIN.WATER_DEEP,))) self.assertEqual(coordinates, set(self.p1.nearest_cells)) def test_get_destination_coordinates__back(self): self.assertTrue(len(self.p1.nearest_cells) > 3) # two coordinates will be in coordinates set, other will not x_1, y_1 = self.p1.nearest_cells[0] map_info_storage.item.terrain[y_1][x_1] = TERRAIN.WATER_DEEP x_2, y_2 = self.p1.nearest_cells[1] map_info_storage.item.terrain[y_2][x_2] = TERRAIN.WATER_DEEP coordinates = set() for i in range(100): coordinates.add(prototypes.ActionMoveNearPlacePrototype._get_destination_coordinates(back=True, place=self.p1, terrains=(TERRAIN.WATER_DEEP,))) self.assertEqual(coordinates, set([(self.p1.x, self.p1.y)])) @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) def test_processed(self): current_time = TimePrototype.get_current_time() self.storage.process_turn(continue_steps_if_needed=False) x, y = self.action_move.get_destination() self.hero.position.set_coordinates(x, y, x, y, percents=1) current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) # can end in field or in start place self.assertTrue(self.hero.actions.current_action.TYPE in [prototypes.ActionIdlenessPrototype.TYPE, prototypes.ActionInPlacePrototype.TYPE]) self.assertTrue(self.hero.position.is_walking or self.hero.position.place) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) def test_not_ready(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_move) self.assertTrue(self.hero.position.is_walking or self.hero.position.place) # can end in start place self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) @mock.patch('the_tale.game.heroes.position.Position.subroad_len', lambda self: 1) def test_modify_speed(self): with mock.patch('the_tale.game.heroes.objects.Hero.modify_move_speed', mock.Mock(return_value=self.hero.move_speed)) as speed_modifier_call_counter: self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(speed_modifier_call_counter.call_count, 1) def test_full_move_and_back(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionIdlenessPrototype.TYPE) self.assertTrue(self.hero.position.is_walking or self.hero.position.place) # can end in start place prototypes.ActionMoveNearPlacePrototype.create(hero=self.hero, place=self.p1, back=True) while self.hero.position.place is None or self.hero.position.place.id != self.p1.id: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.assertTrue(not self.hero.position.is_walking) self.storage._test_save() def test_move_change_place_coordinates_and_back(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionIdlenessPrototype.TYPE) self.assertTrue(self.hero.position.is_walking or self.hero.position.place) # can end in start place prototypes.ActionMoveNearPlacePrototype.create(hero=self.hero, place=self.p1, back=True) self.p1.x = self.p1.x + 1 self.p1.y = self.p1.y + 1 places_logic.save_place(self.p1) while self.hero.position.place is None or self.hero.position.place.id != self.p1.id: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.assertTrue(not self.hero.position.is_walking) self.storage._test_save() def test_full(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() def test_full__start_equal_to_finish(self): self.action_move.destination_x = self.p1.x self.action_move.destination_y = self.p1.y current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: True) def test_battle(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionBattlePvE1x1Prototype.TYPE) self.storage._test_save() def test_regenerate_energy_on_move(self): self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.PRAY) self.hero.last_energy_regeneration_at_turn -= max(next(zip(*heroes_relations.ENERGY_REGENERATION.select('period')))) self.action_move.state = self.action_move.STATE.MOVING self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE) self.storage._test_save() def test_not_regenerate_energy_on_move_for_sacrifice(self): self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.SACRIFICE) self.hero.last_energy_regeneration_at_turn -= max(next(zip(*heroes_relations.ENERGY_REGENERATION.select('period')))) self.action_move.state = self.action_move.STATE.MOVING self.storage.process_turn(continue_steps_if_needed=False) self.assertNotEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE) self.storage._test_save() def test_regenerate_energy_after_battle_for_sacrifice(self): self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.SACRIFICE) self.hero.last_energy_regeneration_at_turn -= max(next(zip(*heroes_relations.ENERGY_REGENERATION.select('period')))) self.action_move.state = self.action_move.STATE.BATTLE self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE) self.storage._test_save() def test_rest(self): self.hero.health = 1 self.action_move.state = self.action_move.STATE.BATTLE self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRestPrototype.TYPE) self.storage._test_save() @mock.patch('the_tale.game.companions.objects.Companion.need_heal', True) def test_heal_companion(self): self.action_move.state = self.action_move.STATE.BATTLE companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveNearPlacePrototype.TYPE) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionHealCompanionPrototype.TYPE) self.assertEqual(self.action_move.state, prototypes.ActionMoveNearPlacePrototype.STATE.HEALING_COMPANION) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveNearPlacePrototype.TYPE) self.assertEqual(self.hero.actions.current_action.state, prototypes.ActionMoveNearPlacePrototype.STATE.HEALING_COMPANION) @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_say_wisdom', lambda hero: True) @mock.patch('the_tale.game.balance.constants.COMPANIONS_EXP_PER_MOVE_PROBABILITY', 1.0) def test_companion_say_wisdom(self): companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.action_move.state, self.action_move.STATE.MOVING) with self.check_delta(lambda: self.hero.experience, c.COMPANIONS_EXP_PER_MOVE_GET_EXP): self.storage.process_turn(continue_steps_if_needed=False) self.assertTrue(self.hero.journal.messages[-1].key.is_COMPANIONS_SAY_WISDOM) self.storage._test_save() def test_resurrect(self): self.hero.kill() self.action_move.state = self.action_move.STATE.BATTLE self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionResurrectPrototype.TYPE) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) def test_stop_when_quest_required_replane(self): while self.action_move.state != prototypes.ActionMoveNearPlacePrototype.STATE.MOVING: self.storage.process_turn(continue_steps_if_needed=False) self.assertFalse(self.action_move.replane_required) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.action_move.state, prototypes.ActionMoveNearPlacePrototype.STATE.MOVING) self.action_move.replane_required = True self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.action_move.state, prototypes.ActionMoveNearPlacePrototype.STATE.PROCESSED)
class RestActionTest(UseAbilityTaskMixin, testcase.TestCase): PROCESSOR = Help def setUp(self): super(RestActionTest, self).setUp() create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.action_rest = ActionRestPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_rest.leader, True) self.assertEqual(self.action_rest.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_processed(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_not_ready(self): self.hero.health = 1 self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_rest) self.assertTrue(self.hero.health > 1) self.storage._test_save() def test_ability_heal(self): self.hero.health = 1 old_percents = self.action_rest.percents ability = self.PROCESSOR() with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL): self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage))) self.assertTrue(self.hero.health > 1) self.assertTrue(old_percents < self.action_rest.percents) self.assertEqual(self.hero.actions.current_action.percents, self.action_rest.percents) def test_ability_heal__healed(self): self.hero.health = self.hero.max_health - 1 ability = self.PROCESSOR() with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL): self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage))) self.assertEqual(self.hero.health, self.hero.max_health) self.assertTrue(self.action_rest.percents, 1) self.assertEqual(self.action_rest.state, self.action_rest.STATE.PROCESSED) def test_full(self): self.hero.health = 1 while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.health, self.hero.max_health) self.storage._test_save()
class ActionEquippingTest(testcase.TestCase): def setUp(self): super(ActionEquippingTest, self).setUp() create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.action_equipping = ActionEquippingPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_equipping.leader, True) self.assertEqual(self.action_equipping.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_processed(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_equip(self): artifact = artifacts_storage.artifacts.generate_artifact_from_list( artifacts_storage.artifacts.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact.power = Power(666, 666) equip_slot = artifact.type.equipment_slot self.hero.equipment.unequip(equip_slot) self.hero.bag.put_artifact(artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_equipping) self.assertEqual(len(list(self.hero.bag.items())), 0) equip_slot = artifact.type.equipment_slot self.assertEqual(self.hero.equipment.get(equip_slot), artifact) self.storage._test_save() def test_switch_artifact(self): artifact = artifacts_storage.artifacts.generate_artifact_from_list( artifacts_storage.artifacts.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact.power = Power(13, 13) equip_slot = artifact.type.equipment_slot self.hero.equipment.unequip(equip_slot) self.hero.equipment.equip(equip_slot, artifact) new_artifact = artifacts_storage.artifacts.generate_artifact_from_list( [artifact.record], self.hero.level + 1, rarity=artifacts_relations.RARITY.NORMAL) new_artifact.power = Power(666, 666) self.hero.bag.put_artifact(new_artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_equipping) self.assertEqual(len(list(self.hero.bag.items())), 1) self.assertEqual( list(self.hero.bag.items())[0][1].power, Power(13, 13)) equip_slot = artifact.type.equipment_slot self.assertEqual(self.hero.equipment.get(equip_slot), new_artifact) self.assertEqual( self.hero.equipment.get(equip_slot).power, Power(666, 666)) turn.increment() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save()
class MoveNearActionTest(testcase.TestCase): def setUp(self): super(MoveNearActionTest, self).setUp() self.p1, self.p2, self.p3 = create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.hero.position.set_place(self.p1) self.action_move = prototypes.ActionMoveNearPlacePrototype.create( hero=self.hero, place=self.p1, back=False) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_move.leader, True) self.assertEqual(self.action_move.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_get_destination_coordinates(self): self.assertTrue( len(self.p1.nearest_cells) > 3) # two coordinates will be in coordinates set, other will not x_1, y_1 = self.p1.nearest_cells[0] map_info_storage.item.terrain[y_1][x_1] = TERRAIN.WATER_DEEP x_2, y_2 = self.p1.nearest_cells[1] map_info_storage.item.terrain[y_2][x_2] = TERRAIN.WATER_DEEP coordinates = set() for i in range(100): coordinates.add( prototypes.ActionMoveNearPlacePrototype. _get_destination_coordinates(back=False, place=self.p1, terrains=(TERRAIN.WATER_DEEP, ))) self.assertEqual(coordinates, set([(x_1, y_1), (x_2, y_2)])) def test_get_destination_coordinates__no_terrains(self): self.assertTrue( len(self.p1.nearest_cells) > 3) # two coordinates will be in coordinates set, other will not coordinates = set() for i in range(100): coordinates.add( prototypes.ActionMoveNearPlacePrototype. _get_destination_coordinates(back=False, place=self.p1, terrains=(TERRAIN.WATER_DEEP, ))) self.assertEqual(coordinates, set(self.p1.nearest_cells)) def test_get_destination_coordinates__back(self): self.assertTrue( len(self.p1.nearest_cells) > 3) # two coordinates will be in coordinates set, other will not x_1, y_1 = self.p1.nearest_cells[0] map_info_storage.item.terrain[y_1][x_1] = TERRAIN.WATER_DEEP x_2, y_2 = self.p1.nearest_cells[1] map_info_storage.item.terrain[y_2][x_2] = TERRAIN.WATER_DEEP coordinates = set() for i in range(100): coordinates.add( prototypes.ActionMoveNearPlacePrototype. _get_destination_coordinates(back=True, place=self.p1, terrains=(TERRAIN.WATER_DEEP, ))) self.assertEqual(coordinates, set([(self.p1.x, self.p1.y)])) @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) def test_processed(self): current_time = TimePrototype.get_current_time() self.storage.process_turn(continue_steps_if_needed=False) x, y = self.action_move.get_destination() self.hero.position.set_coordinates(x, y, x, y, percents=1) current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) # can end in field or in start place self.assertTrue(self.hero.actions.current_action.TYPE in [ prototypes.ActionIdlenessPrototype.TYPE, prototypes.ActionInPlacePrototype.TYPE ]) self.assertTrue(self.hero.position.is_walking or self.hero.position.place) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) def test_not_ready(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_move) self.assertTrue(self.hero.position.is_walking or self.hero.position.place) # can end in start place self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) @mock.patch('the_tale.game.heroes.position.Position.subroad_len', lambda self: 1) def test_modify_speed(self): with mock.patch('the_tale.game.heroes.objects.Hero.modify_move_speed', mock.Mock(return_value=self.hero.move_speed) ) as speed_modifier_call_counter: self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(speed_modifier_call_counter.call_count, 1) def test_full_move_and_back(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionIdlenessPrototype.TYPE) self.assertTrue(self.hero.position.is_walking or self.hero.position.place) # can end in start place prototypes.ActionMoveNearPlacePrototype.create(hero=self.hero, place=self.p1, back=True) while self.hero.position.place is None or self.hero.position.place.id != self.p1.id: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.assertTrue(not self.hero.position.is_walking) self.storage._test_save() def test_move_change_place_coordinates_and_back(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionIdlenessPrototype.TYPE) self.assertTrue(self.hero.position.is_walking or self.hero.position.place) # can end in start place prototypes.ActionMoveNearPlacePrototype.create(hero=self.hero, place=self.p1, back=True) self.p1.x = self.p1.x + 1 self.p1.y = self.p1.y + 1 places_logic.save_place(self.p1) while self.hero.position.place is None or self.hero.position.place.id != self.p1.id: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.assertTrue(not self.hero.position.is_walking) self.storage._test_save() def test_full(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() def test_full__start_equal_to_finish(self): self.action_move.destination_x = self.p1.x self.action_move.destination_y = self.p1.y current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: True) def test_battle(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionBattlePvE1x1Prototype.TYPE) self.storage._test_save() def test_regenerate_energy_on_move(self): self.hero.preferences.set_energy_regeneration_type( heroes_relations.ENERGY_REGENERATION.PRAY) self.hero.last_energy_regeneration_at_turn -= max( next(zip(*heroes_relations.ENERGY_REGENERATION.select('period')))) self.action_move.state = self.action_move.STATE.MOVING self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE) self.storage._test_save() def test_not_regenerate_energy_on_move_for_sacrifice(self): self.hero.preferences.set_energy_regeneration_type( heroes_relations.ENERGY_REGENERATION.SACRIFICE) self.hero.last_energy_regeneration_at_turn -= max( next(zip(*heroes_relations.ENERGY_REGENERATION.select('period')))) self.action_move.state = self.action_move.STATE.MOVING self.storage.process_turn(continue_steps_if_needed=False) self.assertNotEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE) self.storage._test_save() def test_regenerate_energy_after_battle_for_sacrifice(self): self.hero.preferences.set_energy_regeneration_type( heroes_relations.ENERGY_REGENERATION.SACRIFICE) self.hero.last_energy_regeneration_at_turn -= max( next(zip(*heroes_relations.ENERGY_REGENERATION.select('period')))) self.action_move.state = self.action_move.STATE.BATTLE self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE) self.storage._test_save() def test_rest(self): self.hero.health = 1 self.action_move.state = self.action_move.STATE.BATTLE self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRestPrototype.TYPE) self.storage._test_save() @mock.patch('the_tale.game.companions.objects.Companion.need_heal', True) def test_heal_companion(self): self.action_move.state = self.action_move.STATE.BATTLE companion_record = next( companions_storage.companions.enabled_companions()) self.hero.set_companion( companions_logic.create_companion(companion_record)) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveNearPlacePrototype.TYPE) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionHealCompanionPrototype.TYPE) self.assertEqual( self.action_move.state, prototypes.ActionMoveNearPlacePrototype.STATE.HEALING_COMPANION) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveNearPlacePrototype.TYPE) self.assertEqual( self.hero.actions.current_action.state, prototypes.ActionMoveNearPlacePrototype.STATE.HEALING_COMPANION) @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_say_wisdom', lambda hero: True) @mock.patch( 'the_tale.game.balance.constants.COMPANIONS_EXP_PER_MOVE_PROBABILITY', 1.0) def test_companion_say_wisdom(self): companion_record = next( companions_storage.companions.enabled_companions()) self.hero.set_companion( companions_logic.create_companion(companion_record)) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.action_move.state, self.action_move.STATE.MOVING) with self.check_delta(lambda: self.hero.experience, c.COMPANIONS_EXP_PER_MOVE_GET_EXP): self.storage.process_turn(continue_steps_if_needed=False) self.assertTrue( self.hero.journal.messages[-1].key.is_COMPANIONS_SAY_WISDOM) self.storage._test_save() def test_resurrect(self): self.hero.kill() self.action_move.state = self.action_move.STATE.BATTLE self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionResurrectPrototype.TYPE) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) def test_stop_when_quest_required_replane(self): while self.action_move.state != prototypes.ActionMoveNearPlacePrototype.STATE.MOVING: self.storage.process_turn(continue_steps_if_needed=False) self.assertFalse(self.action_move.replane_required) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.action_move.state, prototypes.ActionMoveNearPlacePrototype.STATE.MOVING) self.action_move.replane_required = True self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual( self.action_move.state, prototypes.ActionMoveNearPlacePrototype.STATE.PROCESSED)
class MoveToActionWithBreaksTest(testcase.TestCase): FIRST_BREAK_AT = 0.75 def setUp(self): super(MoveToActionWithBreaksTest, self).setUp() self.p1, self.p2, self.p3 = 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.action_idl = self.hero.actions.current_action self.hero.position.set_place(self.p1) self.action_move = prototypes.ActionMoveToPrototype.create( hero=self.hero, destination=self.p3, break_at=self.FIRST_BREAK_AT) def test_sequence_move(self): current_time = TimePrototype.get_current_time() while self.hero.actions.current_action != self.action_idl: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.position.road.point_1_id, self.p2.id) self.assertEqual(self.hero.position.road.point_2_id, self.p3.id) real_percents = None prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.p1, break_at=0.9) while self.hero.actions.current_action != self.action_idl: real_percents = self.hero.actions.current_action.percents self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(round(real_percents, 1), 0.9) self.assertEqual(self.hero.position.road.point_1_id, self.p1.id) self.assertEqual(self.hero.position.road.point_2_id, self.p2.id) prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.p2) while self.hero.position.place is None or self.hero.position.place.id != self.p2.id: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.storage._test_save() @mock.patch( 'the_tale.game.heroes.prototypes.HeroPositionPrototype.is_battle_start_needed', lambda self: False) def test_teleport_to_place__break_at(self): self.storage.process_turn(continue_steps_if_needed=False) self.action_move.teleport_to_place(create_inplace_action=True) self.assertEqual(self.hero.position.place.id, self.p2.id) while not self.hero.actions.current_action.TYPE.is_MOVE_TO: self.storage.process_turn(continue_steps_if_needed=False) self.storage.process_turn(continue_steps_if_needed=False) self.assertTrue( self.action_move.teleport_to_place(create_inplace_action=True)) self.assertNotEqual(self.hero.position.road, None) self.assertTrue(self.hero.position.percents < 1) self.assertTrue(self.hero.actions.current_action.TYPE.is_MOVE_TO) self.assertEqual(self.hero.actions.current_action.percents, self.FIRST_BREAK_AT) self.assertTrue(self.action_move.leader) self.assertEqual(self.hero.position.place, None) self.storage._test_save() @mock.patch( 'the_tale.game.heroes.prototypes.HeroPositionPrototype.is_battle_start_needed', lambda self: False) def test_teleport_to_end__break_at(self): self.storage.process_turn(continue_steps_if_needed=False) self.action_move.teleport_to_end() self.assertNotEqual(self.hero.position.road, None) self.assertTrue(self.hero.position.percents < 1.0) self.assertEqual(self.p2.id, self.hero.position.road.point_1_id) self.assertEqual(self.p3.id, self.hero.position.road.point_2_id) self.assertTrue(self.hero.actions.current_action.TYPE.is_MOVE_TO) self.assertEqual(self.hero.actions.current_action.percents, self.FIRST_BREAK_AT) self.assertTrue(self.action_move.leader) self.storage._test_save()
class HealCompanionActionTest(UseAbilityTaskMixin, testcase.TestCase): PROCESSOR = Help def setUp(self): super(HealCompanionActionTest, self).setUp() create_test_map() self.account = self.accounts_factory.create_account() self.storage = LogicStorage() self.storage.load_account_data(self.account) self.hero = self.storage.accounts_to_heroes[self.account.id] self.companion_record = companions_storage.companions.enabled_companions().next() self.hero.set_companion(companions_logic.create_companion(self.companion_record)) self.action_idl = self.hero.actions.current_action self.hero.companion.healed_at_turn = -1 with self.check_increased(lambda: self.hero.companion.healed_at_turn): self.action_heal_companion = prototypes.ActionHealCompanionPrototype.create(hero=self.hero) def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_heal_companion.leader, True) self.assertEqual(self.action_heal_companion.bundle_id, self.action_heal_companion.bundle_id) self.assertEqual(self.action_heal_companion.percents, 0) self.storage._test_save() def test_processed__no_companion(self): self.hero.remove_companion() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_processed__max_health(self): self.assertEqual(self.hero.companion.health, self.hero.companion.max_health) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_not_ready(self): self.hero.companion.health = 1 self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_heal_companion) self.assertTrue(self.hero.companion.health, 1) self.assertTrue(self.action_heal_companion.percents > 0) self.storage._test_save() def test_ability_heal_companion(self): self.hero.companion.health = 1 with self.check_increased(lambda: self.action_heal_companion.percents): with self.check_increased(lambda: self.hero.companion.health): ability = self.PROCESSOR() with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION): self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage))) def test_ability_heal_companion__processed_when_healed(self): self.hero.companion.health -= 1 with self.check_increased(lambda: self.action_heal_companion.percents): with self.check_increased(lambda: self.hero.companion.health): ability = self.PROCESSOR() with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION): self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage))) self.assertTrue(self.action_heal_companion.percents, 1) self.assertEqual(self.action_heal_companion.state, self.action_heal_companion.STATE.PROCESSED) @mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.can_companion_exp_per_heal', lambda hero: True) def test_ability_heal_companion__processed_when_healed__exp_per_heal(self): self.hero.companion.health -= 1 with self.check_delta(lambda: self.hero.experience, c.COMPANIONS_EXP_PER_HEAL): with self.check_increased(lambda: self.hero.companion.health): ability = self.PROCESSOR() with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION): self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage))) self.assertTrue(self.action_heal_companion.percents, 1) self.assertEqual(self.action_heal_companion.state, self.action_heal_companion.STATE.PROCESSED) def test_ability_heal_companion__full_action(self): self.hero.companion.health = 1 current_time = TimePrototype.get_current_time() with self.check_increased(lambda: self.action_heal_companion.percents): with self.check_increased(lambda: self.hero.companion.health): while self.action_heal_companion.state != self.action_heal_companion.STATE.PROCESSED: current_time.increment_turn() ability = self.PROCESSOR() with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL_COMPANION): self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage))) def test_full(self): self.hero.companion.health = 1 current_time = TimePrototype.get_current_time() with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() @mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.can_companion_exp_per_heal', lambda hero: True) def test_full__exp_per_heal(self): self.hero.companion.health = 1 with self.check_delta(lambda: self.hero.experience, c.COMPANIONS_EXP_PER_HEAL): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() @mock.patch('the_tale.common.utils.logic.randint_from_1', lambda v: v) @mock.patch('the_tale.game.balance.constants.COMPANIONS_REGEN_ON_HEAL_PER_HEAL', 1.0) @mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.can_companion_regenerate', lambda hero: True) def test_full__regeneration(self): self.hero.companion.health = 1 current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.companion.health, 1+c.COMPANIONS_HEALTH_PER_HEAL+c.COMPANIONS_REGEN_ON_HEAL_AMOUNT) self.storage._test_save() @mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.companion_heal_probability', 1) @mock.patch('the_tale.common.utils.logic.randint_from_1', lambda v: v) def test_companion_healing_by_hero(self): current_time = TimePrototype.get_current_time() self.hero.companion.health = 1 with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL+c.COMPANIONS_REGEN_BY_HERO): self.action_heal_companion.state = self.action_heal_companion.STATE.PROCESSED self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() @mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.companion_heal_probability', 0) @mock.patch('the_tale.common.utils.logic.randint_from_1', lambda v: v) def test_companion_healing_by_hero__not_healed(self): current_time = TimePrototype.get_current_time() self.hero.companion.health = 1 with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEALTH_PER_HEAL): self.action_heal_companion.state = self.action_heal_companion.STATE.PROCESSED self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn()
class ResurrectActionTest(testcase.TestCase): def setUp(self): super(ResurrectActionTest, self).setUp() create_test_map() self.account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(self.account) self.hero = self.storage.accounts_to_heroes[self.account.id] self.action_idl = self.hero.actions.current_action self.hero.kill() self.action_resurrect = ActionResurrectPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_resurrect.leader, True) self.assertEqual(self.action_resurrect.bundle_id, self.action_idl.bundle_id) self.assertEqual(len(self.action_resurrect.HELP_CHOICES), 1) self.assertTrue( list(self.action_resurrect.HELP_CHOICES)[0].is_RESURRECT) self.storage._test_save() def test_processed(self): for i in range(c.TURNS_TO_RESURRECT - 1): self.storage.process_turn() turn.increment() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_resurrect) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.health, self.hero.max_health) self.assertEqual(self.hero.is_alive, True) self.storage._test_save() def test_full(self): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.health, self.hero.max_health) self.assertEqual(self.hero.is_alive, True) self.storage._test_save() def test_fast_resurrect(self): self.action_resurrect.fast_resurrect() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.health, self.hero.max_health) self.assertEqual(self.hero.is_alive, True) self.storage._test_save()
class InPlaceActionSpendMoneyTest(testcase.TestCase): def setUp(self): super(InPlaceActionSpendMoneyTest, 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.action_idl = self.hero.actions.current_action self.action_inplace = prototypes.ActionInPlacePrototype.create(hero=self.hero) def test_no_money(self): self.hero.money = 1 self.storage.process_turn() self.assertEqual(self.hero.money, 1) self.assertEqual(self.hero.statistics.money_spend, 0) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.buy_price', lambda hero: -100) def test_buy_price_less_than_zero(self): money = self.hero.spend_amount self.hero.money = money self.assertEqual(self.action_inplace.try_to_spend_money(), 1) self.assertEqual(self.hero.statistics.money_spend, 1) def test_instant_heal(self): while not self.hero.next_spending.is_INSTANT_HEAL: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money + 666 self.hero.health = 1 self.storage.process_turn() self.assertEqual(self.hero.money, 666) self.assertEqual(self.hero.health, self.hero.max_health) self.assertEqual(self.hero.statistics.money_spend, money) self.assertEqual(self.hero.statistics.money_spend_for_heal, money) self.storage._test_save() def test_instant_heal__switch_on_full_health(self): while not self.hero.next_spending.is_INSTANT_HEAL: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money + 666 self.hero.health = self.hero.max_health with mock.patch('the_tale.game.heroes.objects.Hero.switch_spending') as switch_spending: self.storage.process_turn() self.assertEqual(switch_spending.call_count, 1) self.assertEqual(self.hero.money, money + 666) self.assertEqual(self.hero.health, self.hero.max_health) self.assertEqual(self.hero.statistics.money_spend, 0) self.assertEqual(self.hero.statistics.money_spend_for_heal, 0) self.storage._test_save() def test_instant_heal__too_much_health(self): while not self.hero.next_spending.is_INSTANT_HEAL: self.hero.switch_spending() money = self.hero.spend_amount health = (self.hero.max_health * c.SPEND_MONEY_FOR_HEAL_HEALTH_FRACTION) + 1 self.hero.money = money + 666 self.hero.health = health self.storage.process_turn() self.assertTrue(self.hero.money, money + 666) self.assertEqual(self.hero.health, health) self.assertEqual(self.hero.statistics.money_spend, 0) self.assertEqual(self.hero.statistics.money_spend_for_heal, 0) self.storage._test_save() def test_instant_heal__low_health(self): while not self.hero.next_spending.is_INSTANT_HEAL: self.hero.switch_spending() money = self.hero.spend_amount health = (self.hero.max_health * c.SPEND_MONEY_FOR_HEAL_HEALTH_FRACTION) - 1 self.hero.money = money self.hero.health = health self.storage.process_turn() self.assertEqual(self.hero.money, 0) self.assertEqual(self.hero.health, self.hero.max_health) self.assertEqual(self.hero.statistics.money_spend, money) self.assertEqual(self.hero.statistics.money_spend_for_heal, money) self.storage._test_save() def test_buying_artifact_with_hero_preferences(self): while not self.hero.next_spending.is_BUYING_ARTIFACT: self.hero.switch_spending() money = self.hero.spend_amount self.assertEqual(self.hero.statistics.money_spend, 0) self.assertEqual(self.hero.statistics.money_spend_for_artifacts, 0) self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0) #unequip all arefact self.hero.equipment._remove_all() # self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE) heroes_logic.save_hero(self.hero) #buy artifact self.hero.money = money self.storage.process_turn() self.assertTrue(self.hero.money < 1) self.assertEqual(len(self.hero.bag.items()), 0) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_artifacts, money - self.hero.money) self.assertEqual(self.hero.statistics.artifacts_had, 1) # # hero must not buy artifact in preferences slot, he has special quest for this # self.assertEqual(self.hero.equipment.get(EQUIPMENT_SLOT.PLATE), None) # self.storage._test_save() def test_buying_artifact_without_change(self): while not self.hero.next_spending.is_BUYING_ARTIFACT: self.hero.switch_spending() money = self.hero.spend_amount self.assertEqual(self.hero.statistics.money_spend, 0) self.assertEqual(self.hero.statistics.money_spend_for_artifacts, 0) self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0) #unequip all arefact self.hero.equipment._remove_all() heroes_logic.save_hero(self.hero) #buy artifact self.hero.money = money self.storage.process_turn() self.assertEqual(self.hero.money, 0) self.assertEqual(len(self.hero.bag.items()), 0) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_artifacts, money - self.hero.money) self.assertEqual(self.hero.statistics.artifacts_had, 1) self.storage._test_save() def test_buying_artifact_with_change(self): while not self.hero.next_spending.is_BUYING_ARTIFACT: self.hero.switch_spending() # fill all slots with artifacts self.hero.equipment.test_equip_in_all_slots(artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)) money = self.hero.spend_amount #buy artifact self.hero.money = money self.assertEqual(self.hero.statistics.money_spend, 0) self.assertEqual(self.hero.statistics.money_spend_for_artifacts, 0) self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0) self.storage.process_turn() self.assertTrue(self.hero.money > 0) self.assertEqual(len(self.hero.bag.items()), 0) self.assertTrue(self.hero.statistics.money_spend > money - self.hero.money) self.assertTrue(self.hero.statistics.money_spend_for_artifacts > money - self.hero.money) self.assertEqual(self.hero.statistics.artifacts_had, 1) self.assertTrue(self.hero.statistics.money_earned_from_artifacts > 0) self.storage._test_save() def test_not_bying_artifact__when_has_equip_candidates_in_bag(self): while not self.hero.next_spending.is_BUYING_ARTIFACT: self.hero.switch_spending() # fill all slots with artifacts self.hero.equipment.test_equip_in_all_slots(artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)) money = self.hero.spend_amount self.hero.money = money self.hero.bag.put_artifact(artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 666, rarity=RARITY.EPIC)) with self.check_not_changed(lambda: self.hero.statistics.money_spend): with self.check_not_changed(lambda: self.hero.statistics.money_spend_for_artifacts): with self.check_not_changed(lambda: self.hero.statistics.money_earned_from_artifacts): with self.check_not_changed(lambda: self.hero.statistics.artifacts_had): with self.check_not_changed(lambda: self.hero.bag.occupation): self.storage.process_turn() def test_sharpening_artifact(self): while not self.hero.next_spending.is_SHARPENING_ARTIFACT: self.hero.switch_spending() money = self.hero.spend_amount old_power = self.hero.power.clone() self.hero.money = money self.storage.process_turn() self.assertEqual(self.hero.money, 0) self.assertEqual(old_power.total() + 1, self.hero.power.total()) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_sharpening, money - self.hero.money) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.can_upgrade_prefered_slot', True) def test_sharpening_artifact_with_hero_preferences(self): while not self.hero.next_spending.is_SHARPENING_ARTIFACT: self.hero.switch_spending() self.hero.preferences.set_equipment_slot(heroes_relations.EQUIPMENT_SLOT.PLATE) self.hero.level = 666 # enshure that equipment power will be less than max allowerd _power heroes_logic.save_hero(self.hero) money = self.hero.spend_amount old_power = self.hero.power.clone() old_plate_power = self.hero.equipment.get(heroes_relations.EQUIPMENT_SLOT.PLATE).power.clone() self.hero.money = money self.storage.process_turn() self.assertEqual(self.hero.money, 0) self.assertEqual(old_power.total() + 1, self.hero.power.total()) self.assertEqual(old_plate_power.total() + 1, self.hero.equipment.get(heroes_relations.EQUIPMENT_SLOT.PLATE).power.total()) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_sharpening, money - self.hero.money) self.storage._test_save() def test_repair_artifact(self): for artifact in self.hero.equipment.values(): artifact.integrity = artifact.max_integrity test_artifact = artifact test_artifact.integrity = 0 while not self.hero.next_spending.is_REPAIRING_ARTIFACT: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money self.storage.process_turn() self.assertEqual(self.hero.money, 0) self.assertEqual(test_artifact.integrity, test_artifact.max_integrity) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_repairing, money - self.hero.money) self.storage._test_save() def test_useless(self): while not self.hero.next_spending.is_USELESS: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money self.storage.process_turn() self.assertEqual(self.hero.money, 0) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_useless, money - self.hero.money) self.storage._test_save() def test_impact(self): while not self.hero.next_spending.is_IMPACT: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money with mock.patch('the_tale.game.persons.objects.Person.cmd_change_power') as cmd_change_power: self.storage.process_turn() self.assertEqual(cmd_change_power.call_count, 0) self.assertEqual(self.hero.money, 0) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_impact, money - self.hero.money) self.storage._test_save() def test_impact__can_change_power(self): while not self.hero.next_spending.is_IMPACT: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money with mock.patch('the_tale.game.heroes.objects.Hero.can_change_person_power', lambda self, person: True): with mock.patch('the_tale.game.persons.objects.Person.cmd_change_power') as cmd_change_power: self.storage.process_turn() self.assertEqual(cmd_change_power.call_count, 1) self.assertEqual(self.hero.money, 0) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_impact, money - self.hero.money) self.storage._test_save() def test_experience(self): while not self.hero.next_spending.is_EXPERIENCE: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money self.storage.process_turn() self.assertEqual(self.hero.money, 0) self.assertEqual(self.hero.statistics.money_spend, money - self.hero.money) self.assertEqual(self.hero.statistics.money_spend_for_experience, money - self.hero.money) self.storage._test_save() def test_heal_companion(self): self.companion_record = companions_logic.create_random_companion_record('companion', state=companions_relations.STATE.ENABLED) self.hero.set_companion(companions_logic.create_companion(self.companion_record)) self.hero.companion.health = 1 while not self.hero.next_spending.is_HEAL_COMPANION: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money + 666 with self.check_increased(lambda: self.hero.companion.health): with self.check_delta(lambda: self.hero.money, -money): self.storage.process_turn() self.assertEqual(self.hero.statistics.money_spend, money) self.assertEqual(self.hero.statistics.money_spend_for_companions, money) self.storage._test_save() def test_heal_companion__swich_spending_on_full_health(self): self.companion_record = companions_logic.create_random_companion_record('companion', state=companions_relations.STATE.ENABLED) self.hero.set_companion(companions_logic.create_companion(self.companion_record)) while not self.hero.next_spending.is_HEAL_COMPANION: self.hero.switch_spending() self.hero.companion.health = self.hero.companion.max_health money = self.hero.spend_amount self.hero.money = money + 666 with self.check_not_changed(lambda: self.hero.companion.health): with self.check_not_changed(lambda: self.hero.money): with mock.patch('the_tale.game.heroes.objects.Hero.switch_spending') as switch_spending: self.storage.process_turn() self.assertEqual(switch_spending.call_count, 1) self.assertEqual(self.hero.statistics.money_spend, 0) self.assertEqual(self.hero.statistics.money_spend_for_companions, 0) self.storage._test_save() def test_healed_companion(self): self.companion_record = companions_logic.create_random_companion_record('companion', state=companions_relations.STATE.ENABLED) self.hero.set_companion(companions_logic.create_companion(self.companion_record)) self.hero.companion.health = self.hero.companion.max_health while not self.hero.next_spending.is_HEAL_COMPANION: self.hero.switch_spending() money = self.hero.spend_amount self.hero.money = money + 666 with self.check_not_changed(lambda: self.hero.statistics.money_spend): with self.check_not_changed(lambda: self.hero.statistics.money_spend_for_companions): with self.check_not_changed(lambda: self.hero.money): self.storage.process_turn() self.storage._test_save() def test_heal_companion__no_companion(self): self.assertEqual(self.hero.companion, None) self.hero.next_spending = heroes_relations.ITEMS_OF_EXPENDITURE.HEAL_COMPANION money = self.hero.spend_amount self.hero.money = money + 666 with self.check_not_changed(lambda: self.hero.statistics.money_spend): with self.check_not_changed(lambda: self.hero.statistics.money_spend_for_companions): with self.check_not_changed(lambda: self.hero.money): self.storage.process_turn()
class InPlaceActionTest(testcase.TestCase, ActionEventsTestsMixin): def setUp(self): super(InPlaceActionTest, self).setUp() create_test_map() self.account = self.accounts_factory.create_account() self.storage = LogicStorage() self.storage.load_account_data(self.account) self.hero = self.storage.accounts_to_heroes[self.account.id] self.action_idl = self.hero.actions.current_action self.hero.position.previous_place_id = None # test setting prevouse place in action constructor self.action_inplace = prototypes.ActionInPlacePrototype.create(hero=self.hero) self.action_event = self.action_inplace def test_create(self): self.assertEqual(self.hero.position.previous_place, None) self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_inplace.leader, True) self.assertEqual(self.action_inplace.bundle_id, self.action_idl.bundle_id) self.storage._test_save() @mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True) def test_instant_heal_in_resort(self): self.hero.health = 1 self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT) old_messages_len = len (self.hero.journal.messages) prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.health, self.hero.max_health) self.storage._test_save() @mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True) def test_no_instant_heal_in_resort(self): self.hero.health = self.hero.max_health self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT) old_messages_len = len (self.hero.journal.messages) prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.health, self.hero.max_health) self.storage._test_save() @mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True) def test_companion_heal_in_resort__no_companion(self): self.assertEqual(self.hero.companion, None) self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT) prototypes.ActionInPlacePrototype.create(hero=self.hero) self.storage._test_save() @mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True) def test_companion_heal_in_resort__healed_companion(self): companion_record = companions_storage.companions.enabled_companions().next() self.hero.set_companion(companions_logic.create_companion(companion_record)) self.assertEqual(self.hero.companion.health, self.hero.companion.max_health) self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT) prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertFalse(self.hero.journal.messages[-1].key.is_ACTION_INPLACE_COMPANION_HEAL) self.storage._test_save() @mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True) def test_companion_heal_in_resort__damaged_companion(self): companion_record = companions_storage.companions.enabled_companions().next() self.hero.set_companion(companions_logic.create_companion(companion_record)) self.hero.companion.health = 1 self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.RESORT) with self.check_increased(lambda: self.hero.companion.health): prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertTrue(self.hero.journal.messages[-1].key.is_ACTION_INPLACE_COMPANION_HEAL) self.storage._test_save() @mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True) def test_instant_energy_regen_in_holy_city(self): self.hero.energy = 0 self.hero.position.previous_place_id = None self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY) self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place) prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.energy, c.ANGEL_ENERGY_INSTANT_REGENERATION_IN_PLACE) self.storage._test_save() @mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True) def test_instant_energy_regen_in_holy_city__maximum_energy(self): self.hero.energy = self.hero.energy_maximum self.hero.position.previous_place_id = None self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY) self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place) prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.energy, self.hero.energy_maximum) self.storage._test_save() @mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True) def test_instant_energy_regen_in_holy_city__no_regen(self): self.hero.energy = 0 self.hero.position.previous_place_id = None self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.NONE) self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place) prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.energy, 0) self.storage._test_save() @mock.patch('the_tale.game.places.objects.Place.is_modifier_active', lambda self: True) def test_instant_energy_regen_in_holy_city__place_not_changed(self): self.hero.energy = 0 self.hero.position.place.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY) self.hero.position.update_previous_place() self.assertEqual(self.hero.position.place, self.hero.position.previous_place) with self.check_not_changed(lambda: len(self.hero.journal.messages)): prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.energy, 0) self.storage._test_save() def test_tax(self): for place in places_storage.places.all(): place.attrs.tax = 0.2 self.hero.money = 100 self.hero.position.previous_place_id = None self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place) with self.check_delta(lambda: self.hero.statistics.money_spend, 20): with self.check_delta(lambda: self.hero.statistics.money_spend_for_tax, 20): prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.money, 80) self.storage._test_save() def test_tax__no_money(self): for place in places_storage.places.all(): place.attrs.tax = 0.2 self.hero.money = 0 self.hero.position.previous_place_id = None self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place) with self.check_delta(lambda: len(self.hero.journal.messages), 1): with self.check_delta(lambda: self.hero.statistics.money_spend, 0): with self.check_delta(lambda: self.hero.statistics.money_spend_for_tax, 0): prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.money, 0) self.storage._test_save() def test_tax__no_tax(self): for place in places_storage.places.all(): place.attrs.tax = 0.0 self.hero.money = 100 self.hero.position.previous_place_id = None self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place) with self.check_delta(lambda: self.hero.statistics.money_spend, 0): with self.check_delta(lambda: self.hero.statistics.money_spend_for_tax, 0): prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.money, 100) self.storage._test_save() def test_tax__place_not_changed(self): for place in places_storage.places.all(): place.attrs.tax = 0.2 self.hero.money = 100 self.hero.position.update_previous_place() self.assertEqual(self.hero.position.place, self.hero.position.previous_place) with self.check_delta(lambda: len(self.hero.journal.messages), 0): with self.check_delta(lambda: self.hero.statistics.money_spend, 0): with self.check_delta(lambda: self.hero.statistics.money_spend_for_tax, 0): prototypes.ActionInPlacePrototype.create(hero=self.hero) self.assertEqual(self.hero.money, 100) self.storage._test_save() @mock.patch('the_tale.game.balance.constants.PLACE_HABITS_EVENT_PROBABILITY', 1.0) def test_habit_event(self): from the_tale.game.relations import HABIT_HONOR_INTERVAL, HABIT_PEACEFULNESS_INTERVAL for honor in HABIT_HONOR_INTERVAL.records: for peacefulness in HABIT_PEACEFULNESS_INTERVAL.records: self.hero.diary.clear() self.hero.position.previous_place_id = None self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place) with mock.patch('the_tale.game.places.habits.Honor.interval', honor): with mock.patch('the_tale.game.places.habits.Peacefulness.interval', peacefulness): with self.check_delta(self.hero.diary.messages_number, 1): prototypes.ActionInPlacePrototype.create(hero=self.hero) self.storage._test_save() @mock.patch('the_tale.game.balance.constants.PLACE_HABITS_EVENT_PROBABILITY', 0.0) def test_habit_event__no_event(self): self.hero.position.previous_place_id = None self.assertNotEqual(self.hero.position.place, self.hero.position.previous_place) with self.check_not_changed(lambda: len(self.hero.diary.messages)): prototypes.ActionInPlacePrototype.create(hero=self.hero) self.storage._test_save() @mock.patch('the_tale.game.balance.constants.PLACE_HABITS_EVENT_PROBABILITY', 1.0) def test_habit_event__not_visit(self): self.hero.position.update_previous_place() self.assertEqual(self.hero.position.place, self.hero.position.previous_place) with self.check_not_changed(lambda: len(self.hero.diary.messages)): prototypes.ActionInPlacePrototype.create(hero=self.hero) self.storage._test_save() def test_processed(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.position.previous_place, self.hero.position.place) self.storage._test_save() def test_regenerate_energy_action_create(self): self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.PRAY) self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0]) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 3) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE) self.storage._test_save() def test_regenerate_energy_action_not_create_for_sacrifice(self): self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.SACRIFICE) self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0]) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_heal_action_create(self): self.hero.health = 1 self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 3) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRestPrototype.TYPE) self.storage._test_save() @mock.patch('the_tale.game.companions.objects.Companion.need_heal', True) def test_heal_companion_action_create(self): companion_record = companions_storage.companions.enabled_companions().next() self.hero.set_companion(companions_logic.create_companion(companion_record)) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 3) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionHealCompanionPrototype.TYPE) self.assertEqual(self.action_inplace.state, prototypes.ActionInPlacePrototype.STATE.HEALING_COMPANION) self.storage._test_save() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.storage._test_save() @mock.patch('the_tale.game.companions.objects.Companion.need_heal', True) def test_heal_companion_action_create__no_companion(self): self.assertEqual(self.hero.companion, None) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionIdlenessPrototype.TYPE) self.storage._test_save() def test_trade_action_create(self): for i in xrange(int(c.MAX_BAG_SIZE * c.BAG_SIZE_TO_SELL_LOOT_FRACTION) + 1): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.loot, 1, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 3) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionTradingPrototype.TYPE) self.storage._test_save() def test_equip_action_create(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) artifact.power = Power(666, 666) self.hero.bag.put_artifact(artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 3) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionEquippingPrototype.TYPE) self.storage._test_save() def test_full(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn() current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save()
class IdlenessActionTest(testcase.TestCase): def setUp(self): super(IdlenessActionTest, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.account = AccountPrototype.get_by_id(account_id) self.storage = LogicStorage() self.storage.load_account_data(self.account) self.hero = self.storage.accounts_to_heroes[self.account.id] self.action_idl = self.hero.actions.current_action def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, True) self.assertEqual(self.action_idl.percents, 1.0) self.storage._test_save() def test_first_quest(self): self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionQuestPrototype.TYPE) self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.QUEST) self.assertEqual(self.action_idl.bundle_id, self.hero.account_id) self.storage._test_save() def test_reset_percents_on_quest_end(self): self.action_idl.percents = 1.0 self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.QUEST self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.action_idl.percents, 0.0) def test_inplace(self): self.action_idl.percents = 1.0 self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.QUEST self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.IN_PLACE) self.storage._test_save() def test_waiting(self): self.action_idl.percents = 0.0 self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.IN_PLACE self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.WAITING) self.storage._test_save() def test_regenerate_energy_action_create(self): self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.PRAY) self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0]) self.action_idl.percents = 0.0 self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionRegenerateEnergyPrototype.TYPE) self.storage._test_save() def test_regenerate_energy_action_not_create_for_sacrifice(self): self.action_idl.percents = 0 self.hero.preferences.set_energy_regeneration_type(heroes_relations.ENERGY_REGENERATION.SACRIFICE) self.hero.last_energy_regeneration_at_turn -= max(zip(*heroes_relations.ENERGY_REGENERATION.select('period'))[0]) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_full_waiting(self): self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.WAITING self.action_idl.percents = 0 current_time = TimePrototype.get_current_time() for i in xrange(c.TURNS_TO_IDLE*self.hero.level): self.storage.process_turn() current_time.increment_turn() self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionQuestPrototype.TYPE) self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.QUEST) self.storage._test_save() def test_initiate_quest(self): self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.WAITING self.action_idl.percents = 0 self.action_idl.init_quest() self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionQuestPrototype.TYPE) self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.QUEST) self.storage._test_save() def test_initiate_quest_just_after_quest(self): self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.QUEST self.action_idl.percents = 0 self.action_idl.init_quest() self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionQuestPrototype.TYPE) self.assertEqual(self.action_idl.state, prototypes.ActionIdlenessPrototype.STATE.QUEST) self.storage._test_save() def test_help_choices__contain_start_quest(self): self.action_idl.percents = 0.0 self.assertTrue(HELP_CHOICES.START_QUEST in self.action_idl.HELP_CHOICES) def test_help_choices__start_quest_removed(self): self.action_idl.percents = 1.0 self.assertFalse(HELP_CHOICES.START_QUEST in self.action_idl.HELP_CHOICES) @mock.patch('the_tale.game.heroes.prototypes.HeroPositionPrototype.is_battle_start_needed', lambda self: False) def test_return_from_road__after_quest(self): self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.QUEST self.hero.position.set_road(list(roads_storage.all())[0], percents=0.5) self.storage.process_turn() self.assertEqual(self.hero.actions.number, 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveToPrototype.TYPE) @mock.patch('the_tale.game.heroes.prototypes.HeroPositionPrototype.is_battle_start_needed', lambda self: False) def test_return_from_wild_terrain__after_quest(self): self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.QUEST self.hero.position.set_coordinates(0, 0, 5, 5, percents=0) self.storage.process_turn() self.assertEqual(self.hero.actions.number, 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveNearPlacePrototype.TYPE) @mock.patch('the_tale.game.heroes.prototypes.HeroPositionPrototype.is_battle_start_needed', lambda self: False) def test_return_from_road__after_resurrect(self): self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.RESURRECT self.hero.position.set_road(list(roads_storage.all())[0], percents=0.5) self.storage.process_turn() self.assertEqual(self.hero.actions.number, 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveToPrototype.TYPE) @mock.patch('the_tale.game.heroes.prototypes.HeroPositionPrototype.is_battle_start_needed', lambda self: False) def test_return_from_wild_terrain__after_resurrect(self): self.action_idl.state = prototypes.ActionIdlenessPrototype.STATE.RESURRECT self.hero.position.set_coordinates(0, 0, 5, 5, percents=0) self.storage.process_turn() self.assertEqual(self.hero.actions.number, 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveNearPlacePrototype.TYPE) def test_resurrect(self): self.hero.is_alive = False self.storage.process_turn() self.assertEqual(self.hero.actions.number, 2) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionResurrectPrototype.TYPE)
class MoveToActionWithBreaksTest(testcase.TestCase): FIRST_BREAK_AT = 0.75 def setUp(self): super(MoveToActionWithBreaksTest, self).setUp() self.p1, self.p2, self.p3 = create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.hero.position.set_place(self.p1) self.action_move = prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.p3, break_at=self.FIRST_BREAK_AT) def test_sequence_move(self): current_time = TimePrototype.get_current_time() while self.hero.actions.current_action != self.action_idl: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.position.road.point_1_id, self.p2.id) self.assertEqual(self.hero.position.road.point_2_id, self.p3.id) real_percents = None prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.p1, break_at=0.9) while self.hero.actions.current_action != self.action_idl: real_percents = self.hero.actions.current_action.percents self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(round(real_percents, 1), 0.9) self.assertEqual(self.hero.position.road.point_1_id, self.p1.id) self.assertEqual(self.hero.position.road.point_2_id, self.p2.id) prototypes.ActionMoveToPrototype.create(hero=self.hero, destination=self.p2) while self.hero.position.place is None or self.hero.position.place.id != self.p2.id: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionInPlacePrototype.TYPE) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) def test_teleport_to_place__break_at(self): self.storage.process_turn(continue_steps_if_needed=False) self.action_move.teleport_to_place(create_inplace_action=True) self.assertEqual(self.hero.position.place.id, self.p2.id) while not self.hero.actions.current_action.TYPE.is_MOVE_TO: self.storage.process_turn(continue_steps_if_needed=False) self.storage.process_turn(continue_steps_if_needed=False) self.assertTrue(self.action_move.teleport_to_place(create_inplace_action=True)) self.assertNotEqual(self.hero.position.road, None) self.assertTrue(self.hero.position.percents < 1) self.assertTrue(self.hero.actions.current_action.TYPE.is_MOVE_TO) self.assertEqual(self.hero.actions.current_action.percents, self.FIRST_BREAK_AT) self.assertTrue(self.action_move.leader) self.assertEqual(self.hero.position.place, None) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.is_battle_start_needed', lambda self: False) def test_teleport_to_end__break_at(self): self.storage.process_turn(continue_steps_if_needed=False) self.action_move.teleport_to_end() self.assertNotEqual(self.hero.position.road, None) self.assertTrue(self.hero.position.percents < 1.0) self.assertEqual(self.p2.id, self.hero.position.road.point_1_id) self.assertEqual(self.p3.id, self.hero.position.road.point_2_id) self.assertTrue(self.hero.actions.current_action.TYPE.is_MOVE_TO) self.assertEqual(self.hero.actions.current_action.percents, self.FIRST_BREAK_AT) self.assertTrue(self.action_move.leader) self.storage._test_save()
class QuestActionTests(testcase.TestCase): def setUp(self): super(QuestActionTests, 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.action_idl = self.hero.actions.current_action self.action_quest = prototypes.ActionQuestPrototype.create(hero=self.hero) def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_quest.leader, True) self.assertEqual(self.action_quest.state, self.action_quest.STATE.SEARCHING) self.assertEqual(self.action_quest.bundle_id, self.action_idl.bundle_id) self.assertFalse(self.hero.quests.has_quests) self.storage._test_save() def test_setup_quest(self): quests_helpers.setup_quest(self.hero) self.assertEqual(self.action_quest.state, self.action_quest.STATE.PROCESSING) self.assertTrue(self.hero.quests.has_quests) self.storage._test_save() def test_one_step(self): self.storage.process_turn() # quest can create new action on first step self.assertTrue(2 <= len(self.hero.actions.actions_list) <= 3) self.storage._test_save() def test_step_with_no_quest(self): quests_helpers.setup_quest(self.hero) self.hero.quests.pop_quest() self.storage.process_turn() self.assertEqual(self.action_idl.leader, True) def test_need_equipping(self): with mock.patch('the_tale.game.heroes.objects.Hero.need_equipping', lambda hero: True): self.storage.process_turn() self.assertEqual(self.action_quest.state, self.action_quest.STATE.EQUIPPING) self.assertTrue(self.hero.actions.current_action.TYPE.is_EQUIPPING) self.storage.process_turn() self.assertEqual(self.action_quest.state, self.action_quest.STATE.EQUIPPING) self.assertTrue(self.hero.actions.current_action.TYPE.is_QUEST) self.storage.process_turn() self.assertEqual(self.action_quest.state, self.action_quest.STATE.PROCESSING) def test_full_quest(self): current_time = TimePrototype.get_current_time() # just test that quest will be ended while not self.action_idl.leader: self.storage.process_turn() current_time.increment_turn() self.storage._test_save() self.assertFalse(self.hero.quests.has_quests)
class RegenerateEnergyActionTest(testcase.TestCase): def setUp(self): super(RegenerateEnergyActionTest, self).setUp() create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.action_regenerate = ActionRegenerateEnergyPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_regenerate.leader, True) self.assertEqual(self.action_regenerate.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_not_ready(self): self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_regenerate) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_double_energy', False) def test_full(self): with self.check_delta(lambda: tt_api_energy.energy_balance(self.hero.account_id), self.hero.preferences.energy_regeneration_type.amount): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() time.sleep(0.1) self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.need_regenerate_energy, False) self.assertEqual(self.hero.last_energy_regeneration_at_turn, turn.number()-1) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_double_energy', False) @mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_energy', False) def test_full__regeneration_restricted(self): with self.check_not_changed(lambda: tt_api_energy.energy_balance(self.hero.account_id)): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() time.sleep(0.1) self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.need_regenerate_energy, False) self.assertEqual(self.hero.last_energy_regeneration_at_turn, turn.number()-1) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_double_energy', True) def test_full__double_energy(self): with self.check_delta(lambda: tt_api_energy.energy_balance(self.hero.account_id), self.hero.preferences.energy_regeneration_type.amount * 2): while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) turn.increment() time.sleep(0.1) self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.need_regenerate_energy, False) self.assertEqual(self.hero.last_energy_regeneration_at_turn, turn.number()-1) self.storage._test_save()
class ResurrectActionTest(testcase.TestCase): def setUp(self): super(ResurrectActionTest, self).setUp() create_test_map() self.account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(self.account) self.hero = self.storage.accounts_to_heroes[self.account.id] self.action_idl = self.hero.actions.current_action self.hero.kill() self.action_resurrect = ActionResurrectPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_resurrect.leader, True) self.assertEqual(self.action_resurrect.bundle_id, self.action_idl.bundle_id) self.assertEqual(len(self.action_resurrect.HELP_CHOICES), 1) self.assertTrue(list(self.action_resurrect.HELP_CHOICES)[0].is_RESURRECT) self.storage._test_save() def test_processed(self): current_time = TimePrototype.get_current_time() for i in range(c.TURNS_TO_RESURRECT-1): self.storage.process_turn() current_time.increment_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_resurrect) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.health, self.hero.max_health) self.assertEqual(self.hero.is_alive, True) self.storage._test_save() def test_full(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.health, self.hero.max_health) self.assertEqual(self.hero.is_alive, True) self.storage._test_save() def test_fast_resurrect(self): self.action_resurrect.fast_resurrect() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.health, self.hero.max_health) self.assertEqual(self.hero.is_alive, True) self.storage._test_save()
class RegenerateEnergyActionTest(testcase.TestCase): def setUp(self): super(RegenerateEnergyActionTest, 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.action_idl = self.hero.actions.current_action self.action_regenerate = ActionRegenerateEnergyPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_regenerate.leader, True) self.assertEqual(self.action_regenerate.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_not_ready(self): self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_regenerate) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_double_energy', False) def test_full(self): self.hero.change_energy(-self.hero.energy) current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.energy, self.hero.preferences.energy_regeneration_type.amount) self.assertEqual(self.hero.need_regenerate_energy, False) self.assertEqual(self.hero.last_energy_regeneration_at_turn, TimePrototype.get_current_turn_number()-1) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.can_regenerate_double_energy', True) def test_full__double_energy(self): self.hero.change_energy(-self.hero.energy) current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.energy, self.hero.preferences.energy_regeneration_type.amount * 2) self.assertEqual(self.hero.need_regenerate_energy, False) self.assertEqual(self.hero.last_energy_regeneration_at_turn, TimePrototype.get_current_turn_number()-1) self.storage._test_save()
class TradingActionTest(testcase.TestCase): def setUp(self): super(TradingActionTest, self).setUp() create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.action_trade = ActionTradingPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_trade.leader, True) self.assertEqual(self.action_trade.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_processed(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_sell_and_finish(self): old_money_statistics = self.hero.statistics.money_earned old_money = self.hero.money artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.action_trade.percents_barier = 1 self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertTrue(self.hero.money > old_money) self.assertTrue(self.hero.statistics.money_earned > old_money_statistics) self.storage._test_save() def test_sell_and_continue(self): old_money = self.hero.money artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.assertEqual(self.hero.bag.occupation, 2) self.action_trade.percents_barier = 2 current_time = TimePrototype.get_current_time() self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_trade) self.assertEqual(self.hero.bag.occupation, 1) self.assertTrue(self.hero.money > old_money) old_money = self.hero.money current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.bag.occupation, 0) self.assertTrue(self.hero.money > old_money) self.storage._test_save() def test_stop_when_quest_required_replane(self): self.action_idl.percents = 0.0 self.assertFalse(self.action_trade.replane_required) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.action_trade.percents_barier = 2 self.assertEqual(self.hero.bag.occupation, 2) current_time = TimePrototype.get_current_time() self.storage.process_turn() self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_trade) self.action_trade.replane_required = True current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.action_trade.state, self.action_trade.STATE.PROCESSED) self.assertEqual(self.hero.actions.current_action, self.action_idl)
class BattlePvE1x1ActionTest(testcase.TestCase): 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 tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_battle.leader, True) self.assertEqual(self.action_battle.bundle_id, self.action_idl.bundle_id) self.assertEqual(self.action_battle.percents, 0.0) self.assertEqual(self.action_battle.state, self.action_battle.STATE.BATTLE_RUNNING) self.storage._test_save() @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_mob_killed(self): self.assertEqual(self.hero.statistics.pve_kills, 0) self.action_battle.mob.health = 0 self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.statistics.pve_kills, 1) self.storage._test_save() @mock.patch('the_tale.game.balance.constants.ARTIFACTS_PER_BATTLE', 0) @mock.patch('the_tale.game.balance.constants.GET_LOOT_PROBABILITY', 1) @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_loot(self): self.assertEqual(self.hero.statistics.loot_had, 0) self.assertEqual(len(list(self.hero.bag.items())), 0) self.action_battle.mob.health = 0 self.storage.process_turn() self.assertEqual(self.hero.statistics.loot_had, 1) self.assertEqual(len(list(self.hero.bag.items())), 1) self.storage._test_save() @mock.patch('the_tale.game.balance.constants.ARTIFACTS_PER_BATTLE', 1) @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_artifacts(self): self.assertEqual(self.hero.statistics.artifacts_had, 0) self.assertEqual(len(list(self.hero.bag.items())), 0) self.action_battle.mob.health = 0 self.storage.process_turn() self.assertEqual(self.hero.statistics.artifacts_had, 1) self.assertEqual(len(list(self.hero.bag.items())), 1) self.storage._test_save() @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_hero_killed(self): self.assertEqual(self.hero.statistics.pve_deaths, 0) self.hero.health = 0 self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertTrue(not self.hero.is_alive) self.assertEqual(self.hero.statistics.pve_deaths, 1) self.storage._test_save() @mock.patch('the_tale.game.balance.constants.ARTIFACTS_PER_BATTLE', 1) @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_hero_and_mob_killed(self): self.hero.health = 0 self.action_battle.mob.health = 0 with self.check_not_changed(lambda: self.hero.statistics.artifacts_had): with self.check_not_changed(lambda: self.hero.bag.occupation): self.storage.process_turn(continue_steps_if_needed=False) self.assertTrue(self.hero.journal.messages[-1].key.is_ACTION_BATTLEPVE1X1_JOURNAL_HERO_AND_MOB_KILLED) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertTrue(not self.hero.is_alive) self.assertEqual(self.hero.statistics.pve_deaths, 1) self.storage._test_save() def test_full_battle(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn() current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() def test_full_battle__with_companion(self): battle_ability = random.choice([ability for ability in effects.ABILITIES.records if isinstance(ability.effect, effects.BaseBattleAbility)]) companion_record = next(companions_storage.companions.enabled_companions()) companion_record.abilities = container.Container(start=(battle_ability,)) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.hero.reset_accessors_cache() current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn() current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() @mock.patch('the_tale.game.heroes.objects.Hero.companion_damage_probability', 0.0) @mock.patch('the_tale.game.balance.constants.COMPANIONS_WOUNDS_IN_HOUR_FROM_HEAL', 0.0) @mock.patch('the_tale.game.balance.constants.COMPANIONS_EATEN_CORPSES_PER_BATTLE', 1.0) @mock.patch('the_tale.game.mobs.prototypes.MobPrototype.mob_type', game_relations.BEING_TYPE.ANIMAL) @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_eat_corpses', lambda hero: True) def test_full_battle__with_companion__eat_corpse(self): companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) self.hero.reset_accessors_cache() self.hero.companion.health = 10 current_time = TimePrototype.get_current_time() while self.hero.actions.current_action.TYPE == ActionBattlePvE1x1Prototype.TYPE: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.companion.health, 10 + c.COMPANIONS_EATEN_CORPSES_HEAL_AMOUNT) self.storage._test_save() def test_bit_mob(self): old_mob_health = self.action_battle.mob.health old_action_percents = self.action_battle.percents self.action_battle.bit_mob(0.33) self.assertTrue(self.action_battle.mob.health < old_mob_health) self.assertTrue(self.action_battle.percents > old_action_percents) self.assertTrue(self.action_battle.updated) def test_bit_mob_and_kill(self): self.action_battle.bit_mob(1) self.assertEqual(self.action_battle.mob.health, self.action_battle.mob.max_health - 1) self.assertTrue(0 < self.action_battle.percents < 1) self.assertTrue(self.action_battle.updated) self.assertEqual(self.action_battle.state, self.action_battle.STATE.BATTLE_RUNNING) self.action_battle.bit_mob(self.action_battle.mob.max_health) self.assertEqual(self.action_battle.mob.health, 0) self.assertEqual(self.action_battle.percents, 1) self.assertTrue(self.action_battle.updated) self.assertEqual(self.action_battle.state, self.action_battle.STATE.PROCESSED) def test_fast_resurrect__not_processed(self): self.action_battle.hero.kill() self.assertFalse(self.action_battle.fast_resurrect()) self.assertFalse(self.action_battle.hero.is_alive) def test_fast_resurrect__hero_is_alive(self): self.action_battle.state = self.action_battle.STATE.PROCESSED self.assertFalse(self.action_battle.fast_resurrect()) self.assertTrue(self.action_battle.hero.is_alive) def test_fast_resurrect__success(self): self.action_battle.hero.kill() self.action_battle.state = self.action_battle.STATE.PROCESSED self.assertTrue(self.action_battle.fast_resurrect()) self.assertTrue(self.action_battle.hero.is_alive) def test_help_choices(self): self.assertTrue(HELP_CHOICES.LIGHTING in self.action_battle.HELP_CHOICES) self.action_battle.mob.health = 0 self.assertFalse(HELP_CHOICES.LIGHTING in self.action_battle.HELP_CHOICES) self.action_battle.mob.health = 1 self.action_battle.hero.kill() self.assertEqual(self.action_battle.HELP_CHOICES, set((HELP_CHOICES.RESURRECT,))) @mock.patch('the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 1.01) @mock.patch('the_tale.game.heroes.habits.Honor.interval', game_relations.HABIT_HONOR_INTERVAL.LEFT_3) def test_kill_before_start(self): self.hero.actions.pop_action() with self.check_delta(lambda: self.hero.statistics.pve_kills, 1): 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) @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_do_exorcism', lambda hero: True) def test_companion_exorcims__demon(self): self.companion_record = companions_logic.create_random_companion_record('exorcist', state=companions_relations.STATE.ENABLED) self.hero.set_companion(companions_logic.create_companion(self.companion_record)) demon_record = mobs_prototypes.MobRecordPrototype.create_random('demon', type=game_relations.BEING_TYPE.DEMON) demon = mobs_prototypes.MobPrototype(record_id=demon_record.id, level=self.hero.level, is_boss=False) self.hero.actions.pop_action() with self.check_delta(lambda: self.hero.statistics.pve_kills, 1): action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=demon) 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) @mock.patch('the_tale.game.heroes.objects.Hero.can_companion_do_exorcism', lambda hero: True) def test_companion_exorcims__not_demon(self): self.companion_record = companions_logic.create_random_companion_record('exorcist', state=companions_relations.STATE.ENABLED) self.hero.set_companion(companions_logic.create_companion(self.companion_record)) not_demon_record = mobs_prototypes.MobRecordPrototype.create_random('demon', type=game_relations.BEING_TYPE.random(exclude=(game_relations.BEING_TYPE.DEMON, ))) not_demon = mobs_prototypes.MobPrototype(record_id=not_demon_record.id, level=self.hero.level, is_boss=False) self.hero.actions.pop_action() with self.check_delta(lambda: self.hero.statistics.pve_kills, 0): action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=not_demon) self.assertEqual(action_battle.percents, 0.0) self.assertEqual(action_battle.state, self.action_battle.STATE.BATTLE_RUNNING) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action, action_battle) @mock.patch('the_tale.game.balance.constants.PEACEFULL_BATTLE_PROBABILITY', 1.01) @mock.patch('the_tale.game.heroes.habits.Peacefulness.interval', game_relations.HABIT_PEACEFULNESS_INTERVAL.RIGHT_3) 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) @mock.patch('the_tale.game.heroes.objects.Hero.can_leave_battle_in_fear', lambda self: True) def test_fear_battle(self): self.hero.actions.pop_action() mob = next((m for m in mobs_storage.all() if m.type.is_CIVILIZED)) with self.check_delta(lambda: self.hero.statistics.pve_kills, 0): action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mob.create_mob(self.hero, is_boss=False)) 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) @mock.patch('the_tale.game.balance.constants.EXP_FOR_KILL_PROBABILITY', 1.01) @mock.patch('the_tale.game.balance.constants.EXP_FOR_KILL_DELTA', 0) @mock.patch('the_tale.game.heroes.habits.Peacefulness.interval', game_relations.HABIT_PEACEFULNESS_INTERVAL.LEFT_3) 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) @mock.patch('the_tale.game.balance.constants.ARTIFACTS_BREAKS_PER_BATTLE', 1.0) @mock.patch('the_tale.game.artifacts.prototypes.ArtifactPrototype.can_be_broken', lambda self: True) def test_process_artifact_breaking__no_equipment(self): self.hero.equipment._remove_all() old_power = self.hero.power.clone() self.action_battle.process_artifact_breaking() self.assertEqual(old_power, self.hero.power) @mock.patch('the_tale.game.balance.constants.ARTIFACTS_BREAKS_PER_BATTLE', 1.0) @mock.patch('the_tale.game.artifacts.prototypes.ArtifactPrototype.can_be_broken', lambda self: True) def test_process_artifact_breaking__broken(self): for artifact in list(self.hero.equipment.values()): artifact.power = Power(100, 100) old_power = self.hero.power.total() self.action_battle.process_artifact_breaking() self.assertTrue(old_power > self.hero.power.total()) @mock.patch('the_tale.game.balance.constants.ARTIFACTS_BREAKS_PER_BATTLE', 1.0) @mock.patch('the_tale.game.artifacts.prototypes.ArtifactPrototype.can_be_broken', lambda self: False) def test_process_artifact_breaking__not_broken(self): for artifact in list(self.hero.equipment.values()): artifact.power = Power(100, 100) old_power = self.hero.power.total() self.action_battle.process_artifact_breaking() self.assertEqual(old_power, self.hero.power.total()) @mock.patch('the_tale.game.balance.constants.ARTIFACTS_BREAKS_PER_BATTLE', 1.0) @mock.patch('the_tale.game.artifacts.prototypes.ArtifactPrototype.can_be_broken', lambda self: False) def test_process_artifact_breaking__break_only_mostly_damaged(self): for artifact in list(self.hero.equipment.values()): artifact.power = Power(100, 100) artifact.integrity = 0 artifact.integrity = artifact.max_integrity for i in range(100): self.action_battle.process_artifact_breaking() self.assertEqual(artifact.power, Power(100, 100)) def test_process_artifact_breaking__integrity_damage(self): for artifact in list(self.hero.equipment.values()): artifact.integrity = artifact.max_integrity self.action_battle.process_artifact_breaking() for artifact in list(self.hero.equipment.values()): self.assertTrue(artifact.integrity < artifact.max_integrity)
class RestActionTest(UseAbilityTaskMixin, testcase.TestCase): PROCESSOR = Help def setUp(self): super(RestActionTest, self).setUp() create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.action_rest = ActionRestPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_rest.leader, True) self.assertEqual(self.action_rest.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_processed(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_not_ready(self): self.hero.health = 1 self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_rest) self.assertTrue(self.hero.health > 1) self.storage._test_save() def test_ability_heal(self): self.hero.health = 1 old_percents = self.action_rest.percents ability = self.PROCESSOR() with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL): self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage))) self.assertTrue(self.hero.health > 1) self.assertTrue(old_percents < self.action_rest.percents) self.assertEqual(self.hero.actions.current_action.percents, self.action_rest.percents) def test_ability_heal__healed(self): self.hero.health = self.hero.max_health - 1 ability = self.PROCESSOR() with mock.patch('the_tale.game.actions.prototypes.ActionBase.get_help_choice', lambda x: HELP_CHOICES.HEAL): self.assertTrue(ability.use(**self.use_attributes(hero=self.hero, storage=self.storage))) self.assertEqual(self.hero.health, self.hero.max_health) self.assertTrue(self.action_rest.percents, 1) self.assertEqual(self.action_rest.state, self.action_rest.STATE.PROCESSED) def test_full(self): self.hero.health = 1 current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.assertEqual(self.hero.health, self.hero.max_health) self.storage._test_save()
class TradingActionTest(testcase.TestCase): def setUp(self): super(TradingActionTest, 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.action_idl = self.hero.actions.current_action self.action_trade = ActionTradingPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_trade.leader, True) self.assertEqual(self.action_trade.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_processed(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_sell_and_finish(self): old_money_statistics = self.hero.statistics.money_earned old_money = self.hero.money artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.action_trade.percents_barier = 1 self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertTrue(self.hero.money > old_money) self.assertTrue( self.hero.statistics.money_earned > old_money_statistics) self.storage._test_save() def test_sell_and_continue(self): old_money = self.hero.money artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.assertEqual(self.hero.bag.occupation, 2) self.action_trade.percents_barier = 2 current_time = TimePrototype.get_current_time() self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_trade) self.assertEqual(self.hero.bag.occupation, 1) self.assertTrue(self.hero.money > old_money) old_money = self.hero.money current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.bag.occupation, 0) self.assertTrue(self.hero.money > old_money) self.storage._test_save() def test_stop_when_quest_required_replane(self): self.action_idl.percents = 0.0 self.assertFalse(self.action_trade.replane_required) artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.action_trade.percents_barier = 2 self.assertEqual(self.hero.bag.occupation, 2) current_time = TimePrototype.get_current_time() self.storage.process_turn() self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_trade) self.action_trade.replane_required = True current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.action_trade.state, self.action_trade.STATE.PROCESSED) self.assertEqual(self.hero.actions.current_action, self.action_idl)
class QuestActionTests(testcase.TestCase): def setUp(self): super(QuestActionTests, self).setUp() create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.action_quest = prototypes.ActionQuestPrototype.create( hero=self.hero) def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_quest.leader, True) self.assertEqual(self.action_quest.state, self.action_quest.STATE.SEARCHING) self.assertEqual(self.action_quest.bundle_id, self.action_idl.bundle_id) self.assertFalse(self.hero.quests.has_quests) self.storage._test_save() def test_setup_quest(self): quests_helpers.setup_quest(self.hero) self.assertEqual(self.action_quest.state, self.action_quest.STATE.PROCESSING) self.assertTrue(self.hero.quests.has_quests) self.storage._test_save() def test_one_step(self): self.storage.process_turn() # quest can create new action on first step self.assertTrue(2 <= len(self.hero.actions.actions_list) <= 3) self.storage._test_save() def test_step_with_no_quest(self): quests_helpers.setup_quest(self.hero) self.hero.quests.pop_quest() self.storage.process_turn() self.assertEqual(self.action_idl.leader, True) def test_need_equipping(self): with mock.patch('the_tale.game.heroes.objects.Hero.need_equipping', lambda hero: True): self.storage.process_turn() self.assertEqual(self.action_quest.state, self.action_quest.STATE.EQUIPPING) self.assertTrue(self.hero.actions.current_action.TYPE.is_EQUIPPING) self.storage.process_turn() self.assertEqual(self.action_quest.state, self.action_quest.STATE.EQUIPPING) self.assertTrue(self.hero.actions.current_action.TYPE.is_QUEST) self.storage.process_turn() self.assertEqual(self.action_quest.state, self.action_quest.STATE.PROCESSING) def test_full_quest(self): # just test that quest will be ended while not self.action_idl.leader: self.storage.process_turn() turn.increment() self.storage._test_save() self.assertFalse(self.hero.quests.has_quests)
class BattlePvE1x1ActionTest(testcase.TestCase): 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 tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_battle.leader, True) self.assertEqual(self.action_battle.bundle_id, self.action_idl.bundle_id) self.assertEqual(self.action_battle.percents, 0.0) self.assertEqual(self.action_battle.state, self.action_battle.STATE.BATTLE_RUNNING) self.storage._test_save() @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_mob_killed(self): self.assertEqual(self.hero.statistics.pve_kills, 0) self.action_battle.mob.health = 0 self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.statistics.pve_kills, 1) self.storage._test_save() @mock.patch('the_tale.game.balance.constants.ARTIFACTS_PER_BATTLE', 0) @mock.patch('the_tale.game.balance.constants.GET_LOOT_PROBABILITY', 1) @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_loot(self): self.assertEqual(self.hero.statistics.loot_had, 0) self.assertEqual(len(self.hero.bag.items()), 0) self.action_battle.mob.health = 0 self.storage.process_turn() self.assertEqual(self.hero.statistics.loot_had, 1) self.assertEqual(len(self.hero.bag.items()), 1) self.storage._test_save() @mock.patch('the_tale.game.balance.constants.ARTIFACTS_PER_BATTLE', 1) @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_artifacts(self): self.assertEqual(self.hero.statistics.artifacts_had, 0) self.assertEqual(len(self.hero.bag.items()), 0) self.action_battle.mob.health = 0 self.storage.process_turn() self.assertEqual(self.hero.statistics.artifacts_had, 1) self.assertEqual(len(self.hero.bag.items()), 1) self.storage._test_save() @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_hero_killed(self): self.assertEqual(self.hero.statistics.pve_deaths, 0) self.hero.health = 0 self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertTrue(not self.hero.is_alive) self.assertEqual(self.hero.statistics.pve_deaths, 1) self.storage._test_save() @mock.patch('the_tale.game.balance.constants.ARTIFACTS_PER_BATTLE', 1) @mock.patch('the_tale.game.actions.prototypes.battle.make_turn', lambda a, b, c: None) def test_hero_and_mob_killed(self): self.hero.health = 0 self.action_battle.mob.health = 0 with self.check_not_changed( lambda: self.hero.statistics.artifacts_had): with self.check_not_changed(lambda: self.hero.bag.occupation): self.storage.process_turn(continue_steps_if_needed=False) self.assertTrue(self.hero.messages.messages[-1].key. is_ACTION_BATTLEPVE1X1_JOURNAL_HERO_AND_MOB_KILLED) self.assertTrue(self.hero.diary.messages[-1].key. is_ACTION_BATTLEPVE1X1_DIARY_HERO_AND_MOB_KILLED) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertTrue(not self.hero.is_alive) self.assertEqual(self.hero.statistics.pve_deaths, 1) self.storage._test_save() def test_full_battle(self): current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn() current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() def test_full_battle__with_companion(self): battle_ability = random.choice([ ability for ability in effects.ABILITIES.records if isinstance(ability.effect, effects.BaseBattleAbility) ]) companion_record = companions_storage.companions.enabled_companions( ).next() companion_record.abilities = container.Container( start=(battle_ability, )) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.hero.reset_accessors_cache() current_time = TimePrototype.get_current_time() while len(self.hero.actions.actions_list) != 1: self.storage.process_turn() current_time.increment_turn() self.assertTrue(self.action_idl.leader) self.storage._test_save() @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.companion_damage_probability', 0.0) @mock.patch( 'the_tale.game.balance.constants.COMPANIONS_WOUNDS_IN_HOUR_FROM_HEAL', 0.0) @mock.patch( 'the_tale.game.balance.constants.COMPANIONS_EATEN_CORPSES_PER_BATTLE', 1.0) @mock.patch('the_tale.game.mobs.prototypes.MobPrototype.mob_type', mobs_relations.MOB_TYPE.ANIMAL) @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.can_companion_eat_corpses', lambda hero: True) def test_full_battle__with_companion__eat_corpse(self): companion_record = companions_storage.companions.enabled_companions( ).next() self.hero.set_companion( companions_logic.create_companion(companion_record)) self.hero.reset_accessors_cache() self.hero.companion.health = 10 current_time = TimePrototype.get_current_time() while self.hero.actions.current_action.TYPE == ActionBattlePvE1x1Prototype.TYPE: self.storage.process_turn(continue_steps_if_needed=False) current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.companion.health, 10 + c.COMPANIONS_EATEN_CORPSES_HEAL_AMOUNT) self.storage._test_save() def test_bit_mob(self): old_mob_health = self.action_battle.mob.health old_action_percents = self.action_battle.percents self.action_battle.bit_mob(0.33) self.assertTrue(self.action_battle.mob.health < old_mob_health) self.assertTrue(self.action_battle.percents > old_action_percents) self.assertTrue(self.action_battle.updated) def test_bit_mob_and_kill(self): self.action_battle.bit_mob(1) self.assertEqual(self.action_battle.mob.health, 0) self.assertEqual(self.action_battle.percents, 1) self.assertTrue(self.action_battle.updated) self.assertEqual(self.action_battle.state, self.action_battle.STATE.PROCESSED) def test_fast_resurrect__not_processed(self): self.action_battle.hero.kill() self.assertFalse(self.action_battle.fast_resurrect()) self.assertFalse(self.action_battle.hero.is_alive) def test_fast_resurrect__hero_is_alive(self): self.action_battle.state = self.action_battle.STATE.PROCESSED self.assertFalse(self.action_battle.fast_resurrect()) self.assertTrue(self.action_battle.hero.is_alive) def test_fast_resurrect__success(self): self.action_battle.hero.kill() self.action_battle.state = self.action_battle.STATE.PROCESSED self.assertTrue(self.action_battle.fast_resurrect()) self.assertTrue(self.action_battle.hero.is_alive) def test_help_choices(self): self.assertTrue( HELP_CHOICES.LIGHTING in self.action_battle.HELP_CHOICES) self.action_battle.mob.health = 0 self.assertFalse( HELP_CHOICES.LIGHTING in self.action_battle.HELP_CHOICES) self.action_battle.mob.health = 1 self.action_battle.hero.kill() self.assertEqual(self.action_battle.HELP_CHOICES, set((HELP_CHOICES.RESURRECT, ))) @mock.patch( 'the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 1.01) @mock.patch('the_tale.game.heroes.habits.Honor.interval', HABIT_HONOR_INTERVAL.LEFT_3) def test_kill_before_start(self): self.hero.actions.pop_action() with self.check_delta(lambda: self.hero.statistics.pve_kills, 1): 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) @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.can_companion_do_exorcism', lambda hero: True) def test_companion_exorcims__demon(self): self.companion_record = companions_logic.create_random_companion_record( 'exorcist', state=companions_relations.STATE.ENABLED) self.hero.set_companion( companions_logic.create_companion(self.companion_record)) demon_record = mobs_prototypes.MobRecordPrototype.create_random( 'demon', type=mobs_relations.MOB_TYPE.DEMON) demon = mobs_prototypes.MobPrototype(record_id=demon_record.id, level=self.hero.level, is_boss=False) self.hero.actions.pop_action() with self.check_delta(lambda: self.hero.statistics.pve_kills, 1): action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=demon) 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) @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.can_companion_do_exorcism', lambda hero: True) def test_companion_exorcims__not_demon(self): self.companion_record = companions_logic.create_random_companion_record( 'exorcist', state=companions_relations.STATE.ENABLED) self.hero.set_companion( companions_logic.create_companion(self.companion_record)) not_demon_record = mobs_prototypes.MobRecordPrototype.create_random( 'demon', type=mobs_relations.MOB_TYPE.random( exclude=(mobs_relations.MOB_TYPE.DEMON, ))) not_demon = mobs_prototypes.MobPrototype(record_id=not_demon_record.id, level=self.hero.level, is_boss=False) self.hero.actions.pop_action() with self.check_delta(lambda: self.hero.statistics.pve_kills, 0): action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=not_demon) self.assertEqual(action_battle.percents, 0.0) self.assertEqual(action_battle.state, self.action_battle.STATE.BATTLE_RUNNING) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action, action_battle) @mock.patch('the_tale.game.balance.constants.PEACEFULL_BATTLE_PROBABILITY', 1.01) @mock.patch('the_tale.game.heroes.habits.Peacefulness.interval', HABIT_PEACEFULNESS_INTERVAL.RIGHT_3) 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) @mock.patch( 'the_tale.game.heroes.prototypes.HeroPrototype.can_leave_battle_in_fear', lambda self: True) def test_fear_battle(self): self.hero.actions.pop_action() mob = (m for m in mobs_storage.all() if m.type.is_CIVILIZED).next() with self.check_delta(lambda: self.hero.statistics.pve_kills, 0): action_battle = ActionBattlePvE1x1Prototype.create( hero=self.hero, mob=mob.create_mob(self.hero, is_boss=False)) 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) @mock.patch('the_tale.game.balance.constants.EXP_FOR_KILL_PROBABILITY', 1.01) @mock.patch('the_tale.game.balance.constants.EXP_FOR_KILL_DELTA', 0) @mock.patch('the_tale.game.heroes.habits.Peacefulness.interval', HABIT_PEACEFULNESS_INTERVAL.LEFT_3) 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.prototypes.HeroPrototype.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) @mock.patch('the_tale.game.balance.constants.ARTIFACTS_BREAKS_PER_BATTLE', 1.0) @mock.patch( 'the_tale.game.artifacts.prototypes.ArtifactPrototype.can_be_broken', lambda self: True) def test_process_artifact_breaking__no_equipment(self): self.hero.equipment._remove_all() old_power = self.hero.power.clone() self.action_battle.process_artifact_breaking() self.assertEqual(old_power, self.hero.power) @mock.patch('the_tale.game.balance.constants.ARTIFACTS_BREAKS_PER_BATTLE', 1.0) @mock.patch( 'the_tale.game.artifacts.prototypes.ArtifactPrototype.can_be_broken', lambda self: True) def test_process_artifact_breaking__broken(self): for artifact in self.hero.equipment.values(): artifact.power = Power(100, 100) old_power = self.hero.power.total() self.action_battle.process_artifact_breaking() self.assertTrue(old_power > self.hero.power.total()) @mock.patch('the_tale.game.balance.constants.ARTIFACTS_BREAKS_PER_BATTLE', 1.0) @mock.patch( 'the_tale.game.artifacts.prototypes.ArtifactPrototype.can_be_broken', lambda self: False) def test_process_artifact_breaking__not_broken(self): for artifact in self.hero.equipment.values(): artifact.power = Power(100, 100) old_power = self.hero.power.total() self.action_battle.process_artifact_breaking() self.assertEqual(old_power, self.hero.power.total()) @mock.patch('the_tale.game.balance.constants.ARTIFACTS_BREAKS_PER_BATTLE', 1.0) @mock.patch( 'the_tale.game.artifacts.prototypes.ArtifactPrototype.can_be_broken', lambda self: False) def test_process_artifact_breaking__break_only_mostly_damaged(self): for artifact in self.hero.equipment.values(): artifact.power = Power(100, 100) artifact.integrity = 0 artifact.integrity = artifact.max_integrity for i in xrange(100): self.action_battle.process_artifact_breaking() self.assertEqual(artifact.power, Power(100, 100)) def test_process_artifact_breaking__integrity_damage(self): for artifact in self.hero.equipment.values(): artifact.integrity = artifact.max_integrity self.action_battle.process_artifact_breaking() for artifact in self.hero.equipment.values(): self.assertEqual(artifact.integrity, artifact.max_integrity - 1)
class ActionEquippingTest(testcase.TestCase): def setUp(self): super(ActionEquippingTest, self).setUp() create_test_map() account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.action_equipping = ActionEquippingPrototype.create(hero=self.hero) def tearDown(self): pass def test_create(self): self.assertEqual(self.action_idl.leader, False) self.assertEqual(self.action_equipping.leader, True) self.assertEqual(self.action_equipping.bundle_id, self.action_idl.bundle_id) self.storage._test_save() def test_processed(self): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save() def test_equip(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) artifact.power = Power(666, 666) equip_slot = artifact.type.equipment_slot self.hero.equipment.unequip(equip_slot) self.hero.bag.put_artifact(artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_equipping) self.assertEqual(len(list(self.hero.bag.items())), 0) equip_slot = artifact.type.equipment_slot self.assertEqual(self.hero.equipment.get(equip_slot), artifact) self.storage._test_save() def test_switch_artifact(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) artifact.power = Power(13, 13) equip_slot = artifact.type.equipment_slot self.hero.equipment.unequip(equip_slot) self.hero.equipment.equip(equip_slot, artifact) new_artifact = artifacts_storage.generate_artifact_from_list([artifact.record], self.hero.level+1, rarity=RARITY.NORMAL) new_artifact.power = Power(666, 666) self.hero.bag.put_artifact(new_artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_equipping) self.assertEqual(len(list(self.hero.bag.items())), 1) self.assertEqual(list(self.hero.bag.items())[0][1].power, Power(13, 13)) equip_slot = artifact.type.equipment_slot self.assertEqual(self.hero.equipment.get(equip_slot), new_artifact) self.assertEqual(self.hero.equipment.get(equip_slot).power, Power(666, 666)) current_time = TimePrototype.get_current_time() current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save()