コード例 #1
0
    def _get_ui_info(self, hero):
        spending_ui_info = QuestPrototype.next_spending_ui_info(hero.next_spending)

        if self.has_quests:
            return {'quests': [spending_ui_info] + [quest.ui_info() for quest in self.quests_list]}

        return {'quests': [spending_ui_info, QuestPrototype.no_quests_ui_info(in_place=hero.position.place is not None)]}
コード例 #2
0
ファイル: test_quests.py プロジェクト: Alkalit/the-tale
    def quest_test_method(self):

        # defends from first quest rule
        self.hero.statistics.change_quests_done(1)
        self.hero.save()

        current_time = TimePrototype.get_current_time()

        test_upgrade_equipment = random.randint(0, 1) # test child quest or upgrade equipment for SearchSmith

        while self.hero.actions.current_action.TYPE != ActionQuestPrototype.TYPE or not self.hero.quests.has_quests:
            if quest == SearchSmith and test_upgrade_equipment:
                self.hero._model.money = QuestPrototype.upgrade_equipment_cost(self.hero) * 2
                self.hero._model.next_spending = ITEMS_OF_EXPENDITURE.INSTANT_HEAL

            self.storage.process_turn()
            current_time.increment_turn()

        # test if quest is serializable
        s11n.to_json(self.hero.quests.current_quest.serialize())

        self.complete_quest()

        self.assertEqual(self.hero.actions.current_action.TYPE, ActionIdlenessPrototype.TYPE)

        if quest == SearchSmith and test_upgrade_equipment:
            self.assertTrue(self.hero.statistics.money_spend_for_artifacts > 0 or
                            self.hero.statistics.money_spend_for_sharpening > 0)
コード例 #3
0
ファイル: logic.py プロジェクト: serhii73/the-tale
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
コード例 #4
0
ファイル: test_quests.py プロジェクト: serhii73/the-tale
    def quest_test_method(self):

        # defends from first quest rule
        self.hero.statistics.change_quests_done(1)
        heroes_logic.save_hero(self.hero)

        test_upgrade_equipment = random.randint(
            0, 1)  # test child quest or upgrade equipment for SearchSmith

        while self.hero.actions.current_action.TYPE != ActionQuestPrototype.TYPE or not self.hero.quests.has_quests:
            if quest == SearchSmith and test_upgrade_equipment:
                self.hero.money = QuestPrototype.upgrade_equipment_cost(
                    self.hero) * 2
                self.hero.next_spending = heroes_relations.ITEMS_OF_EXPENDITURE.INSTANT_HEAL

            self.storage.process_turn()
            turn.increment()

        # test if quest is serializable
        s11n.to_json(self.hero.quests.current_quest.serialize())

        self.complete_quest()

        self.assertEqual(self.hero.actions.current_action.TYPE,
                         ActionIdlenessPrototype.TYPE)

        if quest == SearchSmith and test_upgrade_equipment:
            self.assertTrue(
                self.hero.statistics.money_spend_for_artifacts > 0
                or self.hero.statistics.money_spend_for_sharpening > 0)
コード例 #5
0
ファイル: container.py プロジェクト: Alkalit/the-tale
 def deserialize(cls, hero, data):
     obj = cls()
     obj.quests_list = [QuestPrototype.deserialize(hero=hero, data=quest_data) for quest_data in data.get('quests', [])]
     obj.history = data.get('history', {})
     obj.interfered_persons = {int(person_id): person_time for person_id, person_time in data.get('interfered_persons', {}).iteritems()}
     obj.hero = hero
     return obj
コード例 #6
0
    def _get_ui_info(self, hero):
        spending_ui_info = QuestPrototype.next_spending_ui_info(
            hero.next_spending)

        if self.has_quests:
            return {
                'quests': [spending_ui_info] +
                [quest.ui_info() for quest in self.quests_list]
            }

        return {
            'quests': [
                spending_ui_info,
                QuestPrototype.no_quests_ui_info(
                    in_place=hero.position.place is not None)
            ]
        }
コード例 #7
0
 def deserialize(cls, data):
     obj = cls()
     obj.quests_list = [
         QuestPrototype.deserialize(data=quest_data)
         for quest_data in data.get('quests', [])
     ]
     obj.history = data.get('history', {})
     obj.interfered_persons = {
         int(person_id): person_time
         for person_id, person_time in data.get('interfered_persons',
                                                {}).iteritems()
     }
     return obj
コード例 #8
0
ファイル: logic.py プロジェクト: serhii73/the-tale
def setup_quest_for_hero(hero, knowledge_base_data):

    # do nothing if hero has already had quest
    if not hero.actions.current_action.searching_quest:
        return

    knowledge_base = KnowledgeBase.deserialize(knowledge_base_data,
                                               fact_classes=facts.FACTS)

    states_to_percents = analysers.percents_collector(knowledge_base)

    quest = QuestPrototype(hero=hero,
                           knowledge_base=knowledge_base,
                           states_to_percents=states_to_percents)

    if quest.machine.can_do_step():
        quest.machine.step()  # do first step to setup pointer

    hero.actions.current_action.setup_quest(quest)
コード例 #9
0
ファイル: logic.py プロジェクト: Alkalit/the-tale
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