mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
* fixed ControlsPermanentCondition
This commit is contained in:
parent
1bff2da1eb
commit
7db8f5e37e
2 changed files with 7 additions and 36 deletions
|
@ -30,6 +30,7 @@ package mage.abilities.condition.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
|
@ -95,15 +96,18 @@ public class ControlsPermanentCondition implements Condition {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
boolean conditionApplies = false;
|
||||
|
||||
FilterPermanent localFilter = filter.copy();
|
||||
localFilter.add(new ControllerIdPredicate(source.getControllerId()));
|
||||
|
||||
switch ( this.type ) {
|
||||
case FEWER_THAN:
|
||||
conditionApplies = game.getBattlefield().countControlled(filter, source.getSourceId(), source.getControllerId(), game) < this.count;
|
||||
conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) < this.count;
|
||||
break;
|
||||
case MORE_THAN:
|
||||
conditionApplies = game.getBattlefield().countControlled(filter, source.getSourceId(), source.getControllerId(), game) > this.count;
|
||||
conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) > this.count;
|
||||
break;
|
||||
case EQUAL_TO:
|
||||
conditionApplies = game.getBattlefield().countControlled(filter, source.getSourceId(), source.getControllerId(), game) == this.count;
|
||||
conditionApplies = game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game) == this.count;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -115,39 +115,6 @@ 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<UUID> 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}
|
||||
|
|
Loading…
Reference in a new issue