Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# TODO not quite sure where this goes. should it be able to react to events
# too?
class Modifier:
def __init__(self, stat, add):
self.stat = stat
self.add = add
def modify(self, attr, value):
if attr is not self.stat:
return value
return value + self.add
Armor = Item(
Equipment(modifiers=[Modifier(ICombatant['strength'], add=3)]),
Render(sprite=Sprite.armor, color='default'),
name='armor',
)
@Equip.perform(Equipment)
def put_on_equipment(event, equipment):
equipment.worn_by.add(event.actor)
@Equip.check(Equipment)
def equipper_must_have_body_part(event, equipment):
# TODO need to implement slots
if IBodied not in event.actor:
log.info("you can't wear that")
event.cancel()
@Unequip.announce(Equipment)
def unequip_success(event, equipment):
log.info("you take off the armor")
@Unequip.perform(Equipment)
def take_off_equipment(event, equipment):
self.worn_by.remove(event.actor)
@Unequip.check(Equipment)
def can_only_equip_whats_equipped(event, equipment):
if event.actor not in equipment.worn_by:
log.info("you're not wearing the armor!")
event.cancel()
@Equip.announce(Equipment)
def equipment_success(event, equipment):
log.info("you put on the armor")