Пример #1
0
    def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position):

        hero = selector.heroes()[0]

        ns = selector._kb.get_next_ns()

        start = facts.Start(uid=ns+'start',
                            type=cls.TYPE,
                            nesting=nesting,
                            description=u'Начало: помочь знакомому',
                            require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid),
                                     requirements.LocatedIn(object=receiver.uid, place=receiver_position.uid)],
                            actions=[actions.Message(type='intro')])

        participants = [facts.QuestParticipant(start=start.uid, participant=initiator.uid, role=ROLES.INITIATOR),
                        facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER) ]

        finish_successed = facts.Finish(uid=ns+'finish_successed',
                                        start=start.uid,
                                        results={ initiator.uid: RESULTS.SUCCESSED,
                                                  receiver.uid: RESULTS.SUCCESSED},
                                        nesting=nesting,
                                        description=u'помощь оказана',
                                        require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)],
                                        actions=[actions.GiveReward(object=hero.uid, type='finish_successed')])

        finish_failed = facts.Finish(uid=ns+'finish_failed',
                                     start=start.uid,
                                     results={ initiator.uid: RESULTS.FAILED,
                                               receiver.uid: RESULTS.FAILED},
                                     nesting=nesting,
                                     description=u'не удалось помочь',
                                     actions=[actions.GiveReward(object=hero.uid, type='finish_failed')])

        help_quest = selector.create_quest_from_person(nesting=nesting+1, initiator=receiver, tags=('can_continue',))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(facts.Jump(state_from=start.uid, state_to=help_fact.uid, start_actions=[actions.Message(type='before_help')]))
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.SUCCESSED:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_successed.uid, start_actions=[actions.Message(type='after_successed_help')]))
                else:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_failed.uid))

        subquest = facts.SubQuest(uid=ns+'help_subquest', members=logic.get_subquest_members(help_quest))

        line = [ start,
                 finish_successed,
                 finish_failed,
                 subquest ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        return line
Пример #2
0
    def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position):

        hero = selector.heroes()[0]

        ns = selector._kb.get_next_ns()

        start = facts.Start(uid=ns+'start',
                            type=cls.TYPE,
                            nesting=nesting,
                            description='Начало: помочь знакомому',
                            require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid),
                                     requirements.LocatedIn(object=receiver.uid, place=receiver_position.uid)],
                            actions=[actions.Message(type='intro')])

        participants = [facts.QuestParticipant(start=start.uid, participant=initiator.uid, role=ROLES.INITIATOR),
                        facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER) ]

        finish_successed = facts.Finish(uid=ns+'finish_successed',
                                        start=start.uid,
                                        results={ initiator.uid: RESULTS.SUCCESSED,
                                                  receiver.uid: RESULTS.SUCCESSED},
                                        nesting=nesting,
                                        description='помощь оказана',
                                        require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)],
                                        actions=[actions.GiveReward(object=hero.uid, type='finish_successed')])

        finish_failed = facts.Finish(uid=ns+'finish_failed',
                                     start=start.uid,
                                     results={ initiator.uid: RESULTS.FAILED,
                                               receiver.uid: RESULTS.FAILED},
                                     nesting=nesting,
                                     description='не удалось помочь',
                                     actions=[actions.GiveReward(object=hero.uid, type='finish_failed')])

        help_quest = selector.create_quest_from_person(nesting=nesting+1, initiator=receiver, tags=('can_continue',))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(facts.Jump(state_from=start.uid, state_to=help_fact.uid, start_actions=[actions.Message(type='before_help')]))
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.SUCCESSED:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_successed.uid, start_actions=[actions.Message(type='after_successed_help')]))
                else:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_failed.uid))

        subquest = facts.SubQuest(uid=ns+'help_subquest', members=logic.get_subquest_members(help_quest))

        line = [ start,
                 finish_successed,
                 finish_failed,
                 subquest ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        return line
Пример #3
0
    def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position):

        hero = selector.heroes()[0]

        ns = selector._kb.get_next_ns()

        start = facts.Start(uid=ns+'start',
                            type=cls.TYPE,
                            nesting=nesting,
                            description=u'Начало: навестить соратника',
                            require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)],
                            actions=[actions.Message(type='intro')])

        participants = [facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER) ]

        meeting = facts.State(uid=ns+'meeting',
                              description=u'встреча с соратником',
                              require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)])

        finish_meeting = facts.Finish(uid=ns+'finish_meeting',
                                      start=start.uid,
                                      results={receiver.uid: RESULTS.SUCCESSED},
                                      nesting=nesting,
                                      description=u'соратнику оказана помощь',
                                      require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)],
                                      actions=[actions.GiveReward(object=hero.uid, type='finish_meeting'),
                                               actions.GivePower(object=receiver.uid, power=1)])

        help_quest = selector.create_quest_from_person(nesting=nesting+1, initiator=receiver, tags=('can_continue',))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(facts.Jump(state_from=meeting.uid, state_to=help_fact.uid, start_actions=[actions.Message(type='before_help')]))
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.SUCCESSED:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_meeting.uid, start_actions=[actions.Message(type='after_help')]))

        subquest = facts.SubQuest(uid=ns+'help_subquest', members=logic.get_subquest_members(help_quest))

        line = [ start,

                 facts.Jump(state_from=start.uid, state_to=meeting.uid),

                 meeting,

                 finish_meeting,

                 subquest
                ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        return line
Пример #4
0
    def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position):

        hero = selector.heroes()[0]

        ns = selector._kb.get_next_ns()

        start = facts.Start(uid=ns+'start',
                            type=cls.TYPE,
                            nesting=nesting,
                            description=u'Начало: навестить соратника',
                            require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)],
                            actions=[actions.Message(type='intro')])

        participants = [facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER) ]

        meeting = facts.State(uid=ns+'meeting',
                              description=u'встреча с соратником',
                              require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)])

        finish_meeting = facts.Finish(uid=ns+'finish_meeting',
                                      start=start.uid,
                                      results={receiver.uid: RESULTS.SUCCESSED},
                                      nesting=nesting,
                                      description=u'соратнику оказана помощь',
                                      require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)],
                                      actions=[actions.GiveReward(object=hero.uid, type='finish_meeting'),
                                               actions.GivePower(object=receiver.uid, power=1)])

        help_quest = selector.create_quest_from_person(nesting=nesting+1, initiator=receiver, tags=('can_continue',))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(facts.Jump(state_from=meeting.uid, state_to=help_fact.uid, start_actions=[actions.Message(type='before_help')]))
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.SUCCESSED:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_meeting.uid, start_actions=[actions.Message(type='after_help')]))

        subquest = facts.SubQuest(uid=ns+'help_subquest', members=logic.get_subquest_members(help_quest))

        line = [ start,

                 facts.Jump(state_from=start.uid, state_to=meeting.uid),

                 meeting,

                 finish_meeting,

                 subquest
                ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        return line
Пример #5
0
    def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position):

        hero = selector.heroes()[0]

        ns = selector._kb.get_next_ns()

        antagonist = selector.new_person(first_initiator=False)
        antagonist_position = selector.place_for(objects=(antagonist.uid,))

        start = facts.Start(uid=ns+'start',
                            type=cls.TYPE,
                            nesting=nesting,
                            description=u'Начало: навредить противнику',
                            require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)],
                            actions=[actions.Message(type='intro')])

        participants = [facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER),
                        facts.QuestParticipant(start=start.uid, participant=antagonist_position.uid, role=ROLES.ANTAGONIST_POSITION) ]

        finish = facts.Finish(uid=ns+'finish',
                              start=start.uid,
                              results={ receiver.uid: RESULTS.FAILED,
                                        antagonist_position.uid: RESULTS.NEUTRAL},
                              nesting=nesting,
                              description=u'навредили противнику',
                              actions=[actions.GiveReward(object=hero.uid, type='finish'),
                                       actions.GivePower(object=receiver.uid, power=-1),
                                       actions.GivePower(object=antagonist_position.uid, power=0)])

        help_quest = selector.create_quest_between_2(nesting=nesting+1, initiator=antagonist, receiver=receiver, tags=('can_continue',))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(facts.Jump(state_from=start.uid, state_to=help_fact.uid))
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.FAILED:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish.uid, start_actions=[actions.Message(type='after_interfere')]))

        subquest = facts.SubQuest(uid=ns+'interfere_subquest', members=logic.get_subquest_members(help_quest))

        line = [ start,
                 finish,
                 subquest
                ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        return line
Пример #6
0
    def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position):

        hero = selector.heroes()[0]

        ns = selector._kb.get_next_ns()

        antagonist = selector.new_person(first_initiator=False)
        antagonist_position = selector.place_for(objects=(antagonist.uid,))

        start = facts.Start(uid=ns+'start',
                            type=cls.TYPE,
                            nesting=nesting,
                            description=u'Начало: навредить противнику',
                            require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)],
                            actions=[actions.Message(type='intro')])

        participants = [facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER),
                        facts.QuestParticipant(start=start.uid, participant=antagonist_position.uid, role=ROLES.ANTAGONIST_POSITION) ]

        finish = facts.Finish(uid=ns+'finish',
                              start=start.uid,
                              results={ receiver.uid: RESULTS.FAILED,
                                        antagonist_position.uid: RESULTS.NEUTRAL},
                              nesting=nesting,
                              description=u'навредили противнику',
                              actions=[actions.GiveReward(object=hero.uid, type='finish')])

        help_quest = selector.create_quest_between_2(nesting=nesting+1, initiator=antagonist, receiver=receiver, tags=('can_continue',))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(facts.Jump(state_from=start.uid, state_to=help_fact.uid))
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.FAILED:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish.uid, start_actions=[actions.Message(type='after_interfere')]))

        subquest = facts.SubQuest(uid=ns+'interfere_subquest', members=logic.get_subquest_members(help_quest))

        line = [ start,
                 finish,
                 subquest
                ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        return line
Пример #7
0
    def construct(cls, nesting, selector, initiator, initiator_position,
                  receiver, receiver_position):

        hero = selector.heroes()[0]

        ns = selector._kb.get_next_ns()

        start = facts.Start(
            uid=ns + 'start',
            type=cls.TYPE,
            nesting=nesting,
            description=u'Начало: выбить долг',
            require=[
                requirements.LocatedIn(object=hero.uid,
                                       place=initiator_position.uid),
                requirements.LocatedIn(object=receiver.uid,
                                       place=receiver_position.uid)
            ],
            actions=[actions.Message(type='intro')])

        participants = [
            facts.QuestParticipant(start=start.uid,
                                   participant=initiator.uid,
                                   role=ROLES.INITIATOR),
            facts.QuestParticipant(start=start.uid,
                                   participant=receiver.uid,
                                   role=ROLES.RECEIVER)
        ]

        choose_method = facts.Choice(
            uid=ns + 'choose_method',
            description=u'Выбрать метод получения долга',
            require=[
                requirements.LocatedIn(object=hero.uid,
                                       place=receiver_position.uid)
            ],
            actions=[actions.Message(type='move_to_receiver')])

        attack = facts.Question(
            uid=ns + 'attack',
            description=u'сражение с подручными должника',
            require=[
                requirements.LocatedIn(object=hero.uid,
                                       place=receiver_position.uid)
            ],
            actions=[
                actions.Message(type='attack'),
                actions.Fight(mercenary=True)
            ],
            condition=[requirements.IsAlive(object=hero.uid)])

        finish_attack_successed = facts.Finish(
            uid=ns + 'finish_attack_successed',
            start=start.uid,
            results={
                initiator.uid: RESULTS.SUCCESSED,
                receiver.uid: RESULTS.FAILED
            },
            nesting=nesting,
            description=u'долг выбит',
            require=[
                requirements.LocatedIn(object=hero.uid,
                                       place=initiator_position.uid)
            ],
            actions=[
                actions.GiveReward(object=hero.uid,
                                   type='finish_attack_successed'),
                actions.GivePower(object=initiator.uid, power=1),
                actions.GivePower(object=receiver.uid, power=-1)
            ])

        finish_attack_failed = facts.Finish(
            uid=ns + 'finish_attack_failed',
            start=start.uid,
            results={
                initiator.uid: RESULTS.NEUTRAL,
                receiver.uid: RESULTS.NEUTRAL
            },
            nesting=nesting,
            description=u'не удалось выбить долг',
            actions=[actions.Message(type='finish_attack_failed')])

        help = facts.State(uid=ns + 'help',
                           description=u'помочь должнику',
                           require=[
                               requirements.LocatedIn(
                                   object=hero.uid,
                                   place=receiver_position.uid)
                           ])

        finish_help = facts.Finish(uid=ns + 'finish_help',
                                   start=start.uid,
                                   results={
                                       initiator.uid: RESULTS.SUCCESSED,
                                       receiver.uid: RESULTS.SUCCESSED
                                   },
                                   nesting=nesting,
                                   description=u'помощь оказана',
                                   require=[
                                       requirements.LocatedIn(
                                           object=hero.uid,
                                           place=initiator_position.uid)
                                   ],
                                   actions=[
                                       actions.GiveReward(object=hero.uid,
                                                          type='finish_help'),
                                       actions.GivePower(object=initiator.uid,
                                                         power=1),
                                       actions.GivePower(object=receiver.uid,
                                                         power=1)
                                   ])

        help_quest = selector.create_quest_from_person(nesting=nesting + 1,
                                                       initiator=receiver,
                                                       tags=('can_continue', ))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(
                    facts.Jump(
                        state_from=help.uid,
                        state_to=help_fact.uid,
                        start_actions=[actions.Message(type='before_help')]))
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.SUCCESSED:
                    help_extra.append(
                        facts.Jump(
                            state_from=help_fact.uid,
                            state_to=finish_help.uid,
                            start_actions=[
                                actions.Message(type='after_successed_help')
                            ]))
                else:
                    help_extra.append(
                        facts.Jump(
                            state_from=help_fact.uid,
                            state_to=attack.uid,
                            start_actions=[
                                actions.Message(type='after_failed_help')
                            ]))

        subquest = facts.SubQuest(
            uid=ns + 'help_subquest',
            members=logic.get_subquest_members(help_quest))

        line = [
            start,
            facts.Jump(state_from=start.uid,
                       state_to=choose_method.uid), choose_method,
            facts.Option(state_from=choose_method.uid,
                         state_to=attack.uid,
                         type='attack',
                         markers=[relations.OPTION_MARKERS.AGGRESSIVE]),
            facts.Option(state_from=choose_method.uid,
                         state_to=help.uid,
                         type='help',
                         markers=[relations.OPTION_MARKERS.UNAGGRESSIVE]),
            help, attack,
            facts.Answer(
                state_from=attack.uid,
                state_to=finish_attack_successed.uid,
                condition=True,
                start_actions=[actions.Message(type='attack_successed')]),
            facts.Answer(state_from=attack.uid,
                         state_to=finish_attack_failed.uid,
                         condition=False,
                         start_actions=[actions.Message(type='attack_failed')
                                        ]), finish_attack_successed,
            finish_attack_failed, finish_help, subquest
        ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        return line
Пример #8
0
    def construct(cls, nesting, selector, initiator, initiator_position,
                  receiver, receiver_position):

        hero = selector.heroes()[0]

        upgrade_equipment_cost = selector.upgrade_equipment_cost().money

        ns = selector._kb.get_next_ns()

        start = facts.Start(uid=ns + 'start_search_smith',
                            type=cls.TYPE,
                            nesting=nesting,
                            description=u'Начало: посещение кузнеца',
                            require=[
                                requirements.LocatedIn(
                                    object=hero.uid,
                                    place=initiator_position.uid)
                            ],
                            actions=[actions.Message(type='intro')])

        participants = [
            facts.QuestParticipant(start=start.uid,
                                   participant=receiver.uid,
                                   role=ROLES.RECEIVER)
        ]

        arriving = facts.Question(
            uid=ns + 'arriving',
            description=u'Прибытие в город',
            condition=[
                requirements.HasMoney(object=hero.uid,
                                      money=upgrade_equipment_cost)
            ],
            require=[
                requirements.LocatedIn(object=hero.uid,
                                       place=receiver_position.uid)
            ])

        upgrade_for_money = facts.State(
            uid=ns + 'upgrade_for_money',
            description=u'Обновление экипировки за деньги',
            actions=[actions.UpgradeEquipment(cost=upgrade_equipment_cost)],
            require=[
                requirements.LocatedIn(object=hero.uid,
                                       place=receiver_position.uid)
            ])

        upgrade_for_quest = facts.State(
            uid=ns + 'upgrade_for_quest',
            description=u'Обновление экипировки за задание',
            actions=[actions.UpgradeEquipment(cost=None)],
            require=[
                requirements.LocatedIn(object=hero.uid,
                                       place=receiver_position.uid)
            ])

        finish_successed = facts.Finish(
            uid=ns + 'finish_successed',
            start=start.uid,
            results={receiver.uid: RESULTS.SUCCESSED},
            nesting=nesting,
            description=u'завершить задание',
            actions=[])

        finish_quest_failed = facts.Finish(
            uid=ns + 'finish_quest_failed',
            start=start.uid,
            results={receiver.uid: RESULTS.NEUTRAL},
            nesting=nesting,
            description=u'завершить задание')

        help_quest = selector.create_quest_from_person(nesting=nesting + 1,
                                                       initiator=receiver,
                                                       tags=('can_continue', ))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(
                    facts.Answer(
                        state_from=arriving.uid,
                        state_to=help_fact.uid,
                        condition=False,
                        start_actions=[actions.Message(type='start_quest')]))
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.SUCCESSED:
                    help_extra.append(
                        facts.Jump(state_from=help_fact.uid,
                                   state_to=upgrade_for_quest.uid,
                                   start_actions=[
                                       actions.Message(type='quest_successed')
                                   ]))
                else:
                    help_extra.append(
                        facts.Jump(state_from=help_fact.uid,
                                   state_to=finish_quest_failed.uid,
                                   start_actions=[
                                       actions.Message(type='quest_failed')
                                   ]))

        subquest = facts.SubQuest(
            uid=ns + 'help_subquest',
            members=logic.get_subquest_members(help_quest))

        line = [
            start,
            facts.Jump(state_from=start.uid, state_to=arriving.uid), arriving,
            facts.Answer(state_from=arriving.uid,
                         state_to=upgrade_for_money.uid,
                         condition=True), upgrade_for_money, upgrade_for_quest,
            facts.Jump(state_from=upgrade_for_money.uid,
                       state_to=finish_successed.uid),
            facts.Jump(state_from=upgrade_for_quest.uid,
                       state_to=finish_successed.uid), finish_successed,
            finish_quest_failed, subquest
        ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        line.append(
            facts.ProfessionMarker(person=receiver.uid,
                                   profession=receiver.profession))

        return line
Пример #9
0
    def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position):

        hero = selector.heroes()[0]

        ns = selector._kb.get_next_ns()

        start = facts.Start(uid=ns+'start',
                            type=cls.TYPE,
                            nesting=nesting,
                            description=u'Начало: выбить долг',
                            require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid),
                                     requirements.LocatedIn(object=receiver.uid, place=receiver_position.uid)],
                            actions=[actions.Message(type='intro')])

        participants = [facts.QuestParticipant(start=start.uid, participant=initiator.uid, role=ROLES.INITIATOR),
                        facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER) ]

        choose_method = facts.Choice(uid=ns+'choose_method',
                                     description=u'Выбрать метод получения долга',
                                     require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)],
                                     actions=[actions.Message(type='move_to_receiver')])


        attack = facts.Question(uid=ns+'attack',
                                description=u'сражение с подручными должника',
                                require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)],
                                actions=[actions.Message(type='attack'),
                                         actions.Fight(mercenary=True)],
                                condition=[requirements.IsAlive(object=hero.uid)])

        finish_attack_successed = facts.Finish(uid=ns+'finish_attack_successed',
                                               start=start.uid,
                                               results={ initiator.uid: RESULTS.SUCCESSED,
                                                         receiver.uid: RESULTS.FAILED},
                                               nesting=nesting,
                                               description=u'долг выбит',
                                               require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)],
                                               actions=[actions.GiveReward(object=hero.uid, type='finish_attack_successed'),
                                                        actions.GivePower(object=initiator.uid, power=1),
                                                        actions.GivePower(object=receiver.uid, power=-1)])

        finish_attack_failed = facts.Finish(uid=ns+'finish_attack_failed',
                                            start=start.uid,
                                            results={ initiator.uid: RESULTS.NEUTRAL,
                                                      receiver.uid: RESULTS.NEUTRAL},
                                            nesting=nesting,
                                            description=u'не удалось выбить долг',
                                            actions=[actions.Message(type='finish_attack_failed')])

        help = facts.State(uid=ns+'help',
                           description=u'помочь должнику',
                           require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)])

        finish_help = facts.Finish(uid=ns+'finish_help',
                                   start=start.uid,
                                   results={ initiator.uid: RESULTS.SUCCESSED,
                                             receiver.uid: RESULTS.SUCCESSED},
                                   nesting=nesting,
                                   description=u'помощь оказана',
                                   require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)],
                                   actions=[actions.GiveReward(object=hero.uid, type='finish_help'),
                                            actions.GivePower(object=initiator.uid, power=1),
                                            actions.GivePower(object=receiver.uid, power=1)])

        help_quest = selector.create_quest_from_person(nesting=nesting+1, initiator=receiver, tags=('can_continue',))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(facts.Jump(state_from=help.uid, state_to=help_fact.uid, start_actions=[actions.Message(type='before_help')]))
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.SUCCESSED:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=finish_help.uid, start_actions=[actions.Message(type='after_successed_help')]))
                else:
                    help_extra.append(facts.Jump(state_from=help_fact.uid, state_to=attack.uid, start_actions=[actions.Message(type='after_failed_help')]))

        subquest = facts.SubQuest(uid=ns+'help_subquest', members=logic.get_subquest_members(help_quest))

        line = [ start,

                 facts.Jump(state_from=start.uid, state_to=choose_method.uid),

                 choose_method,

                 facts.Option(state_from=choose_method.uid, state_to=attack.uid, type='attack', markers=[relations.OPTION_MARKERS.AGGRESSIVE]),
                 facts.Option(state_from=choose_method.uid, state_to=help.uid, type='help', markers=[relations.OPTION_MARKERS.UNAGGRESSIVE]),

                 help,
                 attack,

                 facts.Answer(state_from=attack.uid, state_to=finish_attack_successed.uid, condition=True, start_actions=[actions.Message(type='attack_successed')]),
                 facts.Answer(state_from=attack.uid, state_to=finish_attack_failed.uid, condition=False, start_actions=[actions.Message(type='attack_failed')]),

                 finish_attack_successed,
                 finish_attack_failed,
                 finish_help,

                 subquest
                ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        return line
Пример #10
0
    def construct(cls, nesting, selector, initiator, initiator_position, receiver, receiver_position):

        hero = selector.heroes()[0]

        upgrade_equipment_cost = selector.upgrade_equipment_cost().money

        ns = selector._kb.get_next_ns()

        start = facts.Start(
            uid=ns + "start_search_smith",
            type=cls.TYPE,
            nesting=nesting,
            description=u"Начало: посещение кузнеца",
            require=[requirements.LocatedIn(object=hero.uid, place=initiator_position.uid)],
            actions=[actions.Message(type="intro")],
        )

        participants = [facts.QuestParticipant(start=start.uid, participant=receiver.uid, role=ROLES.RECEIVER)]

        arriving = facts.Question(
            uid=ns + "arriving",
            description=u"Прибытие в город",
            condition=[requirements.HasMoney(object=hero.uid, money=upgrade_equipment_cost)],
            require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)],
        )

        upgrade_for_money = facts.State(
            uid=ns + "upgrade_for_money",
            description=u"Обновление экипировки за деньги",
            actions=[actions.UpgradeEquipment(cost=upgrade_equipment_cost)],
            require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)],
        )

        upgrade_for_quest = facts.State(
            uid=ns + "upgrade_for_quest",
            description=u"Обновление экипировки за задание",
            actions=[actions.UpgradeEquipment(cost=None)],
            require=[requirements.LocatedIn(object=hero.uid, place=receiver_position.uid)],
        )

        finish_successed = facts.Finish(
            uid=ns + "finish_successed",
            start=start.uid,
            results={receiver.uid: RESULTS.SUCCESSED},
            nesting=nesting,
            description=u"завершить задание",
            actions=[actions.GivePower(object=receiver.uid, power=1)],
        )

        finish_quest_failed = facts.Finish(
            uid=ns + "finish_quest_failed",
            start=start.uid,
            results={receiver.uid: RESULTS.NEUTRAL},
            nesting=nesting,
            description=u"завершить задание",
        )

        help_quest = selector.create_quest_from_person(nesting=nesting + 1, initiator=receiver, tags=("can_continue",))
        help_extra = []

        for help_fact in logic.filter_subquest(help_quest, nesting):
            if isinstance(help_fact, facts.Start):
                help_extra.append(
                    facts.Answer(
                        state_from=arriving.uid,
                        state_to=help_fact.uid,
                        condition=False,
                        start_actions=[actions.Message(type="start_quest")],
                    )
                )
            elif isinstance(help_fact, facts.Finish):
                if help_fact.results[receiver.uid] == RESULTS.SUCCESSED:
                    help_extra.append(
                        facts.Jump(
                            state_from=help_fact.uid,
                            state_to=upgrade_for_quest.uid,
                            start_actions=[actions.Message(type="quest_successed")],
                        )
                    )
                else:
                    help_extra.append(
                        facts.Jump(
                            state_from=help_fact.uid,
                            state_to=finish_quest_failed.uid,
                            start_actions=[actions.Message(type="quest_failed")],
                        )
                    )

        subquest = facts.SubQuest(uid=ns + "help_subquest", members=logic.get_subquest_members(help_quest))

        line = [
            start,
            facts.Jump(state_from=start.uid, state_to=arriving.uid),
            arriving,
            facts.Answer(state_from=arriving.uid, state_to=upgrade_for_money.uid, condition=True),
            upgrade_for_money,
            upgrade_for_quest,
            facts.Jump(state_from=upgrade_for_money.uid, state_to=finish_successed.uid),
            facts.Jump(state_from=upgrade_for_quest.uid, state_to=finish_successed.uid),
            finish_successed,
            finish_quest_failed,
            subquest,
        ]

        line.extend(participants)
        line.extend(help_quest)
        line.extend(help_extra)

        line.append(facts.ProfessionMarker(person=receiver.uid, profession=receiver.profession))

        return line