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
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
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