comparison components/equip.py @ 64:b73050f98411

Added equip function.
author KarstenBock@gmx.net
date Wed, 21 Sep 2011 15:43:12 +0200
parents e5acfeca9bc9
children e856b604b650
comparison
equal deleted inserted replaced
63:e5acfeca9bc9 64:b73050f98411
18 Component that stores the equipment (what is being worn/wieled). 18 Component that stores the equipment (what is being worn/wieled).
19 """ 19 """
20 20
21 def __init__(self): 21 def __init__(self):
22 Component.__init__(self, head=object, body=object, leg=object, feet=object, l_arm=object, r_arm=object) 22 Component.__init__(self, head=object, body=object, leg=object, feet=object, l_arm=object, r_arm=object)
23
24 class SlotInvalidError(Exception):
25 """Error that gets raised when the slot is invalid."""
26
27 def __init__(self, slot):
28 self.slot = slot
29
30 def __str__(self):
31 return "\"%s\" is not a valid slot." % self.slot
32
33 def equip(wearer, equipable, slot):
34 """Equip the wearer with the given equipable.
35 @returns The equipable that was at the given slot, or None"""
36 if slot in equipable.possible_slots:
37 try:
38 old_item = getattr(wearer, slot)
39 setattr(wearer, slot, equipable)
40 return old_item
41 except AttributeError:
42 raise SlotInvalidError(slot)
43 return None
44