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_deserialization_of_disabled_mob(self): mob_record = mobs_storage.all()[0] mob = mob_record.create_mob(self.hero) data = mob.serialize() mob_record.state = MOB_RECORD_STATE.DISABLED mob_record.save() mob_2 = MobPrototype.deserialize(data) self.assertNotEqual(mob.id, mob_2.id)
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 get_random_mob(self, hero, mercenary=None, is_boss=False): self.sync() choices = self.get_available_mobs_list( level=hero.level, terrain=hero.position.get_terrain(), mercenary=mercenary) if not choices: return None mob_record = self.choose_mob(choices) return MobPrototype(record_id=mob_record.id, level=hero.level, is_boss=is_boss)
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_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_serialization(self): mob = mobs_storage.all()[0].create_mob(self.hero) self.assertEqual(mob, MobPrototype.deserialize(mob.serialize()))