def setUp(self): super(BaseEffectsTests, 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 = logic.create_companion_record(utg_name=names.generator().get_test_name(), description='description', type=game_relations.BEING_TYPE.random(), max_health=10, dedication=relations.DEDICATION.random(), archetype=game_relations.ARCHETYPE.random(), mode=relations.MODE.random(), abilities=abilities_container.Container(), communication_verbal=game_relations.COMMUNICATION_VERBAL.random(), communication_gestures=game_relations.COMMUNICATION_GESTURES.random(), communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.random(), intellect_level=game_relations.INTELLECT_LEVEL.random(), state=relations.STATE.ENABLED) self.hero.set_companion(logic.create_companion(self.companion_record))
def test_create_companion(self): companion_record = logic.create_companion_record(utg_name=names.generator().get_test_name(), description='description', type=beings_relations.TYPE.random(), max_health=10, dedication=relations.DEDICATION.random(), archetype=game_relations.ARCHETYPE.random(), mode=relations.MODE.random(), abilities=helpers.FAKE_ABILITIES_CONTAINER_1, communication_verbal=beings_relations.COMMUNICATION_VERBAL.random(), communication_gestures=beings_relations.COMMUNICATION_GESTURES.random(), communication_telepathic=beings_relations.COMMUNICATION_TELEPATHIC.random(), intellect_level=beings_relations.INTELLECT_LEVEL.random(), structure=beings_relations.STRUCTURE.random(), features=frozenset((beings_relations.FEATURE.random(), beings_relations.FEATURE.random())), movement=beings_relations.MOVEMENT.random(), body=beings_relations.BODY.random(), size=beings_relations.SIZE.random(), weapons=[artifacts_objects.Weapon(weapon=artifacts_relations.STANDARD_WEAPON.random(), material=tt_artifacts_relations.MATERIAL.random(), power_type=artifacts_relations.ARTIFACT_POWER_TYPE.random())], state=relations.STATE.ENABLED) companion = logic.create_companion(companion_record) self.assertEqual(companion.record.id, companion_record.id) self.assertEqual(companion.health, companion_record.max_health) self.assertEqual(companion.coherence, 0)
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() 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_death_speed(self): companion_record = logic.create_random_companion_record( 'test companion', state=relations.STATE.ENABLED, dedication=relations.DEDICATION.BRAVE) #,#,; companion = logic.create_companion(companion_record) self.hero.set_companion(companion) self.hero.preferences.set_companion_dedication( heroes_relations.COMPANION_DEDICATION.NORMAL) old_health = self.hero.companion.health while self.hero.companion: self.hero.companion.coherence = 50 self.storage.process_turn() turn.increment() self.hero.randomized_level_up() if not self.hero.is_alive: if hasattr(self.hero.actions.current_action, 'fast_resurrect'): self.hero.actions.current_action.fast_resurrect() if self.hero.companion: old_health = self.hero.companion.health
def process_rare_operations(self): from the_tale.accounts.achievements.storage import achievements_storage from the_tale.accounts.achievements.relations import ACHIEVEMENT_TYPE from the_tale.game.companions import storage as companions_storage from the_tale.game.companions import logic as companions_logic current_turn = TimePrototype.get_current_turn_number() passed_interval = current_turn - self.last_rare_operation_at_turn if passed_interval < heroes_settings.RARE_OPERATIONS_INTERVAL: return if self.companion is None and random.random( ) < float(passed_interval ) / c.TURNS_IN_HOUR / c.COMPANIONS_GIVE_COMPANION_AFTER: companions_choices = [ companion for companion in companions_storage.companions.enabled_companions() if any(ability.effect.TYPE.is_LEAVE_HERO for ability in companion.abilities.start) ] if companions_choices: self.set_companion( companions_logic.create_companion( random.choice(companions_choices))) self.quests.sync_interfered_persons() with achievements_storage.verify(type=ACHIEVEMENT_TYPE.TIME, object=self): self.last_rare_operation_at_turn = current_turn
def test_help_choice_has_heal_companion__for_full_health_with_alternative( self): companion_record = next( companions_storage.companions.enabled_companions()) self.hero.set_companion( companions_logic.create_companion(companion_record)) self.check_heal_companion_in_choices(False)
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 setUp(self): super(BaseEffectsTests, 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 = logic.create_companion_record(utg_name=names.generator().get_test_name(), description='description', type=beings_relations.TYPE.random(), max_health=10, dedication=relations.DEDICATION.random(), archetype=game_relations.ARCHETYPE.random(), mode=relations.MODE.random(), abilities=abilities_container.Container(), communication_verbal=beings_relations.COMMUNICATION_VERBAL.random(), communication_gestures=beings_relations.COMMUNICATION_GESTURES.random(), communication_telepathic=beings_relations.COMMUNICATION_TELEPATHIC.random(), intellect_level=beings_relations.INTELLECT_LEVEL.random(), structure=beings_relations.STRUCTURE.random(), features=frozenset((beings_relations.FEATURE.random(), beings_relations.FEATURE.random())), movement=beings_relations.MOVEMENT.random(), body=beings_relations.BODY.random(), size=beings_relations.SIZE.random(), weapons=[artifacts_objects.Weapon(weapon=artifacts_relations.STANDARD_WEAPON.random(), material= tt_artifacts_relations.MATERIAL.random(), power_type=artifacts_relations.ARTIFACT_POWER_TYPE.random())], state=relations.STATE.ENABLED) self.hero.set_companion(logic.create_companion(self.companion_record))
def test_politics_power_multiplier__all_effects(self): with self.check_increased(self.hero.politics_power_multiplier): self.hero.might = 1000 with self.check_increased(self.hero.politics_power_multiplier): self.hero.level = 100 with self.check_increased(self.hero.politics_power_multiplier): self.hero.actual_bills.append(time.time()) self.hero.actual_bills.append(time.time()) with self.check_increased(self.hero.politics_power_multiplier): self.hero.preferences.set_risk_level(relations.RISK_LEVEL.VERY_HIGH) with self.check_increased(self.hero.politics_power_multiplier): self.hero.equipment.get(relations.EQUIPMENT_SLOT.PLATE).record.special_effect = artifacts_relations.ARTIFACT_EFFECT.GREAT_POWER with self.check_increased(self.hero.politics_power_multiplier): companion_record = companions_logic.create_random_companion_record(name='test-companion', state=companions_relations.STATE.ENABLED, abilities=companions_abilities_container.Container(start=(companions_effects.ABILITIES.KNOWN,))) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) with self.check_increased(self.hero.politics_power_multiplier): self.hero.abilities.add(nonbattle_abilities.DIPLOMATIC.get_id(), level=len(nonbattle_abilities.DIPLOMATIC.POWER_MULTIPLIER))
def setUp(self): super(InPlaceActionCompanionLeaveTests, self).setUp() self.place_1, self.place_2, self.place_3 = 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.companion_record = companions_logic.create_random_companion_record('thief', state=companions_relations.STATE.ENABLED) self.hero.set_companion(companions_logic.create_companion(self.companion_record)) self.hero.money = f.expected_gold_in_day(self.hero.level) self.hero.position.set_place(self.place_1) self.hero.position.update_previous_place() self.hero.position.set_place(self.place_2) self.artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.loot, 1, rarity=RARITY.NORMAL) self.hero.put_loot(self.artifact) self.assertEqual(self.hero.bag.occupation, 1) self.hero.position.move_out_place()
def test_politics_power_multiplier__all_effects(self): with self.check_increased(self.hero.politics_power_multiplier): self.hero.might = 1000 with self.check_increased(self.hero.politics_power_multiplier): self.hero._model.level = 100 with self.check_increased(self.hero.politics_power_multiplier): self.hero.actual_bills.append(time.time()) self.hero.actual_bills.append(time.time()) with self.check_increased(self.hero.politics_power_multiplier): self.hero.preferences.set_risk_level( relations.RISK_LEVEL.VERY_HIGH) with self.check_increased(self.hero.politics_power_multiplier): self.hero.equipment.get( relations.EQUIPMENT_SLOT.PLATE ).record.special_effect = artifacts_relations.ARTIFACT_EFFECT.GREAT_POWER with self.check_increased(self.hero.politics_power_multiplier): companion_record = companions_logic.create_random_companion_record( name='test-companion', state=companions_relations.STATE.ENABLED, abilities=companions_abilities_container.Container( start=(companions_effects.ABILITIES.KNOWN, ))) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) with self.check_increased(self.hero.politics_power_multiplier): self.hero.abilities.add( nonbattle_abilities.DIPLOMATIC.get_id(), level=len(nonbattle_abilities.DIPLOMATIC.POWER_MULTIPLIER))
def setUp(self): super(CompanionTests, 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 = logic.create_companion_record( utg_name=names.generator.get_test_name(), description='description', type=game_relations.BEING_TYPE.random(), max_health=10, dedication=relations.DEDICATION.random(), archetype=game_relations.ARCHETYPE.random(), mode=relations.MODE.random(), abilities=abilities_container.Container(), communication_verbal=game_relations.COMMUNICATION_VERBAL.random(), communication_gestures=game_relations.COMMUNICATION_GESTURES. random(), communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC. random(), intellect_level=game_relations.INTELLECT_LEVEL.random(), state=relations.STATE.ENABLED) self.hero.set_companion(logic.create_companion(self.companion_record)) self.companion = self.hero.companion
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()
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)
def test_companion_coherence_speed__companion_alive(self): companion_record = next(companions_storage.companions.enabled_companions()) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.assertFalse(self.hero.companion.is_dead) self.assertGreater(self.hero.companion_coherence_speed, 0)
def set_heroes_companion(hero_1, hero_2): from the_tale.game.companions import storage from the_tale.game.companions import models from the_tale.game.companions import logic COMPANION_NAME = u'test_hero_battle_companion' for companion in storage.companions.all(): if companion.name.startswith(COMPANION_NAME): models.CompanionRecord.objects.filter(id=companion.id).delete() storage.companions.refresh() break companion_record = logic.create_random_companion_record(COMPANION_NAME) hero_1.set_companion(logic.create_companion(companion_record)) hero_2.set_companion(logic.create_companion(companion_record))
def set_heroes_companion(hero_1, hero_2): from the_tale.game.companions import storage from the_tale.game.companions import models from the_tale.game.companions import logic COMPANION_NAME = 'test_hero_battle_companion' for companion in storage.companions.all(): if companion.name.startswith(COMPANION_NAME): models.CompanionRecord.objects.filter(id=companion.id).delete() storage.companions.refresh() break companion_record = logic.create_random_companion_record(COMPANION_NAME) hero_1.set_companion(logic.create_companion(companion_record)) hero_2.set_companion(logic.create_companion(companion_record))
def use(self, task, storage, **kwargs): # pylint: disable=R0911,W0613 card = task.hero.cards.get_card(task.data['card_uid']) companion = companions_logic.create_companion(companions_storage.companions[card.data['companion_id']]) task.hero.set_companion(companion) return task.logic_result(message=u'Поздравляем! Ваш герой получил нового спутника.')
def test_companion_coherence_speed__companion_dead(self): companion_record = next(companions_storage.companions.enabled_companions()) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.hero.companion.health = 0 self.assertTrue(self.hero.companion.is_dead) self.assertEqual(self.hero.companion_coherence_speed, 0)
def test_use__has_companion(self): old_companion_record = random.choice(companions_storage.companions.all()) self.hero.set_companion(companions_logic.create_companion(old_companion_record)) result, step, postsave_actions = self.effect.use(**self.use_attributes(storage=self.storage, hero=self.hero, card_uid=self.card.uid)) self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertEqual(self.hero.companion, None)
def use(self, task, storage, **kwargs): # pylint: disable=R0911,W0613 card = task.hero.cards.get_card(task.data['card_uid']) companion = companions_logic.create_companion( companions_storage.companions[card.data['companion_id']]) task.hero.set_companion(companion) return task.logic_result( message=u'Поздравляем! Ваш герой получил нового спутника.')
def test_companion_damage__bonus_damage__damage_from_heal(self): companion_record = companions_storage.companions.enabled_companions().next() companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) with mock.patch('the_tale.game.balance.constants.COMPANIONS_BONUS_DAMAGE_PROBABILITY', 666666): with mock.patch('the_tale.game.heroes.objects.Hero.companion_damage_probability', 0): with mock.patch('the_tale.game.heroes.objects.Hero.attribute_modifier', lambda s, t: 666 if t.is_COMPANION_DAMAGE else t.default()): for i in xrange(1000): self.assertEqual(self.hero.companion_damage, c.COMPANIONS_DAMAGE_PER_WOUND)
def test_companion_damage__bonus_damage__damage_from_heal(self): companion_record = next(companions_storage.companions.enabled_companions()) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) with mock.patch('the_tale.game.balance.constants.COMPANIONS_BONUS_DAMAGE_PROBABILITY', 666666): with mock.patch('the_tale.game.heroes.objects.Hero.companion_damage_probability', 0): with mock.patch('the_tale.game.heroes.objects.Hero.attribute_modifier', lambda s, t: 666 if t.is_COMPANION_DAMAGE else t.default()): for i in range(1000): self.assertEqual(self.hero.companion_damage, c.COMPANIONS_DAMAGE_PER_WOUND)
def test_heal_companion__on_heal_called(self): companion_record = companions_storage.companions.enabled_companions().next() self.hero.set_companion(companions_logic.create_companion(companion_record)) self.hero.companion.health = 1 with mock.patch('the_tale.game.actions.prototypes.ActionBase.on_heal_companion') as on_heal_companion: self.assertEqual(self.ability.use(**self.use_attributes), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertEqual(on_heal_companion.call_count, 1)
def test_witchcraft(self): self.assertEqual(companions.WITCHCRAFT().modify_attribute(MODIFIERS.COMPANION_UNUSUAL_HEAL, 0), 0.0462962962962963) self.assertEqual(companions.WITCHCRAFT().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_UNUSUAL_HEAL,)), 0), 0) companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', game_relations.BEING_TYPE.SUPERNATURAL): self.assertEqual(self.hero.companion_heal_probability, 0) self.hero.abilities.add(companions.WITCHCRAFT.get_id(), 3) self.assertEqual(self.hero.companion_heal_probability, 0.1388888888888889)
def test_healing(self): self.assertEqual(companions.HEALING().modify_attribute(MODIFIERS.COMPANION_LIVING_HEAL, 0), 0.0462962962962963) self.assertEqual(companions.HEALING().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_LIVING_HEAL,)), 0), 0) companion_record = companions_storage.companions.enabled_companions().next() self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', game_relations.BEING_TYPE.ANIMAL): self.assertEqual(self.hero.companion_heal_probability, 0) self.hero.abilities.add(companions.HEALING.get_id(), 3) self.assertEqual(self.hero.companion_heal_probability, 0.1388888888888889)
def test_service(self): self.assertEqual(companions.SERVICE().modify_attribute(MODIFIERS.COMPANION_CONSTRUCT_COHERENCE_SPEED, 1), 1.2) self.assertEqual(companions.SERVICE().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_CONSTRUCT_COHERENCE_SPEED,)), 1), 1) companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', game_relations.BEING_TYPE.MECHANICAL): self.assertEqual(self.hero.companion_coherence_speed, 1) self.hero.abilities.add(companions.SERVICE.get_id(), 3) self.assertEqual(self.hero.companion_coherence_speed, 1.6)
def use(self, task, storage, **kwargs): # pylint: disable=R0911,W0613 card = objects.Card.deserialize(uuid.UUID(task.data['card']['id']), task.data['card']['data']) companion = companions_logic.create_companion( companions_storage.companions[card.data['companion_id']]) task.hero.set_companion(companion) return task.logic_result( message='Поздравляем! Ваш герой получил нового спутника.')
def test_sacredness(self): self.assertEqual(companions.SACREDNESS().modify_attribute(MODIFIERS.COMPANION_UNUSUAL_COHERENCE_SPEED, 1), 1.2) self.assertEqual(companions.SACREDNESS().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_UNUSUAL_COHERENCE_SPEED,)), 1), 1) companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', game_relations.BEING_TYPE.SUPERNATURAL): self.assertEqual(self.hero.companion_coherence_speed, 1) self.hero.abilities.add(companions.SACREDNESS.get_id(), 3) self.assertEqual(self.hero.companion_coherence_speed, 1.6)
def test_mage_mechanincs(self): self.assertEqual(companions.MAGE_MECHANICS().modify_attribute(MODIFIERS.COMPANION_CONSTRUCT_HEAL, 0), 0.0462962962962963) self.assertEqual(companions.MAGE_MECHANICS().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_CONSTRUCT_HEAL,)), 0), 0) companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', game_relations.BEING_TYPE.MECHANICAL): self.assertEqual(self.hero.companion_heal_probability, 0) self.hero.abilities.add(companions.MAGE_MECHANICS.get_id(), 3) self.assertEqual(self.hero.companion_heal_probability, 0.1388888888888889)
def test_check_attribute(self): companion_record = next(companions_storage.companions.enabled_companions()) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.assertFalse(self.hero.companion.is_dead) with mock.patch('the_tale.game.companions.objects.Companion.check_attribute') as check_attribute: self.hero.check_attribute(relations.MODIFIERS.POWER_TO_ENEMY) self.assertTrue(check_attribute.call_count >= 1)
def test_sociability(self): self.assertEqual(companions.SOCIABILITY().modify_attribute(MODIFIERS.COMPANION_LIVING_COHERENCE_SPEED, 1), 1.2) self.assertEqual(companions.SOCIABILITY().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_LIVING_COHERENCE_SPEED,)), 1), 1) companion_record = companions_storage.companions.enabled_companions().next() self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', game_relations.BEING_TYPE.ANIMAL): self.assertEqual(self.hero.companion_coherence_speed, 1) self.hero.abilities.add(companions.SOCIABILITY.get_id(), 3) self.assertEqual(self.hero.companion_coherence_speed, 1.6)
def test_sacredness(self): self.assertEqual(companions.SACREDNESS().modify_attribute(MODIFIERS.COMPANION_UNUSUAL_COHERENCE_SPEED, 1), 1.2) self.assertEqual(companions.SACREDNESS().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_UNUSUAL_COHERENCE_SPEED,)), 1), 1) companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', beings_relations.TYPE.SUPERNATURAL): self.assertEqual(self.hero.companion_coherence_speed, 1) self.hero.abilities.add(companions.SACREDNESS.get_id(), 3) self.assertEqual(self.hero.companion_coherence_speed, 1.6)
def test_service(self): self.assertEqual(companions.SERVICE().modify_attribute(MODIFIERS.COMPANION_CONSTRUCT_COHERENCE_SPEED, 1), 1.2) self.assertEqual(companions.SERVICE().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_CONSTRUCT_COHERENCE_SPEED,)), 1), 1) companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', beings_relations.TYPE.MECHANICAL): self.assertEqual(self.hero.companion_coherence_speed, 1) self.hero.abilities.add(companions.SERVICE.get_id(), 3) self.assertEqual(self.hero.companion_coherence_speed, 1.6)
def test_mage_mechanincs(self): self.assertEqual(companions.MAGE_MECHANICS().modify_attribute(MODIFIERS.COMPANION_CONSTRUCT_HEAL, 0), 0.11574074074074076) self.assertEqual(companions.MAGE_MECHANICS().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_CONSTRUCT_HEAL,)), 0), 0) companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', beings_relations.TYPE.MECHANICAL): self.assertEqual(self.hero.companion_heal_probability, 0) self.hero.abilities.add(companions.MAGE_MECHANICS.get_id(), 3) self.assertEqual(self.hero.companion_heal_probability, 0.3125)
def test_witchcraft(self): self.assertEqual(companions.WITCHCRAFT().modify_attribute(MODIFIERS.COMPANION_UNUSUAL_HEAL, 0), 0.11574074074074076) self.assertEqual(companions.WITCHCRAFT().modify_attribute(MODIFIERS.random(exclude=(MODIFIERS.COMPANION_UNUSUAL_HEAL,)), 0), 0) companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) with mock.patch('the_tale.game.companions.objects.CompanionRecord.type', beings_relations.TYPE.SUPERNATURAL): self.assertEqual(self.hero.companion_heal_probability, 0) self.hero.abilities.add(companions.WITCHCRAFT.get_id(), 3) self.assertEqual(self.hero.companion_heal_probability, 0.3125)
def test_has_alive_companion(self): companion_record = next( companions_storage.companions.enabled_companions()) companion = companions_logic.create_companion(companion_record) self.hero.set_companion(companion) self.assertTrue(self.hero.has_alive_companion()) self.hero.companion.health = 0 self.assertFalse(self.hero.has_alive_companion())
def test_heal_companion__crit(self): companion_record = companions_storage.companions.enabled_companions().next() self.hero.set_companion(companions_logic.create_companion(companion_record)) self.hero.companion.health = 1 with self.check_delta(lambda: self.hero.companion.health, c.COMPANIONS_HEAL_CRIT_AMOUNT): with self.check_delta(lambda: self.hero.statistics.help_count, 1): self.assertEqual(self.ability.use(**self.use_attributes), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertFalse(self.hero.journal.messages[-1].key.is_ANGEL_ABILITY_HEAL_COMPANION) self.assertTrue(self.hero.journal.messages[-1].key.is_ANGEL_ABILITY_HEAL_COMPANION_CRIT)
def test_heal_companion__full_health(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) with self.check_not_changed(lambda: self.hero.companion.health): with self.check_not_changed(lambda: self.hero.statistics.help_count): self.assertEqual(self.ability.use(**self.use_attributes), (ComplexChangeTask.RESULT.FAILED, ComplexChangeTask.STEP.ERROR, ())) self.assertFalse(self.hero.journal.messages[-1].key.is_ANGEL_ABILITY_HEAL_COMPANION) self.assertFalse(self.hero.journal.messages[-1].key.is_ANGEL_ABILITY_HEAL_COMPANION_CRIT)
def test_teleport_by_teleportator_companion(self): companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) self.assertEqual(self.action_move.state, self.action_move.STATE.CHOOSE_ROAD) with self.check_increased(lambda: self.action_move.percents): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.action_move.state, self.action_move.STATE.IN_CITY) self.assertTrue(any(message.key.is_COMPANIONS_TELEPORT for message in self.hero.journal.messages if message.key is not None))
def test_teleport_by_flying_companion(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_increased(lambda: self.action_move.percents): self.storage.process_turn(continue_steps_if_needed=False) self.assertTrue(self.hero.journal.messages[-1].key.is_COMPANIONS_FLY)
def test_choose_ability__additional_companion_abilities(self): from the_tale.game.heroes.habilities import ABILITIES from the_tale.game.companions.abilities import effects as companions_effects from the_tale.game.companions.abilities import container as abilities_container from the_tale.game.companions import logic as companions_logic from the_tale.game.companions import relations as companions_relations abilities = [ ability for ability in companions_effects.ABILITIES.records if (isinstance(ability.effect, companions_effects.BaseBattleAbility ) and ability.effect.ABILITY.get_id() != 'hit') ] companion_ability = random.choice(abilities) all_abilities = [ ability(level=ability.MAX_LEVEL) for ability in list(ABILITIES.values()) if ability.get_id() != companion_ability.effect.ABILITY.get_id() ] active_abilities = set(ability.get_id() for ability in list(ABILITIES.values()) if ability.ACTIVATION_TYPE.is_ACTIVE) companion_record = companions_logic.create_random_companion_record( 'battle', abilities=abilities_container.Container( start=(companion_ability, )), state=companions_relations.STATE.ENABLED) self.hero.set_companion( companions_logic.create_companion(companion_record)) self.hero.health = 1 # allow regeneration actor = battle.Actor(self.hero, BattleContext()) chosen_abilities = set() # mock abilities modify_attribute instead of hereos, since we test correct work of it def modify_attribute(self, modifier, value): if modifier.is_ADDITIONAL_ABILITIES: return all_abilities return value with mock.patch( 'the_tale.game.heroes.habilities.AbilitiesPrototype.modify_attribute', modify_attribute): for i in range(1000): chosen_abilities.add(actor.choose_ability().get_id()) self.assertEqual(len(active_abilities), len(chosen_abilities) + 1) self.assertEqual( active_abilities - set([companion_ability.effect.ABILITY.get_id()]), chosen_abilities)
def test_use__companion_exists(self): old_companion_record = random.choice([companion for companion in companions_storage.companions.all() if companion.rarity.card_rarity != self.EFFECT.TYPE.rarity]) self.hero.set_companion(companions_logic.create_companion(old_companion_record)) result, step, postsave_actions = self.effect.use(**self.use_attributes(storage=self.storage, hero=self.hero, card_uid=self.card.uid)) self.assertEqual((result, step, postsave_actions), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertEqual(self.hero.companion.record.rarity.card_rarity, self.EFFECT.TYPE.rarity) self.assertNotEqual(self.hero.companion.record.id, old_companion_record.id)
def test_teleport_by_teleportator_companion__not_moving_state(self): companion_record = next(companions_storage.companions.enabled_companions()) self.hero.set_companion(companions_logic.create_companion(companion_record)) self.assertEqual(self.action_move.state, self.action_move.STATE.CHOOSE_ROAD) self.hero.position.set_place(self.p3) # hero in destination with self.check_not_changed(lambda: self.action_move.percents): self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.action_move.state, self.action_move.STATE.PROCESSED) self.assertFalse(self.hero.journal.messages[-1].key.is_COMPANIONS_TELEPORT)
def test_hero_need_heal_companion(self): 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.ActionMoveToPrototype.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.ActionMoveToPrototype.STATE.HEALING_COMPANION) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionMoveToPrototype.TYPE) self.assertEqual(self.hero.actions.current_action.state, prototypes.ActionMoveToPrototype.STATE.HEALING_COMPANION)
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()
def _test_companion_death_speed(self): current_time = game_prototypes.TimePrototype.get_current_time() companion_record = logic.create_random_companion_record( 'test companion', state=relations.STATE.ENABLED, dedication=relations.DEDICATION.BRAVE) #,#,; # abilities=abilities_container.Container(start=(effects.ABILITIES.BODYGUARD,)),# effects.ABILITIES.PUNY)), # dedication=relations.DEDICATION.HEROIC) # abilities=abilities_container.Container(common=(effects.ABILITIES.COWARDLY, )), # dedication=relations.DEDICATION.INDECISIVE) companion = logic.create_companion(companion_record) self.hero.set_companion(companion) # self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.EGOISM) self.hero.preferences.set_companion_dedication( heroes_relations.COMPANION_DEDICATION.NORMAL) # self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.ALTRUISM) # self.hero.preferences.set_companion_dedication(heroes_relations.COMPANION_DEDICATION.EVERY_MAN_FOR_HIMSELF) old_health = self.hero.companion.health print('defend_probability: ', self.hero.companion.defend_in_battle_probability) # for i in xrange(50): # self.hero.randomized_level_up(increment_level=True) while self.hero.companion: self.hero.companion.coherence = 50 self.storage.process_turn() current_time.increment_turn() self.hero.randomized_level_up() if not self.hero.is_alive: if hasattr(self.hero.actions.current_action, 'fast_resurrect'): self.hero.actions.current_action.fast_resurrect() print('!') if self.hero.companion: if old_health != self.hero.companion.health: print( '%.2f:\t%s -> %s [%s] c%s' % ((current_time.turn_number / c.TURNS_IN_HOUR / 24.0), self.hero.companion.health - self.hero.companion.max_health, self.hero.companion.health, self.hero.companion.health - old_health, self.hero.companion.coherence)) old_health = self.hero.companion.health
def setUp(self): super(HealCompanionTestMixin, self).setUp() create_test_map() self.account_1 = self.accounts_factory.create_account() self.storage = LogicStorage() self.storage.load_account_data(self.account_1) self.hero = self.storage.accounts_to_heroes[self.account_1.id] self.hero.set_companion(companions_logic.create_companion(random.choice(companions_storage.companions.all()))) self.card = self.CARD()
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_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()
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()
def prepair_bot(cls, hero, enemy): if not hero.is_bot: return hero.preferences.set_archetype(random.choice(game_relations.ARCHETYPE.records)) hero.reset_level() for i in xrange(enemy.level-1): hero.randomized_level_up(increment_level=True) hero.randomize_equip() if not companions_storage.companions.is_empty(): companion_record = random.choice(companions_storage.companions.all()) hero.set_companion(companions_logic.create_companion(companion_record))
def test_heal_companion__on_heal_action_habits_not_changed(self): habit_effect = random.choice([ability for ability in companions_effects.ABILITIES.records if not isinstance(ability.effect, companions_effects.ChangeHabits)]) companion_record = companions_storage.companions.enabled_companions().next() companion_record.abilities = companions_container.Container(start=[habit_effect]) self.hero.set_companion(companions_logic.create_companion(companion_record)) self.hero.habit_honor.change(100) self.hero.habit_peacefulness.change(-100) self.hero.companion.health = 1 with self.check_not_changed(lambda: self.hero.habit_honor.raw_value + self.hero.habit_peacefulness.raw_value): self.assertEqual(self.ability.use(**self.use_attributes), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ()))
def setUp(self): super(ChangeHeroSpendingsMixin, self).setUp() create_test_map() self.account_1 = self.accounts_factory.create_account() self.storage = LogicStorage() self.storage.load_account_data(self.account_1) self.hero = self.storage.accounts_to_heroes[self.account_1.id] self.card = self.CARD() old_companion_record = random.choice(companions_storage.companions.all()) self.hero.set_companion(companions_logic.create_companion(old_companion_record))