Beispiel #1
0
 def abilities(self, abilities_dict: Dict[str, int]):
     self.wipe_all_abilities()
     for ability, value in abilities_dict.items():
         trait = Trait.get_instance_by_name(ability)
         self._cache["ability"][
             ability] = self.character.trait_values.create(trait=trait,
                                                           value=value)
Beispiel #2
0
 def remove_last_skill_purchase_record(self, trait_name: str) -> int:
     trait = Trait.get_instance_by_name(trait_name)
     purchase = (self.character.trait_purchases.filter(
         trait=trait).order_by("cost").last())
     if not purchase:
         raise ValueError("No purchase found")
     cost = purchase.cost
     purchase.delete()
     return cost
Beispiel #3
0
 def skills(self, skills_dict: Dict[str, int]):
     self.wipe_all_skills()
     for skill, value in skills_dict.items():
         trait = Trait.get_instance_by_name(skill)
         if not trait:
             names = ", ".join(Trait.get_valid_skill_names())
             raise InvalidTrait(
                 f"No trait found by '{skill}'. Valid: {names}")
         self._cache["skill"][skill] = self.character.trait_values.create(
             trait=trait, value=value)
Beispiel #4
0
 def set_trait_value(self, trait_type: str, name: str, value: int):
     """Deletes or sets up a trait value for a character, updating our cache"""
     # if our value is 0 or lower, delete the trait value
     if value <= 0 and name in self._cache[trait_type]:
         trait_value = self._cache[trait_type].pop(name)
         if trait_value.pk:
             trait_value.delete()
     else:  # create/update our trait value to be the new value
         if name in self._cache[trait_type]:
             trait_value = self._cache[trait_type][name]
         else:
             trait = Trait.get_instance_by_name(name)
             if not trait:
                 names = ", ".join(ob.name
                                   for ob in Trait.get_all_instances())
                 raise InvalidTrait(
                     f"No trait found by '{name}'. Valid: {names}")
             trait_value, _ = self.character.trait_values.get_or_create(
                 trait=trait)
             self._cache[trait_type][name] = trait_value
         trait_value.value = value
         trait_value.save()
Beispiel #5
0
 def record_skill_purchase(self, trait_name: str, cost):
     trait = Trait.get_instance_by_name(trait_name)
     self.character.trait_purchases.create(trait=trait, cost=cost)
Beispiel #6
0
 def cure_permanent_wound(self, trait_name: str) -> bool:
     """Returns True if we deleted a permanent wound, False otherwise"""
     trait = Trait.get_instance_by_name(trait_name)
     return self.character.health_status.heal_permanent_wound_for_trait(
         trait)