mirror of
https://github.com/TurTaskProject/TurTaskWeb.git
synced 2025-12-18 21:44:07 +01:00
68 lines
2.7 KiB
Python
68 lines
2.7 KiB
Python
import random
|
|
import math
|
|
|
|
from django.db import models
|
|
from django.utils import timezone
|
|
from django.utils.translation import gettext_lazy as _
|
|
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
|
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
|
|
|
from .managers import CustomAccountManager
|
|
|
|
|
|
class CustomUser(AbstractBaseUser, PermissionsMixin):
|
|
# User fields
|
|
email = models.EmailField(_('email address'), unique=True)
|
|
username = models.CharField(max_length=150, unique=True)
|
|
first_name = models.CharField(max_length=150, blank=True)
|
|
start_date = models.DateTimeField(default=timezone.now)
|
|
about = models.TextField(_('about'), max_length=500, blank=True)
|
|
profile_pic = models.ImageField(upload_to='profile_pics', null=True, blank=True, default='profile_pics/default.png')
|
|
is_staff = models.BooleanField(default=False)
|
|
is_active = models.BooleanField(default=True)
|
|
|
|
# Custom manager
|
|
objects = CustomAccountManager()
|
|
|
|
# Google API
|
|
refresh_token = models.CharField(max_length=255, blank=True, null=True)
|
|
|
|
# Fields for authentication
|
|
USERNAME_FIELD = 'email'
|
|
REQUIRED_FIELDS = ['username', 'first_name']
|
|
|
|
def __str__(self):
|
|
# String representation of the user
|
|
return self.username
|
|
|
|
|
|
def random_luck():
|
|
return random.randint(1, 50)
|
|
|
|
class UserStats(models.Model):
|
|
"""
|
|
Represents User Profiles and Attributes.
|
|
Fields:
|
|
- health: health points of the user.
|
|
- gold: gold points of the user.
|
|
- experience: experience points of the user.
|
|
"""
|
|
user = models.OneToOneField(CustomUser, on_delete=models.CASCADE)
|
|
health = models.IntegerField(default=100)
|
|
gold = models.FloatField(default=0.0)
|
|
experience = models.FloatField(default=0)
|
|
strength = models.IntegerField(default=1,
|
|
validators=[MinValueValidator(1),
|
|
MaxValueValidator(100)])
|
|
intelligence = models.IntegerField(default=1, validators=[MinValueValidator(1),
|
|
MaxValueValidator(100)])
|
|
endurance = models.IntegerField(default=1, validators=[MinValueValidator(1),
|
|
MaxValueValidator(100)])
|
|
perception = models.IntegerField(default=1, validators=[MinValueValidator(1),
|
|
MaxValueValidator(100)])
|
|
luck = models.IntegerField(default=random_luck, validators=[MinValueValidator(1),
|
|
MaxValueValidator(50)],)
|
|
|
|
@property
|
|
def level(self):
|
|
return (math.pow(self.experience, 2) // 225) + 1 |