Whenever you're ready, walk me through how you'd approach this.
Rockstar Games keeps a gameplay-side damage system that every weapon and enemy type routes through. The Entity class below is the version currently checked in, and it has picked up rough edges as more weapon types were bolted on over time.
class Entity {
public:
Entity(int hp) { health = hp; }
void ApplyDamage(int amount, int type) {
if (type == 0) {
health = health - amount;
}
if (type == 1) {
health = health - (amount * 2);
}
if (type == 2) {
health = health - amount + armor;
}
lastDamage = amount;
}
int GetHealth() { return health; }
int health;
int armor = 10;
int lastDamage;
};
Refactor this class so the damage logic is clear and correct, and explain in your own words what each existing branch of ApplyDamage was actually doing before your changes, including anything that looks like a bug.