diff --git a/src/character/admin.py b/src/character/admin.py index 2cbcf10..e3e6f6e 100644 --- a/src/character/admin.py +++ b/src/character/admin.py @@ -59,7 +59,10 @@ class ProfileAdmin(admin.ModelAdmin): search_fields = ["name"] inlines = [PathInline] fieldsets = [ - (None, {"fields": ["name", ("magical_strength", "life_dice")]}), + ( + None, + {"fields": ["name", ("magical_strength", "life_dice", "mana_max_compute")]}, + ), ("Notes", {"fields": ["notes"]}), ("Documentation", {"fields": ["url"]}), ] diff --git a/src/character/management/commands/import_profiles.py b/src/character/management/commands/import_profiles.py index 787e63e..6be6459 100644 --- a/src/character/management/commands/import_profiles.py +++ b/src/character/management/commands/import_profiles.py @@ -25,6 +25,7 @@ class Command(BaseCommand): dice = self.get_dice(name) magical_strength = self.get_magical_strength() notes = self.get_notes(name) + mana_max_compute = self.get_mana_max_compute(name) profile, _ = Profile.objects.update_or_create( name=name, @@ -33,6 +34,7 @@ class Command(BaseCommand): "magical_strength": magical_strength, "notes": notes, "url": url, + "mana_max_compute": mana_max_compute, }, ) self.stdout.write(self.style.SUCCESS(f"Created/updated profile {profile}")) @@ -74,6 +76,13 @@ class Command(BaseCommand): notes = notes.strip() return notes + def get_mana_max_compute(self, name) -> Profile.ManaMax: + if name in ["Barde", "Druide", "Forgesort", "Prêtre"]: + return Profile.ManaMax.LEVEL + elif name in ["Ensorceleur", "Magicien", "Nécromancien"]: + return Profile.ManaMax.DOUBLE_LEVEL + return Profile.ManaMax.NO_MANA + def setup_selenium(self) -> None: options = webdriver.FirefoxOptions() options.add_argument("-headless") diff --git a/src/character/migrations/0016_profile_mana_max_compute.py b/src/character/migrations/0016_profile_mana_max_compute.py new file mode 100644 index 0000000..e61e7a7 --- /dev/null +++ b/src/character/migrations/0016_profile_mana_max_compute.py @@ -0,0 +1,26 @@ +# Generated by Django 4.1.2 on 2022-10-30 21:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("character", "0015_character_recovery_points_remaining"), + ] + + operations = [ + migrations.AddField( + model_name="profile", + name="mana_max_compute", + field=models.PositiveSmallIntegerField( + choices=[ + (0, "Pas de mana"), + (1, "1 x niveau + mod. magique"), + (2, "2 x niveau + mod. magique"), + ], + default=0, + verbose_name="calcul mana max", + ), + ), + ] diff --git a/src/character/migrations/max_migration.txt b/src/character/migrations/max_migration.txt index 43cdd14..5e040a1 100644 --- a/src/character/migrations/max_migration.txt +++ b/src/character/migrations/max_migration.txt @@ -1 +1 @@ -0015_character_recovery_points_remaining +0016_profile_mana_max_compute diff --git a/src/character/models/character.py b/src/character/models/character.py index 2b71650..1ddee1d 100644 --- a/src/character/models/character.py +++ b/src/character/models/character.py @@ -17,6 +17,11 @@ class Profile(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Mode WISDOM = "SAG", "Sagesse" CHARISMA = "CHA", "Charisme" + class ManaMax(models.IntegerChoices): + NO_MANA = 0, "Pas de mana" + LEVEL = 1, "1 x niveau + mod. magique" + DOUBLE_LEVEL = 2, "2 x niveau + mod. magique" + magical_strength = models.CharField( max_length=3, choices=MagicalStrength.choices, @@ -26,6 +31,9 @@ class Profile(DocumentedModel, UniquelyNamedModel, TimeStampedModel, models.Mode life_dice = models.PositiveSmallIntegerField( choices=Dice.choices, verbose_name="dé de vie" ) + mana_max_compute = models.PositiveSmallIntegerField( + choices=ManaMax.choices, verbose_name="calcul mana max", default=ManaMax.NO_MANA + ) notes = models.TextField(blank=True, verbose_name="notes") class Meta: @@ -202,16 +210,17 @@ class Character(models.Model): @property def attack_magic(self) -> int: + return self.level + self.modifier_magic + + @property + def modifier_magic(self) -> int: modifier_map = { Profile.MagicalStrength.INTELLIGENCE: self.modifier_intelligence, Profile.MagicalStrength.WISDOM: self.modifier_wisdom, Profile.MagicalStrength.CHARISMA: self.modifier_charisma, Profile.MagicalStrength.NONE: 0, } - - return self.level + modifier_map.get( - Profile.MagicalStrength(self.profile.magical_strength) - ) + return modifier_map.get(Profile.MagicalStrength(self.profile.magical_strength)) @property def defense(self) -> int: @@ -221,7 +230,13 @@ class Character(models.Model): @property def mana_max(self) -> int: - return 2 * self.level + self.modifier_intelligence + mana_max_compute = self.profile.mana_max_compute + if mana_max_compute == Profile.ManaMax.NO_MANA: + return 0 + elif mana_max_compute == Profile.ManaMax.LEVEL: + return self.level + self.modifier_intelligence + else: + return 2 * self.level + self.modifier_intelligence @property def height_m(self) -> float: diff --git a/src/character/templates/character/view.html b/src/character/templates/character/view.html index 8345bee..bb63781 100644 --- a/src/character/templates/character/view.html +++ b/src/character/templates/character/view.html @@ -152,7 +152,16 @@ PM max - {{ character.mana_max }} + + {{ character.mana_max }} +