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 sharp_artifact(self): choices = list(relations.EQUIPMENT_SLOT.records) random.shuffle(choices) if self.preferences.equipment_slot is not None and self.can_upgrade_prefered_slot: choices.insert(0, self.preferences.equipment_slot) distribution = self.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval( distribution, self.level) # pylint: disable=W0612 for slot in choices: artifact = self.equipment.get(slot) if artifact is not None and artifact.sharp(distribution, max_power): self.equipment.updated = True return artifact # if all artifacts are on maximum level random.shuffle(choices) for slot in choices: artifact = self.equipment.get(slot) if artifact is not None and artifact.sharp( distribution, max_power, force=True): self.equipment.updated = True return artifact
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_only_better_for_prefered_slot(self): self.hero.level = 9999 self.hero.preferences.set(relations.PREFERENCE_TYPE.EQUIPMENT_SLOT, relations.EQUIPMENT_SLOT.PLATE) # just set any artifact self.hero.receive_artifact(equip=True, better=False, prefered_slot=True, prefered_item=True, archetype=True) distribution = self.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval( distribution, self.hero.level) for i in range(100): old_artifact = self.hero.equipment.get( relations.EQUIPMENT_SLOT.PLATE) old_artifact.power = max_power - Power(1, 1) self.hero.receive_artifact(equip=True, better=True, prefered_slot=True, prefered_item=True, archetype=True) self.assertTrue( self.hero.equipment.get(relations.EQUIPMENT_SLOT.PLATE ).preference_rating(distribution) > old_artifact.preference_rating(distribution))
def test_receive_artifacts_slots_choices__better_false(self): distribution = self.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.hero.level) # pylint: disable=W0612 for artifact in list(self.hero.equipment.values()): artifact.power = max_power self.assertEqual(set(self.hero.receive_artifacts_slots_choices(better=False, prefered_slot=False, prefered_item=False)), set(relations.EQUIPMENT_SLOT.records))
def test_receive_artifacts_slots_choices__better_false(self): distribution = self.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.hero.level) # pylint: disable=W0612 for artifact in self.hero.equipment.values(): artifact.power = max_power self.assertEqual(set(self.hero.receive_artifacts_slots_choices(better=False, prefered_slot=False, prefered_item=False)), set(relations.EQUIPMENT_SLOT.records))
def use(self, task, storage, **kwargs): # pylint: disable=R0911,W0613 for artifact in task.hero.equipment.values(): distribution = task.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, task.hero.level) artifact.sharp(distribution=distribution, max_power=max_power, force=True) return task.logic_result(message=u"Вся экипировка героя улучшена")
def use(self, task, storage, **kwargs): # pylint: disable=R0911,W0613 artifact = random.choice(task.hero.equipment.values()) distribution=task.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, task.hero.level) artifact.sharp(distribution=distribution, max_power=max_power, force=True) return task.logic_result(message=u'Улучшена экипировка героя: %(artifact)s' % {'artifact': artifact.html_label()})
def test_sharp_preferences_with_max_power(self): distribution = self.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.hero.level) self.hero.preferences.set_equipment_slot(relations.EQUIPMENT_SLOT.HAND_PRIMARY) artifact = self.hero.equipment.get(relations.EQUIPMENT_SLOT.HAND_PRIMARY) artifact.power = max_power artifact = self.hero.sharp_artifact() self.assertFalse(artifact.type.is_MAIN_HAND)
def test_sharp_preferences_with_max_power(self): distribution = self.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.hero.level) self.hero.preferences.set_equipment_slot(relations.EQUIPMENT_SLOT.HAND_PRIMARY) artifact = self.hero.equipment.get(relations.EQUIPMENT_SLOT.HAND_PRIMARY) artifact.power = max_power artifact = self.hero.sharp_artifact() self.assertFalse(artifact.type.is_MAIN_HAND)
def use(self, task, storage, **kwargs): # pylint: disable=R0911,W0613 for artifact in task.hero.equipment.values(): distribution = task.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval( distribution, task.hero.level) artifact.sharp(distribution=distribution, max_power=max_power, force=True) return task.logic_result(message=u'Вся экипировка героя улучшена')
def use(self, task, storage, **kwargs): # pylint: disable=R0911,W0613 artifact = random.choice(task.hero.equipment.values()) distribution = task.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval( distribution, task.hero.level) artifact.sharp(distribution=distribution, max_power=max_power, force=True) return task.logic_result( message=u'Улучшена экипировка героя: %(artifact)s' % {'artifact': artifact.html_label()})
def test_sharp_artifact_when_all_artifacts_has_max_power(self): distribution = self.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.hero.level) for artifact in self.hero.equipment.equipment.values(): artifact.power = max_power.clone() old_power = self.hero.power artifact = self.hero.sharp_artifact() self.assertTrue(self.hero.power.physic > old_power.physic or self.hero.power.magic > old_power.magic) self.assertTrue(artifact.power == max_power + Power(1, 0) or artifact.power == max_power + Power(0, 1)) self.assertTrue(self.hero.equipment.updated)
def test_only_better_for_prefered_slot(self): self.hero._model.level = 9999 self.hero.preferences.set_equipment_slot(relations.EQUIPMENT_SLOT.PLATE) # just set any artifact self.hero.receive_artifact(equip=True, better=False, prefered_slot=True, prefered_item=True, archetype=True) distribution = self.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.hero.level) for i in xrange(100): old_artifact = self.hero.equipment.get(relations.EQUIPMENT_SLOT.PLATE) old_artifact.power = max_power - Power(1, 1) self.hero.receive_artifact(equip=True, better=True, prefered_slot=True, prefered_item=True, archetype=True) self.assertTrue(self.hero.equipment.get(relations.EQUIPMENT_SLOT.PLATE).preference_rating(distribution) > old_artifact.preference_rating(distribution))
def test_sharp_artifact_when_all_artifacts_has_max_power(self): distribution = self.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.hero.level) for artifact in self.hero.equipment.equipment.values(): artifact.power = max_power.clone() old_power = self.hero.power artifact = self.hero.sharp_artifact() self.assertTrue(self.hero.power.physic > old_power.physic or self.hero.power.magic > old_power.magic) self.assertTrue(artifact.power == max_power + Power(1, 0) or artifact.power == max_power + Power(0, 1)) self.assertTrue(self.hero.equipment.updated)
def test_sharp_artifact_when_all_artifacts_has_max_power(self): distribution = self.hero.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.hero.level) for artifact in list(self.hero.equipment.equipment.values()): artifact.power = max_power.clone() old_power = self.hero.power with mock.patch('the_tale.game.heroes.bag.Equipment.mark_updated') as mark_updated: artifact = self.hero.sharp_artifact() self.assertTrue(mark_updated.call_count >= 1) self.assertTrue(self.hero.power.physic > old_power.physic or self.hero.power.magic > old_power.magic) self.assertTrue(artifact.power == max_power + Power(1, 0) or artifact.power == max_power + Power(0, 1))
def sharp_artifact(self): choices = list(relations.EQUIPMENT_SLOT.records) random.shuffle(choices) if self.preferences.equipment_slot is not None and self.can_upgrade_prefered_slot: choices.insert(0, self.preferences.equipment_slot) distribution = self.preferences.archetype.power_distribution min_power, max_power = Power.artifact_power_interval(distribution, self.level) # pylint: disable=W0612 for slot in choices: artifact = self.equipment.get(slot) if artifact is not None and artifact.sharp(distribution, max_power): self.equipment.updated = True return artifact # if all artifacts are on maximum level random.shuffle(choices) for slot in choices: artifact = self.equipment.get(slot) if artifact is not None and artifact.sharp(distribution, max_power, force=True): self.equipment.updated = True return artifact