feat: add progression models and service structure
This commit is contained in:
@@ -1,3 +1,73 @@
|
||||
# apps/achivements/models.py
|
||||
|
||||
import uuid
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
class Achievement(models.Model):
|
||||
class RuleType(models.TextChoices):
|
||||
TASK_COUNT = "task_count", "Nombre de réalisations"
|
||||
SKILL_XP = "skill_xp", "XP dans une compétence"
|
||||
TREE_XP = "tree_xp", "XP dans un arbre"
|
||||
TOTAL_XP = "total_xp", "XP total"
|
||||
DISTINCT_TASKS = "distinct_tasks", "Tâches différentes"
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
slug = models.SlugField(max_length=100, unique=True)
|
||||
name = models.CharField(max_length=160)
|
||||
description = models.TextField(blank=True)
|
||||
icon = models.CharField(max_length=80, blank=True)
|
||||
|
||||
rule_type = models.CharField(max_length=32, choices=RuleType.choices)
|
||||
rule_config = models.JSONField(default=dict)
|
||||
|
||||
xp_reward = models.PositiveIntegerField(default=0)
|
||||
is_secret = models.BooleanField(default=False)
|
||||
is_active = models.BooleanField(default=True)
|
||||
|
||||
|
||||
class PlayerAchievement(models.Model):
|
||||
player = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="achievements",
|
||||
)
|
||||
achievement = models.ForeignKey(
|
||||
Achievement,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="players",
|
||||
)
|
||||
unlocked_at = models.DateTimeField(auto_now_add=True)
|
||||
progress_snapshot = models.JSONField(default=dict)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=("player", "achievement"),
|
||||
name="unique_player_achievement",
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
class Title(models.Model):
|
||||
slug = models.SlugField(max_length=100, unique=True)
|
||||
name = models.CharField(max_length=120)
|
||||
description = models.TextField(blank=True)
|
||||
achievement = models.OneToOneField(
|
||||
Achievement,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="title",
|
||||
)
|
||||
|
||||
|
||||
class PlayerTitle(models.Model):
|
||||
player = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="titles",
|
||||
)
|
||||
title = models.ForeignKey(Title, on_delete=models.CASCADE)
|
||||
unlocked_at = models.DateTimeField(auto_now_add=True)
|
||||
is_equipped = models.BooleanField(default=False)
|
||||
|
||||
Reference in New Issue
Block a user