def test_no_stop_when_quest_required_replane(self): self.action_idl.percents = 0.0 self.assertFalse(self.action_trade.replane_required) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.action_trade.percents_barier = 2 self.assertEqual(self.hero.bag.occupation, 2) current_time = TimePrototype.get_current_time() self.storage.process_turn() self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_trade) self.action_trade.replane_required = True current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.bag.occupation, 0) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.action_trade.state, self.action_trade.STATE.PROCESSED) self.assertEqual(self.hero.actions.current_action, self.action_idl)
def test_drop_cheapest_item(self): artifact_1 = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact_2 = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact_1.power = Power(200, 200) artifact_2.power = Power(1, 1) self.hero.bag.put_artifact(artifact_1) self.hero.bag.put_artifact(artifact_2) distribution = self.hero.preferences.archetype.power_distribution self.assertEqual(self.hero.bag.occupation, 2) dropped_item = self.hero.bag.drop_cheapest_item(distribution) self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(dropped_item.id, artifact_2.id) self.assertEqual(self.hero.bag.values()[0].id, artifact_1.id)
def test_generate_artifact_from_list(self): helmet_2 = ArtifactRecordPrototype.create_random( 'helmet_2', type_=relations.ARTIFACT_TYPE.HELMET) plate_2 = ArtifactRecordPrototype.create_random( 'plate_2', type_=relations.ARTIFACT_TYPE.PLATE) boots_2 = ArtifactRecordPrototype.create_random( 'boots_2', type_=relations.ARTIFACT_TYPE.BOOTS) helmet_3 = ArtifactRecordPrototype.create_random( 'helmet_3', type_=relations.ARTIFACT_TYPE.HELMET) plate_3 = ArtifactRecordPrototype.create_random( 'plate_3', type_=relations.ARTIFACT_TYPE.PLATE) boots_3 = ArtifactRecordPrototype.create_random( 'boots_3', type_=relations.ARTIFACT_TYPE.BOOTS) artifacts = [helmet_2, plate_2, boots_2] artifacts_ids = [artifact.uuid for artifact in artifacts] for i in xrange(100): artifact = artifacts_storage.generate_artifact_from_list( artifacts, 1, rarity=relations.RARITY.NORMAL) self.assertTrue(artifact.id in artifacts_ids + heroes_relations.EQUIPMENT_SLOT.default_uids()) artifacts = [helmet_3, plate_3, boots_3] artifacts_ids = [artifact.uuid for artifact in artifacts] for i in xrange(100): artifact = artifacts_storage.generate_artifact_from_list( artifacts, 1, rarity=relations.RARITY.NORMAL) self.assertTrue(artifact.id in artifacts_ids + heroes_relations.EQUIPMENT_SLOT.default_uids())
def test_sell_and_continue(self): old_money = self.hero.money artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.assertEqual(self.hero.bag.occupation, 2) self.action_trade.percents_barier = 2 current_time = TimePrototype.get_current_time() self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_trade) self.assertEqual(self.hero.bag.occupation, 1) self.assertTrue(self.hero.money > old_money) old_money = self.hero.money current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.bag.occupation, 0) self.assertTrue(self.hero.money > old_money) self.storage._test_save()
def test_stop_when_quest_required_replane(self): self.action_idl.percents = 0.0 self.assertFalse(self.action_trade.replane_required) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.action_trade.percents_barier = 2 self.assertEqual(self.hero.bag.occupation, 2) current_time = TimePrototype.get_current_time() self.storage.process_turn() self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_trade) self.action_trade.replane_required = True current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.action_trade.state, self.action_trade.STATE.PROCESSED) self.assertEqual(self.hero.actions.current_action, self.action_idl)
def test_sell_and_continue(self): old_money = self.hero.money artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.assertEqual(self.hero.bag.occupation, 2) self.action_trade.percents_barier = 2 current_time = TimePrototype.get_current_time() self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_trade) self.assertEqual(self.hero.bag.occupation, 1) self.assertTrue(self.hero.money > old_money) old_money = self.hero.money current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertEqual(self.hero.bag.occupation, 0) self.assertTrue(self.hero.money > old_money) self.storage._test_save()
def test_not_bying_artifact__when_has_equip_candidates_in_bag(self): while not self.hero.next_spending.is_BUYING_ARTIFACT: self.hero.switch_spending() # fill all slots with artifacts self.hero.equipment.test_equip_in_all_slots( artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)) money = self.hero.spend_amount self.hero._model.money = money self.hero.bag.put_artifact( artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, 666, rarity=RARITY.EPIC)) with self.check_not_changed(lambda: self.hero.statistics.money_spend): with self.check_not_changed( lambda: self.hero.statistics.money_spend_for_artifacts): with self.check_not_changed(lambda: self.hero.statistics. money_earned_from_artifacts): with self.check_not_changed( lambda: self.hero.statistics.artifacts_had): with self.check_not_changed( lambda: self.hero.bag.occupation): self.storage.process_turn()
def test_serialize(self): self.bag.put_artifact( artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) ) self.bag.put_artifact( artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) ) self.assertEqual(self.bag.serialize(), bag.Bag.deserialize(self.hero, self.bag.serialize()).serialize())
def test_serialize(self): self.bag.put_artifact( artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL)) self.bag.put_artifact( artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL)) self.assertEqual(self.bag.serialize(), bag.Bag.deserialize(self.bag.serialize()).serialize())
def test_compare_drop__artifact_and_artifact(self): artifact_1 = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=artifacts_relations.RARITY.NORMAL) artifact_2 = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=artifacts_relations.RARITY.NORMAL) artifact_2.power = Power(1, 1) artifact_1.power = Power(2, 2) distribution = self.hero.preferences.archetype.power_distribution self.assertTrue(self.hero.bag._compare_drop(distribution, artifact_1, artifact_2)) self.assertFalse(self.hero.bag._compare_drop(distribution, artifact_2, artifact_1))
def test_equipping_process(self): self.assertEqual(self.hero.get_equip_candidates(), (None, None, None)) #equip artefact in empty slot artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) equip_slot = artifact.type.equipment_slot self.hero.equipment.unequip(equip_slot) self.hero.bag.put_artifact(artifact) slot, unequipped, equipped = self.hero.get_equip_candidates() self.assertTrue(slot) self.assertTrue(unequipped is None) self.assertEqual(equipped, artifact) with mock.patch( 'the_tale.game.heroes.objects.Hero.reset_accessors_cache' ) as reset_accessors_cache: self.hero.change_equipment(slot, unequipped, equipped) self.assertEqual(reset_accessors_cache.call_count, 1) self.assertTrue(not self.hero.bag.items()) self.assertEqual(self.hero.equipment.get(slot), artifact) # change artifact new_artifact = artifacts_storage.generate_artifact_from_list( [artifact.record], self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) new_artifact.power = artifact.power + Power(1, 1) self.hero.bag.put_artifact(new_artifact) slot, unequipped, equipped = self.hero.get_equip_candidates() self.assertTrue(slot) self.assertEqual(unequipped, artifact) self.assertEqual(equipped, new_artifact) with mock.patch( 'the_tale.game.heroes.objects.Hero.reset_accessors_cache' ) as reset_accessors_cache: self.hero.change_equipment(slot, unequipped, equipped) self.assertEqual(reset_accessors_cache.call_count, 1) self.assertEqual(self.hero.bag.items()[0][1], artifact) self.assertEqual(len(self.hero.bag.items()), 1) self.assertEqual(self.hero.equipment.get(slot), new_artifact) self.storage._test_save()
def test_compare_drop__artifact_and_artifact(self): artifact_1 = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=artifacts_relations.RARITY.NORMAL) artifact_2 = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=artifacts_relations.RARITY.NORMAL) artifact_2.power = Power(1, 1) artifact_1.power = Power(2, 2) distribution = self.hero.preferences.archetype.power_distribution self.assertTrue(self.hero.bag._compare_drop(distribution, artifact_1, artifact_2)) self.assertFalse(self.hero.bag._compare_drop(distribution, artifact_2, artifact_1))
def test_compare_drop__useless_and_artifact(self): distribution = self.hero.preferences.archetype.power_distribution artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, 1, rarity=artifacts_relations.RARITY.NORMAL) loot = artifacts_storage.generate_artifact_from_list( artifacts_storage.loot, 666, rarity=artifacts_relations.RARITY.NORMAL) self.assertFalse( self.hero.bag._compare_drop(distribution, loot, artifact))
def test_compare_drop__useless_and_useless(self): distribution = self.hero.preferences.archetype.power_distribution loot_1 = artifacts_storage.generate_artifact_from_list( artifacts_storage.loot, 2, rarity=artifacts_relations.RARITY.NORMAL) loot_2 = artifacts_storage.generate_artifact_from_list( artifacts_storage.loot, 1, rarity=artifacts_relations.RARITY.NORMAL) self.assertTrue( self.hero.bag._compare_drop(distribution, loot_1, loot_2))
def test_serialize(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) self.equipment.equip(artifact.type.equipment_slot, artifact) self.assertEqual( self.equipment.serialize(), bag.Equipment.deserialize(self.hero, self.equipment.serialize()).serialize() )
def test_damage_integrity__favorite_item(self): new_artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) self.hero.equipment.unequip(new_artifact.type.equipment_slot) self.hero.equipment.equip(new_artifact.type.equipment_slot, new_artifact) old_integrity = new_artifact.integrity self.hero.damage_integrity() not_favorite_integrity = new_artifact.integrity self.hero.preferences.set_favorite_item( new_artifact.type.equipment_slot) self.hero.damage_integrity() favorite_integrity = new_artifact.integrity self.assertTrue( old_integrity - not_favorite_integrity > not_favorite_integrity - favorite_integrity)
def test_damage_integrity__damage_from_artifact_power(self): expected_artifact_power = Power.normal_power_to_level(self.hero.level) new_artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) new_artifact.power = Power(expected_artifact_power / 2, expected_artifact_power / 2) self.hero.equipment.unequip(new_artifact.type.equipment_slot) self.hero.equipment.equip(new_artifact.type.equipment_slot, new_artifact) old_integrity = new_artifact.integrity self.hero.damage_integrity() not_modified_integrity = new_artifact.integrity new_artifact.power = Power(expected_artifact_power, expected_artifact_power) self.hero.damage_integrity() modified_integrity = new_artifact.integrity self.assertTrue( old_integrity - not_modified_integrity < not_modified_integrity - modified_integrity)
def test_put_loot(self): with self.check_delta(lambda: self.hero.bag.occupation, 1): self.hero.put_loot( artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL))
def test_get_equip_candidates__ignore_favorite_item_slot(self): self.assertTrue(self.hero.bag.is_empty) self.assertTrue( self.hero.equipment.get(relations.EQUIPMENT_SLOT.HAND_PRIMARY)) self.assertEqual(self.hero.preferences.favorite_item, None) old_artifact = self.hero.equipment.get( relations.EQUIPMENT_SLOT.HAND_PRIMARY) artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts_for_type( [relations.EQUIPMENT_SLOT.HAND_PRIMARY.artifact_type]), self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact.power = old_artifact.power + Power(1, 1) self.hero.bag.put_artifact(artifact) slot, unequipped, equipped = self.hero.get_equip_candidates() self.assertEqual(slot, relations.EQUIPMENT_SLOT.HAND_PRIMARY) self.assertEqual(unequipped, old_artifact) self.assertEqual(equipped, artifact) self.hero.preferences.set_favorite_item( relations.EQUIPMENT_SLOT.HAND_PRIMARY) slot, unequipped, equipped = self.hero.get_equip_candidates() self.assertEqual(slot, None) self.assertEqual(unequipped, None) self.assertEqual(equipped, None)
def test_buying_artifact_with_change(self): while not self.hero.next_spending.is_BUYING_ARTIFACT: self.hero.switch_spending() # fill all slots with artifacts self.hero.equipment.test_equip_in_all_slots(artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)) money = self.hero.spend_amount #buy artifact self.hero.money = money self.assertEqual(self.hero.statistics.money_spend, 0) self.assertEqual(self.hero.statistics.money_spend_for_artifacts, 0) self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0) self.storage.process_turn() self.assertTrue(self.hero.money > 0) self.assertEqual(len(self.hero.bag.items()), 0) self.assertTrue(self.hero.statistics.money_spend > money - self.hero.money) self.assertTrue(self.hero.statistics.money_spend_for_artifacts > money - self.hero.money) self.assertEqual(self.hero.statistics.artifacts_had, 1) self.assertTrue(self.hero.statistics.money_earned_from_artifacts > 0) self.storage._test_save()
def setUp(self): super(InPlaceActionCompanionLeaveTests, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() self.account = self.accounts_factory.create_account() self.storage = LogicStorage() self.storage.load_account_data(self.account) self.hero = self.storage.accounts_to_heroes[self.account.id] self.action_idl = self.hero.actions.current_action self.companion_record = companions_logic.create_random_companion_record('thief', state=companions_relations.STATE.ENABLED) self.hero.set_companion(companions_logic.create_companion(self.companion_record)) self.hero.money = f.expected_gold_in_day(self.hero.level) self.hero.position.set_place(self.place_1) self.hero.position.update_previous_place() self.hero.position.set_place(self.place_2) self.artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.loot, 1, rarity=RARITY.NORMAL) self.hero.put_loot(self.artifact) self.assertEqual(self.hero.bag.occupation, 1) self.hero.position.move_out_place()
def test_disabled_artifacts(self): loot = ArtifactRecordPrototype.create_random( 'disabled_loot', type_=relations.ARTIFACT_TYPE.USELESS, state=relations.ARTIFACT_RECORD_STATE.DISABLED) artifact = ArtifactRecordPrototype.create_random( 'disabled_artifact', type_=relations.ARTIFACT_TYPE.HELMET, state=relations.ARTIFACT_RECORD_STATE.DISABLED) self.assertFalse( set(['disabled_loot', 'disabled_artifact']) & set(a.uuid for a in artifacts_storage.artifacts)) self.assertFalse( set(['disabled_loot', 'disabled_artifact']) & set(a.uuid for a in artifacts_storage.loot)) self.assertFalse( set(['disabled_loot', 'disabled_artifact']) & set( artifacts_storage.artifacts_for_type([ relations.ARTIFACT_TYPE.USELESS, relations.ARTIFACT_TYPE.HELMET ]))) self.assertEqual( artifacts_storage.generate_artifact_from_list( [loot, artifact], level=1, rarity=relations.RARITY.NORMAL), None)
def test_put_loot__bonus_power_for_artifact(self): artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact.power = Power(0, 0) self.hero.put_loot(artifact) self.assertEqual(artifact.power, Power(1, 1))
def test_artifacts_to_break__all_unbreakable(self): self.hero.equipment._remove_all() for slot in relations.EQUIPMENT_SLOT.records: artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) self.hero.equipment.equip(slot, artifact) self.assertFalse(artifact.can_be_broken()) self.assertEqual(self.hero.artifacts_to_break(), [])
def test_artifacts_to_break__all_unbreakable(self): self.hero.equipment._remove_all() for slot in relations.EQUIPMENT_SLOT.records: artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) self.hero.equipment.equip(slot, artifact) self.assertFalse(artifact.can_be_broken()) self.assertEqual(self.hero.artifacts_to_break(), [])
def test_serialize(self): artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) self.equipment.equip(artifact.type.equipment_slot, artifact) self.assertEqual( self.equipment.serialize(), bag.Equipment.deserialize(self.equipment.serialize()).serialize())
def test_not_bying_artifact__when_has_equip_candidates_in_bag(self): while not self.hero.next_spending.is_BUYING_ARTIFACT: self.hero.switch_spending() # fill all slots with artifacts self.hero.equipment.test_equip_in_all_slots(artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)) money = self.hero.spend_amount self.hero.money = money self.hero.bag.put_artifact(artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 666, rarity=RARITY.EPIC)) with self.check_not_changed(lambda: self.hero.statistics.money_spend): with self.check_not_changed(lambda: self.hero.statistics.money_spend_for_artifacts): with self.check_not_changed(lambda: self.hero.statistics.money_earned_from_artifacts): with self.check_not_changed(lambda: self.hero.statistics.artifacts_had): with self.check_not_changed(lambda: self.hero.bag.occupation): self.storage.process_turn()
def test_compare_drop__none(self): distribution = self.hero.preferences.archetype.power_distribution loot = artifacts_storage.generate_artifact_from_list( artifacts_storage.loot, 666, rarity=artifacts_relations.RARITY.NORMAL) self.assertTrue(self.hero.bag._compare_drop(distribution, None, loot)) self.assertFalse(self.hero.bag._compare_drop(distribution, loot, None))
def test_disabled_artifacts(self): loot = ArtifactRecordPrototype.create_random('disabled_loot', type_=relations.ARTIFACT_TYPE.USELESS, state=relations.ARTIFACT_RECORD_STATE.DISABLED) artifact = ArtifactRecordPrototype.create_random('disabled_artifact', type_=relations.ARTIFACT_TYPE.HELMET, state=relations.ARTIFACT_RECORD_STATE.DISABLED) self.assertFalse(set(['disabled_loot', 'disabled_artifact']) & set(a.uuid for a in artifacts_storage.artifacts)) self.assertFalse(set(['disabled_loot', 'disabled_artifact']) & set(a.uuid for a in artifacts_storage.loot)) self.assertFalse(set(['disabled_loot', 'disabled_artifact']) & set(artifacts_storage.artifacts_for_type([relations.ARTIFACT_TYPE.USELESS, relations.ARTIFACT_TYPE.HELMET]))) self.assertEqual(artifacts_storage.generate_artifact_from_list([loot, artifact], level=1, rarity=relations.RARITY.NORMAL), None)
def test_put_loot__bag_is_full(self): with self.check_delta(lambda: self.hero.bag.occupation, self.hero.max_bag_size): for i in xrange(self.hero.max_bag_size * 2): self.hero.put_loot( artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL))
def test_equipping_process(self): self.assertEqual(self.hero.get_equip_candidates(), (None, None, None)) #equip artefact in empty slot artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) equip_slot = artifact.type.equipment_slot self.hero.equipment.unequip(equip_slot) self.hero.bag.put_artifact(artifact) slot, unequipped, equipped = self.hero.get_equip_candidates() self.assertTrue(slot) self.assertTrue(unequipped is None) self.assertEqual(equipped, artifact) with mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.reset_accessors_cache') as reset_accessors_cache: self.hero.change_equipment(slot, unequipped, equipped) self.assertEqual(reset_accessors_cache.call_count, 1) self.assertTrue(not self.hero.bag.items()) self.assertEqual(self.hero.equipment.get(slot), artifact) # change artifact new_artifact = artifacts_storage.generate_artifact_from_list([artifact.record], self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) new_artifact.power = artifact.power + Power(1, 1) self.hero.bag.put_artifact(new_artifact) slot, unequipped, equipped = self.hero.get_equip_candidates() self.assertTrue(slot) self.assertEqual(unequipped, artifact) self.assertEqual(equipped, new_artifact) with mock.patch('the_tale.game.heroes.prototypes.HeroPrototype.reset_accessors_cache') as reset_accessors_cache: self.hero.change_equipment(slot, unequipped, equipped) self.assertEqual(reset_accessors_cache.call_count, 1) self.assertEqual(self.hero.bag.items()[0][1], artifact) self.assertEqual(len(self.hero.bag.items()), 1) self.assertEqual(self.hero.equipment.get(slot), new_artifact) self.storage._test_save()
def test_equip_action_create(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) artifact.power = Power(666, 666) self.hero.bag.put_artifact(artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 3) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionEquippingPrototype.TYPE) self.storage._test_save()
def use(self, task, storage, **kwargs): # pylint: disable=R0911,W0613 artifacts_list, rarity = self.get_new_artifact_data() artifact = artifacts_storage.generate_artifact_from_list(artifacts_list, task.hero.level, rarity=rarity) task.hero.put_loot(artifact, force=True) task.hero.actions.request_replane() return task.logic_result(message=u'В рюкзаке героя появился новый артефакт: %(artifact)s' % {'artifact': artifact.html_label()})
def test_can_safe_artifact_integrity__favorite_item(self): artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) self.hero.preferences.set_favorite_item(artifact.type.equipment_slot) self.assertTrue( any( self.hero.can_safe_artifact_integrity(artifact) for i in xrange(100)))
def test_damage_integrity__safe(self): self.hero.equipment._remove_all() for slot in relations.EQUIPMENT_SLOT.records: artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) self.assertEqual(artifact.integrity, artifact.max_integrity) self.hero.damage_integrity() for artifact in self.hero.equipment.values(): self.assertEqual(artifact.integrity, artifact.max_integrity)
def test_damage_integrity__safe(self): self.hero.equipment._remove_all() for slot in relations.EQUIPMENT_SLOT.records: artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) self.assertEqual(artifact.integrity, artifact.max_integrity) self.hero.damage_integrity() for artifact in list(self.hero.equipment.values()): self.assertEqual(artifact.integrity, artifact.max_integrity)
def test_ui_info_cache(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) self.equipment.equip(artifact.type.equipment_slot, artifact) ui_info = self.equipment.ui_info(self.hero) self.assertEqual(self.equipment._ui_info, ui_info) self.equipment.mark_updated() self.assertEqual(self.equipment._ui_info, None)
def test_ui_info_cache(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) self.equipment.equip(artifact.type.equipment_slot, artifact) ui_info = self.equipment.ui_info(self.hero) self.assertEqual(self.equipment._ui_info, ui_info) self.equipment.mark_updated() self.assertEqual(self.equipment._ui_info, None)
def test_trade_action_create(self): for i in xrange(int(c.MAX_BAG_SIZE * c.BAG_SIZE_TO_SELL_LOOT_FRACTION) + 1): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.loot, 1, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 3) self.assertEqual(self.hero.actions.current_action.TYPE, prototypes.ActionTradingPrototype.TYPE) self.storage._test_save()
def test_can_safe_artifact_integrity__favorite_item__wrong_slot(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) wrong_slot = None for slot in relations.EQUIPMENT_SLOT.records: if artifact.type.equipment_slot != slot: wrong_slot = slot break self.hero.preferences.set_favorite_item(wrong_slot) self.assertFalse(any(self.hero.can_safe_artifact_integrity(artifact) for i in xrange(100)))
def test_drop_cheapest_item(self): artifact_1 = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact_2 = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact_1.power = Power(200, 200) artifact_2.power = Power(1, 1) self.hero.bag.put_artifact(artifact_1) self.hero.bag.put_artifact(artifact_2) distribution = self.hero.preferences.archetype.power_distribution self.assertEqual(self.hero.bag.occupation, 2) dropped_item = self.hero.bag.drop_cheapest_item(distribution) self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(dropped_item.id, artifact_2.id) self.assertEqual(self.hero.bag.values()[0].id, artifact_1.id)
def test_ui_info_cache(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) self.bag.put_artifact(artifact) ui_info = self.bag.ui_info(self.hero) self.assertEqual(self.bag._ui_info, ui_info) self.bag.mark_updated() self.assertEqual(self.bag._ui_info, None)
def test_ui_info_cache(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) self.bag.put_artifact(artifact) ui_info = self.bag.ui_info(self.hero) self.assertEqual(self.bag._ui_info, ui_info) self.bag.mark_updated() self.assertEqual(self.bag._ui_info, None)
def test_success__critical(self): self.hero.bag.put_artifact(artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)) old_money_stats = self.hero.statistics.money_earned_from_help self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(self.ability.use(**self.use_attributes), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ())) self.assertEqual(self.hero.bag.occupation, 0) self.assertTrue(old_money_stats < self.hero.statistics.money_earned_from_help)
def test_success(self): self.hero.bag.put_artifact( artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL)) with self.check_delta(lambda: self.hero.bag.occupation, -1): with self.check_delta(lambda: self.hero.cards.help_count, 1): self.assertEqual(self.ability.use(**self.use_attributes), (ComplexChangeTask.RESULT.SUCCESSED, ComplexChangeTask.STEP.SUCCESS, ()))
def test_generate_artifact_from_list(self): helmet_2 = ArtifactRecordPrototype.create_random('helmet_2', type_=relations.ARTIFACT_TYPE.HELMET) plate_2 = ArtifactRecordPrototype.create_random('plate_2', type_=relations.ARTIFACT_TYPE.PLATE) boots_2 = ArtifactRecordPrototype.create_random('boots_2', type_=relations.ARTIFACT_TYPE.BOOTS) helmet_3 = ArtifactRecordPrototype.create_random('helmet_3', type_=relations.ARTIFACT_TYPE.HELMET) plate_3 = ArtifactRecordPrototype.create_random('plate_3', type_=relations.ARTIFACT_TYPE.PLATE) boots_3 = ArtifactRecordPrototype.create_random('boots_3', type_=relations.ARTIFACT_TYPE.BOOTS) artifacts = [helmet_2, plate_2, boots_2] artifacts_ids = [artifact.uuid for artifact in artifacts] for i in range(100): artifact = artifacts_storage.generate_artifact_from_list(artifacts, 1, rarity=relations.RARITY.NORMAL) self.assertTrue(artifact.id in artifacts_ids + heroes_relations.EQUIPMENT_SLOT.default_uids()) artifacts = [helmet_3, plate_3, boots_3] artifacts_ids = [artifact.uuid for artifact in artifacts] for i in range(100): artifact = artifacts_storage.generate_artifact_from_list(artifacts, 1, rarity=relations.RARITY.NORMAL) self.assertTrue(artifact.id in artifacts_ids + heroes_relations.EQUIPMENT_SLOT.default_uids())
def test_switch_artifact(self): artifact = artifacts_storage.generate_artifact_from_list( artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) artifact.power = Power(13, 13) equip_slot = artifact.type.equipment_slot self.hero.equipment.unequip(equip_slot) self.hero.equipment.equip(equip_slot, artifact) new_artifact = artifacts_storage.generate_artifact_from_list( [artifact.record], self.hero.level + 1, rarity=RARITY.NORMAL) new_artifact.power = Power(666, 666) self.hero.bag.put_artifact(new_artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_equipping) self.assertEqual(len(list(self.hero.bag.items())), 1) self.assertEqual( list(self.hero.bag.items())[0][1].power, Power(13, 13)) equip_slot = artifact.type.equipment_slot self.assertEqual(self.hero.equipment.get(equip_slot), new_artifact) self.assertEqual( self.hero.equipment.get(equip_slot).power, Power(666, 666)) current_time = TimePrototype.get_current_time() current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save()
def test_base_equip__in_filled_slot(self): self.hero.equipment._remove_all() for slot in relations.EQUIPMENT_SLOT.records: self.hero.equipment.equip(slot, artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL)) with self.check_delta(lambda: self.hero.statistics.artifacts_had, 1): equipped, unequipped, coins = self.hero.receive_artifact(equip=True, better=False, prefered_slot=True, prefered_item=True, archetype=True) self.assertEqual(self.hero.equipment.get(equipped.type.equipment_slot), equipped) self.assertFalse(equipped in self.hero.bag.values()) self.assertFalse(unequipped in self.hero.bag.values()) self.assertTrue(coins > 0)
def test_artifacts_to_break__all_broken__from_all(self): self.hero.equipment._remove_all() for slot in relations.EQUIPMENT_SLOT.records: artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact.integrity = slot.value artifact.max_integrity = 100 self.hero.equipment.equip(slot, artifact) self.assertTrue(artifact.can_be_broken()) for i in xrange(100): for candidate in self.hero.artifacts_to_break(from_all=True): self.assertTrue(candidate.integrity <= int(c.EQUIP_SLOTS_NUMBER * c.EQUIPMENT_BREAK_FRACTION) + 1)
def randomize_equip(self): for slot in relations.EQUIPMENT_SLOT.records: self.equipment.unequip(slot) artifacts_list = self.receive_artifacts_choices(better=False, prefered_slot=False, prefered_item=False, archetype=True) artifacts_list = [artifact for artifact in artifacts_list if artifact.type.equipment_slot == slot] if not artifacts_list: continue artifact = artifacts_storage.generate_artifact_from_list(artifacts_list, self.level, rarity=artifacts_relations.RARITY.NORMAL) self.equipment.equip(slot, artifact)
def test_switch_artifact(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) artifact.power = Power(13, 13) equip_slot = artifact.type.equipment_slot self.hero.equipment.unequip(equip_slot) self.hero.equipment.equip(equip_slot, artifact) new_artifact = artifacts_storage.generate_artifact_from_list([artifact.record], self.hero.level+1, rarity=RARITY.NORMAL) new_artifact.power = Power(666, 666) self.hero.bag.put_artifact(new_artifact) self.storage.process_turn() self.assertEqual(len(self.hero.actions.actions_list), 2) self.assertEqual(self.hero.actions.current_action, self.action_equipping) self.assertEqual(len(list(self.hero.bag.items())), 1) self.assertEqual(list(self.hero.bag.items())[0][1].power, Power(13, 13)) equip_slot = artifact.type.equipment_slot self.assertEqual(self.hero.equipment.get(equip_slot), new_artifact) self.assertEqual(self.hero.equipment.get(equip_slot).power, Power(666, 666)) current_time = TimePrototype.get_current_time() current_time.increment_turn() self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.storage._test_save()
def test_pop_artifact(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, 1, rarity=RARITY.NORMAL) self.bag.put_artifact(artifact) self.bag.updated = False self.bag._ui_info = "fake ui info" with self.check_delta(lambda: self.bag.occupation, -1): self.bag.pop_artifact(artifact) self.assertTrue(self.bag.updated) self.assertEqual(self.bag._ui_info, None) self.assertEqual(self.bag.bag, {})
def test_sell_artifact__sell_price_less_than_zero(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(self.hero.money, 0) self.assertEqual(self.hero.statistics.money_earned_from_loot, 0) self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0) self.assertEqual(self.hero.sell_artifact(artifact), 1) self.assertEqual(self.hero.bag.occupation, 0) self.assertEqual(self.hero.money, 1) self.assertEqual(self.hero.statistics.money_earned_from_loot, 0) self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 1)
def test_sell_and_finish(self): old_money_statistics = self.hero.statistics.money_earned old_money = self.hero.money artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts, self.hero.level, rarity=RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.action_trade.percents_barier = 1 self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(len(self.hero.actions.actions_list), 1) self.assertEqual(self.hero.actions.current_action, self.action_idl) self.assertTrue(self.hero.money > old_money) self.assertTrue(self.hero.statistics.money_earned > old_money_statistics) self.storage._test_save()
def test_get_equip_candidates__worst_integrity(self): self.assertTrue(self.hero.bag.is_empty) self.assertTrue(self.hero.equipment.get(relations.EQUIPMENT_SLOT.HAND_PRIMARY)) old_artifact = self.hero.equipment.get(relations.EQUIPMENT_SLOT.HAND_PRIMARY) artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.artifacts_for_type([relations.EQUIPMENT_SLOT.HAND_PRIMARY.artifact_type]), self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) artifact.power = old_artifact.power artifact.integrity = old_artifact.integrity - 1 self.hero.bag.put_artifact(artifact) slot, unequipped, equipped = self.hero.get_equip_candidates() self.assertEqual(slot, None) self.assertEqual(unequipped, None) self.assertEqual(equipped, None)
def test_sell_artifact__useless(self): artifact = artifacts_storage.generate_artifact_from_list(artifacts_storage.loot, self.hero.level, rarity=artifacts_relations.RARITY.NORMAL) self.hero.bag.put_artifact(artifact) self.assertEqual(self.hero.bag.occupation, 1) self.assertEqual(self.hero.money, 0) self.assertEqual(self.hero.statistics.money_earned_from_loot, 0) self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0) price = self.hero.sell_artifact(artifact) self.assertTrue(price > 0) self.assertEqual(self.hero.bag.occupation, 0) self.assertEqual(self.hero.money, price) self.assertEqual(self.hero.statistics.money_earned_from_loot, price) self.assertEqual(self.hero.statistics.money_earned_from_artifacts, 0)