예제 #1
0
    def __init__(self):
        self.hitDelegate = None
        self.damageDelegate = None
        self.speedDelegate = None

        self.effectDelegates = []
        self.makes_contact = False
        self.powerPoints = 0
        self.currPowerPoints = 0

        self.preconditionsStep = PreconditionStep(self)
        self.announcementStep = AnnouncementStep(self)
        self.removePPStep = RemovePPStep(self)
        self.hitStep = HitStep(self)
        self.damageStep = DamageStep(self)
        self.effectsStep = EffectsStep(self)
        self.handleContactStep = HandleContactStep(self)
        self.handleMissEffectsStep = HandleMissEffectsStep(self)
 def  setUp(self):
     """ Build the Step for the test """
     self.attack = Attack()
     self.effects = [self, self]
     self.attack.effectDelegates = self.effects
     
     self.step = HandleMissEffectsStep(self.attack)
     
     self.calledApplyEffect = 0
     self.messages = ["My Test Message"]
class perform(unittest.TestCase):
    """ Test cases of perform """
    
    def  setUp(self):
        """ Build the Step for the test """
        self.attack = Attack()
        self.effects = [self, self]
        self.attack.effectDelegates = self.effects
        
        self.step = HandleMissEffectsStep(self.attack)
        
        self.calledApplyEffect = 0
        self.messages = ["My Test Message"]
        
    def applyOnMissFlag(self):
        """ Test that when an effect has the applyOnMiss Flag the effect is used """
        self.applyOnMiss = True
        messages = self.step.perform(None, None, None)
        
        numberOfEffects = len(self.effects)
        self.assertEquals(numberOfEffects, self.calledApplyEffect, "Should have called apply effect for each effect")
        self.assertEquals(self.messages*numberOfEffects, messages, "Should receive the messages from each effect")
        
    def effectOnMissFunction(self):
        """ Test that when an effect has the efffectOnMiss Flag the effect is used """
        self.effectOnMiss = self.applyEffect
        messages = self.step.perform(None, None, None)
        
        numberOfEffects = len(self.effects)
        self.assertEquals(numberOfEffects, self.calledApplyEffect, "Should have called apply effect for each effect")
        self.assertEquals(self.messages*numberOfEffects, messages, "Should receive the messages from each effect")
        
    def otherwise(self):
        """ Test that when an effect has neither Flag nothing happens """
        messages = self.step.perform(None, None, None)
        
        self.assertEquals(0, self.calledApplyEffect, "Should not have called apply effect")
        self.assertEquals([], messages, "Should receive no messages when the effects are prevented")
        
    def applyEffect(self, user, target, environment):
        self.calledApplyEffect += 1
        return self.messages
예제 #4
0
class Attack:
    """ Represents an Attack """
    def __init__(self):
        self.hitDelegate = None
        self.damageDelegate = None
        self.speedDelegate = None

        self.effectDelegates = []
        self.makes_contact = False
        self.powerPoints = 0
        self.currPowerPoints = 0

        self.preconditionsStep = PreconditionStep(self)
        self.announcementStep = AnnouncementStep(self)
        self.removePPStep = RemovePPStep(self)
        self.hitStep = HitStep(self)
        self.damageStep = DamageStep(self)
        self.effectsStep = EffectsStep(self)
        self.handleContactStep = HandleContactStep(self)
        self.handleMissEffectsStep = HandleMissEffectsStep(self)

    def use(self, user, target, environment):
        """ Uses the current attack Object in a Battle """
        messages = []
        messages += self.preconditionsStep.perform(user, target, environment)
        if self.preconditionsStep.passed:
            messages += self.announcementStep.perform(user, target,
                                                      environment)
            messages += self.removePPStep.perform(user, target, environment)
            messages += self.hitStep.perform(user, target, environment)
            if self.hitStep.hit:
                messages += self.damageStep.perform(user, target, environment)
                messages += self.effectsStep.perform(user, target, environment)
                messages += self.handleContactStep.perform(
                    user, target, environment)
            else:
                messages += self.handleMissEffectsStep.perform(
                    user, target, environment)

        return messages

    # Helper Methods
    def addDelegate(self, delegateCategory, delegate):
        """ Adds a delegate to an Attack Object """
        if delegateCategory == Tags.effectDelegateTag:
            self.effectDelegates.append(delegate)
            return
        setattr(self, delegateCategory, delegate)

    def isStatus(self):
        """ Returns if the Attack is a status attack """
        return isinstance(self.damageDelegate, NullDamageDelegate)
예제 #5
0
class Attack:
    """ Represents an Attack """
    
    def __init__(self):
        self.hitDelegate = None
        self.damageDelegate = None
        self.speedDelegate = None
        
        self.effectDelegates = []
        self.makes_contact = False
        self.powerPoints = 0
        self.currPowerPoints = 0
        
        self.preconditionsStep = PreconditionStep(self)
        self.announcementStep = AnnouncementStep(self)
        self.removePPStep = RemovePPStep(self)
        self.hitStep = HitStep(self)
        self.damageStep = DamageStep(self)
        self.effectsStep = EffectsStep(self)
        self.handleContactStep = HandleContactStep(self)
        self.handleMissEffectsStep = HandleMissEffectsStep(self)
        
    def use(self, user, target, environment):
        """ Uses the current attack Object in a Battle """
        messages = []
        messages += self.preconditionsStep.perform(user, target, environment)
        if self.preconditionsStep.passed:
            messages += self.announcementStep.perform(user, target, environment)
            messages += self.removePPStep.perform(user, target, environment)
            messages += self.hitStep.perform(user, target, environment)
            if self.hitStep.hit:
                messages += self.damageStep.perform(user, target, environment)
                messages += self.effectsStep.perform(user, target, environment)
                messages += self.handleContactStep.perform(user, target, environment)
            else:
                messages += self.handleMissEffectsStep.perform(user, target, environment)
        
        return messages
        
    # Helper Methods
    def addDelegate(self, delegateCategory, delegate):
        """ Adds a delegate to an Attack Object """
        if delegateCategory == Tags.effectDelegateTag:
            self.effectDelegates.append(delegate)
            return
        setattr(self, delegateCategory, delegate)
        
    def isStatus(self):
        """ Returns if the Attack is a status attack """
        return isinstance(self.damageDelegate, NullDamageDelegate)
예제 #6
0
 def __init__(self):
     self.hitDelegate = None
     self.damageDelegate = None
     self.speedDelegate = None
     
     self.effectDelegates = []
     self.makes_contact = False
     self.powerPoints = 0
     self.currPowerPoints = 0
     
     self.preconditionsStep = PreconditionStep(self)
     self.announcementStep = AnnouncementStep(self)
     self.removePPStep = RemovePPStep(self)
     self.hitStep = HitStep(self)
     self.damageStep = DamageStep(self)
     self.effectsStep = EffectsStep(self)
     self.handleContactStep = HandleContactStep(self)
     self.handleMissEffectsStep = HandleMissEffectsStep(self)