Page 1 of 1

Damage Prevention

PostPosted: 19 Nov 2010, 20:10
by Sloth
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:
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;
    }

Re: Damage Prevention

PostPosted: 19 Nov 2010, 20:59
by friarsol
This would work for all basic damage prevention, which considering the sore lack of Prevention, will be handy.

Here's some brainstorming for a future version of damage prevention:

Code: Select all
Class Prevention
{
Card source;  // Source of what is doing the preventing
String ValidDamage; // If things can only prevent a certain "type" of damage(Burrenton Forge-Tender)
int preventMax;  // Maximum Damage it can prevent in a turn
int preventLeft;  // Prevent buffer still left
boolean preventAll; // If the ability will prevent ALL damage from a source.
boolean yourChoice; // Not required to use prevention ability (Auriok Replica, Circle of Protections)
boolean clearOnFullUse; // After preventAll is used or preventLeft == 0, does this get cleared? (Callous Giant)
boolean clearEndOfTurn;  // Does this effect get removed end of turn? If not, reset (Urza's Armor) so things like this don't need to be hardcoded
Command preventCmd; // Does something happen when damage is prevented? Build an Ability and put it on the stack. (Reverse Damage and many others)
}
And just kept a list of Prevention objects in Card/Player.

Whenever something tries to Prevent Damage on the Human or HumanControlled card, it could provide the list to the Player to see which order to do prevention. After all the prevention is handled, any remaining damage is dealt

At end of turn, delete anything the list that has untilEndOfTurn set to true. Anything left will be reset to preventMax.

Re: Damage Prevention

PostPosted: 19 Nov 2010, 21:15
by Sloth
Ups, I just hardcoded some of the cards (those with static abilities affecting players). But static abilities affecting creatures should be keyworded in a uniform way (I think we have about 5 keywords with prevention at the moment).

For cards with activated abilities, I think about coding them with a new AF. I'm not sure if I'm able to catch all abilities, though (I will start with the simple ones like Femeref Healer)

Re: Damage Prevention

PostPosted: 20 Nov 2010, 09:04
by Sloth
I continued with the static abilities and added the keyword:

PreventAllDamageBy [Valid Card restriction]

All damage dealt to cards with this keywords from cards specified will be prevented.

Example:
Code: Select all
Name:Enchanted Being
ManaCost:1 W W
Types:Creature Human
Text:Prevent all combat damage that would be dealt to Enchanted Being by enchanted creatures.
PT:2/2
K:PreventAllDamageBy Creature.enchanted
SVar:Rarity:Common
SVar:Picture:http://www.wizards.com/global/images/magic/general/enchanted_being.jpg
End