Beispiel #1
0
    def satisfy_located_in(self, requirement):
        from . import logic

        object_fact = self.knowledge_base[requirement.object]

        if isinstance(object_fact, facts.Person):
            person_uid = object_fact.uid
            person = persons_storage.persons[object_fact.externals['id']]

            new_place_uid= uids.place(person.place.id)

            if new_place_uid not in self.knowledge_base:
                self.knowledge_base += logic.fact_place(person.place)

            # переписываем все ограничения в базе
            for fact in self.knowledge_base.filter(facts.State):
                for state_requirement in fact.require:
                    if isinstance(state_requirement, requirements.LocatedIn) and state_requirement.object == person_uid:
                        state_requirement.place = new_place_uid

            return

        if not isinstance(object_fact, facts.Hero) or self.hero.id != object_fact.externals['id']:
            raise exceptions.UnknownRequirementError(requirement=requirement)

        self._move_hero_to(destination=places_storage.places[self.knowledge_base[requirement.place].externals['id']])
Beispiel #2
0
    def satisfy_located_in(self, requirement):
        from . import logic

        object_fact = self.knowledge_base[requirement.object]

        if isinstance(object_fact, facts.Person):
            person_uid = object_fact.uid
            person = persons_storage.persons[object_fact.externals['id']]

            new_place_uid = uids.place(person.place.id)

            if new_place_uid not in self.knowledge_base:
                self.knowledge_base += logic.fact_place(person.place)

            # переписываем все ограничения в базе
            for fact in self.knowledge_base.filter(facts.State):
                for state_requirement in fact.require:
                    if isinstance(state_requirement, requirements.LocatedIn
                                  ) and state_requirement.object == person_uid:
                        state_requirement.place = new_place_uid

            return

        if not isinstance(
                object_fact,
                facts.Hero) or self.hero.id != object_fact.externals['id']:
            raise exceptions.UnknownRequirementError(requirement=requirement)

        self._move_hero_to(destination=places_storage.places[
            self.knowledge_base[requirement.place].externals['id']])
Beispiel #3
0
def fill_places(kb, hero_info, max_distance):
    places = []

    for place in places_storage.all():
        path_length = waymarks_storage.look_for_road(places_storage[hero_info.position_place_id], place).length

        if path_length > max_distance:
            continue

        places.append((path_length, place))

    places.sort()


    chosen_places = []

    for base_distance, place in places:
        for chosen_place in chosen_places:
            path_length = waymarks_storage.look_for_road(chosen_place, place).length

            if path_length > max_distance:
                break

        else:
            chosen_places.append(place)


    for place in chosen_places:
        uid = uids.place(place.id)

        if uid in kb:
            continue

        kb += fact_place(place)
Beispiel #4
0
def fill_places(kb, hero_info, max_distance):
    places = []

    for place in places_storage.places.all():
        path_length = waymarks_storage.look_for_road(
            places_storage.places[hero_info.position_place_id], place).length

        if path_length > max_distance:
            continue

        places.append((path_length, place))

    places.sort(key=lambda x: x[0])

    chosen_places = []

    for base_distance, place in places:
        for chosen_place in chosen_places:
            path_length = waymarks_storage.look_for_road(chosen_place,
                                                         place).length

            if path_length > max_distance:
                break

        else:
            chosen_places.append(place)

    for place in chosen_places:
        uid = uids.place(place.id)

        if uid in kb:
            continue

        kb += fact_place(place)
Beispiel #5
0
def setup_persons(kb, hero_info):
    for person in persons_storage.persons_storage.filter(state=PERSON_STATE.IN_GAME):
        place_uid = uids.place(person.place.id)

        if place_uid not in kb:
            continue

        f_person = fact_person(person)
        kb += f_person
        kb += facts.LocatedIn(object=f_person.uid, place=place_uid)
Beispiel #6
0
def setup_persons(kb, hero_info):
    for person in persons_storage.persons.all():
        place_uid = uids.place(person.place.id)

        if place_uid not in kb:
            continue

        f_person = fact_person(person)
        kb += f_person
        kb += facts.LocatedIn(object=f_person.uid, place=place_uid)
Beispiel #7
0
def setup_persons(kb, hero_info):
    for person in persons_storage.persons.all():
        place_uid = uids.place(person.place.id)

        if place_uid not in kb:
            continue

        f_person = fact_person(person)
        kb += f_person
        kb += facts.LocatedIn(object=f_person.uid, place=place_uid)
Beispiel #8
0
def setup_persons(kb, hero_info):
    for person in persons_storage.persons_storage.filter(
            state=PERSON_STATE.IN_GAME):
        place_uid = uids.place(person.place.id)

        if place_uid not in kb:
            continue

        f_person = fact_person(person)
        kb += f_person
        kb += facts.LocatedIn(object=f_person.uid, place=place_uid)
Beispiel #9
0
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)
Beispiel #10
0
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)
Beispiel #11
0
def fact_located_in(person):
    return facts.LocatedIn(object=uids.person(person.id), place=uids.place(person.place.id))
Beispiel #12
0
def fact_place(place):
    return facts.Place(uid=uids.place(place.id),
                       terrains=[terrain.value for terrain in place.terrains],
                       externals={'id': place.id},
                       type=place.modifier.TYPE.quest_type if place.modifier else QUEST_PLACE_TYPE.NONE)
Beispiel #13
0
def fact_located_in(person):
    return facts.LocatedIn(object=uids.person(person.id),
                           place=uids.place(person.place.id))
Beispiel #14
0
def fact_place(place):
    return facts.Place(uid=uids.place(place.id),
                       terrains=[terrain.value for terrain in place.terrains],
                       externals={'id': place.id},
                       type=place._modifier.quest_type)
Beispiel #15
0
def fact_place(place):
    return facts.Place(uid=uids.place(place.id),
                       terrains=[terrain.value for terrain in place.terrains],
                       externals={'id': place.id},
                       type=place._modifier.quest_type)
Beispiel #16
0
def fact_place(place):
    return facts.Place(uid=uids.place(place.id),
                       terrains=[terrain.value for terrain in place.terrains],
                       externals={'id': place.id},
                       type=place.modifier.TYPE.quest_type
                       if place.modifier else QUEST_PLACE_TYPE.NONE)