Display capability points counter

This commit is contained in:
Gabriel Augendre 2022-11-10 22:44:53 +01:00
parent 0470cb869b
commit ca32576054
4 changed files with 19 additions and 1 deletions

View file

@ -119,6 +119,12 @@ class Capability(DocumentedModel, TimeStampedModel, models.Model):
def natural_key(self): def natural_key(self):
return (self.path_id, self.rank) return (self.path_id, self.rank)
@property
def capability_points_cost(self) -> int:
if self.rank in [1, 2]:
return 1
return 2
class RacialCapabilityManager(models.Manager): class RacialCapabilityManager(models.Manager):
def get_by_natural_key(self, name: str, race_id: int): def get_by_natural_key(self, name: str, race_id: int):

View file

@ -332,6 +332,18 @@ class Character(models.Model):
return 0 return 0
return self.mana_remaining / self.mana_max * 100 return self.mana_remaining / self.mana_max * 100
@property
def capability_points_max(self) -> int:
return 2 * self.level
@property
def capability_points_used(self) -> int:
return sum(cap.capability_points_cost for cap in self.capabilities.only("rank"))
@property
def capability_points_remaining(self) -> int:
return self.capability_points_max - self.capability_points_used
def get_modifier_for_weapon(self, weapon: Weapon) -> int: def get_modifier_for_weapon(self, weapon: Weapon) -> int:
modifier_map = { modifier_map = {
Weapon.Category.RANGE: self.modifier_dexterity, Weapon.Category.RANGE: self.modifier_dexterity,

View file

@ -484,7 +484,6 @@
{% include "character/snippets/character_details/equipment_display.html" %} {% include "character/snippets/character_details/equipment_display.html" %}
</div> </div>
</div> </div>
<h2>Voies & Capacités</h2>
{% include "character/snippets/character_details/paths_and_capabilities.html" %} {% include "character/snippets/character_details/paths_and_capabilities.html" %}
{% if character|managed_by:user %} {% if character|managed_by:user %}

View file

@ -1,6 +1,7 @@
{% load character_extras %} {% load character_extras %}
{% load django_bootstrap5 %} {% load django_bootstrap5 %}
<div id="paths-and-capabilities"> <div id="paths-and-capabilities">
<h2>Voies & Capacités <span class="badge text-bg-{% if character.capability_points_remaining > 0 %}success{% elif character.capability_points_remaining == 0 %}secondary{% else %}danger{% endif %} rounded-pill">{{ character.capability_points_remaining }}</span></h2>
{% if character|managed_by:user %} {% if character|managed_by:user %}
<form> <form>
{% csrf_token %} {% csrf_token %}