fix a bug that cause ControlsPermanentCondition effect works incorrectly.

This commit is contained in:
Li REN 2013-07-14 03:10:12 -04:00
parent 670864d78b
commit d0787fb9fa
2 changed files with 36 additions and 3 deletions

View file

@ -97,13 +97,13 @@ public class ControlsPermanentCondition implements Condition {
switch ( this.type ) { switch ( this.type ) {
case FEWER_THAN: 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; break;
case MORE_THAN: 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; break;
case EQUAL_TO: 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; break;
} }

View file

@ -116,6 +116,39 @@ public class Battlefield implements Serializable {
return count; 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} * Returns true if the battlefield contains at least 1 {@link Permanent}
* that matches the filter. * that matches the filter.