"""Anti-magic trap:  drains your magical energy away.

Copyright 2001 Cabochon Technologies, Inc.
Author:  Steve Yegge
"""

from wyvern.lib.classes.traps import AbstractTrap
from wyvern.lib import Monster, Player, Range

class anti_magic_trap(AbstractTrap):

    def initialize(self):
        self.super__initialize()
        self.setDefaultCategory("traps")
        self.setDefaultBitmap("rune_blue")
        self.setProperty('short', 'anti-magic trap')
        self.addProperty("nopickup")
        self.setWeight("10 lb")

    def steppedOn(self, monster):
        self.reveal(monster)
        monster.message("You feel your magical energy drain away!")

        if not isinstance(monster, Monster):
            return

        sp = monster.getIntProperty("sp")
        if sp == 0:
            return

        drain = Range.randomValue(1, sp)
        if isinstance(monster, Player):
            monster.adjustSP(-drain)
        else:
            monster.adjustIntProperty('sp', -drain)

    def toString(self, *args):
        if len(args) > 0:
            return self.super__toString(args[0])
        else:
            return 'anti-magic trap'