mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-04 22:03:56 +01:00
Fix mana max compute
This commit is contained in:
parent
991de5a5bb
commit
72bd9ec079
6 changed files with 70 additions and 8 deletions
|
@ -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"]}),
|
||||
]
|
||||
|
|
|
@ -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")
|
||||
|
|
26
src/character/migrations/0016_profile_mana_max_compute.py
Normal file
26
src/character/migrations/0016_profile_mana_max_compute.py
Normal file
|
@ -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",
|
||||
),
|
||||
),
|
||||
]
|
|
@ -1 +1 @@
|
|||
0015_character_recovery_points_remaining
|
||||
0016_profile_mana_max_compute
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -152,7 +152,16 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<th scope="row">PM max</th>
|
||||
<td>{{ character.mana_max }}</td>
|
||||
<td data-bs-toggle="tooltip"
|
||||
data-bs-placement="top"
|
||||
{% if character.profile.mana_max_compute == 1 %}
|
||||
data-bs-title="{{ character.level }} (niveau) + {{ character.modifier_magic }} (mod. {{ character.profile.magical_strength }})"
|
||||
{% elif character.profile.mana_max_compute == 2 %}
|
||||
data-bs-title="2 x {{ character.level }} (niveau) + {{ character.modifier_magic }} (mod. {{ character.profile.magical_strength }})"
|
||||
{% endif %}
|
||||
>
|
||||
{{ character.mana_max }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
|
|
Loading…
Reference in a new issue