From 976a9724cd056afcd41b6cd4bbc58ceb938880ea Mon Sep 17 00:00:00 2001 From: North Date: Mon, 25 Jun 2012 01:15:36 +0300 Subject: [PATCH] Fixed ControlsBiggestOrTiedCreatureCondition. --- ...ontrolsBiggestOrTiedCreatureCondition.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Mage/src/mage/abilities/condition/common/ControlsBiggestOrTiedCreatureCondition.java b/Mage/src/mage/abilities/condition/common/ControlsBiggestOrTiedCreatureCondition.java index 2b6adc785d5..7663b4e0b10 100644 --- a/Mage/src/mage/abilities/condition/common/ControlsBiggestOrTiedCreatureCondition.java +++ b/Mage/src/mage/abilities/condition/common/ControlsBiggestOrTiedCreatureCondition.java @@ -32,6 +32,10 @@ import mage.abilities.condition.Condition; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.UUID; /** @@ -52,16 +56,24 @@ public class ControlsBiggestOrTiedCreatureCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - UUID controller = null; - int maxPower = -1; - for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) { - if (permanent != null) { - if (maxPower == -1 || permanent.getPower().getValue() >= maxPower) { - maxPower = permanent.getPower().getValue(); - controller = (permanent.getControllerId()); - } + Set controllers = new HashSet(); + Integer maxPower = null; + + List permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getId(), game); + for (Permanent permanent : permanents) { + if (permanent == null) { + continue; + } + + int power = permanent.getPower().getValue(); + if (maxPower == null || power > maxPower) { + maxPower = permanent.getPower().getValue(); + controllers.clear(); + } + if (power == maxPower) { + controllers.add(permanent.getControllerId()); } } - return controller != null && controller.equals(source.getControllerId()); + return controllers.contains(source.getControllerId()); } }