def _fight(self, action): from the_tale.game.actions.prototypes import ActionBattlePvE1x1Prototype if action.mob is not None: mob = mobs_storage[self.knowledge_base[action.mob].externals["id"]].create_mob(self.hero, is_boss=True) else: mob = mobs_storage.get_random_mob(self.hero, mercenary=action.mercenary, is_boss=True) if mob is None: mobs_storage.get_random_mob(self.hero, is_boss=True) ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mob)
def setUp(self): super(BattlePvE1x1ActionTest, self).setUp() create_test_map() result, account_id, bundle_id = register_user('test_user') self.storage = LogicStorage() self.storage.load_account_data(AccountPrototype.get_by_id(account_id)) self.hero = self.storage.accounts_to_heroes[account_id] self.hero._model.level = 6 self.hero.health = self.hero.max_health # do half of tests with companion if random.random() < 0.5: companion_record = companions_storage.companions.enabled_companions( ).next() companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.hero.companion.health = 1 self.action_idl = self.hero.actions.current_action with mock.patch( 'the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 0): self.action_battle = ActionBattlePvE1x1Prototype.create( hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero))
def test_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)
def setUp(self): super(BattlePvE1x1ActionTest, self).setUp() create_test_map() account = self.accounts_factory.create_account() self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.hero.level = 6 self.hero.health = self.hero.max_health # do half of tests with companion if random.random() < 0.5: companion_record = next(companions_storage.companions.enabled_companions()) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.hero.companion.health = 1 self.action_idl = self.hero.actions.current_action with mock.patch('the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 0): self.action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero))
def test_use(self): from the_tale.game.actions.prototypes import ActionBattlePvE1x1Prototype from the_tale.game.mobs.storage import mobs_storage with mock.patch('the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 0): ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) self.assertTrue(self.hero.actions.current_action.TYPE.is_BATTLE_PVE_1X1) self.assertTrue(self.hero.actions.current_action.mob.health > 0) self.assertTrue(self.hero.actions.current_action.percents < 1) result, step, postsave_actions = self.card.use(**self.use_attributes(storage=self.storage, hero=self.hero)) self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertTrue(self.hero.actions.current_action.mob.health <= 0) self.assertEqual(self.hero.actions.current_action.percents, 1)
def _fight(self, action): from the_tale.game.actions.prototypes import ActionBattlePvE1x1Prototype if action.mob is not None: mob = mobs_storage.mobs[self.knowledge_base[ action.mob].externals['id']].create_mob(self.hero, is_boss=True) else: mob = mobs_storage.mobs.get_random_mob(self.hero, mercenary=action.mercenary, is_boss=True) if mob is None: mobs_storage.mobs.get_random_mob(self.hero, is_boss=True) ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mob)
def test_peacefull_battle(self): self.hero.actions.pop_action() with self.check_delta(lambda: self.hero.statistics.pve_kills, 0): action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) self.assertEqual(action_battle.percents, 1.0) self.assertEqual(action_battle.state, self.action_battle.STATE.PROCESSED) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action, self.action_idl)
def test_experience_for_kill(self): mob = mobs_storage.create_mob_for_hero(self.hero) mob.health = 0 with self.check_delta(lambda: self.hero.statistics.pve_kills, 1): with mock.patch('the_tale.game.heroes.objects.Hero.add_experience') as add_experience: with mock.patch('the_tale.game.actions.prototypes.ActionBattlePvE1x1Prototype.process_artifact_breaking') as process_artifact_breaking: action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mob) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(add_experience.call_args_list, [mock.call(c.EXP_FOR_KILL)]) self.assertEqual(process_artifact_breaking.call_count, 1) self.assertEqual(action_battle.state, self.action_battle.STATE.PROCESSED)
def test_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)
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)
def test_use(self): from the_tale.game.actions.prototypes import ActionBattlePvE1x1Prototype from the_tale.game.mobs.storage import mobs_storage with mock.patch( 'the_tale.game.balance.constants.KILL_BEFORE_BATTLE_PROBABILITY', 0): ActionBattlePvE1x1Prototype.create( hero=self.hero, mob=mobs_storage.create_mob_for_hero(self.hero)) self.assertTrue( self.hero.actions.current_action.TYPE.is_BATTLE_PVE_1X1) self.assertTrue(self.hero.actions.current_action.mob.health > 0) self.assertTrue(self.hero.actions.current_action.percents < 1) result, step, postsave_actions = self.card.use( **self.use_attributes(storage=self.storage, hero=self.hero)) self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertTrue(self.hero.actions.current_action.mob.health <= 0) self.assertEqual(self.hero.actions.current_action.percents, 1)
def test_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)
def check_companion_exorcims(self, mob_type): 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)) mob_record = mobs_logic.create_random_mob_record('demon', type=mob_type) mob = mobs_objects.Mob(record_id=mob_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=mob) 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)