mirror of
https://github.com/Crocmagnon/charasheet.git
synced 2024-11-22 14:38:03 +01:00
Change initiative mechanism
This commit is contained in:
parent
0b2d0e002b
commit
8a21e54179
7 changed files with 104 additions and 8 deletions
|
@ -132,7 +132,14 @@ class CharacterAdmin(admin.ModelAdmin):
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"Combat",
|
"Combat",
|
||||||
{"fields": ["initiative", "attack_melee", "attack_range", "attack_magic"]},
|
{
|
||||||
|
"fields": [
|
||||||
|
("initiative_misc", "modifier_initiative"),
|
||||||
|
"attack_melee",
|
||||||
|
"attack_range",
|
||||||
|
"attack_magic",
|
||||||
|
]
|
||||||
|
},
|
||||||
),
|
),
|
||||||
("Vitalité", {"fields": [("health_max", "health_remaining")]}),
|
("Vitalité", {"fields": [("health_max", "health_remaining")]}),
|
||||||
("Défense", {"fields": ["armor", "shield", "defense_misc", "defense"]}),
|
("Défense", {"fields": ["armor", "shield", "defense_misc", "defense"]}),
|
||||||
|
@ -163,7 +170,7 @@ class CharacterAdmin(admin.ModelAdmin):
|
||||||
"modifier_intelligence",
|
"modifier_intelligence",
|
||||||
"modifier_wisdom",
|
"modifier_wisdom",
|
||||||
"modifier_charisma",
|
"modifier_charisma",
|
||||||
"initiative",
|
"modifier_initiative",
|
||||||
"attack_melee",
|
"attack_melee",
|
||||||
"attack_range",
|
"attack_range",
|
||||||
"attack_magic",
|
"attack_magic",
|
||||||
|
|
18
src/character/migrations/0027_character_initiative_misc.py
Normal file
18
src/character/migrations/0027_character_initiative_misc.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 4.1.2 on 2022-11-02 12:01
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("character", "0026_alter_capability_name"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="character",
|
||||||
|
name="initiative_misc",
|
||||||
|
field=models.SmallIntegerField(default=0, verbose_name="divers initiative"),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1 +1 @@
|
||||||
0026_alter_capability_name
|
0027_character_initiative_misc
|
||||||
|
|
|
@ -148,6 +148,10 @@ class Character(models.Model):
|
||||||
shield = models.PositiveSmallIntegerField(verbose_name="bouclier", default=0)
|
shield = models.PositiveSmallIntegerField(verbose_name="bouclier", default=0)
|
||||||
defense_misc = models.SmallIntegerField(verbose_name="divers défense", default=0)
|
defense_misc = models.SmallIntegerField(verbose_name="divers défense", default=0)
|
||||||
|
|
||||||
|
initiative_misc = models.SmallIntegerField(
|
||||||
|
verbose_name="divers initiative", default=0
|
||||||
|
)
|
||||||
|
|
||||||
capabilities = models.ManyToManyField(
|
capabilities = models.ManyToManyField(
|
||||||
"character.Capability", blank=True, verbose_name="capacités"
|
"character.Capability", blank=True, verbose_name="capacités"
|
||||||
)
|
)
|
||||||
|
@ -218,8 +222,8 @@ class Character(models.Model):
|
||||||
return modifier(self.value_charisma)
|
return modifier(self.value_charisma)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def initiative(self) -> int:
|
def modifier_initiative(self) -> int:
|
||||||
return self.value_dexterity
|
return self.modifier_dexterity + self.initiative_misc
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def attack_melee(self) -> int:
|
def attack_melee(self) -> int:
|
||||||
|
|
|
@ -67,11 +67,45 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="table-group-divider">
|
<tbody class="table-group-divider">
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Initiative</th>
|
<th scope="row">
|
||||||
|
Initiative divers
|
||||||
|
<div class="btn-group btn-group-sm float-end" role="group">
|
||||||
|
<button
|
||||||
|
hx-get="{% url "character:initiative_misc_change" pk=character.pk %}?value=ko"
|
||||||
|
hx-target="#initiative-misc"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-outline-danger"><i class="fa-solid fa-battery-empty"></i></button>
|
||||||
|
<button
|
||||||
|
hx-get="{% url "character:initiative_misc_change" pk=character.pk %}?value=-1"
|
||||||
|
hx-target="#initiative-misc"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-danger"><i class="fa-solid fa-minus"></i></button>
|
||||||
|
<button
|
||||||
|
hx-get="{% url "character:initiative_misc_change" pk=character.pk %}?value=1"
|
||||||
|
hx-target="#initiative-misc"
|
||||||
|
hx-swap="innerHTML"
|
||||||
|
type="button"
|
||||||
|
class="btn btn-success"><i class="fa-solid fa-plus"></i></button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled
|
||||||
|
class="btn btn-outline-secondary"><i class="fa-solid fa-battery-full"></i></button>
|
||||||
|
</div>
|
||||||
|
</th>
|
||||||
|
<td id="initiative-misc">
|
||||||
|
{{ character.initiative_misc }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Mod. initiative</th>
|
||||||
<td data-bs-toggle="tooltip"
|
<td data-bs-toggle="tooltip"
|
||||||
data-bs-placement="left"
|
data-bs-placement="left"
|
||||||
data-bs-title="valeur DEX">
|
data-bs-title="{{ character.modifier_dexterity }} (mod. DEX) + {{ character.initiative_misc }} (divers)"
|
||||||
{{ character.initiative }}
|
hx-get="{% url "character:get_initiative" pk=character.pk %}"
|
||||||
|
hx-trigger="update_initiative from:#fight-table">
|
||||||
|
{{ character.modifier_initiative }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -28,6 +28,16 @@ urlpatterns = [
|
||||||
views.character_defense_misc_change,
|
views.character_defense_misc_change,
|
||||||
name="defense_misc_change",
|
name="defense_misc_change",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"<int:pk>/get_initiative/",
|
||||||
|
views.character_get_initiative,
|
||||||
|
name="get_initiative",
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"<int:pk>/initiative_misc_change/",
|
||||||
|
views.character_initiative_misc_change,
|
||||||
|
name="initiative_misc_change",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"<int:pk>/equipment_change/",
|
"<int:pk>/equipment_change/",
|
||||||
views.character_equipment_change,
|
views.character_equipment_change,
|
||||||
|
|
|
@ -106,6 +106,18 @@ def character_defense_misc_change(request, pk: int):
|
||||||
return trigger_client_event(response, "update_defense", {})
|
return trigger_client_event(response, "update_defense", {})
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def character_initiative_misc_change(request, pk: int):
|
||||||
|
character = get_object_or_404(
|
||||||
|
Character.objects.filter(player=request.user).only("initiative_misc"), pk=pk
|
||||||
|
)
|
||||||
|
value = get_updated_value(request, character.initiative_misc, float("inf"))
|
||||||
|
character.initiative_misc = value
|
||||||
|
character.save(update_fields=["initiative_misc"])
|
||||||
|
response = HttpResponse(value)
|
||||||
|
return trigger_client_event(response, "update_initiative", {})
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def character_luck_points_change(request, pk: int):
|
def character_luck_points_change(request, pk: int):
|
||||||
character = get_object_or_404(
|
character = get_object_or_404(
|
||||||
|
@ -147,6 +159,17 @@ def character_get_defense(request, pk: int):
|
||||||
return HttpResponse(character.defense)
|
return HttpResponse(character.defense)
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def character_get_initiative(request, pk: int):
|
||||||
|
character = get_object_or_404(
|
||||||
|
Character.objects.filter(player=request.user).only(
|
||||||
|
"initiative_misc", "value_dexterity"
|
||||||
|
),
|
||||||
|
pk=pk,
|
||||||
|
)
|
||||||
|
return HttpResponse(character.modifier_initiative)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def character_notes_change(request, pk: int):
|
def character_notes_change(request, pk: int):
|
||||||
return update_text_field(request, pk, "notes")
|
return update_text_field(request, pk, "notes")
|
||||||
|
|
Loading…
Reference in a new issue