gammatools/app/functions/roll_physical_attack.py

29 lines
1.2 KiB
Python

from app.functions.get_attack_roll_outcome import get_attack_roll_outcome
from app.tables.physattack import AttackerHitDiceMatrix, AttackerWeaponClassMatrix
def roll_physical_attack(dac, modifier=0, awc=None, ahd=None):
"""
:param dac: integer. required. defender armour class. used in both matrices.
:param modifier: integer. required. any pluses or minuses to be applied to roll
:param awc: integer. optional(*). Attacker weapon class. This is required, if weapon attack == True.
:param ahd: integer. optional(*). Attacker hit dice. This is required, if weapon attack == False.
:return:
"""
if modifier is None:
modifier = 0
result = {}
if isinstance(awc, int):
hit_table = AttackerWeaponClassMatrix()
result["needed"] = hit_table.get_attack_score(awc, dac)
elif isinstance(ahd, int):
hit_table = AttackerHitDiceMatrix()
result["needed"] = hit_table.get_attack_score(ahd, dac)
# use non-weapon attack lookup table
else:
# handle error state where neither awc nor ahd are integers (None or other non-integer value)
raise ValueError("Either awc or ahd must be an integer.")
return get_attack_roll_outcome(result, modifier)