Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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))
Ejemplo n.º 6
0
    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))