From d0787fb9fa097301c78bad365be40b3cb8553c5d Mon Sep 17 00:00:00 2001 From: Li REN Date: Sun, 14 Jul 2013 03:10:12 -0400 Subject: [PATCH] fix a bug that cause ControlsPermanentCondition effect works incorrectly. --- .../common/ControlsPermanentCondition.java | 6 ++-- Mage/src/mage/game/permanent/Battlefield.java | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/Mage/src/mage/abilities/condition/common/ControlsPermanentCondition.java b/Mage/src/mage/abilities/condition/common/ControlsPermanentCondition.java index 74d76ce6675..38a70496e47 100644 --- a/Mage/src/mage/abilities/condition/common/ControlsPermanentCondition.java +++ b/Mage/src/mage/abilities/condition/common/ControlsPermanentCondition.java @@ -97,13 +97,13 @@ public class ControlsPermanentCondition implements Condition { switch ( this.type ) { case FEWER_THAN: - conditionApplies = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) < this.count; + conditionApplies = game.getBattlefield().countControlled(filter, source.getSourceId(), source.getControllerId(), game) < this.count; break; case MORE_THAN: - conditionApplies = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > this.count; + conditionApplies = game.getBattlefield().countControlled(filter, source.getSourceId(), source.getControllerId(), game) > this.count; break; case EQUAL_TO: - conditionApplies = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == this.count; + conditionApplies = game.getBattlefield().countControlled(filter, source.getSourceId(), source.getControllerId(), game) == this.count; break; } diff --git a/Mage/src/mage/game/permanent/Battlefield.java b/Mage/src/mage/game/permanent/Battlefield.java index 2d149ab4af0..97ce8c7645b 100644 --- a/Mage/src/mage/game/permanent/Battlefield.java +++ b/Mage/src/mage/game/permanent/Battlefield.java @@ -115,6 +115,39 @@ public class Battlefield implements Serializable { } return count; } + + /** + * Returns a count of all {@link Permanent} that are within the range of influence of the specified player id + * and is controlled by specified player ,and that match the supplied filter. + * + * @param filter + * @param sourceId + * @param sourcePlayerId + * @param game + * @return count + */ + public int countControlled(FilterPermanent filter, UUID sourceId, UUID sourcePlayerId, Game game) { + int count = 0; + if (game.getRangeOfInfluence() == RangeOfInfluence.ALL) { + for (Permanent permanent: field.values()) { + if (filter.match(permanent, sourceId, sourcePlayerId, game) + && permanent.getControllerId().equals(sourcePlayerId)) { + count++; + } + } + } + else { + Set range = game.getPlayer(sourcePlayerId).getInRange(); + for (Permanent permanent: field.values()) { + if (range.contains(permanent.getControllerId()) + && filter.match(permanent, sourceId, sourcePlayerId, game) + && permanent.getControllerId().equals(sourcePlayerId)) { + count++; + } + } + } + return count; + } /** * Returns true if the battlefield contains at least 1 {@link Permanent}