forked from External/mage
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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue