I’m afraid I can’t give you a silver bullet to solve all of your problems, and I doubt one exists.
If I read between the lines, I get the impression you don’t have a concrete idea yet on what your game’s combat system is going to be. Am I right in this assumption? You’re thinking a lot about things that might potentially happen during combat, and what all possible edge cases are. This is good, but you should take it one step further and make a list of your combat system’s requirements. It’s a lot easier to write code if you know what the final product should look like in advance, what features it has, and what features it does without.
Are you familiar with software patterns? I can’t (and shouldn’t) tell you what to do, but the ‘strategy’ pattern seems useful here. You could make, for instance, a base class called attackStrategyBase
with one (empty) method that takes an enemy as a parameter:
class AttackBaseStrategy
{
public:
AttackBaseStrategy()=default;
~AttackBaseStrategy()=default;
virtual void applyToEnemy(Enemy enemy) = 0;
};
And then make a whole bunch of classes that extend that base class with everything you could possibly want:
// Header
class SetOnFireStrategy : public AttackBaseStrategy
{
public:
SetOnFireStrategy()=default;
~SetOnFireStrategy()=default;
virtual void applyToEnemy(Enemy enemy) override;
};
// Source
void SetOnFireStrategy::applyToEnemy(Enemy enemy)
{
enemy.addEffect(Effects::Burning);
}
// Header
class DoDamageStrategy : public AttackBaseStrategy
{
public:
DoDamageStrategy()=default;
~DoDamageStrategy()=default;
virtual void applyToEnemy(Enemy enemy) override;
};
// Source
void DoDamageStrategy::applyToEnemy(Enemy enemy)
{
enemy.doDamage(150);
}
// Header
class StealItemStrategy : public AttackBaseStrategy
{
public:
StealItemStrategy()=default;
~StealItemStrategy()=default;
virtual void applyToEnemy(Enemy enemy) override;
};
// Source
void StealItemStrategy::applyToEnemy(Enemy enemy)
{
if (enemy.hasItem())
{
player.addItem(enemy.items.first());
}
}
You can then mix and match these strategy classes as you please. For example, the three classes above could be used to create a single attack that deals 150 damage to an opponent, sets them on fire, and steals the first item in their inventory if they have any.