From f02bb10ab01f444a64bbf7568a7d43c188863e04 Mon Sep 17 00:00:00 2001 From: Sloth Date: Sun, 25 Sep 2011 18:24:42 +0000 Subject: [PATCH] - Added support for "Amount" and "Source" parameters to the PreventDamage static ability. - Converted Daunting Defender, Energy Field and Energy Storm. --- res/cardsfolder/d/daunting_defender.txt | 2 +- res/cardsfolder/e/energy_field.txt | 2 +- res/cardsfolder/e/energy_storm.txt | 3 +- src/main/java/forge/GameEntity.java | 40 +++++-------------- .../StaticAbility_PreventDamage.java | 15 ++++++- 5 files changed, 27 insertions(+), 35 deletions(-) diff --git a/res/cardsfolder/d/daunting_defender.txt b/res/cardsfolder/d/daunting_defender.txt index 7b5447ec8fd..4f050dc8e0c 100644 --- a/res/cardsfolder/d/daunting_defender.txt +++ b/res/cardsfolder/d/daunting_defender.txt @@ -2,7 +2,7 @@ Name:Daunting Defender ManaCost:4 W Types:Creature Human Cleric Text:no text -K:stPreventDamage:Creature.Cleric+YouCtrl:Card:1:If a source would deal damage to a Cleric creature you control, prevent 1 of that damage. +S:Mode$ PreventDamage | Target$ Creature.Cleric+YouCtrl | Amount$ 1 | Description$ If a source would deal damage to a Cleric creature you control, prevent 1 of that damage. PT:3/3 SVar:Rarity:Common SVar:Picture:http://www.wizards.com/global/images/magic/general/daunting_defender.jpg diff --git a/res/cardsfolder/e/energy_field.txt b/res/cardsfolder/e/energy_field.txt index 52fc4f3b98e..c40a174f6b8 100644 --- a/res/cardsfolder/e/energy_field.txt +++ b/res/cardsfolder/e/energy_field.txt @@ -4,7 +4,7 @@ Types:Enchantment Text:no text T:Mode$ ChangesZone | Origin$ Any | Destination$ Graveyard | ValidCard$ Card.YouOwn | Execute$ TrigSac | TriggerZones$ Battlefield | TriggerDescription$ When a card is put into your graveyard from anywhere, sacrifice CARDNAME. SVar:TrigSac:AB$ Sacrifice | Cost$ 0 | Defined$ Self -K:stPreventDamage:You:Card.YouDontCtrl:All:Prevent all damage that would be dealt to you by sources you don't control. +S:Mode$ PreventDamage | Target$ You | Source$ Card.YouDontCtrl | Description$ Prevent all damage that would be dealt to you by sources you don't control. SVar:RemAIDeck:True SVar:Rarity:Rare SVar:Picture:http://www.wizards.com/global/images/magic/general/energy_field.jpg diff --git a/res/cardsfolder/e/energy_storm.txt b/res/cardsfolder/e/energy_storm.txt index 3260d7ed1ca..32d7bd1acc4 100644 --- a/res/cardsfolder/e/energy_storm.txt +++ b/res/cardsfolder/e/energy_storm.txt @@ -4,8 +4,7 @@ Types:Enchantment Text:no text K:Cumulative upkeep:1 K:Permanents don't untap during their controllers' untap steps:Creature.withFlying -K:stPreventDamage:Player:Instant,Sorcery:All:Prevent all damage that would be dealt by instant and sorcery spells. Creatures with flying don't untap during their controller's untap step. -K:stPreventDamage:Permanent:Spell:1:no text +S:Mode$ PreventDamage | Source$ Instant,Sorcery | Description$ Prevent all damage that would be dealt by instant and sorcery spells. Creatures with flying don't untap during their controller's untap step. SVar:RemRandomDeck:True SVar:Rarity:Rare SVar:Picture:http://www.wizards.com/global/images/magic/general/energy_storm.jpg diff --git a/src/main/java/forge/GameEntity.java b/src/main/java/forge/GameEntity.java index 6ba44c3d85c..a0a5918afb3 100644 --- a/src/main/java/forge/GameEntity.java +++ b/src/main/java/forge/GameEntity.java @@ -215,39 +215,21 @@ public abstract class GameEntity extends MyObservable { return false; } - public boolean isValid(final String Restriction, final Player sourceController, final Card source) { - - String incR[] = Restriction.split("\\."); - - if (!incR[0].equals("Player") && - !(incR[0].equals("Opponent") && !this.equals(sourceController)) && - !(incR[0].equals("You") && this.equals(sourceController))) - return false; - - if (incR.length > 1) { - final String excR = incR[1]; - String exR[] = excR.split("\\+"); // Exclusive Restrictions are ... - for (int j = 0; j < exR.length; j++) - if (hasProperty(exR[j], sourceController, source) == false) return false; + public boolean isValid(final String Restrictions[], final Player sourceController, final Card source) { + + for (int i = 0; i < Restrictions.length; i++) { + if (isValid(Restrictions[i], sourceController, source)) return true; } - - return true; + return false; + + }//isValidCard + + public boolean isValid(final String Restriction, final Player sourceController, final Card source) { + return false; } public boolean hasProperty(String Property, final Player sourceController, final Card source) { - - if (Property.equals("You")) { - if (!this.equals(sourceController)) { - return false; - } - } - else if (Property.equals("Opponent")) { - if (this.equals(sourceController)) { - return false; - } - } - - return true; + return false; } // GameEntities can now be Enchanted diff --git a/src/main/java/forge/card/staticAbility/StaticAbility_PreventDamage.java b/src/main/java/forge/card/staticAbility/StaticAbility_PreventDamage.java index 49edd5907a2..fa1c4d62344 100644 --- a/src/main/java/forge/card/staticAbility/StaticAbility_PreventDamage.java +++ b/src/main/java/forge/card/staticAbility/StaticAbility_PreventDamage.java @@ -4,6 +4,7 @@ import java.util.HashMap; import forge.Card; import forge.GameEntity; +import forge.card.cardFactory.CardFactoryUtil; public class StaticAbility_PreventDamage { @@ -17,11 +18,11 @@ public class StaticAbility_PreventDamage { Card hostCard = stAb.getHostCard(); int restDamage = damage; - if(params.containsKey("Source") && !source.isValid(params.get("Source"), hostCard.getController(), hostCard)) { + if(params.containsKey("Source") && !source.isValid(params.get("Source").split(","), hostCard.getController(), hostCard)) { return restDamage; } - if(params.containsKey("Target") && !target.isValid(params.get("Target"), hostCard.getController(), hostCard)) { + if(params.containsKey("Target") && !target.isValid(params.get("Target").split(","), hostCard.getController(), hostCard)) { return restDamage; } @@ -29,6 +30,16 @@ public class StaticAbility_PreventDamage { return 0; } + if(params.get("Amount").matches("[0-9][0-9]?")) { + restDamage = restDamage - Integer.parseInt(params.get("Amount")); + } else { + restDamage = restDamage - CardFactoryUtil.xCount(hostCard, hostCard.getSVar(params.get("Amount"))); + } + + if (restDamage < 0) { + return 0; + } + return restDamage; }