Damage Prevention

Everything is set up for implementing damage prevention, but before adding cards I want to check if you are ok with the way of implementing it.
The card class and the player class each have a new integer variable preventNextDamage that is set to zero from the start. Some cards will raise the value. If the card or player get damaged this value will act as a buffer and only excessive damage will get through. At the end of turn the preventNextDamage value will be set to zero again (because all current cards say "Prevent the next X damage that would be dealt to target creature or player this turn".
Here is the code:
The card class and the player class each have a new integer variable preventNextDamage that is set to zero from the start. Some cards will raise the value. If the card or player get damaged this value will act as a buffer and only excessive damage will get through. At the end of turn the preventNextDamage value will be set to zero again (because all current cards say "Prevent the next X damage that would be dealt to target creature or player this turn".
Here is the code:
- Code: Select all
public int preventDamage(final int damage, Card source, boolean isCombat) {
int restDamage = damage;
if( preventAllDamageToCard(source, isCombat)) {
restDamage = 0;
}
if(restDamage >= preventNextDamage) {
restDamage = restDamage - preventNextDamage;
preventNextDamage = 0;
}
else {
restDamage = 0;
preventNextDamage = preventNextDamage - restDamage;
}
return restDamage;
}