[CLB] Fixed CommanderInPlayCondition, now only triggers for OWN commander. Closes #9125.

This commit is contained in:
Alex Vasile 2022-06-25 11:17:06 -04:00
parent 8cdfd1ee4a
commit 62a8983b48
3 changed files with 42 additions and 2 deletions

View file

@ -15,7 +15,7 @@ public enum CommanderInPlayCondition implements Condition {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
return ControlACommanderCondition.instance.apply(game, source); return ControlYourCommanderCondition.instance.apply(game, source);
} }
@Override @Override

View file

@ -10,6 +10,8 @@ import java.util.Collection;
import java.util.Objects; import java.util.Objects;
/** /**
* Checks if a player control ANY (not just their own) commander.
*
* @author TheElk801 * @author TheElk801
*/ */
public enum ControlACommanderCondition implements Condition { public enum ControlACommanderCondition implements Condition {
@ -31,6 +33,6 @@ public enum ControlACommanderCondition implements Condition {
@Override @Override
public String toString() { public String toString() {
return "If you control a commander"; return "If a control a commander";
} }
} }

View file

@ -0,0 +1,38 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.constants.CommanderCardType;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.Collection;
import java.util.Objects;
/**
* Checks if a player controls their commander.
*
* @author Alex-Vasile
*/
public enum ControlYourCommanderCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
return game.getPlayerList()
.stream()
.map(game::getPlayer)
.filter(Objects::nonNull)
.map(player -> game.getCommandersIds(player, CommanderCardType.COMMANDER_OR_OATHBREAKER, true)) // must search all card parts (example: mdf commander on battlefield)
.flatMap(Collection::stream)
.map(game::getPermanent)
.filter(Objects::nonNull)
.map(Permanent::getOwnerId)
.anyMatch(source.getControllerId()::equals);
}
@Override
public String toString() {
return "If you control your commander";
}
}