McDuck/tapdata/models.py
2024-08-29 14:21:58 +05:00

74 lines
3.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.db import models
from users.models import User
from django.utils import timezone
from datetime import timedelta
from django.utils.translation import gettext_lazy as _
class Farming(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
coins_per_min = models.BigIntegerField('Монет за мин', default=1, blank=True)
coins = models.BigIntegerField('Количество MCDK', default=0, blank=True)
start_time = models.DateTimeField('Время и дата начала фарминга', null=True, blank=True)
percent = models.IntegerField("Дополнительные проценты фарминга", default=0)
is_auto_collection_active = models.BooleanField('Автосбор активен', default=False)
auto_collection_end_time = models.DateTimeField('Время окончания автосбора', null=True, blank=True)
bonus_multiplier = models.FloatField('Множитель скорости фарминга', default=1.0, blank=True)
bonus_end_time = models.DateTimeField('Время окончания бонуса', null=True, blank=True)
def __str__(self):
return f'{self.user.username} имеет {self.coins} MCDK'
class Meta:
verbose_name = 'Данные фарминга'
verbose_name_plural = 'Данные фармингов'
def apply_auto_collection(self, duration_days):
self.is_auto_collection_active = True
self.auto_collection_end_time = timezone.now() + timedelta(days=duration_days)
self.save()
def apply_bonus_multiplier(self, percent, duration_days):
self.bonus_multiplier = 1 + (percent / 100)
self.bonus_end_time = timezone.now() + timedelta(days=duration_days)
self.save()
def update_farming(self):
current_time = timezone.now()
# Обновление авто-сбора
if self.is_auto_collection_active and self.auto_collection_end_time < current_time:
self.is_auto_collection_active = False
self.auto_collection_end_time = None
self.save()
# Обновление бонусного множителя
if self.bonus_multiplier > 1.0 and self.bonus_end_time < current_time:
self.bonus_multiplier = 1.0
self.bonus_end_time = None
self.save()
# Обновление монет с учетом бонусного множителя
self.coins += self.coins_per_min * self.bonus_multiplier
self.save()
# Призы с колеса фортуны
class Prizes(models.Model):
class PrizeTypeEnum(models.TextChoices):
COINS = 'CN', _('Coins')
ACCELERATION = 'AL', _('Acceleration')
AUTO_COLLECTION = 'AC', _('Auto_collection')
prize_type = models.CharField('Тип приза', choices=PrizeTypeEnum.choices, max_length=250)
time = models.IntegerField('Время награды в днях', null=True, blank=True)
coins = models.BigIntegerField('Количество MCDK (Необязательно)', null=True, blank=True)
percent = models.IntegerField('Процент (Необязательно)', null=True, blank=True)
def __str__(self):
return f'Тип приза - {self.prize_type}'
class Meta:
verbose_name = 'Приз'
verbose_name_plural = 'Призы'