Пример #1
0
    def loadFromDB(cursor, parent):
        """ Builds a HitDelegate from database"""
        type, id = HitDelegateFactory.GetTypeAndID(cursor, parent.name)

        if type == "ALWAYS":
            return AlwaysHitDelegate(HitDelegateFactory.MISS)

        elif type == "CORE":
            accuracy = GetParameters(cursor, "accuracy", "CoreHitDelegate", id)
            return HitDelegate(parent, accuracy)

        elif type == "CRASH":
            accuracy = int(element.find(Tags.hitTag).text)
            element = element.find(Tags.effectDelegateTag)
            delegate = EffectDelegateFactory.loadFromXML(element, parent)
            return CrashDelegate(parent, accuracy, HitDelegateFactory.MISS,
                                 delegate)

        elif type == "PIERCE DODGE":
            accuracy = int(element.find(Tags.hitTag).text)
            pierce = element.find(Tags.pierceTag).text
            return PierceDodgeDelegate(parent, accuracy, pierce)

        elif type == "SELF":
            return HitSelfDelegate()

        elif type == "STATUS ALWAYS":
            return AlwaysHitDelegate(HitDelegateFactory.STATUSMISS)

        elif type == "STATUS CORE":
            accuracy = GetParameters(cursor, "accuracy", "CoreHitDelegate", id)
            return StatusHitDelegate(parent, accuracy)
Пример #2
0
 def loadFromPokemonFile(file):
     """ Load an attack as saved within a Pokemon instance in a file """
     attack = Attack()
     attackdex = AttackFactory.getAttackdexTree()
   
     attack.name = file.readline().strip()
 
     temp = ""
     while (temp.find(attack.name) == -1):
         """ Read the file until you find the species we need """
         temp = attackdex.readline().strip()
 
     attack.type = attackdex.readline().strip()
     
     #Load delegates
     attack.hitDelegate = HitDelegateFactory.loadFromAttackDex(attackdex, attack)
     attack.damageDelegate = DamageDelegateFactory.loadFromAttackDex(attackdex, attack)
         
     attack.effectDelegate = EffectDelegateFactory.loadFromAttackDex(attackdex)
 
     # Get currPP and PP from file
     values = file.readline().strip().split(" ")
     attack.powerPoints = int(values[0])
     attack.currPowerPoints = int(values[1])
             
     attackdex.close()
 
     return attack
Пример #3
0
    def loadFromXML(element, parent):
        """ Builds a HitDelegate from XML """
        delegateType = element.find(Tags.typeTag).text

        if delegateType == "ALWAYS":
            return AlwaysHitDelegate(HitDelegateFactory.MISS)

        elif delegateType == "CORE":
            accuracy = int(element.find(Tags.hitTag).text)
            return HitDelegate(parent, accuracy)

        elif delegateType == "CRASH":
            accuracy = int(element.find(Tags.hitTag).text)
            element = element.find(Tags.effectDelegateTag)
            delegate = EffectDelegateFactory.loadFromXML(element, parent)
            return CrashDelegate(parent, accuracy, HitDelegateFactory.MISS,
                                 delegate)

        elif delegateType == "PIERCE DODGE":
            accuracy = int(element.find(Tags.hitTag).text)
            pierce = element.find(Tags.pierceTag).text
            return PierceDodgeDelegate(parent, accuracy, pierce)

        elif delegateType == "SELF":
            return HitSelfDelegate()

        elif delegateType == "STATUS ALWAYS":
            return AlwaysHitDelegate(HitDelegateFactory.STATUSMISS)

        elif delegateType == "STATUS CORE":
            accuracy = int(element.find(Tags.hitTag).text)
            return StatusHitDelegate(parent, accuracy)
Пример #4
0
 def loadFromDB(cursor, parent):
     """ Builds a HitDelegate from database"""
     type, id = HitDelegateFactory.GetTypeAndID(cursor, parent.name)
     
     if type == "ALWAYS":
         return AlwaysHitDelegate(HitDelegateFactory.MISS)
     
     elif type == "CORE":
         accuracy = GetParameters(cursor, "accuracy", "CoreHitDelegate", id)
         return HitDelegate(parent, accuracy)    
         
     elif type == "CRASH":
         accuracy = int(element.find(Tags.hitTag).text)
         element = element.find(Tags.effectDelegateTag)
         delegate = EffectDelegateFactory.loadFromXML(element, parent)
         return CrashDelegate(parent, accuracy, HitDelegateFactory.MISS, delegate)
         
     elif type == "PIERCE DODGE":
         accuracy = int(element.find(Tags.hitTag).text)
         pierce = element.find(Tags.pierceTag).text
         return PierceDodgeDelegate(parent, accuracy, pierce)
         
     elif type == "SELF":
         return HitSelfDelegate()
         
     elif type == "STATUS ALWAYS":
         return AlwaysHitDelegate(HitDelegateFactory.STATUSMISS)
         
     elif type == "STATUS CORE":
         accuracy = GetParameters(cursor, "accuracy", "CoreHitDelegate", id)
         return StatusHitDelegate(parent, accuracy)
Пример #5
0
 def loadFromXML(element, parent):
     """ Builds a HitDelegate from XML """
     delegateType = element.find(Tags.typeTag).text
     
     if delegateType == "ALWAYS":
         return AlwaysHitDelegate(HitDelegateFactory.MISS)
     
     elif delegateType == "CORE":
         accuracy = int(element.find(Tags.hitTag).text)
         return HitDelegate(parent, accuracy)
         
     elif delegateType == "CRASH":
         accuracy = int(element.find(Tags.hitTag).text)
         element = element.find(Tags.effectDelegateTag)
         delegate = EffectDelegateFactory.loadFromXML(element, parent)
         return CrashDelegate(parent, accuracy, HitDelegateFactory.MISS, delegate)
         
     elif delegateType == "PIERCE DODGE":
         accuracy = int(element.find(Tags.hitTag).text)
         pierce = element.find(Tags.pierceTag).text
         return PierceDodgeDelegate(parent, accuracy, pierce)
         
     elif delegateType == "SELF":
         return HitSelfDelegate()
         
     elif delegateType == "STATUS ALWAYS":
         return AlwaysHitDelegate(HitDelegateFactory.STATUSMISS)
         
     elif delegateType == "STATUS CORE":
         accuracy = int(element.find(Tags.hitTag).text)
         return StatusHitDelegate(parent, accuracy)
Пример #6
0
 def buildAttackFromDB(cursor, name):
     """ Build an Attack from a Database connection """
     attack = Attack()
     
     cursor.execute("SELECT Type.name from Attack, Type where Attack.name = ? and Attack.type_id = Type.id", (name,))
     type = cursor.fetchone()[0]
     
     attack.name = name
     attack.type = type
     
     # Delegates
     for delegateCategory in AttackFactory.factories.keys():
         delegate = AttackFactory.getDelegateDB(cursor, delegateCategory, attack)
         attack.addDelegate(delegateCategory, delegate)
         
     attack.effectDelegates = EffectDelegateFactory.loadAllEffectsFromDB(cursor, attack)
             
     return attack
Пример #7
0
 def buildAttackFromXML(tree):
     """ Build an Attack from XML tree """
     attack = Attack()
     
     attack.name = tree.find(Tags.nameTag).text
     attack.type = tree.find(Tags.typeTag).text
     attack.makes_contact = Tags.contactAttribute in tree.attrib
     
     # Delegates
     for delegateCategory in AttackFactory.factories.keys():
         delegate = AttackFactory.getDelegate(tree, delegateCategory, attack)
         attack.addDelegate(delegateCategory, delegate)
         
     effects = tree.find(Tags.effectDelegatesTag)
     
     if effects is not None:
         for effect in effects.getchildren():
             delegate = EffectDelegateFactory.loadFromXML(effect, attack)
             attack.addDelegate(Tags.effectDelegateTag, delegate)
             
     return attack
Пример #8
0
    def buildAbilityFromXML(tree):
        """ Builds a DamageDelegate from XML """
        name = tree.find(Tags.nameTag).text
        abilityType = tree.find(Tags.typeTag).text

        if abilityType == "ACC MOD":
            mod = float(tree.find(Tags.degreeTag).text)
            return AccModAbility(name, mod)

        elif abilityType == "BOOST STAB":
            return BoostStabAbility(name)

        elif abilityType == "CANT LOWER STAT":
            stat = tree.find(Tags.statTag).text
            return CantLowerStatAbility(name, stat)

        elif abilityType == "CONFUSION IMMUNITY":
            return ConfusionImmunityAbility(name)

        elif abilityType == "DEFENSE EFFECTIVENESS":
            entries = {}
            effectivenessTree = tree.find(Tags.effectivenessesTag)
            for entry in effectivenessTree.getchildren():
                type = entry.find(Tags.typeTag).text
                effectiveness = float(entry.find(Tags.effectivenessTag).text)
                message = entry.find(Tags.messageTag).text
                entries[type] = {}
                entries[type]['effectiveness'] = effectiveness
                entries[type]['message'] = message
            return ResistTypeAbility(name, entries)

        elif abilityType == "EFFECT AFTER TURN":
            effectsTree = tree.find(Tags.effectDelegatesTag)
            effects = []

            for effectTree in effectsTree.getchildren():
                effect = EffectDelegateFactory.loadFromXML(effectTree, None)
                effects.append(effect)

            return EffectAfterTurnAbility(name, effects)

        elif abilityType == "EFFECT ON CONTACT":
            effectsTree = tree.find(Tags.effectDelegatesTag)
            effects = []

            for effectTree in effectsTree.getchildren():
                effect = EffectDelegateFactory.loadFromXML(effectTree, None)
                effects.append(effect)

            return EffectOnContactAbility(name, effects)

        elif abilityType == "EFFECT ON CRIT":
            effectsTree = tree.find(Tags.effectDelegatesTag)
            effects = []

            for effectTree in effectsTree.getchildren():
                effect = EffectDelegateFactory.loadFromXML(effectTree, None)
                effects.append(effect)

            return EffectOnCritAbility(name, effects)

        elif abilityType == "EFFECT ON STAT MOD":
            message = tree.find(Tags.messageTag).text
            effectsTree = tree.find(Tags.effectDelegatesTag)
            effects = []

            for effectTree in effectsTree.getchildren():
                effect = EffectDelegateFactory.loadFromXML(effectTree, None)
                effects.append(effect)

            return EffectOnStatModAbility(name, effects, message)

        elif abilityType == "NO CRIT":
            return NoCritAbility(name)

        elif abilityType == "PRESSURE":
            return PressureAbility(name)

        elif abilityType == "PREVENT RECOIL":
            return PreventRecoilAbility(name)

        elif abilityType == "SKIP TURN":
            return SkipTurnAbility(name)

        elif abilityType == "SNIPER":
            return SniperAbility(name)

        elif abilityType == "STAT MOD ON STATUS":
            stat = tree.find(Tags.statTag).text
            mod = float(tree.find(Tags.degreeTag).text)
            return StatModOnStatusAbility(name, stat, mod)
Пример #9
0
 def buildAbilityFromXML(tree):
     """ Builds a DamageDelegate from XML """
     name = tree.find(Tags.nameTag).text
     abilityType = tree.find(Tags.typeTag).text
     
     if abilityType == "ACC MOD":
         mod = float(tree.find(Tags.degreeTag).text)
         return AccModAbility(name, mod)
     
     elif abilityType == "BOOST STAB":
         return BoostStabAbility(name)
     
     elif abilityType == "CANT LOWER STAT":
         stat = tree.find(Tags.statTag).text
         return CantLowerStatAbility(name, stat)
         
     elif abilityType == "CONFUSION IMMUNITY":
         return ConfusionImmunityAbility(name)
       
     elif abilityType == "DEFENSE EFFECTIVENESS":
         entries = {}
         effectivenessTree = tree.find(Tags.effectivenessesTag)
         for entry in effectivenessTree.getchildren():
             type = entry.find(Tags.typeTag).text
             effectiveness = float(entry.find(Tags.effectivenessTag).text)
             message = entry.find(Tags.messageTag).text
             entries[type] = {}
             entries[type]['effectiveness'] = effectiveness
             entries[type]['message'] = message
         return ResistTypeAbility(name, entries)
       
     elif abilityType == "EFFECT AFTER TURN":
         effectsTree = tree.find(Tags.effectDelegatesTag)
         effects = []
     
         for effectTree in effectsTree.getchildren():
             effect = EffectDelegateFactory.loadFromXML(effectTree, None)
             effects.append(effect)
             
         return EffectAfterTurnAbility(name, effects)
     
     elif abilityType == "EFFECT ON CONTACT":
         effectsTree = tree.find(Tags.effectDelegatesTag)
         effects = []
     
         for effectTree in effectsTree.getchildren():
             effect = EffectDelegateFactory.loadFromXML(effectTree, None)
             effects.append(effect)
             
         return EffectOnContactAbility(name, effects)
     
     elif abilityType == "EFFECT ON CRIT":
         effectsTree = tree.find(Tags.effectDelegatesTag)
         effects = []
     
         for effectTree in effectsTree.getchildren():
             effect = EffectDelegateFactory.loadFromXML(effectTree, None)
             effects.append(effect)
             
         return EffectOnCritAbility(name, effects)
         
     elif abilityType == "EFFECT ON STAT MOD":
         message  =  tree.find(Tags.messageTag).text
         effectsTree = tree.find(Tags.effectDelegatesTag)
         effects = []
     
         for effectTree in effectsTree.getchildren():
             effect = EffectDelegateFactory.loadFromXML(effectTree, None)
             effects.append(effect)
             
         return EffectOnStatModAbility(name, effects, message)
         
     elif abilityType == "NO CRIT":
         return NoCritAbility(name)
         
     elif abilityType == "PRESSURE":
         return PressureAbility(name)
         
     elif abilityType == "PREVENT RECOIL":
         return PreventRecoilAbility(name)
         
     elif abilityType == "SKIP TURN":
         return SkipTurnAbility(name)
         
     elif abilityType == "SNIPER":
         return SniperAbility(name)
     
     elif abilityType == "STAT MOD ON STATUS":
         stat = tree.find(Tags.statTag).text
         mod = float(tree.find(Tags.degreeTag).text)
         return StatModOnStatusAbility(name, stat, mod)