mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
Implementing The Prismatic Piper (Ready for review) (#8164)
* [CMR] Implemented The Prismatic Piper * updated commander validation to handle The Prismatic Piper * created abstract base class for commander variants * added ability to prismatic piper * added game init handling * small revert * small reorganization of tests * added some validation tests for piper * added more tests for piper * add another test * added decklist comments to tests * added some more piper tests * added another test * added mana option tests * added a companion test * fix conflict * updated abstract commander to work with Friends forever * merge fix * Deck: added details for illegal validation of companion card; Co-authored-by: Oleg Agafonov <jaydi85@gmail.com>
This commit is contained in:
parent
966cb7ccb7
commit
02017b9a88
33 changed files with 1753 additions and 1272 deletions
|
|
@ -0,0 +1,33 @@
|
|||
package mage.abilities.common;
|
||||
|
||||
import mage.abilities.StaticAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class CommanderChooseColorAbility extends StaticAbility {
|
||||
|
||||
public CommanderChooseColorAbility() {
|
||||
super(Zone.ALL, null);
|
||||
}
|
||||
|
||||
private CommanderChooseColorAbility(final CommanderChooseColorAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommanderChooseColorAbility copy() {
|
||||
return new CommanderChooseColorAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "If {this} is your commander, choose a color before the game begins. {this} is the chosen color.";
|
||||
}
|
||||
|
||||
public static boolean checkCard(Card card) {
|
||||
return card.getAbilities().stream().anyMatch(CommanderChooseColorAbility.class::isInstance);
|
||||
}
|
||||
}
|
||||
|
|
@ -41,8 +41,12 @@ public class CompanionAbility extends SpecialAction {
|
|||
return "Companion — " + companionCondition.getRule();
|
||||
}
|
||||
|
||||
public boolean isLegal(Set<Card> cards, int startingHandSize) {
|
||||
final public boolean isLegal(Set<Card> cards, int startingHandSize) {
|
||||
return companionCondition.isLegal(cards, startingHandSize);
|
||||
}
|
||||
|
||||
final public String getLegalRule() {
|
||||
return companionCondition.getRule();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import java.util.Map.Entry;
|
|||
*/
|
||||
public class Constructed extends DeckValidator {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DeckValidator.class);
|
||||
private static final Logger logger = Logger.getLogger(Constructed.class);
|
||||
|
||||
private static final List<String> anyNumberCardsAllowed = new ArrayList<>(Arrays.asList(
|
||||
"Relentless Rats", "Shadowborn Apostle", "Rat Colony",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
package mage.filter;
|
||||
|
||||
import mage.ObjectColor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
|
|
@ -108,6 +112,62 @@ public class FilterMana implements Serializable {
|
|||
return colorCount;
|
||||
}
|
||||
|
||||
public void addAll(FilterMana filterMana) {
|
||||
if (filterMana.white) {
|
||||
this.white = true;
|
||||
}
|
||||
if (filterMana.blue) {
|
||||
this.blue = true;
|
||||
}
|
||||
if (filterMana.black) {
|
||||
this.black = true;
|
||||
}
|
||||
if (filterMana.red) {
|
||||
this.red = true;
|
||||
}
|
||||
if (filterMana.green) {
|
||||
this.green = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAll(FilterMana filterMana) {
|
||||
if (filterMana.white) {
|
||||
this.white = false;
|
||||
}
|
||||
if (filterMana.blue) {
|
||||
this.blue = false;
|
||||
}
|
||||
if (filterMana.black) {
|
||||
this.black = false;
|
||||
}
|
||||
if (filterMana.red) {
|
||||
this.red = false;
|
||||
}
|
||||
if (filterMana.green) {
|
||||
this.green = false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<ObjectColor> getColors() {
|
||||
List<ObjectColor> colors = new ArrayList<>();
|
||||
if (this.white) {
|
||||
colors.add(ObjectColor.WHITE);
|
||||
}
|
||||
if (this.blue) {
|
||||
colors.add(ObjectColor.BLUE);
|
||||
}
|
||||
if (this.black) {
|
||||
colors.add(ObjectColor.BLACK);
|
||||
}
|
||||
if (this.red) {
|
||||
colors.add(ObjectColor.RED);
|
||||
}
|
||||
if (this.green) {
|
||||
colors.add(ObjectColor.GREEN);
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
public FilterMana copy() {
|
||||
return new FilterMana(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,25 @@
|
|||
package mage.game;
|
||||
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.CommanderChooseColorAbility;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.common.InfoEffect;
|
||||
import mage.abilities.effects.common.continuous.CommanderReplacementEffect;
|
||||
import mage.abilities.effects.common.cost.CommanderCostModification;
|
||||
import mage.abilities.keyword.CompanionAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.choices.ChoiceColor;
|
||||
import mage.constants.*;
|
||||
import mage.filter.FilterMana;
|
||||
import mage.game.mulligan.Mulligan;
|
||||
import mage.game.turn.TurnMod;
|
||||
import mage.players.Player;
|
||||
import mage.watchers.common.CommanderInfoWatcher;
|
||||
import mage.watchers.common.CommanderPlaysCountWatcher;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class GameCommanderImpl extends GameImpl {
|
||||
|
||||
|
|
@ -40,6 +44,49 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
this.checkCommanderDamage = game.checkCommanderDamage;
|
||||
}
|
||||
|
||||
private void handlePipers(Player player, Set<Card> commanders) {
|
||||
int piperCount = commanders
|
||||
.stream()
|
||||
.filter(CommanderChooseColorAbility::checkCard)
|
||||
.mapToInt(x -> 1)
|
||||
.sum();
|
||||
if (piperCount < 1) {
|
||||
return;
|
||||
}
|
||||
FilterMana leftoverColors = new FilterMana();
|
||||
Stream.concat(
|
||||
player.getLibrary().getCards(this).stream(),
|
||||
player.getSideboard().getCards(this).stream()
|
||||
).map(Card::getColorIdentity).forEach(leftoverColors::addAll);
|
||||
FilterMana nonPiperIdentity = new FilterMana();
|
||||
commanders
|
||||
.stream()
|
||||
.filter(card -> !CommanderChooseColorAbility.checkCard(card))
|
||||
.map(Card::getColorIdentity)
|
||||
.forEach(nonPiperIdentity::addAll);
|
||||
leftoverColors.removeAll(nonPiperIdentity);
|
||||
if (piperCount < leftoverColors.getColorCount()) {
|
||||
throw new UnsupportedOperationException("This deck should not be legal, something went wrong");
|
||||
}
|
||||
Iterator<ObjectColor> iterator = leftoverColors.getColors().listIterator();
|
||||
for (Card commander : commanders) {
|
||||
if (!CommanderChooseColorAbility.checkCard(commander)) {
|
||||
continue;
|
||||
}
|
||||
ObjectColor color;
|
||||
if (!iterator.hasNext()) {
|
||||
ChoiceColor choiceColor = new ChoiceColor(
|
||||
true, "Choose a color for " + commander.getName()
|
||||
);
|
||||
player.choose(Outcome.Neutral, choiceColor, this);
|
||||
color = choiceColor.getColor();
|
||||
} else {
|
||||
color = iterator.next();
|
||||
}
|
||||
commander.getColor().addColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init(UUID choosingPlayerId) {
|
||||
// Karn Liberated calls it to restart game, all data and commanders must be re-initialized
|
||||
|
|
@ -50,25 +97,31 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
// move commanders to command zone
|
||||
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
|
||||
Player player = getPlayer(playerId);
|
||||
if (player != null) {
|
||||
// add new commanders
|
||||
for (UUID cardId : player.getSideboard()) {
|
||||
Card card = this.getCard(cardId);
|
||||
if (card != null) {
|
||||
// Check for companions. If it is the only card in the sideboard, it is the commander, not a companion.
|
||||
if (player.getSideboard().size() > 1 && card.getAbilities(this).stream().anyMatch(ability -> ability instanceof CompanionAbility)) {
|
||||
continue;
|
||||
}
|
||||
addCommander(card, player);
|
||||
}
|
||||
if (player == null) {
|
||||
continue;
|
||||
}
|
||||
// add new commanders
|
||||
Set<Card> commanders = new HashSet<>();
|
||||
for (UUID cardId : player.getSideboard()) {
|
||||
Card card = this.getCard(cardId);
|
||||
if (card == null) {
|
||||
continue;
|
||||
}
|
||||
// Check for companions. If it is the only card in the sideboard, it is the commander, not a companion.
|
||||
if (player.getSideboard().size() > 1 && card.getAbilities(this).stream().anyMatch(CompanionAbility.class::isInstance)) {
|
||||
continue;
|
||||
}
|
||||
commanders.add(card);
|
||||
addCommander(card, player);
|
||||
}
|
||||
|
||||
// init commanders
|
||||
for (UUID commanderId : this.getCommandersIds(player, CommanderCardType.ANY, false)) {
|
||||
Card commander = this.getCard(commanderId);
|
||||
if (commander != null) {
|
||||
initCommander(commander, player);
|
||||
}
|
||||
handlePipers(player, commanders);
|
||||
|
||||
// init commanders
|
||||
for (UUID commanderId : this.getCommandersIds(player, CommanderCardType.ANY, false)) {
|
||||
Card commander = this.getCard(commanderId);
|
||||
if (commander != null) {
|
||||
initCommander(commander, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1129,12 +1129,13 @@ public abstract class GameImpl implements Game {
|
|||
Map<Player, Card> playerCompanionMap = new HashMap<>();
|
||||
for (Player player : state.getPlayers().values()) {
|
||||
// Make a list of legal companions present in the sideboard
|
||||
Set<Card> cards = new HashSet<>(player.getLibrary().getCards(this));
|
||||
Set<Card> potentialCompanions = new HashSet<>();
|
||||
for (Card card : player.getSideboard().getUniqueCards(this)) {
|
||||
for (Ability ability : card.getAbilities(this)) {
|
||||
if (ability instanceof CompanionAbility) {
|
||||
CompanionAbility companionAbility = (CompanionAbility) ability;
|
||||
if (companionAbility.isLegal(new HashSet<>(player.getLibrary().getCards(this)), startingHandSize)) {
|
||||
if (companionAbility.isLegal(cards, startingHandSize)) {
|
||||
potentialCompanions.add(card);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue