def _create_random_quest_for_hero(hero_info, start_quests, without_restrictions=False): knowledge_base = get_knowledge_base(hero_info, without_restrictions=without_restrictions) selector = Selector(knowledge_base, QUESTS_BASE, social_connection_probability=c.QUESTS_SOCIAL_CONNECTIONS_FRACTION) hero_uid = uids.hero(hero_info.id) quests_facts = selector.create_quest_from_place(nesting=0, initiator_position=selector.place_for(objects=(hero_uid,)), allowed=start_quests, excluded=[], tags=('can_start', )) knowledge_base += quests_facts transformators.activate_events(knowledge_base) # TODO: after remove restricted states transformators.remove_restricted_states(knowledge_base) transformators.remove_broken_states(knowledge_base) # MUST be called after all graph changes transformators.determine_default_choices(knowledge_base, preferred_markers=hero_info.prefered_quest_markers) # MUST be called after all graph changes and on valid graph transformators.remove_unused_actors(knowledge_base) knowledge_base.validate_consistency(WORLD_RESTRICTIONS) knowledge_base.validate_consistency(QUEST_RESTRICTIONS) return knowledge_base
def _create_random_quest_for_hero(hero_info, start_quests, without_restrictions=False): knowledge_base = get_knowledge_base( hero_info, without_restrictions=without_restrictions) selector = Selector(knowledge_base, QUESTS_BASE, social_connection_probability=0) hero_uid = uids.hero(hero_info.id) quests_facts = selector.create_quest_from_place( nesting=0, initiator_position=selector.place_for(objects=(hero_uid, )), allowed=start_quests, excluded=[], tags=('can_start', )) knowledge_base += quests_facts transformators.activate_events( knowledge_base) # TODO: after remove restricted states transformators.remove_restricted_states(knowledge_base) transformators.remove_broken_states( knowledge_base) # MUST be called after all graph changes transformators.determine_default_choices( knowledge_base, preferred_markers=hero_info.prefered_quest_markers ) # MUST be called after all graph changes and on valid graph transformators.remove_unused_actors(knowledge_base) knowledge_base.validate_consistency(WORLD_RESTRICTIONS) knowledge_base.validate_consistency(QUEST_RESTRICTIONS) return knowledge_base
def quest_test_method(self): from questgen.selectors import Selector from the_tale.game.quests import logic from the_tale.game.quests import uids knowledge_base = logic.get_knowledge_base( logic.create_hero_info(self.hero)) qb = QuestsBase() qb += [q.quest_class for q in quests] selector = Selector(knowledge_base, qb) hero_uid = uids.hero(self.hero.id) quests_facts = selector.create_quest_from_place( nesting=0, initiator_position=selector.place_for(objects=(hero_uid, )), allowed=[quest.quest_class.TYPE], excluded=[], tags=('can_start', )) knowledge_base += quests_facts self.check_quest(knowledge_base)
def get_knowledge_base(hero_info, without_restrictions=False): # pylint: disable=R0912 kb = KnowledgeBase() hero_uid = uids.hero(hero_info.id) kb += facts.Hero(uid=hero_uid, externals={'id': hero_info.id}) setup_places(kb, hero_info) setup_persons(kb, hero_info) setup_preferences(kb, hero_info) setup_social_connections(kb) if not without_restrictions: for person in persons_storage.persons.all(): if person.place.id == hero_info.position_place_id and person.id in hero_info.interfered_persons: kb += facts.NotFirstInitiator(person=uids.person(person.id)) kb.validate_consistency(WORLD_RESTRICTIONS) kb += [ facts.UpgradeEquipmentCost( money=QuestPrototype.upgrade_equipment_cost(hero_info)) ] return kb
def setup_preferences(kb, hero_info): hero_uid = uids.hero(hero_info.id) if hero_info.preferences_mob_id is not None: f_mob = fact_mob( mobs_storage.mobs_storage[hero_info.preferences_mob_id]) if f_mob.uid not in kb: kb += f_mob kb += facts.PreferenceMob(object=hero_uid, mob=f_mob.uid) if hero_info.preferences_place_id is not None: f_place = fact_place( places_storage.places[hero_info.preferences_place_id]) if f_place.uid not in kb: kb += f_place kb += facts.PreferenceHometown(object=hero_uid, place=f_place.uid) if hero_info.preferences_friend_id is not None: friend = persons_storage.persons[hero_info.preferences_friend_id] f_place = fact_place(friend.place) f_person = fact_person(friend) if f_place.uid not in kb: kb += f_place if f_person.uid not in kb: kb += f_person kb += facts.PreferenceFriend(object=hero_uid, person=f_person.uid) kb += facts.ExceptBadBranches(object=f_person.uid) if hero_info.preferences_enemy_id: enemy = persons_storage.persons[hero_info.preferences_enemy_id] f_place = fact_place(enemy.place) f_person = fact_person(enemy) if f_place.uid not in kb: kb += f_place if f_person.uid not in kb: kb += f_person kb += facts.PreferenceEnemy(object=hero_uid, person=f_person.uid) kb += facts.ExceptGoodBranches(object=f_person.uid) if hero_info.preferences_equipment_slot: kb += facts.PreferenceEquipmentSlot( object=hero_uid, equipment_slot=hero_info.preferences_equipment_slot.value)
def setUp(self): super(LogicTestsBase, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() 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.hero_uid = uids.hero(self.hero.id) self.knowledge_base = KnowledgeBase()
def setUp(self): super(LogicTestsBase, self).setUp() self.place_1, self.place_2, self.place_3 = create_test_map() 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.hero_uid = uids.hero(self.hero.id) self.knowledge_base = KnowledgeBase()
def setup_places(kb, hero_info): if hero_info.is_first_quest_path_required: fill_places_for_first_quest(kb, hero_info) elif hero_info.is_short_quest_path_required: fill_places(kb, hero_info, max_distance=c.QUEST_AREA_SHORT_RADIUS) else: fill_places(kb, hero_info, max_distance=c.QUEST_AREA_RADIUS) hero_position_uid = uids.place(hero_info.position_place_id) if hero_position_uid not in kb: kb += fact_place(places_storage[hero_info.position_place_id]) kb += facts.LocatedIn(object=uids.hero(hero_info.id), place=hero_position_uid) if len(list(kb.filter(facts.Place))) < 2: fill_places(kb, hero_info, max_distance=c.QUEST_AREA_MAXIMUM_RADIUS)
def setup_preferences(kb, hero_info): hero_uid = uids.hero(hero_info.id) if hero_info.preferences_mob_id is not None: f_mob = fact_mob(mobs_storage.mobs_storage[hero_info.preferences_mob_id]) if f_mob.uid not in kb: kb += f_mob kb += facts.PreferenceMob(object=hero_uid, mob=f_mob.uid) if hero_info.preferences_place_id is not None: f_place = fact_place(places_storage[hero_info.preferences_place_id]) if f_place.uid not in kb: kb += f_place kb += facts.PreferenceHometown(object=hero_uid, place=f_place.uid) if hero_info.preferences_friend_id is not None: friend = persons_storage.persons_storage[hero_info.preferences_friend_id] f_place = fact_place(friend.place) f_person = fact_person(friend) if f_place.uid not in kb: kb += f_place if f_person.uid not in kb: kb += f_person kb += facts.PreferenceFriend(object=hero_uid, person=f_person.uid) kb += facts.ExceptBadBranches(object=f_person.uid) if hero_info.preferences_enemy_id: enemy = persons_storage.persons_storage[hero_info.preferences_enemy_id] f_place = fact_place(enemy.place) f_person = fact_person(enemy) if f_place.uid not in kb: kb += f_place if f_person.uid not in kb: kb += f_person kb += facts.PreferenceEnemy(object=hero_uid, person=f_person.uid) kb += facts.ExceptGoodBranches(object=f_person.uid) if hero_info.preferences_equipment_slot: kb += facts.PreferenceEquipmentSlot(object=hero_uid, equipment_slot=hero_info.preferences_equipment_slot.value)
def setup_places(kb, hero_info): if hero_info.is_first_quest_path_required: fill_places_for_first_quest(kb, hero_info) elif hero_info.is_short_quest_path_required: fill_places(kb, hero_info, max_distance=c.QUEST_AREA_SHORT_RADIUS) else: fill_places(kb, hero_info, max_distance=c.QUEST_AREA_RADIUS) hero_position_uid = uids.place(hero_info.position_place_id) if hero_position_uid not in kb: kb += fact_place(places_storage.places[hero_info.position_place_id]) kb += facts.LocatedIn(object=uids.hero(hero_info.id), place=hero_position_uid) if len(list(kb.filter(facts.Place))) < 2: fill_places(kb, hero_info, max_distance=c.QUEST_AREA_MAXIMUM_RADIUS)
def quest_test_method(self): from questgen.selectors import Selector from the_tale.game.quests import logic from the_tale.game.quests import uids knowledge_base = logic.get_knowledge_base(logic.create_hero_info(self.hero)) qb = QuestsBase() qb += [q.quest_class for q in quests] selector = Selector(knowledge_base, qb) hero_uid = uids.hero(self.hero.id) quests_facts = selector.create_quest_from_place(nesting=0, initiator_position=selector.place_for(objects=(hero_uid,)), allowed=[quest.quest_class.TYPE], excluded=[], tags=('can_start',)) knowledge_base += quests_facts self.check_quest(knowledge_base)
def get_knowledge_base(hero_info, without_restrictions=False): # pylint: disable=R0912 kb = KnowledgeBase() hero_uid = uids.hero(hero_info.id) kb += facts.Hero(uid=hero_uid, externals={'id': hero_info.id}) setup_places(kb, hero_info) setup_persons(kb, hero_info) setup_preferences(kb, hero_info) setup_social_connections(kb) if not without_restrictions: for person in persons_storage.persons_storage.filter(state=PERSON_STATE.IN_GAME): if person.place.id == hero_info.position_place_id and person.id in hero_info.interfered_persons: kb += facts.NotFirstInitiator(person=uids.person(person.id)) kb.validate_consistency(WORLD_RESTRICTIONS) kb += [facts.UpgradeEquipmentCost(money=QuestPrototype.upgrade_equipment_cost(hero_info))] return kb