updated how weapons are handled

This commit is contained in:
Ben Cook
2019-01-01 17:11:39 -05:00
parent 708a39403c
commit 2d7a25724b
9 changed files with 61 additions and 53 deletions
+3 -16
View File
@@ -617,30 +617,17 @@ class Character():
"""
# Retrieve the weapon class from the weapons module
if isinstance(weapon, weapons.Weapon):
weapon_ = type(weapon)()
weapon_ = type(weapon)(wielder=self)
elif isinstance(weapon, str):
try:
NewWeapon = findattr(weapons, weapon)
except AttributeError:
raise AttributeError(f'Weapon "{weapon}" is not defined')
weapon_ = NewWeapon()
weapon_ = NewWeapon(wielder=self)
elif issubclass(weapon, weapons.Weapon):
weapon_ = weapon()
weapon_ = weapon(wielder=self)
else:
raise AttributeError(f'Weapon "{weapon}" is not defined')
# check if features add any bonuses
for f in self.features:
weapon_ = f.weapon_func(weapon_)
# Set weapon attributes based on character
if weapon_.is_finesse:
ability_mod = max(self.strength.modifier, self.dexterity.modifier)
else:
ability_mod = getattr(self, weapon_.ability).modifier
weapon_.attack_bonus += ability_mod
weapon_.bonus_damage += ability_mod
# Check for prifiency
if self.is_proficient(weapon_):
weapon_.attack_bonus += self.proficiency_bonus
# Save it to the array
self.weapons.append(weapon_)