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 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 compress(self, data_list): common = list() start = set() coherence = None honor = None peacefulness = None for field, ability in zip(relations.FIELDS.records, data_list): if ability is u'': continue if field in (relations.FIELDS.START_1, relations.FIELDS.START_2, relations.FIELDS.START_3, relations.FIELDS.START_4, relations.FIELDS.START_5): start.add(ability) elif field.is_COHERENCE_SPEED: coherence = ability elif field.is_HONOR: honor = ability elif field.is_PEACEFULNESS: peacefulness = ability elif ability: common.append(ability) return container.Container(common=common, start=start, coherence=coherence, honor=honor, peacefulness=peacefulness)
def test_modify_attribute(self): checked_abilities = [ ability for ability in heroes_companions_abilities.ABILITIES.itervalues() if issubclass( ability, heroes_companions_abilities._CompanionAbilityModifier) ] for ability_class in checked_abilities: for companion_ability in companions_effects.ABILITIES.records: if ability_class.EFFECT_TYPE != companion_ability.effect.TYPE.metatype: continue if hasattr(companion_ability.effect, 'ABILITY'): # skip battle abilities continue if companion_ability.effect.MODIFIER is None: # skip complex abilities continue self.hero.abilities.reset() self.hero.reset_accessors_cache() self.companion_record.abilities = abilities_container.Container( start=(companion_ability, )) with self.check_changed( lambda: self.companion.modify_attribute( companion_ability.effect.MODIFIER, companion_ability.effect.MODIFIER.default())): self.hero.abilities.add( ability_class.get_id(), random.randint(1, ability_class.MAX_LEVEL))
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 create_random_companion_record( name, type=game_relations.BEING_TYPE.CIVILIZED, max_health=int(c.COMPANIONS_MEDIUM_HEALTH), dedication=relations.DEDICATION.BRAVE, archetype=game_relations.ARCHETYPE.NEUTRAL, state=relations.STATE.DISABLED, abilities=abilities_container.Container(), mode=relations.MODE.AUTOMATIC, communication_verbal=game_relations.COMMUNICATION_VERBAL.CAN, communication_gestures=game_relations.COMMUNICATION_GESTURES.CAN, communication_telepathic=game_relations.COMMUNICATION_TELEPATHIC.CAN, intellect_level=game_relations.INTELLECT_LEVEL.LOW): return create_companion_record( utg_name=names.generator.get_test_name(name=name), description=u'description-%s' % name, type=type, max_health=max_health, dedication=dedication, archetype=archetype, mode=mode, abilities=abilities, state=state, communication_verbal=communication_verbal, communication_gestures=communication_gestures, communication_telepathic=communication_telepathic, intellect_level=intellect_level)
def apply_ability(self, ability): container = abilities_container.Container(common=(), start=frozenset((ability, )), coherence=None, honor=None, peacefulness=None) self.companion_record.abilities = container self.hero.reset_accessors_cache()
def setUp(self): super(ContainerTests, self).setUp() self.container_1 = abilities_container.Container( common=(effects.ABILITIES.PEACEFUL, effects.ABILITIES.SNEAKY), start=frozenset(), coherence=effects.ABILITIES.MANAGING, honor=None, peacefulness=effects.ABILITIES.AGGRESSIVE) self.container_2 = abilities_container.Container( common=(effects.ABILITIES.PEACEFUL, effects.ABILITIES.HONEST, effects.ABILITIES.CANNY), start=frozenset( (effects.ABILITIES.BONA_FIDE, effects.ABILITIES.PEACEFUL)), coherence=None, honor=effects.ABILITIES.SNEAKY, peacefulness=effects.ABILITIES.AGGRESSIVE)
def create_random_companion_record( name, type=beings_relations.TYPE.CIVILIZED, max_health=int(c.COMPANIONS_MEDIUM_HEALTH), dedication=relations.DEDICATION.BRAVE, archetype=game_relations.ARCHETYPE.NEUTRAL, state=relations.STATE.DISABLED, abilities=abilities_container.Container(), mode=relations.MODE.AUTOMATIC, communication_verbal=beings_relations.COMMUNICATION_VERBAL.CAN, communication_gestures=beings_relations.COMMUNICATION_GESTURES.CAN, communication_telepathic=beings_relations.COMMUNICATION_TELEPATHIC.CAN, intellect_level=beings_relations.INTELLECT_LEVEL.LOW, structure=beings_relations.STRUCTURE.STRUCTURE_2, features=frozenset((beings_relations.FEATURE.FEATURE_1, beings_relations.FEATURE.FEATURE_3)), movement=beings_relations.MOVEMENT.MOVEMENT_4, body=beings_relations.BODY.BODY_5, size=beings_relations.SIZE.SIZE_3, orientation=beings_relations.ORIENTATION.VERTICAL, weapons=None): if weapons is None: weapons = [ artifacts_objects.Weapon( weapon=artifacts_relations.STANDARD_WEAPON.WEAPON_1, material=tt_artifacts_relations.MATERIAL.MATERIAL_1, power_type=artifacts_relations.ARTIFACT_POWER_TYPE.NEUTRAL), artifacts_objects.Weapon( weapon=artifacts_relations.STANDARD_WEAPON.WEAPON_3, material=tt_artifacts_relations.MATERIAL.MATERIAL_3, power_type=artifacts_relations.ARTIFACT_POWER_TYPE.MOST_MAGICAL ) ] return create_companion_record( utg_name=names.generator().get_test_name(name=name), description='description-%s' % name, type=type, max_health=max_health, dedication=dedication, archetype=archetype, mode=mode, abilities=abilities, state=state, communication_verbal=communication_verbal, communication_gestures=communication_gestures, communication_telepathic=communication_telepathic, intellect_level=intellect_level, structure=structure, features=features, movement=movement, body=body, size=size, orientation=orientation, weapons=weapons)
def test_has_same_effects(self): self.assertTrue(self.container_1.has_same_effects()) self.assertTrue(self.container_2.has_same_effects()) container_3 = abilities_container.Container( common=(effects.ABILITIES.OBSTINATE, effects.ABILITIES.PEACEFUL), start=frozenset((effects.ABILITIES.CANNY, )), coherence=None, honor=None, peacefulness=None) self.assertFalse(container_3.has_same_effects())
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_strike(self): from the_tale.game.companions.abilities import effects from the_tale.game.companions.abilities import container battle_ability = random.choice([ability for ability in effects.ABILITIES.records if isinstance(ability.effect, effects.BaseBattleAbility)]) self.hero.companion.record.abilities = container.Container(start=(battle_ability,)) self.hero.reset_accessors_cache() actor_1, actor_2 = self.get_actors() self.assertTrue(actor_1.has_companion) self.assertFalse(actor_2.has_companion) self.assertTrue(battle.try_companion_strike(attacker=actor_1, defender=actor_2, messenger=self.hero))
def create_random_companion_record(name, type=relations.TYPE.LIVING, max_health=int(c.COMPANIONS_MEDIUM_HEALTH), dedication=relations.DEDICATION.BRAVE, archetype=game_relations.ARCHETYPE.NEUTRAL, state=relations.STATE.DISABLED, abilities=abilities_container.Container(), mode=relations.MODE.AUTOMATIC): return create_companion_record( utg_name=names.generator.get_test_name(name=name), description=u'description-%s' % name, type=type, max_health=max_health, dedication=dedication, archetype=archetype, mode=mode, abilities=abilities, state=state)
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=relations.TYPE.random(), max_health=10, dedication=relations.DEDICATION.random(), archetype=game_relations.ARCHETYPE.random(), mode=relations.MODE.random(), abilities=abilities_container.Container(), state=relations.STATE.ENABLED) self.hero.set_companion(logic.create_companion(self.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, ()))
# coding: utf-8 from the_tale.game.companions import relations from the_tale.game.companions.abilities import container as abilities_container from the_tale.game.companions.abilities import forms as abilities_forms from the_tale.game.companions.abilities import effects FAKE_ABILITIES_CONTAINER_1 = abilities_container.Container( common=(effects.ABILITIES.HEALER, effects.ABILITIES.FAN, effects.ABILITIES.CUTE), start=frozenset(), coherence=effects.ABILITIES.OBSTINATE, honor=None, peacefulness=effects.ABILITIES.PEACEFUL) FAKE_ABILITIES_CONTAINER_2 = abilities_container.Container( common=(effects.ABILITIES.HEALER, effects.ABILITIES.TORTURER), start=frozenset((effects.ABILITIES.CLEVER, effects.ABILITIES.CUTE)), coherence=effects.ABILITIES.OBSTINATE, honor=effects.ABILITIES.HONEST, peacefulness=None) def get_abilities_post_data(abilities, prefix='abilities'): widgets_data = abilities_forms.decompress_abilities(abilities) data = { '%s_%d' % (prefix, i): value for i, value in enumerate(widgets_data) if value is not None