def __init__(self, turns, turnToAttack, message, weatherType):
     """ Builds a Weather Charge Delegate """
     self.weatherType = weatherType
     ChargeDelegate.__init__(self, turns, turnToAttack, message)
 def isCharging(self, user, environment):
     """ Determines if the attack should not be completed because it is charging """
     self.getTurns(environment)
     if environment.weather.type == self.weatherType:
         self.turnOn = self.turnToAttack
     return ChargeDelegate.isCharging(self, user, environment)
 def __init__(self, turns, turnToAttack, message, weatherType):
     """ Builds a Weather Charge Delegate """
     self.weatherType = weatherType
     ChargeDelegate.__init__(self, turns, turnToAttack, message)
    def loadFromXML(element, parent):
        """ Builds a HitDelegate from a XML file """
        delegateType = element.find(Tags.typeTag).text

        if delegateType == "APPLY LOCK":
            turns = int(element.find(Tags.turnsTag).text)
            affectUser = int(element.find(Tags.affectUserTag).text)
            delegate = ApplyLockDelegate(turns, affectUser)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "CHANCE":
            chance = int(element.find(Tags.chanceTag).text)
            effects = EffectDelegateFactory.getEffects(element,
                                                       Tags.effectDelegatesTag,
                                                       parent)
            delegate = ChanceDelegate(chance, effects)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.REGULAR)
            return delegate

        elif delegateType == "CHARGE":
            turns = int(element.find(Tags.turnsTag).text)
            hitOnTurn = int(element.find(Tags.hitOnTurnTag).text)
            message = element.find(Tags.messageTag).text
            delegate = ChargeDelegate(turns, hitOnTurn, message)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "CONFUSE":
            affectUser = int(element.find(Tags.affectUserTag).text)
            delegate = ConfuseDelegate(affectUser)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.AFFECT_USER)
            return delegate

        elif delegateType == "CRIT MOD":
            degree = int(element.find(Tags.degreeTag).text)
            delegate = CritModDelegate(degree)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.AFFECT_USER)
            return delegate

        elif delegateType == "CURE STATUS":
            status = element.find(Tags.statusTag).text
            affectUser = int(element.find(Tags.affectUserTag).text)
            delegate = CureStatusDelegate(status, affectUser)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.AFFECT_USER)
            return delegate

        elif delegateType == "DAMAGE IS EFFECT":
            parent.damageDelegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return parent.damageDelegate

        elif delegateType == "DIVERGE ON FAINT":
            divergeEffectsXML = element.find(Tags.divergeEffectsTag)
            divergeEffects = []
            for effectDelegate in divergeEffectsXML.getchildren():
                divergeEffects.append(
                    EffectDelegateFactory.loadFromXML(effectDelegate, parent))

            normalEffectsXML = element.find(Tags.normalEffectsTag)
            normalEffects = []
            for effectDelegate in normalEffectsXML.getchildren():
                normalEffects.append(
                    EffectDelegateFactory.loadFromXML(effectDelegate, parent))

            delegate = DivergeOnFaintDelegate(divergeEffects, normalEffects)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.REGULAR)
            return delegate

        elif delegateType == "DODGE":
            dodgeType = element.find(Tags.dodgeTypeTag).text
            message = element.find(Tags.messageTag).text
            delegate = DodgeDelegate(dodgeType, message)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "FLINCH":
            delegate = FlinchDelegate()
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.TARGET)
            return delegate

        elif delegateType == "HEAL DAMAGE RATIO":
            healRatio = int(element.find(Tags.ratioTag).text)
            delegate = HealByDamageRatioDelegate(healRatio)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "HEAL HP RATIO":
            healRatio = int(element.find(Tags.ratioTag).text)
            delegate = HealByHPRatioDelegate(healRatio)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "LEECH":
            startMessage = element.find(Tags.startMessageTag).text
            message = element.find(Tags.messageTag).text
            delegate = LeechDelegate(startMessage, message, parent.type)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "MULTI TURN RANGE":
            min = int(element.find(Tags.minTag).text)
            max = int(element.find(Tags.maxTag).text)
            effects = EffectDelegateFactory.getEffects(element,
                                                       Tags.effectDelegatesTag,
                                                       parent)
            delegate = MultiTurnRangeDelegate(min, max, effects)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "RND STAT MOD":
            degree = int(element.find(Tags.degreeTag).text)
            affectUser = int(element.find(Tags.affectUserTag).text)
            delegate = RandomStatModDelegate(degree, affectUser)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.AFFECT_USER)
            return delegate

        elif delegateType == "RECOIL":
            recoilRatio = int(element.find(Tags.ratioTag).text)
            delegate = RecoilDelegate(recoilRatio)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "RESET STAT MODS":
            delegate = ResetStatModsDelegate()
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.REGULAR)
            return delegate

        elif delegateType == "RANDOM SWITCH":
            affectUser = int(element.find(Tags.affectUserTag).text)
            reset = int(element.find(Tags.resetTag).text)
            delegate = RandomSwitchDelegate(affectUser, reset)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.AFFECT_USER)
            return delegate

        elif delegateType == "PERIODIC HEAL":
            startMessage = element.find(Tags.startMessageTag).text
            message = element.find(Tags.messageTag).text
            delegate = PeriodicHealDelegate(startMessage, message)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "SELFDESTRUCT":
            delegate = SelfDestructDelegate()
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "START WEATHER":
            weatherType = element.find(Tags.weatherTag).text
            delegate = StartWeatherDelegate(weatherType)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "STAT MOD":
            stat = element.find(Tags.statTag).text
            degree = int(element.find(Tags.degreeTag).text)
            affectUser = int(element.find(Tags.affectUserTag).text)
            delegate = StatModDelegate(stat, degree, affectUser)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.AFFECT_USER)
            return delegate

        elif delegateType == "STATUS":
            status = element.find(Tags.statusTag).text
            affectUser = int(element.find(Tags.affectUserTag).text)
            delegate = ApplyStatusDelegate(parent, status, affectUser)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.AFFECT_USER)
            return delegate

        elif delegateType == "SWAP ABILITY":
            delegate = SwapAbilityDelegate()
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.EITHER)
            return delegate

        elif delegateType == "SWAP STATS":
            stat1 = element.find(Tags.stat1Tag).text
            stat2 = element.find(Tags.stat2Tag).text
            delegate = SwapStatDelegate(stat1, stat2)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "SWAP STAT MODS":
            delegate = SwapStatModsDelegate()
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.EITHER)
            return delegate

        elif delegateType == "SWITCH":
            affectUser = int(element.find(Tags.affectUserTag).text)
            reset = int(element.find(Tags.resetTag).text)
            delegate = SwitchDelegate(affectUser, reset)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.AFFECT_USER)
            return delegate

        elif delegateType == "TRAP":
            startMessage = element.find(Tags.startMessageTag).text
            message = element.find(Tags.messageTag).text
            doneMessage = element.find(Tags.doneMessageTag).text
            delegate = TrapDelegate(startMessage, message, doneMessage)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.TARGET)
            return delegate

        elif delegateType == "USELESS":
            delegate = UselessDelegate()
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate

        elif delegateType == "WEATHER CHARGE":
            turns = int(element.find(Tags.turnsTag).text)
            hitOnTurn = int(element.find(Tags.hitOnTurnTag).text)
            message = element.find(Tags.messageTag).text
            weatherType = element.find(Tags.weatherTag).text
            delegate = WeatherChargeDelegate(turns, hitOnTurn, message,
                                             weatherType)
            delegate.faintHandler = FaintHandlerFactory.buildFromType(
                FaintHandlerFactory.USER)
            return delegate
 def isCharging(self, user, environment):
     """ Determines if the attack should not be completed because it is charging """
     self.getTurns(environment)
     if environment.weather.type == self.weatherType:
         self.turnOn = self.turnToAttack
     return ChargeDelegate.isCharging(self, user, environment)