From 28148c21dbdeae751e3cbc426aa767cc26dd7a6b Mon Sep 17 00:00:00 2001 From: jendave Date: Sat, 6 Aug 2011 09:10:09 +0000 Subject: [PATCH] - Centralized all "Protection from" checks to the hasProtectionFrom function. --- src/forge/CardFactoryUtil.java | 17 +++++++++++++++-- src/forge/CombatUtil.java | 5 ++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/forge/CardFactoryUtil.java b/src/forge/CardFactoryUtil.java index 25d48d54606..462dd855881 100644 --- a/src/forge/CardFactoryUtil.java +++ b/src/forge/CardFactoryUtil.java @@ -3345,6 +3345,8 @@ public class CardFactoryUtil { if (target.getName().equals("Gaea's Revenge") && !spell.isGreen()) return false; + if(hasProtectionFrom(spell,target)) return false; + if(target.getKeyword() != null) { ArrayList list = target.getKeyword(); @@ -3361,6 +3363,7 @@ public class CardFactoryUtil { if(spell.isAura()) return false; } + /* taken care of by hasProtectionFrom if(kw.equals("Protection from white") && spell.isWhite()) return false; if(kw.equals("Protection from blue") && spell.isBlue()) return false; if(kw.equals("Protection from black") && spell.isBlack()) return false; @@ -3386,6 +3389,7 @@ public class CardFactoryUtil { if(kw.equals("Protection from colored spells") && (spell.isInstant() || spell.isSorcery() || spell.isAura() ) && isColored(spell)) return false; + */ } } return true; @@ -3422,8 +3426,14 @@ public class CardFactoryUtil { if(kw.equals("Protection from artifacts") && card.isArtifact() && !card.getName().contains("Artifact Ward")) return true; + if(kw.equals("Protection from enchantments") && card.getType().contains("Enchantment") && + !card.getName().contains("Tattoo Ward")) return true; + if(kw.equals("Protection from everything")) return true; + if(kw.equals("Protection from colored spells") && (card.isInstant() || card.isSorcery() || card.isAura() ) && + isColored(card)) return true; + if(kw.equals("Protection from Dragons") && (card.getType().contains("Dragon") || card.getKeyword().contains("Changeling"))) return true; if(kw.equals("Protection from Demons") @@ -3433,8 +3443,6 @@ public class CardFactoryUtil { if(kw.equals("Protection from Clerics") && (card.getType().contains("Cleric") || card.getKeyword().contains("Changeling"))) return false; - if(kw.equals("Protection from enchantments") && card.getType().contains("Enchantment") && - !card.getName().contains("Tattoo Ward")) return true; } } return false; @@ -3445,12 +3453,16 @@ public class CardFactoryUtil { //and also combat damage? ArrayList list = receiver.getKeyword(); + if(hasProtectionFrom(spell,receiver)) return false; + String kw = ""; for(int i = 0; i < list.size(); i++) { kw = list.get(i); if(kw.equals("Prevent all damage that would be dealt to CARDNAME by artifact creatures.") && spell.isCreature() && spell.isArtifact()) return false; + + /* taken care of by hasProtectionFrom if(kw.equals("Protection from white") && spell.isWhite()) return false; if(kw.equals("Protection from blue") && spell.isBlue()) return false; if(kw.equals("Protection from black") && spell.isBlack()) return false; @@ -3475,6 +3487,7 @@ public class CardFactoryUtil { if(kw.equals("Protection from everything")) return false; if(kw.equals("Protection from colored spells") && !spell.isPermanent() && isColored(spell) ) return false; + */ } return true; diff --git a/src/forge/CombatUtil.java b/src/forge/CombatUtil.java index 03e3756591b..6f80b58a136 100644 --- a/src/forge/CombatUtil.java +++ b/src/forge/CombatUtil.java @@ -17,7 +17,7 @@ public class CombatUtil { if(attacker == null || blocker == null) return false; - if(!canBlockProtection(attacker, blocker)) return false; + if(CardFactoryUtil.hasProtectionFrom(attacker,blocker)) return false; //rare case: if(blocker.getKeyword().contains("Shadow") @@ -838,6 +838,7 @@ public class CombatUtil { }//canDamage } + /*no longer needed private static boolean canBlockProtection(Card attacker, Card blocker) { ArrayList list = attacker.getKeyword(); @@ -845,6 +846,7 @@ public class CombatUtil { for(int i = 0; i < list.size(); i++) { kw = list.get(i); + if(kw.equals("Protection from creatures") || kw.equals("Protection from everything")) return false; if(kw.equals("Protection from artifacts") && blocker.isArtifact()) return false; @@ -864,6 +866,7 @@ public class CombatUtil { } return true; } + */ public static boolean isDoranInPlay() { CardList all = new CardList();