mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-06 04:26:23 +03:00
backend: добавлена генерация базовых характеристик персонажа
This commit is contained in:
128
backend/migrations/versions/231e5697b63e_.py
Normal file
128
backend/migrations/versions/231e5697b63e_.py
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 231e5697b63e
|
||||||
|
Revises: 57b47e18fdab
|
||||||
|
Create Date: 2022-11-19 21:56:35.469495
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import mysql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '231e5697b63e'
|
||||||
|
down_revision = '57b47e18fdab'
|
||||||
|
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.alter_column('endurance_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('strength_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('agility_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('defence_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('wisdom_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
|
||||||
|
with op.batch_alter_table('character_races', schema=None) as batch_op:
|
||||||
|
batch_op.alter_column('endurance_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('strength_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('agility_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('defence_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('wisdom_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=False)
|
||||||
|
|
||||||
|
with op.batch_alter_table('characters', schema=None) as batch_op:
|
||||||
|
batch_op.alter_column('endurance_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('strength_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('agility_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('defence_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=False)
|
||||||
|
batch_op.alter_column('wisdom_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=False)
|
||||||
|
|
||||||
|
# ### 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.alter_column('wisdom_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('defence_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('agility_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('strength_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('endurance_base',
|
||||||
|
existing_type=mysql.INTEGER(),
|
||||||
|
nullable=True)
|
||||||
|
|
||||||
|
with op.batch_alter_table('character_races', schema=None) as batch_op:
|
||||||
|
batch_op.alter_column('wisdom_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('defence_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('agility_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('strength_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('endurance_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
|
||||||
|
with op.batch_alter_table('character_classes', schema=None) as batch_op:
|
||||||
|
batch_op.alter_column('wisdom_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('defence_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('agility_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('strength_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
batch_op.alter_column('endurance_koef',
|
||||||
|
existing_type=mysql.FLOAT(),
|
||||||
|
nullable=True)
|
||||||
|
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -36,11 +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)
|
endurance_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
strength_koef = db.Column(db.Float(), nullable=True, unique=False)
|
strength_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
agility_koef = db.Column(db.Float(), nullable=True, unique=False)
|
agility_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
defence_koef = db.Column(db.Float(), nullable=True, unique=False)
|
defence_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
wisdom_koef = db.Column(db.Float(), nullable=True, unique=False)
|
wisdom_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -55,11 +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)
|
endurance_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
strength_koef = db.Column(db.Float(), nullable=True, unique=False)
|
strength_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
agility_koef = db.Column(db.Float(), nullable=True, unique=False)
|
agility_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
defence_koef = db.Column(db.Float(), nullable=True, unique=False)
|
defence_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
wisdom_koef = db.Column(db.Float(), nullable=True, unique=False)
|
wisdom_koef = db.Column(db.Float(), nullable=False, unique=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
@@ -90,36 +90,60 @@ class Character(db.Model, SerializerMixin):
|
|||||||
created_on = db.Column(
|
created_on = db.Column(
|
||||||
db.DateTime, nullable=False, default=datetime.datetime.now()
|
db.DateTime, nullable=False, default=datetime.datetime.now()
|
||||||
)
|
)
|
||||||
|
endurance_base = db.Column(db.Integer(), nullable=False, unique=False)
|
||||||
|
strength_base = db.Column(db.Integer(), nullable=False, unique=False)
|
||||||
|
agility_base = db.Column(db.Integer(), nullable=False, unique=False)
|
||||||
|
defence_base = db.Column(db.Integer(), nullable=False, unique=False)
|
||||||
|
wisdom_base = db.Column(db.Integer(), nullable=False, unique=False)
|
||||||
|
|
||||||
endurance_base = db.Column(db.Integer(), nullable=True, unique=False)
|
def __init__(self, **kwargs):
|
||||||
strength_base = db.Column(db.Integer(), nullable=True, unique=False)
|
super().__init__(**kwargs)
|
||||||
agility_base = db.Column(db.Integer(), nullable=True, unique=False)
|
|
||||||
defence_base = db.Column(db.Integer(), nullable=True, unique=False)
|
char_race = CharacterRace.query.get(self.character_race)
|
||||||
wisdom_base = db.Column(db.Integer(), nullable=True, unique=False)
|
char_class = CharacterClass.query.get(self.character_class)
|
||||||
|
|
||||||
|
self.endurance_base = (
|
||||||
|
100 * char_race.endurance_koef * char_class.endurance_koef
|
||||||
|
)
|
||||||
|
self.strength_base = (
|
||||||
|
100 * char_race.strength_koef * char_class.strength_koef
|
||||||
|
)
|
||||||
|
self.agility_base = (
|
||||||
|
100 * char_race.agility_koef * char_class.agility_koef
|
||||||
|
)
|
||||||
|
self.defence_base = (
|
||||||
|
100 * char_race.defence_koef * char_class.defence_koef
|
||||||
|
)
|
||||||
|
self.wisdom_base = 100 * char_race.wisdom_koef * char_class.wisdom_koef
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def attack_power(self):
|
def battle_stats(self):
|
||||||
return (
|
char_race = CharacterRace.query.get(self.character_race)
|
||||||
|
char_class = CharacterClass.query.get(self.character_class)
|
||||||
|
|
||||||
|
attack_power = (
|
||||||
self.strength_base
|
self.strength_base
|
||||||
* self.character_race.strength_koef
|
* char_race.strength_koef
|
||||||
* self.character_class.strength_koef
|
* char_class.strength_koef
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
defence_chance = (
|
||||||
def defence_chance(self):
|
|
||||||
return (
|
|
||||||
self.defence_base
|
self.defence_base
|
||||||
* self.character_race.defence_koef
|
* char_race.defence_koef
|
||||||
* self.character_class.defence_koef
|
* char_class.defence_koef
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
dodge_chance = (
|
||||||
def saving_chance(self):
|
|
||||||
return (
|
|
||||||
self.agility_base
|
self.agility_base
|
||||||
* self.character_race.agility_koef
|
* char_race.agility_koef
|
||||||
* self.character_class.agility_koef
|
* char_class.agility_koef
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return {
|
||||||
|
"attack_power": attack_power,
|
||||||
|
"defence_chance": defence_chance,
|
||||||
|
"dodge_chance": dodge_chance,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user