def test_mobs_without_artifacts(self): self.request_login(self.account_2.email) from the_tale.game.mobs.prototypes import MobRecordPrototype from the_tale.game.artifacts.prototypes import ArtifactRecordPrototype mob_without_loot = MobRecordPrototype.create_random('no_loot') mob_without_artifact = MobRecordPrototype.create_random('no_artifact') mob_without_loot_on_first_level = MobRecordPrototype.create_random( 'no_loot_on_1_level') mob_without_artifact_on_firs_level = MobRecordPrototype.create_random( 'no_artifact_on_1_level') ArtifactRecordPrototype.create_random( 'not_first_loot', mob=mob_without_loot_on_first_level, level=mob_without_loot_on_first_level.level + 1) ArtifactRecordPrototype.create_random( 'not_first_artifact', mob=mob_without_artifact_on_firs_level, level=mob_without_artifact_on_firs_level.level + 1) self.check_html_ok(self.request_html( reverse('portal:developers-info:mobs-and-artifacts')), texts=[ mob_without_loot.name, mob_without_artifact.name, mob_without_loot_on_first_level.name, mob_without_artifact_on_firs_level.name ])
def setUp(self): super(MobsStorageTests, self).setUp() create_test_map() self.mob_1, self.mob_2, self.mob_3 = mobs_storage.all() self.mob_1.type = MOB_TYPE.CIVILIZED self.mob_1.save() self.mob_2.type = MOB_TYPE.BARBARIAN self.mob_2.save() self.mob_3.type = MOB_TYPE.CIVILIZED self.mob_3.save() self.bandit = MobRecordPrototype.create(uuid='bandit', level=1, utg_name=names.generator.get_test_name(name='bandint'), description='description', abilities=['hit'], terrains=[TERRAIN.PLANE_SAND], type=MOB_TYPE.CIVILIZED, state=MOB_RECORD_STATE.ENABLED) self.bandint_wrong = MobRecordPrototype.create(uuid='bandit_wrong', level=1, utg_name=names.generator.get_test_name(name='bandit_wrong'), description='bandit_wrong description', abilities=['hit'], terrains=[TERRAIN.PLANE_SAND], type=MOB_TYPE.CIVILIZED, state=MOB_RECORD_STATE.DISABLED)
def setUp(self): super(MobsStorageTests, self).setUp() create_test_map() self.mob_1, self.mob_2, self.mob_3 = mobs_storage.all() self.mob_1.type = MOB_TYPE.CIVILIZED self.mob_1.save() self.mob_2.type = MOB_TYPE.BARBARIAN self.mob_2.save() self.mob_3.type = MOB_TYPE.CIVILIZED self.mob_3.save() self.bandit = MobRecordPrototype.create( uuid='bandit', level=1, utg_name=names.generator.get_test_name(name='bandint'), description='description', abilities=['hit'], terrains=[TERRAIN.PLANE_SAND], type=MOB_TYPE.CIVILIZED, state=MOB_RECORD_STATE.ENABLED) self.bandint_wrong = MobRecordPrototype.create( uuid='bandit_wrong', level=1, utg_name=names.generator.get_test_name(name='bandit_wrong'), description='bandit_wrong description', abilities=['hit'], terrains=[TERRAIN.PLANE_SAND], type=MOB_TYPE.CIVILIZED, state=MOB_RECORD_STATE.DISABLED)
def test_choose_mob__when_actions__total_actions(self): account = self.accounts_factory.create_account() hero = heroes_logic.load_hero(account_id=account.id) MobRecordPrototype.create_random('action_1', global_action_probability=0.66) MobRecordPrototype.create_random('action_2', global_action_probability=0.66) counter = collections.Counter([mobs_storage.get_random_mob(hero).id for i in range(10000)]) self.assertEqual(sum([count for uuid, count in counter.items() if uuid not in ('action_1', 'action_2')], 0), 0) self.assertTrue(abs(counter['action_2'] - counter['action_1']) < 0.2 * counter['action_2'])
def test_choose_mob__when_actions(self): account = self.accounts_factory.create_account() hero = heroes_logic.load_hero(account_id=account.id) MobRecordPrototype.create_random("action_1", global_action_probability=0.25) MobRecordPrototype.create_random("action_2", global_action_probability=0.10) counter = collections.Counter([mobs_storage.get_random_mob(hero).id for i in xrange(1000)]) non_actions_count = sum(count for uuid, count in counter.iteritems() if uuid not in ("action_1", "action_2")) self.assertTrue(counter["action_2"] < counter["action_1"] < non_actions_count)
def test_choose_mob__when_actions__total_actions(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) MobRecordPrototype.create_random('action_1', global_action_probability=0.66) MobRecordPrototype.create_random('action_2', global_action_probability=0.66) counter = collections.Counter([mobs_storage.get_random_mob(hero).id for i in xrange(10000)]) self.assertEqual(sum([count for uuid, count in counter.iteritems() if uuid not in ('action_1', 'action_2')], 0), 0) self.assertTrue(abs(counter['action_2'] - counter['action_1']) < 0.2 * counter['action_2'])
def test_generate_artifact__rarity(self): from the_tale.game.mobs.prototypes import MobPrototype, MobRecordPrototype self.hero.level = 5 mob_record = MobRecordPrototype.create_random( uuid="bandit", level=2, state=mobs_relations.MOB_RECORD_STATE.ENABLED ) mob = MobPrototype(record_id=mob_record.id, level=3) ArtifactRecordPrototype.create_random( "bandit_artifact", mob=mob_record, type_=relations.ARTIFACT_TYPE.HELMET, state=relations.ARTIFACT_RECORD_STATE.ENABLED, ) with mock.patch( "the_tale.game.artifacts.storage.ArtifactsStorage.get_rarity_type", lambda self, hero: relations.RARITY.NORMAL, ): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertTrue(artifact.rarity.is_NORMAL) with mock.patch( "the_tale.game.artifacts.storage.ArtifactsStorage.get_rarity_type", lambda self, hero: relations.RARITY.RARE ): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertTrue(artifact.rarity.is_RARE) with mock.patch( "the_tale.game.artifacts.storage.ArtifactsStorage.get_rarity_type", lambda self, hero: relations.RARITY.EPIC ): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertTrue(artifact.rarity.is_EPIC)
def test_generate_artifact(self): from the_tale.game.mobs.prototypes import MobPrototype, MobRecordPrototype self.hero.level = 5 mob_record = MobRecordPrototype.create_random(uuid='bandit', level=2, state=mobs_relations.MOB_RECORD_STATE.ENABLED) mob = MobPrototype(record_id=mob_record.id, level=3) artifact_1 = ArtifactRecordPrototype.create_random('bandit_loot', mob=mob_record, type_=relations.ARTIFACT_TYPE.USELESS, state=relations.ARTIFACT_RECORD_STATE.ENABLED) artifact_2 = ArtifactRecordPrototype.create_random('bandit_artifact', mob=mob_record, type_=relations.ARTIFACT_TYPE.HELMET, state=relations.ARTIFACT_RECORD_STATE.ENABLED) with mock.patch('the_tale.game.heroes.objects.Hero.artifacts_probability', lambda self, mob: 1.0): with mock.patch('the_tale.game.heroes.objects.Hero.loot_probability', lambda self, mob: 1.0): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertEqual(artifact.level, mob.level) self.assertFalse(artifact.type.is_USELESS) self.assertEqual(artifact_2.id, artifact.record.id) with mock.patch('the_tale.game.heroes.objects.Hero.artifacts_probability', lambda self, mob: 0.0): with mock.patch('the_tale.game.heroes.objects.Hero.loot_probability', lambda self, mob: 1.0): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertEqual(artifact.level, mob.record.level) self.assertTrue(artifact.type.is_USELESS) self.assertEqual(artifact_1.id, artifact.record.id) with mock.patch('the_tale.game.heroes.objects.Hero.artifacts_probability', lambda self, mob: 0.0): with mock.patch('the_tale.game.heroes.objects.Hero.loot_probability', lambda self, mob: 0.0): self.assertEqual(artifacts_storage.generate_loot(self.hero, mob), None)
def test_linguistics_restrictions_on_create(self): with mock.patch('the_tale.linguistics.logic.sync_restriction') as sync_restriction: mob = MobRecordPrototype.create_random(uuid='bandit', state=MOB_RECORD_STATE.DISABLED) self.assertEqual(sync_restriction.call_args_list, [mock.call(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=mob.id, name=mob.name)])
def test_generate_artifact__rarity(self): from the_tale.game.mobs.prototypes import MobPrototype, MobRecordPrototype self.hero.level = 5 mob_record = MobRecordPrototype.create_random( uuid='bandit', level=2, state=mobs_relations.MOB_RECORD_STATE.ENABLED) mob = MobPrototype(record_id=mob_record.id, level=3) ArtifactRecordPrototype.create_random( 'bandit_artifact', mob=mob_record, type_=relations.ARTIFACT_TYPE.HELMET, state=relations.ARTIFACT_RECORD_STATE.ENABLED) with mock.patch( 'the_tale.game.artifacts.storage.ArtifactsStorage.get_rarity_type', lambda self, hero: relations.RARITY.NORMAL): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertTrue(artifact.rarity.is_NORMAL) with mock.patch( 'the_tale.game.artifacts.storage.ArtifactsStorage.get_rarity_type', lambda self, hero: relations.RARITY.RARE): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertTrue(artifact.rarity.is_RARE) with mock.patch( 'the_tale.game.artifacts.storage.ArtifactsStorage.get_rarity_type', lambda self, hero: relations.RARITY.EPIC): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertTrue(artifact.rarity.is_EPIC)
def test_linguistics_restrictions_on_create(self): with mock.patch('the_tale.linguistics.logic.sync_restriction') as sync_restriction: mob = MobRecordPrototype.create_random(uuid='bandit', state=MOB_RECORD_STATE.DISABLED) self.assertEqual(sync_restriction.call_args_list, [mock.call(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=mob.id, name=mob.name)])
def test_mob_attributes(self): MobRecordPrototype.create(uuid='bandit', level=1, utg_name=names.generator.get_test_name(name='bandit'), description='bandint', abilities=['hit', 'thick', 'slow', 'extra_strong'], terrains=TERRAIN.records, type=game_relations.BEING_TYPE.CIVILIZED, archetype=game_relations.ARCHETYPE.NEUTRAL, state=MOB_RECORD_STATE.ENABLED) mobs_storage.sync(force=True) bandit = MobPrototype(record_id=mobs_storage.get_by_uuid('bandit').id, level=1) self.assertEqual(bandit.health_cooficient, 1.025) self.assertEqual(bandit.initiative, 0.975) self.assertEqual(bandit.damage_modifier, 1.05)
def test_mob_attributes(self): MobRecordPrototype.create(uuid='bandit', level=1, utg_name=names.generator.get_test_name(name='bandit'), description='bandint', abilities=['hit', 'thick', 'slow', 'extra_strong'], terrains=TERRAIN.records, type=MOB_TYPE.CIVILIZED, archetype=game_relations.ARCHETYPE.NEUTRAL, state=MOB_RECORD_STATE.ENABLED) mobs_storage.sync(force=True) bandit = MobPrototype(record_id=mobs_storage.get_by_uuid('bandit').id, level=1) self.assertEqual(bandit.health_cooficient, 1.025) self.assertEqual(bandit.initiative, 0.975) self.assertEqual(bandit.damage_modifier, 1.05)
def test_choose_mob__when_actions(self): account = self.accounts_factory.create_account() hero = heroes_logic.load_hero(account_id=account.id) MobRecordPrototype.create_random('action_1', global_action_probability=0.25) MobRecordPrototype.create_random('action_2', global_action_probability=0.10) counter = collections.Counter( [mobs_storage.get_random_mob(hero).id for i in xrange(1000)]) non_actions_count = sum(count for uuid, count in counter.iteritems() if uuid not in ('action_1', 'action_2')) self.assertTrue( counter['action_2'] < counter['action_1'] < non_actions_count)
def test_mobs_without_artifacts(self): self.request_login('*****@*****.**') from the_tale.game.mobs.prototypes import MobRecordPrototype from the_tale.game.artifacts.prototypes import ArtifactRecordPrototype mob_without_loot = MobRecordPrototype.create_random('mob_without_loot') mob_without_artifact = MobRecordPrototype.create_random('mob_without_artifact') mob_without_loot_on_first_level = MobRecordPrototype.create_random('mob_without_loot_on_first_level') mob_without_artifact_on_firs_level = MobRecordPrototype.create_random('mob_without_artifact_on_firs_level') ArtifactRecordPrototype.create_random('not_first_loot', mob=mob_without_loot_on_first_level, level=mob_without_loot_on_first_level.level+1) ArtifactRecordPrototype.create_random('not_first_artifact', mob=mob_without_artifact_on_firs_level, level=mob_without_artifact_on_firs_level.level+1) self.check_html_ok(self.request_html(reverse('portal:developers-info:mobs-and-artifacts')), texts=[mob_without_loot.name, mob_without_artifact.name, mob_without_loot_on_first_level.name, mob_without_artifact_on_firs_level.name])
def test_choose_mob__when_actions(self): result, account_id, bundle_id = register_user('test_user_1', '*****@*****.**', '111111') hero = HeroPrototype.get_by_account_id(account_id) MobRecordPrototype.create_random('action_1', global_action_probability=0.25) MobRecordPrototype.create_random('action_2', global_action_probability=0.10) counter = collections.Counter( [mobs_storage.get_random_mob(hero).id for i in xrange(1000)]) non_actions_count = sum(count for uuid, count in counter.iteritems() if uuid not in ('action_1', 'action_2')) self.assertTrue( counter['action_2'] < counter['action_1'] < non_actions_count)
def test_linguistics_restrictions_update_on_save(self): mob = MobRecordPrototype.create_random(uuid='bandit', state=MOB_RECORD_STATE.DISABLED) mob.set_utg_name(names.generator().get_test_name('new-name')) with mock.patch('the_tale.linguistics.logic.sync_restriction') as sync_restriction: mob.save() self.assertEqual(sync_restriction.call_args_list, [mock.call(group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=mob.id, name=mob.name)])
def create_test_map(): linguistics_logic.sync_static_restrictions() map_logic.create_test_my_info() p1 = PlacePrototype.create( x=1, y=1, size=1, utg_name=names.generator.get_test_name(name='1x1')) p2 = PlacePrototype.create( x=3, y=3, size=3, utg_name=names.generator.get_test_name(name='10x10')) p3 = PlacePrototype.create( x=1, y=3, size=3, utg_name=names.generator.get_test_name(name='1x10')) for place in places_storage.all(): place.sync_persons(force_add=True) RoadPrototype.create(point_1=p1, point_2=p2).update() RoadPrototype.create(point_1=p2, point_2=p3).update() update_waymarks() update_nearest_cells() mob_1 = MobRecordPrototype.create_random('mob_1') mob_2 = MobRecordPrototype.create_random('mob_2') mob_3 = MobRecordPrototype.create_random('mob_3') ArtifactRecordPrototype.create_random('loot_1', mob=mob_1) ArtifactRecordPrototype.create_random('loot_2', mob=mob_2) ArtifactRecordPrototype.create_random('loot_3', mob=mob_3) ArtifactRecordPrototype.create_random('helmet_1', type_=ARTIFACT_TYPE.HELMET, mob=mob_1) ArtifactRecordPrototype.create_random('plate_1', type_=ARTIFACT_TYPE.PLATE, mob=mob_2) ArtifactRecordPrototype.create_random('boots_1', type_=ARTIFACT_TYPE.BOOTS, mob=mob_3) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.PANTS, type_=ARTIFACT_TYPE.PANTS) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.BOOTS, type_=ARTIFACT_TYPE.BOOTS) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.PLATE, type_=ARTIFACT_TYPE.PLATE) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.GLOVES, type_=ARTIFACT_TYPE.GLOVES) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.WEAPON, type_=ARTIFACT_TYPE.MAIN_HAND) companions_logic.create_random_companion_record('companion_1', dedication=companions_relations.DEDICATION.HEROIC, state=companions_relations.STATE.ENABLED) companions_logic.create_random_companion_record('companion_2', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.ENABLED) companions_logic.create_random_companion_record('companion_3', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.DISABLED) return p1, p2, p3
def create_test_map(): linguistics_logic.sync_static_restrictions() map_logic.create_test_map_info() p1 = places_logic.create_place( x=1, y=1, size=1, utg_name=names.generator().get_test_name(name='1x1'), race=relations.RACE.HUMAN) p2 = places_logic.create_place( x=3, y=3, size=3, utg_name=names.generator().get_test_name(name='10x10'), race=relations.RACE.HUMAN) p3 = places_logic.create_place( x=1, y=3, size=3, utg_name=names.generator().get_test_name(name='1x10'), race=relations.RACE.HUMAN) for place in places_storage.places.all(): for i in range(3): places_logic.add_person_to_place(place) RoadPrototype.create(point_1=p1, point_2=p2).update() RoadPrototype.create(point_1=p2, point_2=p3).update() update_waymarks() nearest_cells.update_nearest_cells() mob_1 = MobRecordPrototype.create_random('mob_1') mob_2 = MobRecordPrototype.create_random('mob_2') mob_3 = MobRecordPrototype.create_random('mob_3') ArtifactRecordPrototype.create_random('loot_1', mob=mob_1) ArtifactRecordPrototype.create_random('loot_2', mob=mob_2) ArtifactRecordPrototype.create_random('loot_3', mob=mob_3) ArtifactRecordPrototype.create_random('helmet_1', type_=ARTIFACT_TYPE.HELMET, mob=mob_1) ArtifactRecordPrototype.create_random('plate_1', type_=ARTIFACT_TYPE.PLATE, mob=mob_2) ArtifactRecordPrototype.create_random('boots_1', type_=ARTIFACT_TYPE.BOOTS, mob=mob_3) for equipment_slot in heroes_relations.EQUIPMENT_SLOT.records: if equipment_slot.default: ArtifactRecordPrototype.create_random(equipment_slot.default, type_=equipment_slot.artifact_type) companions_logic.create_random_companion_record('companion_1', dedication=companions_relations.DEDICATION.HEROIC, state=companions_relations.STATE.ENABLED) companions_logic.create_random_companion_record('companion_2', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.ENABLED) companions_logic.create_random_companion_record('companion_3', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.DISABLED) return p1, p2, p3
def create_test_map(): linguistics_logic.sync_static_restrictions() map_logic.create_test_map_info() p1 = places_logic.create_place( x=1, y=1, size=1, utg_name=names.generator().get_test_name(name='1x1'), race=relations.RACE.HUMAN) p2 = places_logic.create_place( x=3, y=3, size=3, utg_name=names.generator().get_test_name(name='10x10'), race=relations.RACE.HUMAN) p3 = places_logic.create_place( x=1, y=3, size=3, utg_name=names.generator().get_test_name(name='1x10'), race=relations.RACE.HUMAN) for place in places_storage.places.all(): for i in range(3): places_logic.add_person_to_place(place) RoadPrototype.create(point_1=p1, point_2=p2).update() RoadPrototype.create(point_1=p2, point_2=p3).update() update_waymarks() nearest_cells.update_nearest_cells() mob_1 = MobRecordPrototype.create_random('mob_1') mob_2 = MobRecordPrototype.create_random('mob_2') mob_3 = MobRecordPrototype.create_random('mob_3') ArtifactRecordPrototype.create_random('loot_1', mob=mob_1) ArtifactRecordPrototype.create_random('loot_2', mob=mob_2) ArtifactRecordPrototype.create_random('loot_3', mob=mob_3) ArtifactRecordPrototype.create_random('helmet_1', type_=ARTIFACT_TYPE.HELMET, mob=mob_1) ArtifactRecordPrototype.create_random('plate_1', type_=ARTIFACT_TYPE.PLATE, mob=mob_2) ArtifactRecordPrototype.create_random('boots_1', type_=ARTIFACT_TYPE.BOOTS, mob=mob_3) for equipment_slot in heroes_relations.EQUIPMENT_SLOT.records: if equipment_slot.default: ArtifactRecordPrototype.create_random(equipment_slot.default, type_=equipment_slot.artifact_type) companions_logic.create_random_companion_record('companion_1', dedication=companions_relations.DEDICATION.HEROIC, state=companions_relations.STATE.ENABLED) companions_logic.create_random_companion_record('companion_2', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.ENABLED) companions_logic.create_random_companion_record('companion_3', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.DISABLED) return p1, p2, p3
def test_generate_artifact(self): from the_tale.game.mobs.prototypes import MobPrototype, MobRecordPrototype self.hero.level = 5 mob_record = MobRecordPrototype.create_random( uuid='bandit', level=2, state=mobs_relations.MOB_RECORD_STATE.ENABLED) mob = MobPrototype(record_id=mob_record.id, level=3) artifact_1 = ArtifactRecordPrototype.create_random( 'bandit_loot', mob=mob_record, type_=relations.ARTIFACT_TYPE.USELESS, state=relations.ARTIFACT_RECORD_STATE.ENABLED) artifact_2 = ArtifactRecordPrototype.create_random( 'bandit_artifact', mob=mob_record, type_=relations.ARTIFACT_TYPE.HELMET, state=relations.ARTIFACT_RECORD_STATE.ENABLED) with mock.patch( 'the_tale.game.heroes.objects.Hero.artifacts_probability', lambda self, mob: 1.0): with mock.patch( 'the_tale.game.heroes.objects.Hero.loot_probability', lambda self, mob: 1.0): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertEqual(artifact.level, mob.level) self.assertFalse(artifact.type.is_USELESS) self.assertEqual(artifact_2.id, artifact.record.id) with mock.patch( 'the_tale.game.heroes.objects.Hero.artifacts_probability', lambda self, mob: 0.0): with mock.patch( 'the_tale.game.heroes.objects.Hero.loot_probability', lambda self, mob: 1.0): artifact = artifacts_storage.generate_loot(self.hero, mob) self.assertEqual(artifact.level, mob.record.level) self.assertTrue(artifact.type.is_USELESS) self.assertEqual(artifact_1.id, artifact.record.id) with mock.patch( 'the_tale.game.heroes.objects.Hero.artifacts_probability', lambda self, mob: 0.0): with mock.patch( 'the_tale.game.heroes.objects.Hero.loot_probability', lambda self, mob: 0.0): self.assertEqual( artifacts_storage.generate_loot(self.hero, mob), None)
def construct_mob_with_abilities(abilities, index): from the_tale.game.mobs.prototypes import MobRecordPrototype from the_tale.game.mobs.relations import MOB_RECORD_STATE uuid = 'test_mob %d' % index mob_record = MobRecordPrototype.create(uuid, level=1, utg_name=names.generator.get_test_name(uuid), description='', abilities=abilities, terrains=[], type=game_relations.BEING_TYPE.CIVILIZED, state=MOB_RECORD_STATE.ENABLED) return MobPrototype(level=1, record_id=mob_record.id)
def setUp(self): super(MobsStorageTests, self).setUp() create_test_map() self.mob_1, self.mob_2, self.mob_3 = mobs_storage.all() self.mob_1.type = game_relations.BEING_TYPE.CIVILIZED self.mob_1.save() self.mob_2.type = game_relations.BEING_TYPE.CIVILIZED self.mob_2.is_mercenary = False self.mob_2.save() self.mob_3.type = game_relations.BEING_TYPE.CIVILIZED self.mob_3.save() self.bandit = MobRecordPrototype.create( uuid="bandit", level=1, utg_name=names.generator.get_test_name(name="bandint"), description="description", abilities=["hit"], terrains=[map_relations.TERRAIN.PLANE_SAND], type=game_relations.BEING_TYPE.CIVILIZED, state=MOB_RECORD_STATE.ENABLED, ) self.bandint_wrong = MobRecordPrototype.create( uuid="bandit_wrong", level=1, utg_name=names.generator.get_test_name(name="bandit_wrong"), description="bandit_wrong description", abilities=["hit"], terrains=[map_relations.TERRAIN.PLANE_SAND], type=game_relations.BEING_TYPE.CIVILIZED, state=MOB_RECORD_STATE.DISABLED, )
def test_linguistics_restrictions_update_on_save(self): mob = MobRecordPrototype.create_random(uuid='bandit', state=MOB_RECORD_STATE.DISABLED) mob.set_utg_name(names.generator().get_test_name('new-name')) with mock.patch('the_tale.linguistics.logic.sync_restriction' ) as sync_restriction: mob.save() self.assertEqual(sync_restriction.call_args_list, [ mock.call( group=linguistics_relations.TEMPLATE_RESTRICTION_GROUP.MOB, external_id=mob.id, name=mob.name) ])
def construct_mob_with_abilities(abilities, index): from the_tale.game.mobs.prototypes import MobRecordPrototype from the_tale.game.mobs.relations import MOB_RECORD_STATE uuid = 'test_mob %d' % index mob_record = MobRecordPrototype.create( uuid, level=1, utg_name=names.generator.get_test_name(uuid), description='', abilities=abilities, terrains=[], type=game_relations.BEING_TYPE.CIVILIZED, state=MOB_RECORD_STATE.ENABLED) return MobPrototype(level=1, record_id=mob_record.id)
def test_generate_artifact__rarity_with_normal_probabilities(self): from the_tale.game.mobs.prototypes import MobPrototype, MobRecordPrototype self.hero.level = 5 mob_record = MobRecordPrototype.create_random(uuid='bandit', level=2, state=mobs_relations.MOB_RECORD_STATE.ENABLED) mob = MobPrototype(record_id=mob_record.id, level=3) ArtifactRecordPrototype.create_random('bandit_artifact', mob=mob_record, type_=relations.ARTIFACT_TYPE.HELMET, state=relations.ARTIFACT_RECORD_STATE.ENABLED) rarities = set() for i in range(10000): artifact = artifacts_storage.generate_loot(self.hero, mob) rarities.add(artifact.rarity) self.assertEqual(rarities, set(relations.RARITY.records))
def test_generate_artifact__rarity_with_normal_probabilities(self): from the_tale.game.mobs.prototypes import MobPrototype, MobRecordPrototype from the_tale.game.mobs.models import MOB_RECORD_STATE self.hero._model.level = 5 mob_record = MobRecordPrototype.create_random( uuid='bandit', level=2, state=MOB_RECORD_STATE.ENABLED) mob = MobPrototype(record_id=mob_record.id, level=3) ArtifactRecordPrototype.create_random( 'bandit_artifact', mob=mob_record, type_=relations.ARTIFACT_TYPE.HELMET, state=relations.ARTIFACT_RECORD_STATE.ENABLED) rarities = set() for i in xrange(10000): artifact = artifacts_storage.generate_loot(self.hero, mob) rarities.add(artifact.rarity) self.assertEqual(rarities, set(relations.RARITY.records))
def test_save__not_stored_mob(self): mob = MobRecordPrototype.get_by_id(mobs_storage.all()[0].id) self.assertRaises(exceptions.SaveNotRegisteredMobError, mob.save)
from the_tale.linguistics.forms import WordField from the_tale.game.map.relations import TERRAIN from the_tale.game import relations as game_relations from the_tale.game.heroes.habilities import ABILITIES from the_tale.game.heroes.habilities.battle import HIT from the_tale.game.mobs.prototypes import MobRecordPrototype def to_ability(ability_id): return ABILITIES[ability_id] ABILITY_CHOICES_DICT = dict( (ability.get_id(), ability.NAME) for ability in MobRecordPrototype.get_available_abilities() ) ABILITY_CHOICES = sorted(ABILITY_CHOICES_DICT.items(), key=lambda choice: choice[1]) MOB_TYPE_CHOICES = sorted(game_relations.BEING_TYPE.choices(), key=lambda choice: choice[1]) class MobRecordBaseForm(forms.Form): level = fields.IntegerField(label='минимальный уровень') name = WordField(word_type=utg_relations.WORD_TYPE.NOUN, label='Название') type = fields.TypedChoiceField(label='тип', choices=MOB_TYPE_CHOICES, coerce=game_relations.BEING_TYPE.get_from_name) archetype = fields.TypedChoiceField(label='тип', choices=game_relations.ARCHETYPE.choices(), coerce=game_relations.ARCHETYPE.get_from_name)
def test_storage_version_update_on_create(self): old_version = mobs_storage.version MobRecordPrototype.create_random(uuid="bandit", state=MOB_RECORD_STATE.DISABLED) self.assertNotEqual(old_version, mobs_storage.version)
def create_test_map(): linguistics_logic.sync_static_restrictions() map_logic.create_test_my_info() p1 = PlacePrototype.create( x=1, y=1, size=1, utg_name=names.generator.get_test_name(name='1x1')) p2 = PlacePrototype.create( x=3, y=3, size=3, utg_name=names.generator.get_test_name(name='10x10')) p3 = PlacePrototype.create( x=1, y=3, size=3, utg_name=names.generator.get_test_name(name='1x10')) for place in places_storage.all(): place.sync_persons(force_add=True) RoadPrototype.create(point_1=p1, point_2=p2).update() RoadPrototype.create(point_1=p2, point_2=p3).update() update_waymarks() update_nearest_cells() mob_1 = MobRecordPrototype.create_random('mob_1') mob_2 = MobRecordPrototype.create_random('mob_2') mob_3 = MobRecordPrototype.create_random('mob_3') ArtifactRecordPrototype.create_random('loot_1', mob=mob_1) ArtifactRecordPrototype.create_random('loot_2', mob=mob_2) ArtifactRecordPrototype.create_random('loot_3', mob=mob_3) ArtifactRecordPrototype.create_random('helmet_1', type_=ARTIFACT_TYPE.HELMET, mob=mob_1) ArtifactRecordPrototype.create_random('plate_1', type_=ARTIFACT_TYPE.PLATE, mob=mob_2) ArtifactRecordPrototype.create_random('boots_1', type_=ARTIFACT_TYPE.BOOTS, mob=mob_3) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.PANTS, type_=ARTIFACT_TYPE.PANTS) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.BOOTS, type_=ARTIFACT_TYPE.BOOTS) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.PLATE, type_=ARTIFACT_TYPE.PLATE) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.GLOVES, type_=ARTIFACT_TYPE.GLOVES) ArtifactRecordPrototype.create_random(DEFAULT_HERO_EQUIPMENT.WEAPON, type_=ARTIFACT_TYPE.MAIN_HAND) companions_logic.create_random_companion_record( 'companion_1', dedication=companions_relations.DEDICATION.HEROIC, state=companions_relations.STATE.ENABLED) companions_logic.create_random_companion_record( 'companion_2', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.ENABLED) companions_logic.create_random_companion_record( 'companion_3', dedication=companions_relations.DEDICATION.BOLD, state=companions_relations.STATE.DISABLED) return p1, p2, p3
from the_tale.game import relations as game_relations from the_tale.game.heroes.habilities import ABILITIES from the_tale.game.heroes.habilities.battle import HIT from the_tale.game.mobs.prototypes import MobRecordPrototype def to_ability(ability_id): return ABILITIES[ability_id] ABILITY_CHOICES_DICT = dict( (ability.get_id(), ability.NAME) for ability in MobRecordPrototype.get_available_abilities()) ABILITY_CHOICES = sorted(ABILITY_CHOICES_DICT.items(), key=lambda choice: choice[1]) MOB_TYPE_CHOICES = sorted(game_relations.BEING_TYPE.choices(), key=lambda choice: choice[1]) class MobRecordBaseForm(forms.Form): level = fields.IntegerField(label='минимальный уровень') name = WordField(word_type=utg_relations.WORD_TYPE.NOUN, label='Название') type = fields.TypedChoiceField(
def test_save__not_stored_mob(self): mob = MobRecordPrototype.get_by_id(mobs_storage.all()[0].id) self.assertRaises(exceptions.SaveNotRegisteredMobError, mob.save)
def test_storage_version_update_on_save(self): mob = MobRecordPrototype.create_random(uuid='bandit', state=MOB_RECORD_STATE.DISABLED) old_version = mobs_storage.version mob.save() self.assertNotEqual(old_version, mobs_storage.version)
def test_storage_version_update_on_save(self): mob = MobRecordPrototype.create_random(uuid='bandit', state=MOB_RECORD_STATE.DISABLED) old_version = mobs_storage.version mob.save() self.assertNotEqual(old_version, mobs_storage.version)