mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
[CLB] Fixed CommanderInPlayCondition, now only triggers for OWN commander. Closes #9125.
This commit is contained in:
parent
8cdfd1ee4a
commit
62a8983b48
3 changed files with 42 additions and 2 deletions
|
@ -15,7 +15,7 @@ public enum CommanderInPlayCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return ControlACommanderCondition.instance.apply(game, source);
|
||||
return ControlYourCommanderCondition.instance.apply(game, source);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,8 @@ import java.util.Collection;
|
|||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Checks if a player control ANY (not just their own) commander.
|
||||
*
|
||||
* @author TheElk801
|
||||
*/
|
||||
public enum ControlACommanderCondition implements Condition {
|
||||
|
@ -31,6 +33,6 @@ public enum ControlACommanderCondition implements Condition {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "If you control a commander";
|
||||
return "If a control a commander";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue