Ejemplo n.º 1
0
class applyEffect(unittest.TestCase):
    """ Test that applyEffect returns correctly """ 
    
    def setUp(self):
        """ Setup the attack and Pokemon to use the attack """
        self.pkmn = BuildPokemonBattleWrapper()
        self.delegate = DamageScaleDelegate(None, 50, 1, 1, 5)
        
    def turnZero(self):
        """ Test that applyEffect operates correctly on turn 0 """
        self.delegate.turnOn = 0
        self.pkmn.actionLock = None
        self.delegate.applyEffect(self.pkmn, None, None)
        
        assert self.pkmn.actionLock is not None, "Should have an action Lock"
        assert self.delegate.turnOn == 1, "Turns should be incremented"
        
    def otherwise(self):
        """ Test that applyEffect does not do anything except increment turns if the turn is not zero """
        self.delegate.turnOn = 1
        self.pkmn.actionLock = None
        self.delegate.applyEffect(self.pkmn, None, None)
        
        assert self.pkmn.actionLock is None, "Should not have an actionLock"
        assert self.delegate.turnOn == 2, "Turns should be incremented"
Ejemplo n.º 2
0
class coreDamage(unittest.TestCase):
    """ Test that core damage is calculated correctly """
    def setUp(self):
        """ Build the Pkmn and Delegates for use in the tests """
        power = 50
        isPhysical = 1
        self.delegate = DamageScaleDelegate(None, power, isPhysical, 2, 5)
        self.standardDelegate = DamageDelegate(None, power, isPhysical)

        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()

    def damageIsSameOnFirstTurn(self):
        """ Test that damage is equivalent before the scale kicks in """
        self.delegate.turnsToGo = 0
        standardDamage = self.standardDelegate.coreDamage(
            self.user, self.target)
        damage = self.delegate.coreDamage(self.user, self.target)
        assert standardDamage == damage, "Should be no difference in damage on first turn"

    def damageIsScaled(self):
        """ Test that the damage is scaled when there is a scale """
        self.delegate.turnsToGo = 2
        scale = self.delegate.getScale()

        standardDamage = self.standardDelegate.coreDamage(
            self.user, self.target)
        damage = self.delegate.coreDamage(self.user, self.target)

        assert (
            standardDamage - 2
        ) * scale + 2 == damage, "Damage should be scaled by the scale factor"
Ejemplo n.º 3
0
class coreDamage(unittest.TestCase):
    """ Test that core damage is calculated correctly """ 
    
    def setUp(self):
        """ Build the Pkmn and Delegates for use in the tests """
        power = 50
        isPhysical = 1
        self.delegate = DamageScaleDelegate(None, power, isPhysical, 2, 5)
        self.standardDelegate = DamageDelegate(None, power, isPhysical)
        
        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
        
    def damageIsSameOnFirstTurn(self):
        """ Test that damage is equivalent before the scale kicks in """
        self.delegate.turnsToGo = 0
        standardDamage = self.standardDelegate.coreDamage(self.user, self.target)
        damage = self.delegate.coreDamage(self.user, self.target)
        assert standardDamage == damage, "Should be no difference in damage on first turn"
        
    def damageIsScaled(self):
        """ Test that the damage is scaled when there is a scale """
        self.delegate.turnsToGo = 2
        scale = self.delegate.getScale()
        
        standardDamage = self.standardDelegate.coreDamage(self.user, self.target)
        damage = self.delegate.coreDamage(self.user, self.target)
        
        assert (standardDamage-2)*scale+2 == damage, "Damage should be scaled by the scale factor"
Ejemplo n.º 4
0
    def setUp(self):
        """ Build the Pkmn and Delegates for use in the tests """
        power = 50
        isPhysical = 1
        self.delegate = DamageScaleDelegate(None, power, isPhysical, 2, 5)
        self.standardDelegate = DamageDelegate(None, power, isPhysical)

        self.user = BuildPokemonBattleWrapper()
        self.target = BuildPokemonBattleWrapper()
Ejemplo n.º 5
0
 def setUp(self):
     """ Build the Pkmn and Delegates for use in the tests """
     power = 50
     isPhysical = 1
     self.delegate = DamageScaleDelegate(None, power, isPhysical, 2, 5)
     self.standardDelegate = DamageDelegate(None, power, isPhysical)
     
     self.user = BuildPokemonBattleWrapper()
     self.target = BuildPokemonBattleWrapper()
Ejemplo n.º 6
0
class getScale(unittest.TestCase):
    """ Test that getScale returns correctly """
    def setUp(self):
        """ Setup the attack and Pokemon to use the attack """
        self.factor = 2
        self.delegate = DamageScaleDelegate(None, 50, 1, self.factor, 5)

    def correctScale(self):
        """ Test that getScale returns the correct scale """
        self.delegate.turnOn = 0
        scale = self.delegate.getScale()
        assert scale == 1, "Scale should be 1 when turnsToGo is 0"

    def correctScaleAfterInc(self):
        """ Test that scale returns correctly after the turn increments """
        self.delegate.turnOn = 0
        scale = self.delegate.getScale()

        self.delegate.incTurns()
        scale2 = self.delegate.getScale()

        assert scale == scale2 / self.factor, "Scale should be half of the scale when turnsToGo is 0"
Ejemplo n.º 7
0
class getScale(unittest.TestCase):
    """ Test that getScale returns correctly """ 
    
    def setUp(self):
        """ Setup the attack and Pokemon to use the attack """
        self.factor = 2
        self.delegate = DamageScaleDelegate(None, 50, 1, self.factor, 5)
        
    def correctScale(self):
        """ Test that getScale returns the correct scale """
        self.delegate.turnOn = 0
        scale = self.delegate.getScale()
        assert scale == 1, "Scale should be 1 when turnsToGo is 0"
        
    def correctScaleAfterInc(self):
        """ Test that scale returns correctly after the turn increments """
        self.delegate.turnOn = 0
        scale = self.delegate.getScale()
        
        self.delegate.incTurns()
        scale2 = self.delegate.getScale()
        
        assert scale == scale2/self.factor, "Scale should be half of the scale when turnsToGo is 0"
Ejemplo n.º 8
0
class applyEffect(unittest.TestCase):
    """ Test that applyEffect returns correctly """
    def setUp(self):
        """ Setup the attack and Pokemon to use the attack """
        self.pkmn = BuildPokemonBattleWrapper()
        self.delegate = DamageScaleDelegate(None, 50, 1, 1, 5)

    def turnZero(self):
        """ Test that applyEffect operates correctly on turn 0 """
        self.delegate.turnOn = 0
        self.pkmn.actionLock = None
        self.delegate.applyEffect(self.pkmn, None, None)

        assert self.pkmn.actionLock is not None, "Should have an action Lock"
        assert self.delegate.turnOn == 1, "Turns should be incremented"

    def otherwise(self):
        """ Test that applyEffect does not do anything except increment turns if the turn is not zero """
        self.delegate.turnOn = 1
        self.pkmn.actionLock = None
        self.delegate.applyEffect(self.pkmn, None, None)

        assert self.pkmn.actionLock is None, "Should not have an actionLock"
        assert self.delegate.turnOn == 2, "Turns should be incremented"
Ejemplo n.º 9
0
 def setUp(self):
     """ Setup the attack and Pokemon to use the attack """
     self.pkmn = BuildPokemonBattleWrapper()
     self.delegate = DamageScaleDelegate(None, 50, 1, 1, 5)
Ejemplo n.º 10
0
 def setUp(self):
     """ Setup the attack and Pokemon to use the attack """
     self.factor = 2
     self.delegate = DamageScaleDelegate(None, 50, 1, self.factor, 5)
Ejemplo n.º 11
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.º 12
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)
Ejemplo n.º 13
0
 def setUp(self):
     """ Setup the attack and Pokemon to use the attack """
     self.pkmn = BuildPokemonBattleWrapper()
     self.delegate = DamageScaleDelegate(None, 50, 1, 1, 5)
Ejemplo n.º 14
0
 def setUp(self):
     """ Setup the attack and Pokemon to use the attack """
     self.factor = 2
     self.delegate = DamageScaleDelegate(None, 50, 1, self.factor, 5)