Mercurial > parpg-core
annotate src/parpg/components/equip.py @ 91:1bd609af9329
Added equip function.
author | KarstenBock@gmx.net |
---|---|
date | Wed, 21 Sep 2011 15:43:12 +0200 |
parents | 0319dcc47603 |
children | 0f659c7675f6 |
rev | line source |
---|---|
72
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
1 # This program is free software: you can redistribute it and/or modify |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
2 # it under the terms of the GNU General Public License as published by |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
3 # the Free Software Foundation, either version 3 of the License, or |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
4 # (at your option) any later version. |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
5 # |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
6 # This program is distributed in the hope that it will be useful, |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
9 # GNU General Public License for more details. |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
10 # |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
11 # You should have received a copy of the GNU General Public License |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
12 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
13 |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
14 from bGrease.component import Component |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
15 |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
16 class Equip(Component): |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
17 """ |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
18 Component that stores the equipment (what is being worn/wieled). |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
19 """ |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
20 |
9aebbf4e02f7
Added equip component, wich stores the equipment data of an entity.
KarstenBock@gmx.net
parents:
diff
changeset
|
21 def __init__(self): |
91 | 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 |