Mercurial > parpg-source
diff components/equip.py @ 65:e856b604b650
Changed "import bGrease" to "import parpg.bGrease".
author | KarstenBock@gmx.net |
---|---|
date | Wed, 21 Sep 2011 16:10:14 +0200 |
parents | b73050f98411 |
children | c1959525efda |
line wrap: on
line diff
--- a/components/equip.py Wed Sep 21 15:43:12 2011 +0200 +++ b/components/equip.py Wed Sep 21 16:10:14 2011 +0200 @@ -1,44 +1,44 @@ -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. - -from bGrease.component import Component - -class Equip(Component): - """ - Component that stores the equipment (what is being worn/wieled). - """ - - def __init__(self): - Component.__init__(self, head=object, body=object, leg=object, feet=object, l_arm=object, r_arm=object) - -class SlotInvalidError(Exception): - """Error that gets raised when the slot is invalid.""" - - def __init__(self, slot): - self.slot = slot - - def __str__(self): - return "\"%s\" is not a valid slot." % self.slot - -def equip(wearer, equipable, slot): - """Equip the wearer with the given equipable. - @returns The equipable that was at the given slot, or None""" - if slot in equipable.possible_slots: - try: - old_item = getattr(wearer, slot) - setattr(wearer, slot, equipable) - return old_item - except AttributeError: - raise SlotInvalidError(slot) - return None +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +from parpg.bGrease.component import Component + +class Equip(Component): + """ + Component that stores the equipment (what is being worn/wieled). + """ + + def __init__(self): + Component.__init__(self, head=object, body=object, leg=object, feet=object, l_arm=object, r_arm=object) + +class SlotInvalidError(Exception): + """Error that gets raised when the slot is invalid.""" + + def __init__(self, slot): + self.slot = slot + + def __str__(self): + return "\"%s\" is not a valid slot." % self.slot + +def equip(wearer, equipable, slot): + """Equip the wearer with the given equipable. + @returns The equipable that was at the given slot, or None""" + if slot in equipable.possible_slots: + try: + old_item = getattr(wearer, slot) + setattr(wearer, slot, equipable) + return old_item + except AttributeError: + raise SlotInvalidError(slot) + return None \ No newline at end of file