def __init__(self, source, message, doneMessage): """ Builds a trap with the given message """ self.source = source self.message = message self.doneMessage = doneMessage self.turns = self.getTurns() self.faintHandler = FaintHandlerFactory.buildFromType(FaintHandlerFactory.SOURCE)
def __init__(self, source, message, doneMessage): """ Builds a trap with the given message """ self.source = source self.message = message self.doneMessage = doneMessage self.turns = self.getTurns() self.faintHandler = FaintHandlerFactory.buildFromType( FaintHandlerFactory.SOURCE)
def BuildFaintHandler(type="REGULAR"): """ Builds a faint handler of the given type """ return FaintHandlerFactory.buildFromType(type)
def __init__(self, name): self.name = name self.faintHandler = FaintHandlerFactory.buildFromType( FaintHandlerFactory.USER)
def __init__(self, message): """ Builds a Periodic Heal """ self.message = message self.faintHandler = FaintHandlerFactory.buildFromType( FaintHandlerFactory.USER)
def initialize(self): self.faintHandler = FaintHandlerFactory.buildFromType(FaintHandlerFactory.USER) self.setStatMods()
def __init__(self, message): """ Builds a Periodic Heal """ self.message = message self.faintHandler = FaintHandlerFactory.buildFromType(FaintHandlerFactory.USER)
def __init__(self): self.turns = self.getTurns() self.faintHandler = FaintHandlerFactory.buildFromType(FaintHandlerFactory.USER)
def __init__(self, name): self.name = name self.faintHandler = FaintHandlerFactory.buildFromType(FaintHandlerFactory.USER)
def __init__(self, source, message): """ Build a Leech effect """ self.source = source self.message = message self.faintHandler = FaintHandlerFactory.buildFromType(FaintHandlerFactory.SOURCE)
def BuildFaintHandler(type = "REGULAR"): """ Builds a faint handler of the given type """ return FaintHandlerFactory.buildFromType(type)
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 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 __init__(self, source, message): """ Build a Leech effect """ self.source = source self.message = message self.faintHandler = FaintHandlerFactory.buildFromType( FaintHandlerFactory.SOURCE)