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 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_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 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)))