Beispiel #1
0
class CompanionRecordForm(forms.Form):

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

    max_health = fields.IntegerField(label=u'здоровье',
                                     min_value=c.COMPANIONS_MIN_HEALTH,
                                     max_value=c.COMPANIONS_MAX_HEALTH)

    type = fields.RelationField(label=u'тип', relation=relations.TYPE)
    dedication = fields.RelationField(label=u'самоотверженность',
                                      relation=relations.DEDICATION)
    archetype = fields.RelationField(label=u'архетип',
                                     relation=game_relations.ARCHETYPE)
    mode = fields.RelationField(label=u'режим появления в игре',
                                relation=relations.MODE)

    abilities = abilities_forms.AbilitiesField(label=u'', required=False)

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

    @classmethod
    def get_initials(cls, companion):
        return {
            'description': companion.description,
            'max_health': companion.max_health,
            'type': companion.type,
            'dedication': companion.dedication,
            'archetype': companion.archetype,
            'mode': companion.mode,
            'abilities': companion.abilities,
            'name': companion.utg_name
        }
Beispiel #2
0
class BaseForm(BaseUserForm):
    place = fields.ChoiceField(label='Город')
    power_bonus = fields.RelationField(label='Изменение влияния',
                                       relation=relations.POWER_BONUS_CHANGES)

    def __init__(self, *args, **kwargs):
        super(BaseForm, self).__init__(*args, **kwargs)
        self.fields['place'].choices = places_storage.places.get_choices()
class EquipmentSlot(RelationMixin,
                    form(heroes_relations.PREFERENCE_TYPE.EQUIPMENT_SLOT)):
    value = fields.RelationField(relation=heroes_relations.EQUIPMENT_SLOT,
                                 required=False)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['value'].choices = [(None, 'забыть предпочтение')
                                        ] + self.fields['value'].choices[1:]
Beispiel #4
0
class BaseForm(BaseUserForm):
    person = fields.ChoiceField(label='Мастер')
    power_bonus = fields.RelationField(label='Изменение влияния',
                                       relation=relations.POWER_BONUS_CHANGES)

    def __init__(self, choosen_person_id, *args, **kwargs):
        super(BaseForm, self).__init__(*args, **kwargs)
        self.fields['person'].choices = persons_objects.Person.form_choices(
            choosen_person=persons_storage.persons.get(choosen_person_id))
Beispiel #5
0
class UserForm(BaseUserForm):

    person = fields.ChoiceField(label=u'Член Совета')
    power_bonus = fields.RelationField(label=u'Изменение бонуса влияния',
                                       relation=relations.POWER_BONUS_CHANGES)

    def __init__(self, choosen_person_id, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
        self.fields['person'].choices = PersonPrototype.form_choices(
            only_weak=False,
            choosen_person=persons_storage.get(choosen_person_id))
Beispiel #6
0
class CompanionRecordForm(forms.Form):

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

    max_health = fields.IntegerField(label='здоровье',
                                     min_value=c.COMPANIONS_MIN_HEALTH,
                                     max_value=c.COMPANIONS_MAX_HEALTH)

    type = fields.RelationField(label='тип',
                                relation=game_relations.BEING_TYPE)
    dedication = fields.RelationField(label='самоотверженность',
                                      relation=relations.DEDICATION)
    archetype = fields.RelationField(label='архетип',
                                     relation=game_relations.ARCHETYPE)
    mode = fields.RelationField(label='режим появления в игре',
                                relation=relations.MODE)

    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)

    abilities = abilities_forms.AbilitiesField(label='', required=False)

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

    @classmethod
    def get_initials(cls, companion):
        return {
            'description': companion.description,
            'max_health': companion.max_health,
            'type': companion.type,
            'dedication': companion.dedication,
            'archetype': companion.archetype,
            'mode': companion.mode,
            'abilities': companion.abilities,
            'name': companion.utg_name,
            'communication_verbal': companion.communication_verbal,
            'communication_gestures': companion.communication_gestures,
            'communication_telepathic': companion.communication_telepathic,
            'intellect_level': companion.intellect_level
        }
class FavoriteItem(RelationMixin,
                   form(heroes_relations.PREFERENCE_TYPE.FAVORITE_ITEM)):
    value = fields.RelationField(relation=heroes_relations.EQUIPMENT_SLOT,
                                 required=False)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields['value'].choices = [(None, 'забыть предпочтение')]

        for slot in heroes_relations.EQUIPMENT_SLOT.records:
            artifact = self.hero.equipment.get(slot)

            if artifact is None:
                continue

            self.fields['value'].choices.append((slot, artifact.name))
class BaseForm(BaseUserForm):
    person_1 = fields.ChoiceField(label='Первый Мастер')
    person_2 = fields.ChoiceField(label='Второй Мастер')
    connection_type = fields.RelationField(
        label='Тип связи', relation=persons_relations.SOCIAL_CONNECTION_TYPE)

    def __init__(self, person_1_id, person_2_id, *args, **kwargs):
        super(BaseForm, self).__init__(*args, **kwargs)
        self.fields['person_1'].choices = persons_objects.Person.form_choices(
            choosen_person=persons_storage.persons.get(person_1_id),
            predicate=self.person_filter)
        self.fields['person_2'].choices = persons_objects.Person.form_choices(
            choosen_person=persons_storage.persons.get(person_2_id),
            predicate=self.person_filter)

    def person_filter(self, place, person):
        return not persons_storage.social_connections.connections_limit_reached(
            person)

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

        if 'person_1' not in cleaned_data or 'person_2' not in cleaned_data:
            return cleaned_data  # error in one of that filed, no need to continue cleaning

        person_1 = persons_storage.persons[int(cleaned_data['person_1'])]
        person_2 = persons_storage.persons[int(cleaned_data['person_2'])]

        if person_1.id == person_2.id:
            raise ValidationError('Нужно выбрать разных Мастеров')

        if persons_storage.social_connections.is_connected(person_1, person_2):
            raise ValidationError('Мастера уже имеют социальную связь')

        if (persons_storage.social_connections.connections_limit_reached(
                person_1) or persons_storage.social_connections.
                connections_limit_reached(person_2)):
            raise ValidationError('Один из Мастеров уже имеет максимум связей')

        return cleaned_data
Beispiel #9
0
class Upbringing(forms.Form):
    value = fields.RelationField(label='происхождение',
                                 relation=beings_relations.UPBRINGING)

    def get_card_data(self):
        return {'value': int(self.c.value.value)}
class CompanionEmpathy(RelationMixin,
                       form(heroes_relations.PREFERENCE_TYPE.COMPANION_EMPATHY)
                       ):
    value = fields.RelationField(relation=heroes_relations.COMPANION_EMPATHY)
Beispiel #11
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
Beispiel #12
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
        }
class RiskLevel(RelationMixin,
                form(heroes_relations.PREFERENCE_TYPE.RISK_LEVEL)):
    value = fields.RelationField(relation=heroes_relations.RISK_LEVEL)
class EnergyRegenerationType(
        RelationMixin,
        form(heroes_relations.PREFERENCE_TYPE.ENERGY_REGENERATION_TYPE)):
    value = fields.RelationField(relation=heroes_relations.ENERGY_REGENERATION)
Beispiel #15
0
class DeathAge(forms.Form):
    value = fields.RelationField(label='возраст смерти',
                                 relation=beings_relations.AGE)

    def get_card_data(self):
        return {'value': int(self.c.value.value)}
Beispiel #16
0
class DeathType(forms.Form):
    value = fields.RelationField(label='способ первой смерти',
                                 relation=beings_relations.FIRST_DEATH)

    def get_card_data(self):
        return {'value': int(self.c.value.value)}
class Archetype(RelationMixin,
                form(heroes_relations.PREFERENCE_TYPE.ARCHETYPE)):
    value = fields.RelationField(relation=game_relations.ARCHETYPE)
Beispiel #18
0
class CompanionRecordForm(forms.Form):

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

    max_health = fields.IntegerField(label='здоровье',
                                     min_value=c.COMPANIONS_MIN_HEALTH,
                                     max_value=c.COMPANIONS_MAX_HEALTH)

    type = fields.RelationField(label='тип', relation=beings_relations.TYPE)
    dedication = fields.RelationField(label='самоотверженность',
                                      relation=relations.DEDICATION)
    archetype = fields.RelationField(label='архетип',
                                     relation=game_relations.ARCHETYPE)
    mode = fields.RelationField(label='режим появления в игре',
                                relation=relations.MODE)

    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)

    abilities = abilities_forms.AbilitiesField(label='', required=False)

    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)

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

    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, companion):
        initials = {
            'description': companion.description,
            'max_health': companion.max_health,
            'type': companion.type,
            'dedication': companion.dedication,
            'archetype': companion.archetype,
            'mode': companion.mode,
            'abilities': companion.abilities,
            'name': companion.utg_name,
            'communication_verbal': companion.communication_verbal,
            'communication_gestures': companion.communication_gestures,
            'communication_telepathic': companion.communication_telepathic,
            'intellect_level': companion.intellect_level,
            'structure': companion.structure,
            'features': list(companion.features),
            'movement': companion.movement,
            'body': companion.body,
            'size': companion.size
        }

        for i, weapon in enumerate(companion.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
class CompanionDedication(
        RelationMixin,
        form(heroes_relations.PREFERENCE_TYPE.COMPANION_DEDICATION)):
    value = fields.RelationField(
        relation=heroes_relations.COMPANION_DEDICATION)