diff --git a/Mage/src/mage/abilities/condition/common/OpponentControlsPermanentCondition.java b/Mage/src/mage/abilities/condition/common/OpponentControlsPermanentCondition.java index dfb0f89be91..efb94d0c482 100644 --- a/Mage/src/mage/abilities/condition/common/OpponentControlsPermanentCondition.java +++ b/Mage/src/mage/abilities/condition/common/OpponentControlsPermanentCondition.java @@ -28,31 +28,29 @@ package mage.abilities.condition.common; +import java.util.UUID; import mage.abilities.Ability; import mage.abilities.condition.Condition; -import mage.constants.TargetController; import mage.filter.FilterPermanent; -import mage.filter.predicate.permanent.ControllerPredicate; +import mage.filter.predicate.permanent.ControllerIdPredicate; import mage.game.Game; /** - * + * Checks if one opponent (each opponent is checked on its own) fulfills + * the defined condition of controlling the defined number of permanents. + * * @author LevelX2 */ public class OpponentControlsPermanentCondition implements Condition { public static enum CountType { MORE_THAN, FEWER_THAN, EQUAL_TO }; + private FilterPermanent filter; - private Condition condition; private CountType type; private int count; /** - * Applies a filter and delegates creation to - * {@link #ControlsPermanent(mage.filter.FilterPermanent, mage.abilities.condition.common.ControlsPermanent.CountType, int)} - * with {@link CountType#MORE_THAN}, and 0. - * * @param filter */ public OpponentControlsPermanentCondition(FilterPermanent filter) { @@ -74,46 +72,33 @@ public class OpponentControlsPermanentCondition implements Condition { this.count = count; } - /** - * Applies a filter, a {@link CountType}, and count to permanents on the - * battlefield and calls the decorated condition to see if it - * {@link #apply(mage.game.Game, mage.abilities.Ability) applies} - * as well. This will force both conditions to apply for this to be true. - * - * @param filter - * @param type - * @param count - * @param conditionToDecorate - */ - public OpponentControlsPermanentCondition ( FilterPermanent filter, CountType type, int count, Condition conditionToDecorate ) { - this(filter, type, count); - this.condition = conditionToDecorate; - } - @Override public boolean apply(Game game, Ability source) { - boolean conditionApplies = false; - - FilterPermanent localFilter = filter.copy(); - localFilter.add(new ControllerPredicate(TargetController.OPPONENT)); - - switch ( this.type ) { - case FEWER_THAN: - conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) < this.count; - break; - case MORE_THAN: - conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) > this.count; - break; - case EQUAL_TO: - conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) == this.count; - break; + boolean conditionApplies = false; + for(UUID opponentId :game.getOpponents(source.getControllerId())) { + FilterPermanent localFilter = filter.copy(); + localFilter.add(new ControllerIdPredicate(opponentId)); + switch ( this.type ) { + case FEWER_THAN: + if (game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) < this.count) { + conditionApplies = true; + break; + } + case MORE_THAN: + if (game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) > this.count) { + conditionApplies = true; + break; + } + break; + case EQUAL_TO: + if (game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) == this.count) { + conditionApplies = true; + break; + } + break; + } + } - - //If a decorated condition exists, check it as well and apply them together. - if ( this.condition != null ) { - conditionApplies = conditionApplies && this.condition.apply(game, source); - } - return conditionApplies; }