示例#1
0
文件: forms.py 项目: pavetok/the-tale
class NewAchievementForm(forms.Form):

    approved = fields.BooleanField(label=u'Одобрена', required=False)

    order = fields.IntegerField()

    group = fields.TypedChoiceField(label=u'Группа', choices=sorted(ACHIEVEMENT_GROUP.choices(), key=lambda g: g[1]), coerce=ACHIEVEMENT_GROUP.get_from_name)
    type = fields.TypedChoiceField(label=u'Тип', choices=sorted(ACHIEVEMENT_TYPE.choices(), key=lambda g: g[1]), coerce=ACHIEVEMENT_TYPE.get_from_name)

    caption = fields.CharField(label=u'Название', max_length=AchievementPrototype.CAPTION_MAX_LENGTH, min_length=1)

    description = bbcode.BBField(label=u'Описание', min_length=1, max_length=AchievementPrototype.DESCRIPTION_MAX_LENGTH)

    barrier = fields.IntegerField(label=u'Барьер')

    points = fields.IntegerField(label=u'Очки')

    item_1 = fields.ChoiceField(label=u'награда 1', choices=[], required=False)
    item_2 = fields.ChoiceField(label=u'награда 2', choices=[], required=False)
    item_3 = fields.ChoiceField(label=u'награда 3', choices=[], required=False)

    def __init__(self, *args, **kwargs):
        super(NewAchievementForm, self).__init__(*args, **kwargs)
        self.fields['item_1'].choices = [('', u'-----')] + items_storage.form_choices()
        self.fields['item_2'].choices = [('', u'-----')] + items_storage.form_choices()
        self.fields['item_3'].choices = [('', u'-----')] + items_storage.form_choices()

    clean_item_1 = create_clean_item_method(1)
    clean_item_2 = create_clean_item_method(2)
    clean_item_3 = create_clean_item_method(3)
示例#2
0
class BanForm(forms.Form):
    ban_type = fields.TypedChoiceField(label='тип',
                                       choices=relations.BAN_TYPE.choices(),
                                       coerce=relations.BAN_TYPE.get_from_name)
    ban_time = fields.TypedChoiceField(label='длительность',
                                       choices=relations.BAN_TIME.choices(),
                                       coerce=relations.BAN_TIME.get_from_name)

    description = fields.TextField(label='обоснование', required=True)
示例#3
0
class EditNameForm(forms.Form):

    race = fields.TypedChoiceField(label=u'раса',
                                   choices=RACE.choices(),
                                   coerce=RACE.get_from_name)
    gender = fields.TypedChoiceField(label=u'пол',
                                     choices=GENDER.choices(),
                                     coerce=GENDER.get_from_name)
    name = WordField(word_type=utg_relations.WORD_TYPE.NOUN,
                     label=u'имя',
                     skip_markers=(utg_relations.NOUN_FORM.COUNTABLE, ),
                     show_properties=False)

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

        name = cleaned_data.get('name')

        if name is not None:
            for name_form in cleaned_data['name'].forms:
                if len(name_form) > models.Hero.MAX_NAME_LENGTH:
                    raise ValidationError(
                        u'Слишком длинное имя, максимальное число символов: %d'
                        % modelsHero.MAX_NAME_LENGTH)

                if len(name_form) < conf.heroes_settings.NAME_MIN_LENGHT:
                    raise ValidationError(
                        u'Слишком короткое имя, минимальное число символов: %d'
                        % conf.heroes_settings.NAME_MIN_LENGHT)

                if NAME_REGEX.match(name_form) is None:
                    print name_form
                    raise ValidationError(
                        u'Имя героя может содержать только следующие символы: %s'
                        % conf.heroes_settings.NAME_SYMBOLS_DESCRITION)

            name.properties = name.properties.clone(
                cleaned_data['gender'].utg_id)

        return cleaned_data

    @classmethod
    def get_initials(cls, hero):
        return {
            'gender': hero.gender,
            'race': hero.race,
            'name': hero.utg_name
        }
示例#4
0
class UserForm(BaseUserForm):

    place = fields.ChoiceField(label=u'Город')
    new_modifier = fields.TypedChoiceField(label=u'Новая специализация',
                                           choices=sorted(
                                               CITY_MODIFIERS.choices(),
                                               key=lambda g: g[1]),
                                           coerce=CITY_MODIFIERS.get_from_name)

    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        self.fields['place'].choices = places_storage.places.get_choices()

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

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

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

        return cleaned_data
示例#5
0
class BaseForm(BaseUserForm):
    place = fields.ChoiceField(label='Город')
    new_race = fields.TypedChoiceField(
        label='Новая раса',
        choices=sorted([(record, record.multiple_text)
                        for record in game_relations.RACE.records],
                       key=lambda g: g[1]),
        coerce=game_relations.RACE.get_from_name)

    def __init__(self, *args, **kwargs):
        super(BaseForm, self).__init__(*args, **kwargs)
        self.fields['place'].choices = places_storage.places.get_choices()

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

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

        if race:
            if race == place.race:
                raise ValidationError('Город уже принадлежит выбранной расе.')

            if not any(race == person.race for person in place.persons):
                raise ValidationError(
                    'В городе должен быть Мастер соответствующей расы.')

        return cleaned_data
示例#6
0
文件: forms.py 项目: pavetok/the-tale
def ChoiceField(filter=lambda ability: True, sort_key=None):
    choices = [('', u'---')] + sorted(
        [(ability, u'%s [%d]' % (ability.text, ability.rarity_delta))
         for ability in effects.ABILITIES.records if filter(ability)],
        key=sort_key)
    return fields.TypedChoiceField(label=u'',
                                   choices=choices,
                                   required=False,
                                   coerce=effects.ABILITIES.get_from_name)
示例#7
0
class BaseForm(BaseUserForm):
    place = fields.ChoiceField(label='Город')
    new_modifier = fields.TypedChoiceField(label='Новая специализация',
                                           choices=sorted(
                                               CITY_MODIFIERS.choices(),
                                               key=lambda g: g[1]),
                                           coerce=CITY_MODIFIERS.get_from_name)

    def __init__(self, *args, **kwargs):
        super(BaseForm, self).__init__(*args, **kwargs)
        self.fields['place'].choices = places_storage.places.get_choices()
示例#8
0
class SettingsForm(forms.Form):
    personal_messages_subscription = fields.BooleanField(required=False,
                                                         label='получать письма о новых личных сообщениях')

    news_subscription = fields.BooleanField(required=False,
                                            label='получать письма о новостях')

    description = bbcode.BBField(required=False, label='Несколько слов о Вас, для страницы Вашего аккаунта', max_length=conf.accounts_settings.MAX_ACCOUNT_DESCRIPTION_LENGTH)

    gender = fields.TypedChoiceField(required=True,
                                     label='Пол (необходим для корректного создания фраз, в которых упоминается игрок)',
                                     choices=((game_relations.GENDER.MASCULINE, game_relations.GENDER.MASCULINE.text),
                                              (game_relations.GENDER.FEMININE, game_relations.GENDER.FEMININE.text)),
                                     coerce=game_relations.GENDER.get_from_name,
                                     initial=game_relations.GENDER.MASCULINE)
示例#9
0
class BaseForm(BaseUserForm):
    declined_bill = fields.TypedChoiceField(label='Отменяемый закон', coerce=int)

    def __init__(self, *args, **kwargs):
        super(BaseForm, self).__init__(*args, **kwargs)
        bills = [exchange.bill for exchange in places_storage.resource_exchanges.all() if exchange.bill]
        self.fields['declined_bill'].choices = [(bill.id, bill.caption) for bill in bills]

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

        if 'declined_bill' not in cleaned_data or not places_storage.resource_exchanges.get_exchange_for_bill_id(cleaned_data['declined_bill']):
            raise ValidationError('Закон уже не действует или не может быть отменён')

        return cleaned_data
示例#10
0
class UserForm(BaseUserForm):

    place = fields.ChoiceField(label=u'Город')
    conversion = fields.TypedChoiceField(label=u'Тип конверсии', choices=CONVERSION.choices(), coerce=CONVERSION.get_from_name)

    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        self.fields['place'].choices = places_storage.get_choices()

    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
示例#11
0
文件: forms.py 项目: angru/the-tale
def get_fields(word_type):
    form_fields = {}

    form_fields.update(get_word_fields_dict(word_type))

    for static_property, required in word_type.properties.iteritems():
        property_type = utg_relations.PROPERTY_TYPE.index_relation[static_property]
        choices = [(r, r.text) for r in static_property.records]
        if not required:
            choices = [('', u' — ')] + choices
        field = fields.TypedChoiceField(label=property_type.text,
                                        choices=choices,
                                        coerce=static_property.get_from_name,
                                        required=False)

        form_fields['%s_%s' % (WORD_FIELD_PREFIX, static_property.__name__)] = field

    return form_fields
示例#12
0
class UserForm(BaseUserForm):

    place_1 = fields.ChoiceField(label=u'Первый город')
    place_2 = fields.ChoiceField(label=u'Второй город')

    resource_1 = fields.TypedChoiceField(
        label=u'Ресурс от первого города',
        choices=ALLOWED_EXCHANGE_TYPES_CHOICES,
        coerce=RESOURCE_EXCHANGE_TYPE.get_from_name)
    resource_2 = fields.TypedChoiceField(
        label=u'Ресурс от второго города',
        choices=ALLOWED_EXCHANGE_TYPES_CHOICES,
        coerce=RESOURCE_EXCHANGE_TYPE.get_from_name)

    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        self.fields['place_1'].choices = places_storage.places.get_choices()
        self.fields['place_2'].choices = places_storage.places.get_choices()

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

        place_1 = places_storage.places.get(int(cleaned_data['place_1']))
        place_2 = places_storage.places.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(
                places_storage.resource_exchanges.get_exchanges_for_place(
                    place_1))
                or c.PLACE_MAX_BILLS_NUMBER <= len(
                    places_storage.resource_exchanges.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
示例#13
0
class MobRecordBaseForm(forms.Form):

    level = fields.IntegerField(label='минимальный уровень')

    name = WordField(word_type=utg_relations.WORD_TYPE.NOUN, label='Название')

    type = fields.TypedChoiceField(
        label='тип',
        choices=MOB_TYPE_CHOICES,
        coerce=game_relations.BEING_TYPE.get_from_name)
    archetype = fields.TypedChoiceField(
        label='тип',
        choices=game_relations.ARCHETYPE.choices(),
        coerce=game_relations.ARCHETYPE.get_from_name)

    global_action_probability = fields.FloatField(
        label=
        'вероятность встретить монстра, если идёт его набег (от 0 до 1, 0 — нет набега)'
    )

    terrains = fields.TypedMultipleChoiceField(label='места обитания',
                                               choices=TERRAIN.choices(),
                                               coerce=TERRAIN.get_from_name)

    abilities = fields.MultipleChoiceField(label='способности',
                                           choices=ABILITY_CHOICES)

    description = bbcode.BBField(label='Описание', required=False)

    is_mercenary = fields.BooleanField(label='может быть наёмником',
                                       required=False)
    is_eatable = fields.BooleanField(label='съедобный', required=False)

    communication_verbal = fields.RelationField(
        label='вербальное общение',
        relation=game_relations.COMMUNICATION_VERBAL)
    communication_gestures = fields.RelationField(
        label='невербальное общение',
        relation=game_relations.COMMUNICATION_GESTURES)
    communication_telepathic = fields.RelationField(
        label='телепатия', relation=game_relations.COMMUNICATION_TELEPATHIC)

    intellect_level = fields.RelationField(
        label='уровень интеллекта', relation=game_relations.INTELLECT_LEVEL)

    def clean_abilities(self):
        abilities_ids = self.cleaned_data['abilities']

        if HIT.get_id() not in abilities_ids:
            abilities_ids.append(HIT.get_id())

        if not abilities_ids:
            raise ValidationError('не указаны способности монстра')

        for ability_id in abilities_ids:
            if ability_id not in ABILITY_CHOICES_DICT:
                raise ValidationError(
                    'неверный идентификатор способности монстра')

        return frozenset(abilities_ids)

    def clean_terrains(self):
        terrains = self.cleaned_data['terrains']

        if not terrains:
            raise ValidationError('не указаны места обитания монстра')

        return frozenset(terrains)

    @classmethod
    def get_initials(cls, mob):
        return {
            'description': mob.description,
            'type': mob.type,
            'name': mob.utg_name,
            'archetype': mob.archetype,
            'level': mob.level,
            'global_action_probability': mob.global_action_probability,
            'terrains': mob.terrains,
            'abilities': mob.abilities,
            'communication_verbal': mob.communication_verbal,
            'communication_gestures': mob.communication_gestures,
            'communication_telepathic': mob.communication_telepathic,
            'intellect_level': mob.intellect_level,
            'is_mercenary': mob.is_mercenary,
            'is_eatable': mob.is_eatable
        }
示例#14
0
文件: forms.py 项目: pavetok/the-tale
class ArtifactRecordBaseForm(forms.Form):

    level = fields.IntegerField(label=u'минимальный уровень')

    name = WordField(word_type=utg_relations.WORD_TYPE.NOUN, label=u'Название')

    description = bbcode.BBField(label=u'Описание', required=False)

    type = fields.TypedChoiceField(
        label=u'тип',
        choices=relations.ARTIFACT_TYPE.choices(),
        coerce=relations.ARTIFACT_TYPE.get_from_name)
    power_type = fields.TypedChoiceField(
        label=u'тип силы',
        choices=relations.ARTIFACT_POWER_TYPE.choices(),
        coerce=relations.ARTIFACT_POWER_TYPE.get_from_name)

    rare_effect = fields.TypedChoiceField(
        label=u'редкий эффект',
        choices=EFFECT_CHOICES,
        coerce=relations.ARTIFACT_EFFECT.get_from_name)
    epic_effect = fields.TypedChoiceField(
        label=u'эпический эффект',
        choices=EFFECT_CHOICES,
        coerce=relations.ARTIFACT_EFFECT.get_from_name)

    special_effect = fields.TypedChoiceField(
        label=u'особое свойство',
        choices=EFFECT_CHOICES,
        coerce=relations.ARTIFACT_EFFECT.get_from_name)

    mob = fields.ChoiceField(label=u'Монстр', required=False)

    def __init__(self, *args, **kwargs):
        super(ArtifactRecordBaseForm, self).__init__(*args, **kwargs)
        self.fields['mob'].choices = [('', u'-------')] + [
            (mob.id, mob.name)
            for mob in sorted(mobs_storage.all(), key=lambda mob: mob.name)
        ]

    def clean_mob(self):
        mob = self.cleaned_data.get('mob')

        if mob:
            return mobs_storage[int(mob)]

        return None

    @classmethod
    def get_initials(cls, artifact):
        return {
            'level': artifact.level,
            'name': artifact.utg_name,
            'type': artifact.type,
            'power_type': artifact.power_type,
            'rare_effect': artifact.rare_effect,
            'epic_effect': artifact.epic_effect,
            'special_effect': artifact.special_effect,
            'description': artifact.description,
            'mob': artifact.mob.id if artifact.mob is not None else None
        }
示例#15
0
class GiveAwardForm(forms.Form):
    type = fields.TypedChoiceField(label='тип', choices=relations.AWARD_TYPE.choices(), coerce=relations.AWARD_TYPE.get_from_name)
    description = fields.TextField(label='обоснование', required=False)
示例#16
0
class MobRecordBaseForm(forms.Form):

    level = fields.IntegerField(label='минимальный уровень')

    name = WordField(word_type=utg_relations.WORD_TYPE.NOUN, label='Название')

    type = fields.TypedChoiceField(label='тип',
                                   choices=MOB_TYPE_CHOICES,
                                   coerce=beings_relations.TYPE.get_from_name)
    archetype = fields.TypedChoiceField(
        label='тип',
        choices=game_relations.ARCHETYPE.choices(),
        coerce=game_relations.ARCHETYPE.get_from_name)

    global_action_probability = fields.FloatField(
        label=
        'вероятность встретить монстра, если идёт его набег (от 0 до 1, 0 — нет набега)'
    )

    terrains = fields.TypedMultipleChoiceField(label='места обитания',
                                               choices=TERRAIN.choices(),
                                               coerce=TERRAIN.get_from_name)

    abilities = fields.MultipleChoiceField(label='способности',
                                           choices=ABILITY_CHOICES)

    description = bbcode.BBField(label='Описание', required=False)

    is_mercenary = fields.BooleanField(label='может быть наёмником',
                                       required=False)
    is_eatable = fields.BooleanField(label='съедобный', required=False)

    communication_verbal = fields.RelationField(
        label='вербальное общение',
        relation=beings_relations.COMMUNICATION_VERBAL)
    communication_gestures = fields.RelationField(
        label='невербальное общение',
        relation=beings_relations.COMMUNICATION_GESTURES)
    communication_telepathic = fields.RelationField(
        label='телепатия', relation=beings_relations.COMMUNICATION_TELEPATHIC)

    intellect_level = fields.RelationField(
        label='уровень интеллекта', relation=beings_relations.INTELLECT_LEVEL)

    structure = fields.RelationField(label='структура',
                                     relation=beings_relations.STRUCTURE)
    features = fields.TypedMultipleChoiceField(
        label='особенности',
        choices=beings_relations.FEATURE.choices(),
        coerce=beings_relations.FEATURE.get_from_name)
    movement = fields.RelationField(label='способ передвижения',
                                    relation=beings_relations.MOVEMENT)
    body = fields.RelationField(label='телосложение',
                                relation=beings_relations.BODY)
    size = fields.RelationField(label='размер', relation=beings_relations.SIZE)

    weapon_1 = fields.RelationField(
        label='оружие 1', relation=artifacts_relations.STANDARD_WEAPON)
    material_1 = fields.RelationField(label='материал оружия 1',
                                      relation=tt_artifacts_relations.MATERIAL)
    power_type_1 = fields.RelationField(
        label='тип силы оружия 1',
        relation=artifacts_relations.ARTIFACT_POWER_TYPE)

    weapon_2 = fields.RelationField(
        label='оружие 2',
        required=False,
        relation=artifacts_relations.STANDARD_WEAPON)
    material_2 = fields.RelationField(label='материал оружия 2',
                                      required=False,
                                      relation=tt_artifacts_relations.MATERIAL)
    power_type_2 = fields.RelationField(
        label='тип силы оружия 2',
        required=False,
        relation=artifacts_relations.ARTIFACT_POWER_TYPE)

    weapon_3 = fields.RelationField(
        label='оружие 3',
        required=False,
        relation=artifacts_relations.STANDARD_WEAPON)
    material_3 = fields.RelationField(label='материал оружия 3',
                                      required=False,
                                      relation=tt_artifacts_relations.MATERIAL)
    power_type_3 = fields.RelationField(
        label='тип силы оружия 3',
        required=False,
        relation=artifacts_relations.ARTIFACT_POWER_TYPE)

    def clean_abilities(self):
        abilities_ids = self.cleaned_data['abilities']

        if HIT.get_id() not in abilities_ids:
            abilities_ids.append(HIT.get_id())

        if not abilities_ids:
            raise ValidationError('не указаны способности монстра')

        for ability_id in abilities_ids:
            if ability_id not in ABILITY_CHOICES_DICT:
                raise ValidationError(
                    'неверный идентификатор способности монстра')

        return frozenset(abilities_ids)

    def clean_terrains(self):
        terrains = self.cleaned_data['terrains']

        if not terrains:
            raise ValidationError('не указаны места обитания монстра')

        return frozenset(terrains)

    def clean_features(self):
        features = self.cleaned_data['features']

        if not features:
            return frozenset()

        return frozenset(features)

    def get_weapons(self):
        weapons = []

        if self.c.weapon_1 and self.c.material_1 and self.c.power_type_1:
            weapons.append(
                artifacts_objects.Weapon(weapon=self.c.weapon_1,
                                         material=self.c.material_1,
                                         power_type=self.c.power_type_1))

        if self.c.weapon_2 and self.c.material_2 and self.c.power_type_2:
            weapons.append(
                artifacts_objects.Weapon(weapon=self.c.weapon_2,
                                         material=self.c.material_2,
                                         power_type=self.c.power_type_2))

        if self.c.weapon_3 and self.c.material_3 and self.c.power_type_3:
            weapons.append(
                artifacts_objects.Weapon(weapon=self.c.weapon_3,
                                         material=self.c.material_3,
                                         power_type=self.c.power_type_3))

        return weapons

    @classmethod
    def get_initials(cls, mob):
        initials = {
            'description': mob.description,
            'type': mob.type,
            'name': mob.utg_name,
            'archetype': mob.archetype,
            'level': mob.level,
            'global_action_probability': mob.global_action_probability,
            'terrains': mob.terrains,
            'abilities': mob.abilities,
            'communication_verbal': mob.communication_verbal,
            'communication_gestures': mob.communication_gestures,
            'communication_telepathic': mob.communication_telepathic,
            'intellect_level': mob.intellect_level,
            'structure': mob.structure,
            'features': list(mob.features),
            'movement': mob.movement,
            'body': mob.body,
            'size': mob.size,
            'is_mercenary': mob.is_mercenary,
            'is_eatable': mob.is_eatable
        }

        for i, weapon in enumerate(mob.weapons, start=1):
            initials['weapon_{}'.format(i)] = weapon.type
            initials['material_{}'.format(i)] = weapon.material
            initials['power_type_{}'.format(i)] = weapon.power_type

        return initials
示例#17
0
class ChoosePreferencesForm(forms.Form):

    preference_id = fields.CharField(max_length=32, required=False)
    preference_type = fields.TypedChoiceField(
        choices=relations.PREFERENCE_TYPE.choices(),
        coerce=relations.PREFERENCE_TYPE.get_from_name)
示例#18
0
文件: forms.py 项目: pavetok/the-tale
class MobRecordBaseForm(forms.Form):

    level = fields.IntegerField(label=u'минимальный уровень')

    name = WordField(word_type=utg_relations.WORD_TYPE.NOUN, label=u'Название')

    type = fields.TypedChoiceField(label=u'тип',
                                   choices=MOB_TYPE_CHOICES,
                                   coerce=MOB_TYPE.get_from_name)
    archetype = fields.TypedChoiceField(
        label=u'тип',
        choices=game_relations.ARCHETYPE.choices(),
        coerce=game_relations.ARCHETYPE.get_from_name)

    global_action_probability = fields.FloatField(
        label=
        u'вероятность встретить монстра, если идёт его набег (от 0 до 1, 0 — нет набега)'
    )

    terrains = fields.TypedMultipleChoiceField(label=u'места обитания',
                                               choices=TERRAIN.choices(),
                                               coerce=TERRAIN.get_from_name)

    abilities = fields.MultipleChoiceField(label=u'способности',
                                           choices=ABILITY_CHOICES)

    description = bbcode.BBField(label=u'Описание', required=False)

    def clean_abilities(self):
        abilities_ids = self.cleaned_data['abilities']

        if HIT.get_id() not in abilities_ids:
            abilities_ids.append(HIT.get_id())

        if not abilities_ids:
            raise ValidationError(u'не указаны способности монстра')

        for ability_id in abilities_ids:
            if ability_id not in ABILITY_CHOICES_DICT:
                raise ValidationError(
                    u'неверный идентификатор способности монстра')

        return frozenset(abilities_ids)

    def clean_terrains(self):
        terrains = self.cleaned_data['terrains']

        if not terrains:
            raise ValidationError(u'не указаны места обитания монстра')

        return frozenset(terrains)

    @classmethod
    def get_initials(cls, mob):
        return {
            'description': mob.description,
            'type': mob.type,
            'name': mob.utg_name,
            'archetype': mob.archetype,
            'level': mob.level,
            'global_action_probability': mob.global_action_probability,
            'terrains': mob.terrains,
            'abilities': mob.abilities
        }