def test_preference_rating(self): self.assertEqual(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(100, 100), PowerDistribution(0.5, 0.5)), 100) self.assertEqual(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(100, 100), PowerDistribution(0.2, 0.8)), 100) self.assertEqual(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(100, 100), PowerDistribution(0.8, 0.2)), 100) self.assertEqual(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(100, 200), PowerDistribution(0.5, 0.5)), 150) self.assertEqual(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(100, 200), PowerDistribution(0.2, 0.8)), 180) self.assertEqual(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(100, 200), PowerDistribution(0.8, 0.2)), 120) self.assertEqual(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(200, 100), PowerDistribution(0.5, 0.5)), 150) self.assertEqual(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(200, 100), PowerDistribution(0.2, 0.8)), 120) self.assertEqual(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(200, 100), PowerDistribution(0.8, 0.2)), 180)
def receive_artifacts_slots_choices(self, better, prefered_slot, prefered_item): from the_tale.game.artifacts.prototypes import ArtifactPrototype allowed_slots = list(relations.EQUIPMENT_SLOT.records) slot_choices = list(allowed_slots) if prefered_slot and self.preferences.equipment_slot and self.can_upgrade_prefered_slot: slot_choices = [self.preferences.equipment_slot] if prefered_item and self.preferences.favorite_item and self.preferences.favorite_item in slot_choices: #after prefered slot, since prefered item is more important slot_choices.remove(self.preferences.favorite_item) result_choices = [] if better: for slot in slot_choices: artifact = self.equipment.get(slot) if artifact is not None: distribution = self.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.level) # pylint: disable=W0612 if artifact.preference_rating(distribution) >= ArtifactPrototype._preference_rating(artifact.rarity, max_power, distribution): continue result_choices.append(slot) else: result_choices = slot_choices return result_choices
def deserialize(cls, hero, data): obj = cls() obj.next_uuid = data.get('next_uuid', 0) obj.bag = {} for uuid, artifact_data in data.get('bag', {}).items(): artifact = ArtifactPrototype.deserialize(artifact_data) obj.bag[int(uuid)] = artifact return obj
def test_purchase_artifact__better_artifact__min_level(self): self.assertEqual(self.hero.level, 1) rarity = RARITY.NORMAL distribution = self.hero.preferences.archetype.power_distribution middle_power = Power.power_to_artifact(distribution, self.hero.level) for i in xrange(100): self.assertTrue(self.hero.purchase_artifact(rarity=RARITY.NORMAL, better=True).preference_rating(distribution) > ArtifactPrototype._preference_rating(rarity, middle_power, distribution))
def test_deserialization_of_disabled_artifact(self): artifact_record = artifacts_storage.all()[0] artifact = artifact_record.create_artifact(level=7, power=Power(1, 1)) data = artifact.serialize() artifact_record.state = relations.ARTIFACT_RECORD_STATE.DISABLED artifact_record.save() artifact_2 = ArtifactPrototype.deserialize(data) self.assertNotEqual(artifact.id, artifact_2.id)
def test_deserialization_of_disabled_artifact(self): artifact_record = artifacts_storage.all()[0] artifact = artifact_record.create_artifact(level=7, power=Power(1, 1)) data = artifact.serialize() artifact_record.state = relations.ARTIFACT_RECORD_STATE.DISABLED artifact_record.save() artifact_2 = ArtifactPrototype.deserialize(data) self.assertNotEqual(artifact.id, artifact_2.id)
def test_artifacts_attributes(self): ArtifactRecordPrototype.create( uuid='bandit_loot', level=1, utg_name=names.generator.get_test_name('artifact'), description='bandit loot description', type_=relations.ARTIFACT_TYPE.HELMET, power_type=relations.ARTIFACT_POWER_TYPE.NEUTRAL) loot = ArtifactPrototype( record_id=artifacts_storage.get_by_uuid('bandit_loot').id, level=1) self.assertFalse(loot.is_useless)
def test_purchase_artifact__better_artifact__large_level(self): self.hero.level = 100 self.assertEqual(self.hero.level, 100) rarity = RARITY.NORMAL distribution = self.hero.preferences.archetype.power_distribution middle_power = Power.power_to_artifact(distribution, self.hero.level) N = 100 with mock.patch('the_tale.game.actions.container.ActionsContainer.request_replane') as request_replane: for i in xrange(N): self.assertTrue(self.hero.purchase_artifact(rarity=RARITY.NORMAL, better=True).preference_rating(distribution) > ArtifactPrototype._preference_rating(rarity, middle_power, distribution)) self.assertEqual(request_replane.call_count, N)
def receive_artifacts_slots_choices(self, better, prefered_slot, prefered_item): from the_tale.game.artifacts.prototypes import ArtifactPrototype allowed_slots = list(relations.EQUIPMENT_SLOT.records) slot_choices = list(allowed_slots) if prefered_slot and self.preferences.equipment_slot and self.can_upgrade_prefered_slot: slot_choices = [self.preferences.equipment_slot] if prefered_item and self.preferences.favorite_item and self.preferences.favorite_item in slot_choices: #after prefered slot, since prefered item is more important slot_choices.remove(self.preferences.favorite_item) result_choices = [] if better: for slot in slot_choices: artifact = self.equipment.get(slot) if artifact is not None: distribution = self.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval( distribution, self.level) # pylint: disable=W0612 if artifact.preference_rating( distribution ) >= ArtifactPrototype._preference_rating( artifact.rarity, max_power, distribution): continue result_choices.append(slot) else: result_choices = slot_choices return result_choices
def deserialize(cls, hero, data): obj = cls() obj.equipment = dict( (int(slot), ArtifactPrototype.deserialize(artifact_data)) for slot, artifact_data in data.items() if artifact_data) obj.hero = hero return obj
def test_serialization(self): artifact = artifacts_storage.all()[0].create_artifact(level=6, power=Power( 1, 100)) self.assertEqual(artifact, ArtifactPrototype.deserialize(artifact.serialize()))
def test_serialization(self): artifact = artifacts_storage.all()[0].create_artifact(level=6, power=Power(1, 100)) self.assertEqual(artifact, ArtifactPrototype.deserialize(artifact.serialize()))
def test_preference_rating__rarity(self): self.assertTrue(ArtifactPrototype._preference_rating(relations.RARITY.NORMAL, Power(100, 100), PowerDistribution(0.5, 0.5)) < ArtifactPrototype._preference_rating(relations.RARITY.RARE, Power(100, 100), PowerDistribution(0.5, 0.5)) < ArtifactPrototype._preference_rating(relations.RARITY.EPIC, Power(100, 100), PowerDistribution(0.5, 0.5)))