def setUp(self): super(QuestsTestBase, self).setUp() self.p1, self.p2, self.p3 = create_test_map() # add more persons, to lower conflicts places_logic.add_person_to_place(self.p1) places_logic.add_person_to_place(self.p1) places_logic.add_person_to_place(self.p2) places_logic.add_person_to_place(self.p2) places_logic.add_person_to_place(self.p3) places_logic.add_person_to_place(self.p3) account = self.accounts_factory.create_account(is_fast=True) self.storage = LogicStorage() self.storage.load_account_data(account) self.hero = self.storage.accounts_to_heroes[account.id] self.action_idl = self.hero.actions.current_action self.hero.money += 1 self.hero.preferences.set_mob(mobs_storage.all()[0]) self.hero.preferences.set_place(self.p1) self.hero.preferences.set_friend(self.p1.persons[0]) self.hero.preferences.set_enemy(self.p2.persons[0]) self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE) self.hero.position.set_place(self.p3) heroes_logic.save_hero(self.hero) self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY) places_logic.save_place(self.p2) self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH persons_logic.save_person(self.p1.persons[0])
def setUp(self): super(TestCreateRequests, self).setUp() self.request_logout() self.request_login(self.account_2.email) self.mob = mobs_storage.all()[0]
def test_initialize(self): self.assertEqual(len(mobs_storage.all()), 5) self.assertEqual(mobs_storage.mobs_number, 5) self.assertEqual(sum(mobs_storage._types_count.itervalues()), 5) self.assertTrue( mobs_storage.mob_type_fraction(game_relations.BEING_TYPE.CIVILIZED) > 2.0 / 5)
def setUp(self): super(TestCreateRequests, self).setUp() self.request_logout() self.request_login('*****@*****.**') self.mob = mobs_storage.all()[0]
def setUp(self): super(MobsStorageTests, self).setUp() create_test_map() self.mob_1, self.mob_2, self.mob_3 = mobs_storage.all() self.mob_1.type = MOB_TYPE.CIVILIZED self.mob_1.save() self.mob_2.type = MOB_TYPE.BARBARIAN self.mob_2.save() self.mob_3.type = MOB_TYPE.CIVILIZED self.mob_3.save() self.bandit = MobRecordPrototype.create(uuid='bandit', level=1, utg_name=names.generator.get_test_name(name='bandint'), description='description', abilities=['hit'], terrains=[TERRAIN.PLANE_SAND], type=MOB_TYPE.CIVILIZED, state=MOB_RECORD_STATE.ENABLED) self.bandint_wrong = MobRecordPrototype.create(uuid='bandit_wrong', level=1, utg_name=names.generator.get_test_name(name='bandit_wrong'), description='bandit_wrong description', abilities=['hit'], terrains=[TERRAIN.PLANE_SAND], type=MOB_TYPE.CIVILIZED, state=MOB_RECORD_STATE.DISABLED)
def setUp(self): super(QuestsTestBase, self).setUp() self.p1, self.p2, self.p3 = create_test_map() # add more persons, to lower conflicts self.p1.add_person() self.p1.add_person() self.p2.add_person() self.p2.add_person() self.p3.add_person() self.p3.add_person() persons_logic.sync_social_connections() result, account_id, bundle_id = register_user('test_user') self.storage = LogicStorage() self.storage.load_account_data(AccountPrototype.get_by_id(account_id)) self.hero = self.storage.accounts_to_heroes[account_id] self.action_idl = self.hero.actions.current_action self.hero._model.money += 1 self.hero.preferences.set_mob(mobs_storage.all()[0]) self.hero.preferences.set_place(self.p1) self.hero.preferences.set_friend(self.p1.persons[0]) self.hero.preferences.set_enemy(self.p2.persons[0]) self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE) self.hero.position.set_place(self.p3) self.hero.save() self.p2.modifier = HolyCity(self.p2) self.p2.save() self.p1.persons[0]._model.type = PERSON_TYPE.BLACKSMITH self.p1.persons[0].save()
def setUp(self): super(QuestsTestBase, self).setUp() self.p1, self.p2, self.p3 = create_test_map() # add more persons, to lower conflicts places_logic.add_person_to_place(self.p1) places_logic.add_person_to_place(self.p1) places_logic.add_person_to_place(self.p2) places_logic.add_person_to_place(self.p2) places_logic.add_person_to_place(self.p3) places_logic.add_person_to_place(self.p3) persons_logic.sync_social_connections() result, account_id, bundle_id = register_user('test_user') self.storage = LogicStorage() self.storage.load_account_data(AccountPrototype.get_by_id(account_id)) self.hero = self.storage.accounts_to_heroes[account_id] self.action_idl = self.hero.actions.current_action self.hero.money += 1 self.hero.preferences.set_mob(mobs_storage.all()[0]) self.hero.preferences.set_place(self.p1) self.hero.preferences.set_friend(self.p1.persons[0]) self.hero.preferences.set_enemy(self.p2.persons[0]) self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.PLATE) self.hero.position.set_place(self.p3) heroes_logic.save_hero(self.hero) self.p2.set_modifier(places_modifiers.CITY_MODIFIERS.HOLY_CITY) places_logic.save_place(self.p2) self.p1.persons[0].type = PERSON_TYPE.BLACKSMITH persons_logic.save_person(self.p1.persons[0])
def setUp(self): super(MobsStorageTests, self).setUp() create_test_map() self.mob_1, self.mob_2, self.mob_3 = mobs_storage.all() self.mob_1.type = MOB_TYPE.CIVILIZED self.mob_1.save() self.mob_2.type = MOB_TYPE.BARBARIAN self.mob_2.save() self.mob_3.type = MOB_TYPE.CIVILIZED self.mob_3.save() self.bandit = MobRecordPrototype.create( uuid='bandit', level=1, utg_name=names.generator.get_test_name(name='bandint'), description='description', abilities=['hit'], terrains=[TERRAIN.PLANE_SAND], type=MOB_TYPE.CIVILIZED, state=MOB_RECORD_STATE.ENABLED) self.bandint_wrong = MobRecordPrototype.create( uuid='bandit_wrong', level=1, utg_name=names.generator.get_test_name(name='bandit_wrong'), description='bandit_wrong description', abilities=['hit'], terrains=[TERRAIN.PLANE_SAND], type=MOB_TYPE.CIVILIZED, state=MOB_RECORD_STATE.DISABLED)
def test_load_data(self): self.assertEqual(len(mobs_storage.all()), 3) # create_test_map create 3 random mobs self.assertFalse(mobs_storage.has_mob('wrong_id')) self.assertTrue(mobs_storage.has_mob('mob_1')) self.assertTrue(mobs_storage.has_mob('mob_2')) self.assertTrue(mobs_storage.has_mob('mob_3'))
def test_mob(self): mob = mobs_storage.all()[0] self.hero.preferences.set_mob(mob) logic.setup_preferences(self.knowledge_base, self.get_hero_info()) f_mob = logic.fact_mob(mob) self.check_facts(mobs=[f_mob], prefered_mobs=[facts.PreferenceMob(object=self.hero_uid, mob=f_mob.uid)])
def setUp(self): super(TestUpdateRequests, self).setUp() self.request_logout() self.request_login(self.account_2.email) self.check_ajax_ok(self.client.post(reverse("game:artifacts:create"), self.get_create_data())) self.artifact = ArtifactRecordPrototype(ArtifactRecord.objects.all().order_by("-created_at")[0]) self.mob = mobs_storage.all()[0]
def setUp(self): super(TestUpdateRequests, self).setUp() self.request_logout() self.request_login('*****@*****.**') self.check_ajax_ok(self.client.post(reverse('game:artifacts:create'), self.get_create_data())) self.artifact = ArtifactRecordPrototype(ArtifactRecord.objects.all().order_by('-created_at')[0]) self.mob = mobs_storage.all()[0]
def test_deserialization_of_disabled_mob(self): mob_record = mobs_storage.all()[0] mob = mob_record.create_mob(self.hero) data = mob.serialize() mob_record.state = MOB_RECORD_STATE.DISABLED mob_record.save() mob_2 = MobPrototype.deserialize(data) self.assertNotEqual(mob.id, mob_2.id)
def test_mob(self): mob = mobs_storage.all()[0] self.hero.preferences.set_mob(mob) logic.setup_preferences(self.knowledge_base, self.get_hero_info()) f_mob = logic.fact_mob(mob) self.check_facts(mobs=[f_mob], prefered_mobs=[ facts.PreferenceMob(object=self.hero_uid, mob=f_mob.uid) ])
def test_create_hero_info__all_properties(self): self.hero.level = 11 self.hero.position.set_place(self.place_1) mob = mobs_storage.all()[0] self.hero.preferences.set_mob(mob) place = self.place_1 self.hero.preferences.set_place(place) friend = self.place_2.persons[0] self.hero.preferences.set_friend(friend) enemy = self.place_2.persons[1] self.hero.preferences.set_enemy(enemy) self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.HELMET) interfered_person = self.place_3.persons[0] self.hero.quests.add_interfered_person(interfered_person.id) is_first_quest_path_required = random.choice((True, False)) is_short_quest_path_required = random.choice((True, False)) prefered_quest_markers = set((questgen_relations.OPTION_MARKERS.HONORABLE, questgen_relations.OPTION_MARKERS.AGGRESSIVE)) self.hero.quests.update_history(quest_type='spying', turn_number=0) self.hero.quests.update_history(quest_type='hunt', turn_number=0) with contextlib.nested( mock.patch('the_tale.game.heroes.objects.Hero.is_first_quest_path_required', is_first_quest_path_required), mock.patch('the_tale.game.heroes.objects.Hero.is_short_quest_path_required', is_short_quest_path_required), mock.patch('the_tale.game.heroes.objects.Hero.prefered_quest_markers', lambda hero: prefered_quest_markers) ): hero_info = logic.create_hero_info(self.hero) self.assertEqual(hero_info.id, self.hero.id) self.assertEqual(hero_info.level, self.hero.level) self.assertEqual(hero_info.position_place_id, self.hero.position.place.id) self.assertEqual(hero_info.preferences_mob_id, self.hero.preferences.mob.id) self.assertEqual(hero_info.preferences_place_id, self.hero.preferences.place.id) self.assertEqual(hero_info.preferences_friend_id, self.hero.preferences.friend.id) self.assertEqual(hero_info.preferences_enemy_id, self.hero.preferences.enemy.id) self.assertEqual(hero_info.preferences_equipment_slot, self.hero.preferences.equipment_slot) self.assertEqual(hero_info.interfered_persons, [interfered_person.id]) self.assertEqual(hero_info.is_first_quest_path_required, is_first_quest_path_required) self.assertEqual(hero_info.is_short_quest_path_required, is_short_quest_path_required) self.assertItemsEqual(hero_info.excluded_quests, self.hero.quests.history.keys()) self.assertEqual(hero_info.prefered_quest_markers, prefered_quest_markers) self.assertEqual(hero_info.quests_priorities, self.hero.get_quests_priorities()) self.check_serialization(hero_info)
def setUp(self): super(TestUpdateRequests, self).setUp() self.request_logout() self.request_login('*****@*****.**') self.check_ajax_ok( self.client.post(reverse('game:artifacts:create'), self.get_create_data())) self.artifact = ArtifactRecordPrototype( ArtifactRecord.objects.all().order_by('-created_at')[0]) self.mob = mobs_storage.all()[0]
def test_fear_battle(self): self.hero.actions.pop_action() mob = next((m for m in mobs_storage.all() if m.type.is_CIVILIZED)) with self.check_delta(lambda: self.hero.statistics.pve_kills, 0): action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mob.create_mob(self.hero, is_boss=False)) self.assertEqual(action_battle.percents, 1.0) self.assertEqual(action_battle.state, self.action_battle.STATE.PROCESSED) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action, self.action_idl)
def test_fear_battle(self): self.hero.actions.pop_action() mob = (m for m in mobs_storage.all() if m.type.is_CIVILIZED).next() with self.check_delta(lambda: self.hero.statistics.pve_kills, 0): action_battle = ActionBattlePvE1x1Prototype.create(hero=self.hero, mob=mob.create_mob(self.hero, is_boss=False)) self.assertEqual(action_battle.percents, 1.0) self.assertEqual(action_battle.state, self.action_battle.STATE.PROCESSED) self.storage.process_turn(continue_steps_if_needed=False) self.assertEqual(self.hero.actions.current_action, self.action_idl)
def setUp(self): super(TestModerateRequests, self).setUp() self.request_logout() self.request_login(self.account_2.email) self.mob = mobs_storage.all()[0] self.check_ajax_ok( self.client.post(reverse('game:artifacts:create'), self.get_create_data())) self.artifact = ArtifactRecordPrototype( ArtifactRecord.objects.all().order_by('-created_at')[0]) self.name = names.generator().get_test_name(name='new name') self.request_logout() self.request_login(self.account_3.email)
def setUp(self): super(MobsStorageTests, self).setUp() create_test_map() self.mob_1, self.mob_2, self.mob_3 = mobs_storage.all() self.mob_1.type = game_relations.BEING_TYPE.CIVILIZED self.mob_1.save() self.mob_2.type = game_relations.BEING_TYPE.CIVILIZED self.mob_2.is_mercenary = False self.mob_2.save() self.mob_3.type = game_relations.BEING_TYPE.CIVILIZED self.mob_3.save() self.bandit = MobRecordPrototype.create( uuid="bandit", level=1, utg_name=names.generator.get_test_name(name="bandint"), description="description", abilities=["hit"], terrains=[map_relations.TERRAIN.PLANE_SAND], type=game_relations.BEING_TYPE.CIVILIZED, state=MOB_RECORD_STATE.ENABLED, ) self.bandint_wrong = MobRecordPrototype.create( uuid="bandit_wrong", level=1, utg_name=names.generator.get_test_name(name="bandit_wrong"), description="bandit_wrong description", abilities=["hit"], terrains=[map_relations.TERRAIN.PLANE_SAND], type=game_relations.BEING_TYPE.CIVILIZED, state=MOB_RECORD_STATE.DISABLED, )
def __init__(self, *args, **kwargs): super(ArtifactRecordBaseForm, self).__init__(*args, **kwargs) self.fields['mob'].choices = [('', u'-------')] + [ (mob.id, mob.name) for mob in sorted(mobs_storage.all(), key=lambda mob: mob.name) ]
def __init__(self, *args, **kwargs): super(ArtifactRecordBaseForm, self).__init__(*args, **kwargs) self.fields['mob'].choices = [('', '-------')] + [(mob.id, mob.name) for mob in sorted(mobs_storage.all(), key=lambda mob: mob.name)]
def test_in_game(self): ability = self.get_ability(effects.LootProbability) with self.check_changed( lambda: self.hero.loot_probability(mobs_storage.all()[0])): self.apply_ability(ability)
def test_save__not_stored_mob(self): mob = MobRecordPrototype.get_by_id(mobs_storage.all()[0].id) self.assertRaises(exceptions.SaveNotRegisteredMobError, mob.save)
def test_create_hero_info__all_properties(self): self.hero.level = 11 self.hero.position.set_place(self.place_1) mob = mobs_storage.all()[0] self.hero.preferences.set_mob(mob) place = self.place_1 self.hero.preferences.set_place(place) friend = self.place_2.persons[0] self.hero.preferences.set_friend(friend) enemy = self.place_2.persons[1] self.hero.preferences.set_enemy(enemy) self.hero.preferences.set_equipment_slot(EQUIPMENT_SLOT.HELMET) interfered_person = self.place_3.persons[0] self.hero.quests.add_interfered_person(interfered_person.id) is_first_quest_path_required = random.choice((True, False)) is_short_quest_path_required = random.choice((True, False)) prefered_quest_markers = set( (questgen_relations.OPTION_MARKERS.HONORABLE, questgen_relations.OPTION_MARKERS.AGGRESSIVE)) self.hero.quests.update_history(quest_type='spying', turn_number=0) self.hero.quests.update_history(quest_type='hunt', turn_number=0) with mock.patch('the_tale.game.heroes.objects.Hero.is_first_quest_path_required', is_first_quest_path_required), \ mock.patch('the_tale.game.heroes.objects.Hero.is_short_quest_path_required', is_short_quest_path_required), \ mock.patch('the_tale.game.heroes.objects.Hero.prefered_quest_markers', lambda hero: prefered_quest_markers): hero_info = logic.create_hero_info(self.hero) self.assertEqual(hero_info.id, self.hero.id) self.assertEqual(hero_info.level, self.hero.level) self.assertEqual(hero_info.position_place_id, self.hero.position.place.id) self.assertEqual(hero_info.preferences_mob_id, self.hero.preferences.mob.id) self.assertEqual(hero_info.preferences_place_id, self.hero.preferences.place.id) self.assertEqual(hero_info.preferences_friend_id, self.hero.preferences.friend.id) self.assertEqual(hero_info.preferences_enemy_id, self.hero.preferences.enemy.id) self.assertEqual(hero_info.preferences_equipment_slot, self.hero.preferences.equipment_slot) self.assertEqual(hero_info.interfered_persons, [interfered_person.id]) self.assertEqual(hero_info.is_first_quest_path_required, is_first_quest_path_required) self.assertEqual(hero_info.is_short_quest_path_required, is_short_quest_path_required) self.assertCountEqual(hero_info.excluded_quests, list(self.hero.quests.history.keys())) self.assertEqual(hero_info.prefered_quest_markers, prefered_quest_markers) self.assertEqual(hero_info.quests_priorities, self.hero.get_quests_priorities()) self.check_serialization(hero_info)
def test_serialization(self): mob = mobs_storage.all()[0].create_mob(self.hero) self.assertEqual(mob, MobPrototype.deserialize(mob.serialize()))
def test_in_game(self): ability = self.get_ability(effects.LootProbability) with self.check_changed(lambda: self.hero.loot_probability(mobs_storage.all()[0])): self.apply_ability(ability)
def test_initialize(self): self.assertEqual(len(mobs_storage.all()), 5) self.assertEqual(mobs_storage.mobs_number, 5) self.assertEqual(sum(mobs_storage._types_count.itervalues()), 5) self.assertTrue(mobs_storage.mob_type_fraction(game_relations.BEING_TYPE.CIVILIZED) > 2.0 / 5)