forked from External/mage
put comparing logic in counttype, remove all switches
This commit is contained in:
parent
0adc715499
commit
3d029d6ad5
8 changed files with 66 additions and 145 deletions
|
|
@ -29,6 +29,7 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.CountType;
|
||||
import mage.abilities.condition.Condition;
|
||||
|
|
@ -39,7 +40,7 @@ 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
|
||||
*/
|
||||
|
||||
|
|
@ -66,7 +67,7 @@ public class OpponentControlsPermanentCondition implements Condition {
|
|||
* @param type
|
||||
* @param count
|
||||
*/
|
||||
public OpponentControlsPermanentCondition ( FilterPermanent filter, CountType type, int count ) {
|
||||
public OpponentControlsPermanentCondition(FilterPermanent filter, CountType type, int count) {
|
||||
this.filter = filter;
|
||||
this.type = type;
|
||||
this.count = count;
|
||||
|
|
@ -74,30 +75,16 @@ public class OpponentControlsPermanentCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
boolean conditionApplies = false;
|
||||
for(UUID opponentId :game.getOpponents(source.getControllerId())) {
|
||||
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 (CountType.compare(game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game), type, this.count)) {
|
||||
conditionApplies = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
return conditionApplies;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue