mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-06 04:26:23 +03:00
backend:добавили характеристика расы и класса
This commit is contained in:
68
backend/migrations/versions/57b47e18fdab_.py
Normal file
68
backend/migrations/versions/57b47e18fdab_.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 57b47e18fdab
|
||||||
|
Revises: 370968e335df
|
||||||
|
Create Date: 2022-11-19 20:40:22.680225
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '57b47e18fdab'
|
||||||
|
down_revision = '370968e335df'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('character_classes', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('endurance_koef', sa.Float(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('strength_koef', sa.Float(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('agility_koef', sa.Float(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('defence_koef', sa.Float(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('wisdom_koef', sa.Float(), nullable=True))
|
||||||
|
|
||||||
|
with op.batch_alter_table('character_races', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('endurance_koef', sa.Float(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('strength_koef', sa.Float(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('agility_koef', sa.Float(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('defence_koef', sa.Float(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('wisdom_koef', sa.Float(), nullable=True))
|
||||||
|
|
||||||
|
with op.batch_alter_table('characters', schema=None) as batch_op:
|
||||||
|
batch_op.add_column(sa.Column('endurance_base', sa.Integer(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('strength_base', sa.Integer(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('agility_base', sa.Integer(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('defence_base', sa.Integer(), nullable=True))
|
||||||
|
batch_op.add_column(sa.Column('wisdom_base', sa.Integer(), nullable=True))
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
with op.batch_alter_table('characters', schema=None) as batch_op:
|
||||||
|
batch_op.drop_column('wisdom_base')
|
||||||
|
batch_op.drop_column('defence_base')
|
||||||
|
batch_op.drop_column('agility_base')
|
||||||
|
batch_op.drop_column('strength_base')
|
||||||
|
batch_op.drop_column('endurance_base')
|
||||||
|
|
||||||
|
with op.batch_alter_table('character_races', schema=None) as batch_op:
|
||||||
|
batch_op.drop_column('wisdom_koef')
|
||||||
|
batch_op.drop_column('defence_koef')
|
||||||
|
batch_op.drop_column('agility_koef')
|
||||||
|
batch_op.drop_column('strength_koef')
|
||||||
|
batch_op.drop_column('endurance_koef')
|
||||||
|
|
||||||
|
with op.batch_alter_table('character_classes', schema=None) as batch_op:
|
||||||
|
batch_op.drop_column('wisdom_koef')
|
||||||
|
batch_op.drop_column('defence_koef')
|
||||||
|
batch_op.drop_column('agility_koef')
|
||||||
|
batch_op.drop_column('strength_koef')
|
||||||
|
batch_op.drop_column('endurance_koef')
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -1,14 +1,65 @@
|
|||||||
[
|
[
|
||||||
|
{
|
||||||
|
"table_name": "character_races",
|
||||||
|
"records": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Человек",
|
||||||
|
"endurance_koef": 1,
|
||||||
|
"strength_koef": 1,
|
||||||
|
"agility_koef": 1,
|
||||||
|
"defence_koef": 1,
|
||||||
|
"wisdom_koef": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"name": "Орк",
|
||||||
|
"endurance_koef": 1.5,
|
||||||
|
"strength_koef": 1,
|
||||||
|
"agility_koef": 0.5,
|
||||||
|
"defence_koef": 1.5,
|
||||||
|
"wisdom_koef": 0.5
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "Эльф",
|
||||||
|
"endurance_koef": 0.5,
|
||||||
|
"strength_koef": 1.5,
|
||||||
|
"agility_koef": 1.5,
|
||||||
|
"defence_koef": 0.5,
|
||||||
|
"wisdom_koef": 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"table_name": "character_classes",
|
"table_name": "character_classes",
|
||||||
"records": [
|
"records": [
|
||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "Тест1"
|
"name": "Воин",
|
||||||
|
"endurance_koef": 1.5,
|
||||||
|
"strength_koef": 1,
|
||||||
|
"agility_koef": 1,
|
||||||
|
"defence_koef": 1.5,
|
||||||
|
"wisdom_koef": 0.5
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"name": "Тест2"
|
"name": "Вор",
|
||||||
|
"endurance_koef": 0.5,
|
||||||
|
"strength_koef": 1.2,
|
||||||
|
"agility_koef": 1.5,
|
||||||
|
"defence_koef": 0.5,
|
||||||
|
"wisdom_koef": 0.1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"name": "Маг",
|
||||||
|
"endurance_koef": 1,
|
||||||
|
"strength_koef": 0.5,
|
||||||
|
"agility_koef": 0.5,
|
||||||
|
"defence_koef": 1,
|
||||||
|
"wisdom_koef": 1.5
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ class CharacterRace(db.Model, SerializerMixin):
|
|||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(255), nullable=True, unique=True)
|
name = db.Column(db.String(255), nullable=True, unique=True)
|
||||||
characters = db.relationship("Character", backref="race", lazy="dynamic")
|
characters = db.relationship("Character", backref="race", lazy="dynamic")
|
||||||
|
endurance_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
strength_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
agility_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
defence_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
wisdom_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -50,6 +55,11 @@ class CharacterClass(db.Model, SerializerMixin):
|
|||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(255), nullable=True, unique=True)
|
name = db.Column(db.String(255), nullable=True, unique=True)
|
||||||
characters = db.relationship("Character", backref="class", lazy="dynamic")
|
characters = db.relationship("Character", backref="class", lazy="dynamic")
|
||||||
|
endurance_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
strength_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
agility_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
defence_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
wisdom_koef = db.Column(db.Float(), nullable=True, unique=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -81,5 +91,35 @@ class Character(db.Model, SerializerMixin):
|
|||||||
db.DateTime, nullable=False, default=datetime.datetime.now()
|
db.DateTime, nullable=False, default=datetime.datetime.now()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
endurance_base = db.Column(db.Integer(), nullable=True, unique=False)
|
||||||
|
strength_base = db.Column(db.Integer(), nullable=True, unique=False)
|
||||||
|
agility_base = db.Column(db.Integer(), nullable=True, unique=False)
|
||||||
|
defence_base = db.Column(db.Integer(), nullable=True, unique=False)
|
||||||
|
wisdom_base = db.Column(db.Integer(), nullable=True, unique=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def attack_power(self):
|
||||||
|
return (
|
||||||
|
self.strength_base
|
||||||
|
* self.character_race.strength_koef
|
||||||
|
* self.character_class.strength_koef
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def defence_chance(self):
|
||||||
|
return (
|
||||||
|
self.defence_base
|
||||||
|
* self.character_race.defence_koef
|
||||||
|
* self.character_class.defence_koef
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def saving_chance(self):
|
||||||
|
return (
|
||||||
|
self.agility_base
|
||||||
|
* self.character_race.agility_koef
|
||||||
|
* self.character_class.agility_koef
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user