Separate attack and protection

This commit is contained in:
Gabriel Augendre 2022-11-02 20:46:07 +01:00
parent df07ff357a
commit 8e4ec595e1
3 changed files with 60 additions and 2 deletions

View file

@ -63,7 +63,7 @@
<div class="col-sm-12 col-md-6 col-lg-6 col-xl"> <div class="col-sm-12 col-md-6 col-lg-6 col-xl">
<table id="fight-table" class="table table-hover table-sm"> <table id="fight-table" class="table table-hover table-sm">
<thead> <thead>
<tr><th scope="col" colspan="2">Combat</th></tr> <tr><th scope="col" colspan="2">Attaque</th></tr>
</thead> </thead>
<tbody class="table-group-divider"> <tbody class="table-group-divider">
<tr> <tr>
@ -132,6 +132,47 @@
{{ character.attack_magic|modifier }} {{ character.attack_magic|modifier }}
</td> </td>
</tr> </tr>
</tbody>
</table>
</div>
<div class="col-sm-12 col-md-6 col-lg-6 col-xl">
<table id="fight-table" class="table table-hover table-sm">
<thead>
<tr><th scope="col" colspan="2">Protection</th></tr>
</thead>
<tbody class="table-group-divider">
<tr>
<th scope="row">
Armure
<div class="btn-group btn-group-sm float-end" role="group">
<button
hx-get="{% url "character:armor_change" pk=character.pk %}?value=ko"
hx-target="#armor"
hx-swap="innerHTML"
type="button"
class="btn btn-outline-danger"><i class="fa-solid fa-battery-empty"></i></button>
<button
hx-get="{% url "character:armor_change" pk=character.pk %}?value=-1"
hx-target="#armor"
hx-swap="innerHTML"
type="button"
class="btn btn-danger"><i class="fa-solid fa-minus"></i></button>
<button
hx-get="{% url "character:armor_change" pk=character.pk %}?value=1"
hx-target="#armor"
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="armor">
{{ character.armor }}
</td>
</tr>
<tr> <tr>
<th scope="row"> <th scope="row">
Bouclier Bouclier
@ -200,7 +241,7 @@
<th scope="row">Défense</th> <th scope="row">Défense</th>
<td data-bs-toggle="tooltip" <td data-bs-toggle="tooltip"
data-bs-placement="left" data-bs-placement="left"
data-bs-title="10 + {{ character.armor }} (armure) + {{ character.shield }} (bouclier) + {{ character.modifier_dexterity }} (mod. DEX) + {{ character.defense_misc }} (divers)" data-bs-title="10 + armure + bouclier + mod. DEX + divers"
hx-get="{% url "character:get_defense" pk=character.pk %}" hx-get="{% url "character:get_defense" pk=character.pk %}"
hx-trigger="update_defense from:#fight-table"> hx-trigger="update_defense from:#fight-table">
{{ character.defense }} {{ character.defense }}

View file

@ -33,6 +33,11 @@ urlpatterns = [
views.character_shield_change, views.character_shield_change,
name="shield_change", name="shield_change",
), ),
path(
"<int:pk>/armor_change/",
views.character_armor_change,
name="armor_change",
),
path( path(
"<int:pk>/get_initiative/", "<int:pk>/get_initiative/",
views.character_get_initiative, views.character_get_initiative,

View file

@ -119,6 +119,18 @@ def character_shield_change(request, pk: int):
return trigger_client_event(response, "update_defense", {}) return trigger_client_event(response, "update_defense", {})
@login_required
def character_armor_change(request, pk: int):
character = get_object_or_404(
Character.objects.filter(player=request.user).only("armor"), pk=pk
)
value = get_updated_value(request, character.armor, float("inf"))
character.armor = value
character.save(update_fields=["armor"])
response = HttpResponse(value)
return trigger_client_event(response, "update_defense", {})
@login_required @login_required
def character_initiative_misc_change(request, pk: int): def character_initiative_misc_change(request, pk: int):
character = get_object_or_404( character = get_object_or_404(