Ejemplo n.º 1
0
 def setUp(self):
     """ Setup the attack and Pokemon to use the attack """
     self.user = BuildPokemonBattleWrapper()
     self.target = BuildPokemonBattleWrapper()
     
     self.userPkmn = self.user.pkmn
     self.targetPkmn = self.target.pkmn
     
     self.stat = "SPD"
     self.delegate = StatRatioRangeDelegate(None, 1, self.stat)
     self.lvl = 50
Ejemplo n.º 2
0
class getPower(unittest.TestCase):
    """ Test that core damage is calculated correctly """ 
    
    def setUp(self):
        """ Setup the attack and Pokemon to use the attack """
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        
        self.userPkmn = self.user.pkmn
        self.targetPkmn = self.target.pkmn
        
        self.stat = "SPD"
        self.delegate = StatRatioRangeDelegate(None, 1, self.stat)
        self.lvl = 50
        
    def basePower(self):
        """ Test that the base power is correct """
        self.userPkmn.battleDelegate.stats[self.stat] = 25
        self.targetPkmn.battleDelegate.stats[self.stat] = 25
        power = self.delegate.getPower(self.user, self.target)
        
        assert power == StatRatioRangeDelegate.base, "Power should be the base when the ratio of the stat is 0"
        
    def powerIsLarger(self):
        """ Test that the power is greater when the user's stat is lower """
        self.userPkmn.battleDelegate.stats[self.stat] = 20
        self.targetPkmn.battleDelegate.stats[self.stat] = 25
        power = self.delegate.getPower(self.user, self.target)
        
        assert power > StatRatioRangeDelegate.base, "Power should be larger when user's stat decreases"
        
    def powerIsSmaller(self):
        """ Test that the power is smaller when the user's stat is higher """
        self.userPkmn.battleDelegate.stats[self.stat] = 30
        self.targetPkmn.battleDelegate.stats[self.stat] = 25
        power = self.delegate.getPower(self.user, self.target)
        
        assert power < StatRatioRangeDelegate.base, "Power should be smaller when user's stat increases"
        
    def powerIsMax(self):
        """ Test that the power is not greater than the max """
        self.userPkmn.battleDelegate.stats[self.stat] = 1
        self.targetPkmn.battleDelegate.stats[self.stat] = 300
        power = self.delegate.getPower(self.user, self.target)
        
        assert power ==  StatRatioRangeDelegate.max, "Power should be max at greatest"
Ejemplo n.º 3
0
    def loadFromDB(cursor, parent):
        """ Loads an attack Damage Delegate from a Database """
        type, id = DamageDelegateFactory.GetTypeAndID(cursor, parent.name)

        if type == "BOOST ON STATUS":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            return BoostDamageOnStatusDelegate(parent, power, isPhysical)

        elif type == "CORE":
            parameters = ["power", "physical"]
            power, physical = GetParameters(cursor, parameters,
                                            "CoreDamageDelegate", id)
            return DamageDelegate(parent, power, physical)

        elif type == "EFFECT ON DAMAGE":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            return EffectOnDamageDelegate(parent, power, isPhysical)

        elif type == "FIXED":
            isPhysical = int(element.find(Tags.physicalTag).text)
            damage = int(element.find(Tags.damageTag).text)
            return FixedDelegate(parent, damage, isPhysical)

        elif type == "HALF HEALTH":
            isPhysical = int(element.find(Tags.physicalTag).text)
            return HalfHealthDelegate(parent, isPhysical)

        elif type == "LEVEL":
            isPhysical = int(element.find(Tags.physicalTag).text)
            return LevelDelegate(parent, isPhysical)

        elif type == "NO FAINT":
            parameters = ["power", "physical"]
            power, physical = GetParameters(cursor, parameters,
                                            "NoFaintDamage", id)
            return NoFaintDelegate(parent, power, physical)

        elif type == "ONE HIT KO":
            isPhysical = int(element.find(Tags.physicalTag).text)
            return OneHitDelegate(parent, isPhysical)

        elif type == "PIERCE DODGE 2X":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            pierce = element.find(Tags.pierceTag).text
            return PierceDodge2XDelegate(parent, power, isPhysical, pierce)

        elif type == "SCALE":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            factor = int(element.find(Tags.factorTag).text)
            turns = int(element.find(Tags.turnsTag).text)
            return DamageScaleDelegate(parent, power, isPhysical, factor,
                                       turns)

        elif type == "STAT RATIO FIXED":
            isPhysical = int(element.find(Tags.physicalTag).text)
            stat = element.find(Tags.statTag).text
            return StatRatioFixedDelegate(parent, isPhysical, stat)

        elif type == "STAT RATIO RANGE":
            isPhysical = int(element.find(Tags.physicalTag).text)
            stat = element.find(Tags.statTag).text
            return StatRatioRangeDelegate(parent, isPhysical, stat)

        cursor.close()
Ejemplo n.º 4
0
    def loadFromXML(element, parent):
        """ Builds a DamageDelegate from XML """
        delegateType = element.find(Tags.typeTag).text

        if delegateType == "BOOST ON STATUS":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            return BoostDamageOnStatusDelegate(parent, power, isPhysical)

        elif delegateType == "CORE":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            return DamageDelegate(parent, power, isPhysical)

        elif delegateType == "EFFECT ON DAMAGE":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            return EffectOnDamageDelegate(parent, power, isPhysical)

        elif delegateType == "FIXED":
            isPhysical = int(element.find(Tags.physicalTag).text)
            damage = int(element.find(Tags.damageTag).text)
            return FixedDelegate(parent, damage, isPhysical)

        elif delegateType == "HALF HEALTH":
            isPhysical = int(element.find(Tags.physicalTag).text)
            return HalfHealthDelegate(parent, isPhysical)

        elif delegateType == "LEVEL":
            isPhysical = int(element.find(Tags.physicalTag).text)
            return LevelDelegate(parent, isPhysical)

        elif delegateType == "NO FAINT":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            return NoFaintDelegate(parent, power, isPhysical)

        elif delegateType == "ONE HIT KO":
            isPhysical = int(element.find(Tags.physicalTag).text)
            return OneHitDelegate(parent, isPhysical)

        elif delegateType == "PIERCE DODGE 2X":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            pierce = element.find(Tags.pierceTag).text
            return PierceDodge2XDelegate(parent, power, isPhysical, pierce)

        elif delegateType == "SCALE":
            power = int(element.find(Tags.powerTag).text)
            isPhysical = int(element.find(Tags.physicalTag).text)
            factor = int(element.find(Tags.factorTag).text)
            turns = int(element.find(Tags.turnsTag).text)
            return DamageScaleDelegate(parent, power, isPhysical, factor,
                                       turns)

        elif delegateType == "STAT RATIO FIXED":
            isPhysical = int(element.find(Tags.physicalTag).text)
            stat = element.find(Tags.statTag).text
            return StatRatioFixedDelegate(parent, isPhysical, stat)

        elif delegateType == "STAT RATIO RANGE":
            isPhysical = int(element.find(Tags.physicalTag).text)
            stat = element.find(Tags.statTag).text
            return StatRatioRangeDelegate(parent, isPhysical, stat)