def clean(self):
        cleaned_data = super(UserForm, self).clean()

        place_1 = places_storage.get(int(cleaned_data['place_1']))
        place_2 = places_storage.get(int(cleaned_data['place_2']))

        if roads_storage.get_by_places(place_1, place_2) is None:
            raise ValidationError(u'Обмениваться ресурсами могут только города связаные дорогой')

        if (c.PLACE_MAX_BILLS_NUMBER <= len(resource_exchange_storage.get_exchanges_for_place(place_1)) or
            c.PLACE_MAX_BILLS_NUMBER <= len(resource_exchange_storage.get_exchanges_for_place(place_2)) ):
            raise ValidationError(u'Один город может поддерживать не более чем %(max_exchanges)d активных законов' %  {'max_exchanges': c.PLACE_MAX_BILLS_NUMBER})

        resource_1 = cleaned_data.get('resource_1')
        resource_2 = cleaned_data.get('resource_2')

        if resource_1 is None:
            raise ValidationError(u'Не указан ресурс от первого города')

        if resource_2 is None:
            raise ValidationError(u'Не указан ресурс от второго города')

        if resource_1 not in ALLOWED_EXCHANGE_TYPES:
            raise ValidationError(u'Нельзя заключить договор на обмен ресурса «%s»' % resource_1.text)

        if resource_2 not in ALLOWED_EXCHANGE_TYPES:
            raise ValidationError(u'Нельзя заключить договор на обмен ресурса «%s»' % resource_2.text)

        if resource_1.parameter == resource_2.parameter:
            raise ValidationError(u'Нельзя заключить договор на обмен одинаковыми ресурсами')

        return cleaned_data
示例#2
0
 def do_move_near(self, action):
     if action.place:
         self._move_hero_near(destination=places_storage.get(
             self.knowledge_base[action.place].externals['id']),
                              terrains=action.terrains)
     else:
         self._move_hero_near(destination=None, terrains=action.terrains)
示例#3
0
    def clean(self):
        cleaned_data = super(UserForm, self).clean()

        place = places_storage.get(int(cleaned_data['place']))

        if (c.PLACE_MAX_BILLS_NUMBER <= len(resource_exchange_storage.get_exchanges_for_place(place)) ):
            raise ValidationError(u'Один город может поддерживать не более чем %(max_exchanges)d активных закона' %  {'max_exchanges': c.PLACE_MAX_BILLS_NUMBER})

        return cleaned_data
    def clean(self):
        cleaned_data = super(UserForm, self).clean()

        place_1 = places_storage.get(int(cleaned_data['place_1']))
        place_2 = places_storage.get(int(cleaned_data['place_2']))

        if roads_storage.get_by_places(place_1, place_2) is None:
            raise ValidationError(
                u'Обмениваться ресурсами могут только города связаные дорогой')

        if (c.PLACE_MAX_BILLS_NUMBER <= len(
                resource_exchange_storage.get_exchanges_for_place(place_1))
                or c.PLACE_MAX_BILLS_NUMBER <= len(
                    resource_exchange_storage.get_exchanges_for_place(place_2))
            ):
            raise ValidationError(
                u'Один город может поддерживать не более чем %(max_exchanges)d активных законов'
                % {'max_exchanges': c.PLACE_MAX_BILLS_NUMBER})

        resource_1 = cleaned_data.get('resource_1')
        resource_2 = cleaned_data.get('resource_2')

        if resource_1 is None:
            raise ValidationError(u'Не указан ресурс от первого города')

        if resource_2 is None:
            raise ValidationError(u'Не указан ресурс от второго города')

        if resource_1 not in ALLOWED_EXCHANGE_TYPES:
            raise ValidationError(
                u'Нельзя заключить договор на обмен ресурса «%s»' %
                resource_1.text)

        if resource_2 not in ALLOWED_EXCHANGE_TYPES:
            raise ValidationError(
                u'Нельзя заключить договор на обмен ресурса «%s»' %
                resource_2.text)

        if resource_1.parameter == resource_2.parameter:
            raise ValidationError(
                u'Нельзя заключить договор на обмен одинаковыми ресурсами')

        return cleaned_data
示例#5
0
    def satisfy_located_near(self, requirement):
        object_fact = self.knowledge_base[requirement.object]

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

        if requirement.place is None:
            self._move_hero_near(destination=None, terrains=requirement.terrains)
        else:
            self._move_hero_near(destination=places_storage.get(self.knowledge_base[requirement.place].externals['id']), terrains=requirement.terrains)
    def clean(self):
        cleaned_data = super(UserForm, self).clean()

        place = places_storage.get(int(cleaned_data['place']))
        modifier = MODIFIERS[cleaned_data['new_modifier']](place)

        if not modifier.can_be_choosen:
            raise ValidationError(u'В данный момент город "%s" нельзя преобразовать в "%s".' % (place.name, modifier.NAME))

        return cleaned_data
示例#7
0
    def clean(self):
        cleaned_data = super(UserForm, self).clean()

        place = places_storage.get(int(cleaned_data['place']))
        modifier = MODIFIERS[cleaned_data['new_modifier']](place)

        if not modifier.can_be_choosen:
            raise ValidationError(
                u'В данный момент город "%s" нельзя преобразовать в "%s".' %
                (place.name, modifier.NAME))

        return cleaned_data
示例#8
0
    def satisfy_located_near(self, requirement):
        object_fact = self.knowledge_base[requirement.object]

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

        if requirement.place is None:
            self._move_hero_near(destination=None,
                                 terrains=requirement.terrains)
        else:
            self._move_hero_near(destination=places_storage.get(
                self.knowledge_base[requirement.place].externals['id']),
                                 terrains=requirement.terrains)
    def process_place(self, main_task, hero):
        try:
            place_id = int(self.preference_id) if self.preference_id is not None else None
        except:
            main_task.comment = u'unknown place id: %s' % (self.preference_id, )
            self.state = CHOOSE_PREFERENCES_TASK_STATE.UNKNOWN_PLACE
            return POSTPONED_TASK_LOGIC_RESULT.ERROR

        if place_id is not None:

            if place_id not in places_storage:
                main_task.comment = u'unknown place id: %s' % (place_id, )
                self.state = CHOOSE_PREFERENCES_TASK_STATE.UNKNOWN_PLACE
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

        hero.preferences.set_place(places_storage.get(place_id))

        return POSTPONED_TASK_LOGIC_RESULT.SUCCESS
示例#10
0
    def process_place(self, main_task, hero):
        try:
            place_id = int(self.preference_id) if self.preference_id is not None else None
        except:
            main_task.comment = u'unknown place id: %s' % (self.preference_id, )
            self.state = CHOOSE_PREFERENCES_TASK_STATE.UNKNOWN_PLACE
            return POSTPONED_TASK_LOGIC_RESULT.ERROR

        if place_id is not None:

            if place_id not in places_storage:
                main_task.comment = u'unknown place id: %s' % (place_id, )
                self.state = CHOOSE_PREFERENCES_TASK_STATE.UNKNOWN_PLACE
                return POSTPONED_TASK_LOGIC_RESULT.ERROR

        hero.preferences.set_place(places_storage.get(place_id))

        return POSTPONED_TASK_LOGIC_RESULT.SUCCESS
示例#11
0
    def modify_experience(self, experience):
        quest_uid = self.current_info.uid

        experience_modifiers = {}

        for participant in self.knowledge_base.filter(facts.QuestParticipant):
            if quest_uid != participant.start:
                continue
            fact = self.knowledge_base[participant.participant]
            if isinstance(fact, facts.Person):
                place = persons_storage.persons_storage.get(fact.externals['id']).place
            elif isinstance(fact, facts.Place):
                place = places_storage.get(fact.externals['id'])

            experience_modifiers[place.id] = place.get_experience_modifier()

        experience += experience * sum(experience_modifiers.values())
        return experience
示例#12
0
    def modify_experience(self, experience):
        quest_uid = self.current_info.uid

        experience_modifiers = {}

        for participant in self.knowledge_base.filter(facts.QuestParticipant):
            if quest_uid != participant.start:
                continue
            fact = self.knowledge_base[participant.participant]
            if isinstance(fact, facts.Person):
                place = persons_storage.persons_storage.get(
                    fact.externals['id']).place
            elif isinstance(fact, facts.Place):
                place = places_storage.get(fact.externals['id'])

            experience_modifiers[place.id] = place.get_experience_modifier()

        experience += experience * sum(experience_modifiers.values())
        return experience
示例#13
0
    def _prepair_place(self, place_id): return places_storage.get(place_id)

    def _prepair_person(self, person_id): return persons_storage.get(person_id)
示例#14
0
 def previous_place(self):
     return places_storage.get(self.hero._model.pos_previous_place_id)
示例#15
0
    def previous_place(self): return places_storage.get(self.hero._model.pos_previous_place_id)

    def visit_current_place(self):
示例#16
0
    def place(self): return places_storage.get(self.hero._model.pos_place_id)

    @property
示例#17
0
 def place(self):
     return places_storage.get(self.place_id)
示例#18
0
 def do_move_near(self, action):
     if action.place:
         self._move_hero_near(destination=places_storage.get(self.knowledge_base[action.place].externals['id']), terrains=action.terrains)
     else:
         self._move_hero_near(destination=None, terrains=action.terrains)
示例#19
0
 def place_2(self):
     from the_tale.game.map.places.storage import places_storage
     return places_storage.get(self._model.place_2_id)
示例#20
0
 def place(self):
     return places_storage.get(self.place_id)
示例#21
0
 def _prepair_place(self, place_id):
     return places_storage.get(place_id)
示例#22
0
 def place_2(self):
     from the_tale.game.map.places.storage import places_storage
     return places_storage.get(self._model.place_2_id)
示例#23
0
    def place(self): return places_storage.get(self.hero._model.pos_place_id)

    @property
示例#24
0
    def previous_place(self): return places_storage.get(self.hero._model.pos_previous_place_id)

    def update_previous_place(self):