added ALL spells; can add magic weapons/armor/shields using +X in name

This commit is contained in:
Ben Cook
2019-03-21 16:32:18 -04:00
parent 9e7b3485b5
commit 9f608288cf
42 changed files with 14390 additions and 7098 deletions
+13 -1
View File
@@ -1,6 +1,7 @@
import math
from collections import namedtuple
from .armor import NoArmor, NoShield, HeavyArmor
from .armor import NoArmor, NoShield, HeavyArmor, Shield, Armor
from .weapons import Weapon
from .features import (UnarmoredDefenseMonk, UnarmoredDefenseBarbarian,
DraconicResilience, Defense, FastMovement,
UnarmoredMovement, GiftOfTheDepths, RemarkableAthelete,
@@ -17,6 +18,14 @@ def findattr(obj, name):
"""
# Come up with several options
name = name.strip()
# check for +X weapons, armor, shields
bonus = 0
for i in range(1, 11):
if (f'+{i}' in name) or (f'+ {i}' in name):
bonus = i
name = name.replace(f'+{i}', '').replace(f'+ {i}', '')
break
py_name = name.replace('-', '_').replace(' ', '_').replace("'", "")
camel_case = "".join([s.capitalize() for s in py_name.split('_')])
if hasattr(obj, py_name):
@@ -27,6 +36,9 @@ def findattr(obj, name):
attr = getattr(obj, camel_case)
else:
raise AttributeError(f'{obj} has no attribute {name}')
if bonus > 0:
if issubclass(attr, Weapon) or issubclass(attr, Shield) or issubclass(attr, Armor):
attr = attr.improved_version(bonus)
return attr