I'm implementing "On Attack" and "On Receive Damage" within my game and from these two answers(Implementing flexible buff system,Implementing attack class in RPG ) I got that I will be implementing custom handlers which will modify the attack effects. I've included an example below.
My question is - how to handle status changing special effects, such as knockdown, poison over time, petrify, etc? Do I need include them in my attack/damage class and have defender's damage handlers adjust the attack parameters, or is there a better way to handle special effects?
@interface Attack : NSObject -(id)initWithDamage:(int)damage type:(int)damageType; @property (nonatomic)int type; @property (nonatomic)int value; @property (nonatomic)int penetration; @property (nonatomic,strong)NSMutableArray* attackEffects; @end
Here's the understanding that's starting to form in my head:
- Attacker records everything about the attack in an Attack class:
- Create Attack class for each attack
- Record damage type(physical/magical) and value
- Pass Attack to the attacker's (onAttack) handlers
- Each effect within attackers list of buffs applies it's effects to attack,(ex: poison over time, knockdown)
- Pass the attack over to defender for his (onReceiveDamage) buffs to handle
- Defender's list of buffs marked "on receive damage" modifies the attack (poison immunity removes poison over time)
- Pass attack over to the defender to resolve
- Check for special conditions (ex: can't poison undead), further adjust attack effects
- Each effect that has passed the check is applied to defender
Repeat for counter attack.
What I'm concerned about: the method mutates
attack instance, meaning any time I ask a character for
attack, I actually need to get a copy of the
attack class has started as a tuple, and there's already some code around that expects that checking attack is a simple operation. If
attack gets overloaded with effects, and starts to be passed around as copy, this may have implications on my other code.