mirror of
https://github.com/Threnklyn/dungeon-sheets.git
synced 2026-06-05 12:29:39 +02:00
added ALL spells; can add magic weapons/armor/shields using +X in name
This commit is contained in:
+13
-1
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user