From 39404820ded4b8842a483993fe00800204b849c4 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Mon, 17 Oct 2011 09:08:22 -0400 Subject: [PATCH] fixed AI targeting cards with Hexproof --- Mage/src/mage/game/permanent/Permanent.java | 2 +- Mage/src/mage/game/permanent/PermanentImpl.java | 6 ++++-- Mage/src/mage/target/TargetPermanent.java | 8 ++++---- Mage/src/mage/target/common/TargetCreatureOrPlayer.java | 6 +++--- .../mage/target/common/TargetCreatureOrPlayerAmount.java | 6 +++--- Mage/src/mage/target/common/TargetDefender.java | 6 +++--- Mage/src/mage/target/common/TargetPermanentOrPlayer.java | 6 +++--- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index 632f1ec50e..a8aed74ba1 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -74,7 +74,7 @@ public interface Permanent extends Card { public UUID getControllerId(); public boolean changeControllerId(UUID controllerId, Game game); - public boolean canBeTargetedBy(MageObject source); + public boolean canBeTargetedBy(MageObject source, UUID controllerId, Game game); public boolean hasProtectionFrom(MageObject source); public boolean hasSummoningSickness(); public int getDamage(); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index bf532c503e..56b52a19f6 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -647,11 +647,13 @@ public abstract class PermanentImpl> extends CardImpl } @Override - public boolean canBeTargetedBy(MageObject source) { + public boolean canBeTargetedBy(MageObject source, UUID sourceControllerId, Game game) { if (source != null) { if (abilities.containsKey(ShroudAbility.getInstance().getId())) return false; - + if (abilities.containsKey(HexproofAbility.getInstance().getId())) + if (game.getOpponents(controllerId).contains(sourceControllerId)) + return false; if (hasProtectionFrom(source)) return false; } diff --git a/Mage/src/mage/target/TargetPermanent.java b/Mage/src/mage/target/TargetPermanent.java index 0524016547..c98f0a89ca 100644 --- a/Mage/src/mage/target/TargetPermanent.java +++ b/Mage/src/mage/target/TargetPermanent.java @@ -85,8 +85,8 @@ public class TargetPermanent> extends TargetObject< //2. We need to check both source.getId() and source.getSourceId() // first for protection from spells or abilities (e.g. protection from colored spells, r1753) // second for protection from sources (e.g. protection from artifacts + equip ability) - return permanent.canBeTargetedBy(game.getObject(source.getId())) - && permanent.canBeTargetedBy(game.getObject(source.getSourceId())) + return permanent.canBeTargetedBy(game.getObject(source.getId()), controllerId, game) + && permanent.canBeTargetedBy(game.getObject(source.getSourceId()), controllerId, game) && filter.match(permanent, source.getSourceId(), controllerId, game); else return filter.match(permanent, null, controllerId, game); @@ -124,7 +124,7 @@ public class TargetPermanent> extends TargetObject< int count = 0; MageObject targetSource = game.getObject(sourceId); for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { - if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource)) { + if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { count++; if (count >= remainingTargets) return true; @@ -164,7 +164,7 @@ public class TargetPermanent> extends TargetObject< Set possibleTargets = new HashSet(); MageObject targetSource = game.getObject(sourceId); for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { - if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource)) { + if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { possibleTargets.add(permanent.getId()); } } diff --git a/Mage/src/mage/target/common/TargetCreatureOrPlayer.java b/Mage/src/mage/target/common/TargetCreatureOrPlayer.java index d04bcf4f57..063acb324a 100644 --- a/Mage/src/mage/target/common/TargetCreatureOrPlayer.java +++ b/Mage/src/mage/target/common/TargetCreatureOrPlayer.java @@ -99,7 +99,7 @@ public class TargetCreatureOrPlayer extends TargetImpl { if (permanent != null) { if (source != null) //TODO: check for replacement effects - return permanent.canBeTargetedBy(game.getObject(source.getSourceId())) && filter.match(permanent, source.getSourceId(), controllerId, game); + return permanent.canBeTargetedBy(game.getObject(source.getSourceId()), controllerId, game) && filter.match(permanent, source.getSourceId(), controllerId, game); else return filter.match(permanent, source.getSourceId(), controllerId, game); } @@ -134,7 +134,7 @@ public class TargetCreatureOrPlayer extends TargetImpl { } } for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) { - if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { count++; if (count >= this.minNumberOfTargets) return true; @@ -183,7 +183,7 @@ public class TargetCreatureOrPlayer extends TargetImpl { } } for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) { - if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { possibleTargets.add(permanent.getId()); } } diff --git a/Mage/src/mage/target/common/TargetCreatureOrPlayerAmount.java b/Mage/src/mage/target/common/TargetCreatureOrPlayerAmount.java index 18ce9c6404..56e83be7ac 100644 --- a/Mage/src/mage/target/common/TargetCreatureOrPlayerAmount.java +++ b/Mage/src/mage/target/common/TargetCreatureOrPlayerAmount.java @@ -85,7 +85,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount= this.minNumberOfTargets) return true; @@ -152,7 +152,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount { } } for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterPlaneswalkerPermanent(), sourceControllerId, game)) { - if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent)) { count++; if (count >= this.minNumberOfTargets) return true; @@ -133,7 +133,7 @@ public class TargetDefender extends TargetImpl { } } for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterPlaneswalkerPermanent(), sourceControllerId, game)) { - if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent)) { possibleTargets.add(permanent.getId()); } } @@ -195,7 +195,7 @@ public class TargetDefender extends TargetImpl { } Permanent permanent = game.getPermanent(id); if (permanent != null) { - return permanent.canBeTargetedBy(targetSource) && filter.match(permanent); + return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent); } return false; } diff --git a/Mage/src/mage/target/common/TargetPermanentOrPlayer.java b/Mage/src/mage/target/common/TargetPermanentOrPlayer.java index ace188bacd..59721baf05 100644 --- a/Mage/src/mage/target/common/TargetPermanentOrPlayer.java +++ b/Mage/src/mage/target/common/TargetPermanentOrPlayer.java @@ -109,7 +109,7 @@ public class TargetPermanentOrPlayer extends TargetImpl MageObject targetSource = game.getObject(source.getSourceId()); if (permanent != null) { if (source != null) - return permanent.canBeTargetedBy(targetSource) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game); + return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game); else return filter.match(permanent); } @@ -144,7 +144,7 @@ public class TargetPermanentOrPlayer extends TargetImpl } } for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) { - if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { count++; if (count >= this.minNumberOfTargets) return true; @@ -193,7 +193,7 @@ public class TargetPermanentOrPlayer extends TargetImpl } } for (Permanent permanent: game.getBattlefield().getActivePermanents(FilterCreaturePermanent.getDefault(), sourceControllerId, game)) { - if (permanent.canBeTargetedBy(targetSource) && filter.match(permanent, sourceId, sourceControllerId, game)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { possibleTargets.add(permanent.getId()); } }