[LTR] Implement The Grey Havens (#10493)

This commit is contained in:
Susucre 2023-06-23 02:06:10 +02:00 committed by GitHub
parent 6459d64eab
commit 0255761d67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 198 additions and 0 deletions

View file

@ -0,0 +1,54 @@
package mage.cards.t;
import java.util.UUID;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.keyword.ScryEffect;
import mage.abilities.mana.AnyColorCardInYourGraveyardManaAbility;
import mage.abilities.mana.AnyColorPermanentTypesManaAbility;
import mage.abilities.mana.ColorlessManaAbility;
import mage.abilities.mana.ConditionalAnyColorManaAbility;
import mage.constants.SuperType;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.TargetController;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreatureCard;
import mage.filter.common.FilterCreaturePermanent;
/**
*
* @author Susucr
*/
public final class TheGreyHavens extends CardImpl {
private static final FilterCard filter = new FilterCreatureCard("legendary creature card");
static {
filter.add(SuperType.LEGENDARY.getPredicate());
}
public TheGreyHavens(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.LAND}, "");
this.supertype.add(SuperType.LEGENDARY);
// When The Grey Havens enters the battlefield, scry 1.
this.addAbility(new EntersBattlefieldTriggeredAbility(new ScryEffect(1, false)));
// {T}: Add {C}.
this.addAbility(new ColorlessManaAbility());
// {T}: Add one mana of any color among legendary creature cards in your graveyard.
this.addAbility(new AnyColorCardInYourGraveyardManaAbility(filter));
}
private TheGreyHavens(final TheGreyHavens card) {
super(card);
}
@Override
public TheGreyHavens copy() {
return new TheGreyHavens(this);
}
}

View file

@ -242,6 +242,7 @@ public final class TheLordOfTheRingsTalesOfMiddleEarth extends ExpansionSet {
cards.add(new SetCardInfo("The Bath Song", 40, Rarity.UNCOMMON, mage.cards.t.TheBathSong.class));
cards.add(new SetCardInfo("The Battle of Bywater", 2, Rarity.RARE, mage.cards.t.TheBattleOfBywater.class));
cards.add(new SetCardInfo("The Black Breath", 78, Rarity.COMMON, mage.cards.t.TheBlackBreath.class));
cards.add(new SetCardInfo("The Grey Havens", 255, Rarity.UNCOMMON, mage.cards.t.TheGreyHavens.class));
cards.add(new SetCardInfo("The Mouth of Sauron", 216, Rarity.UNCOMMON, mage.cards.t.TheMouthOfSauron.class));
cards.add(new SetCardInfo("The One Ring", 246, Rarity.MYTHIC, mage.cards.t.TheOneRing.class));
cards.add(new SetCardInfo("The Ring Goes South", 186, Rarity.RARE, mage.cards.t.TheRingGoesSouth.class));

View file

@ -0,0 +1,143 @@
package mage.abilities.mana;
import mage.Mana;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.mana.ManaEffect;
import mage.cards.Card;
import mage.choices.Choice;
import mage.constants.ManaType;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.players.Player;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author Susucr
*/
public class AnyColorCardInYourGraveyardManaAbility extends ActivatedManaAbilityImpl {
public AnyColorCardInYourGraveyardManaAbility(FilterCard cardFilter) {
super(Zone.BATTLEFIELD, new AnyColorCardInYourGraveyardManaEffect(cardFilter), new TapSourceCost());
}
public AnyColorCardInYourGraveyardManaAbility(final AnyColorCardInYourGraveyardManaAbility ability) {
super(ability);
}
@Override
public AnyColorCardInYourGraveyardManaAbility copy() {
return new AnyColorCardInYourGraveyardManaAbility(this);
}
@Override
public List<Mana> getNetMana(Game game) {
return ((AnyColorCardInYourGraveyardManaEffect) getEffects().get(0)).getNetMana(game, this);
}
@Override
public boolean definesMana(Game game) {
return true;
}
}
class AnyColorCardInYourGraveyardManaEffect extends ManaEffect {
private final FilterCard filter;
private transient boolean inManaTypeCalculation = false;
public AnyColorCardInYourGraveyardManaEffect(FilterCard cardFilter) {
super();
filter = cardFilter;
staticText = "Add one mana of any color" +
" among " + cardFilter.getMessage() + " in your graveyard.";
}
public AnyColorCardInYourGraveyardManaEffect(final AnyColorCardInYourGraveyardManaEffect effect) {
super(effect);
this.filter = effect.filter.copy();
}
@Override
public List<Mana> getNetMana(Game game, Ability source) {
return game == null ? new ArrayList<>() : ManaType.getManaListFromManaTypes(getManaTypes(game, source), true);
}
@Override
public Mana produceMana(Game game, Ability source) {
if (game == null) {
return null;
}
Set<ManaType> types = getManaTypes(game, source);
if (types.isEmpty()) {
return null;
}
Choice choice = ManaType.getChoiceOfManaTypes(types, true);
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.choose(outcome, choice, game)) {
return null;
}
}
ManaType chosenType = ManaType.findByName(choice.getChoice());
return chosenType == null ? null : new Mana(chosenType);
}
private Set<ManaType> getManaTypes(Game game, Ability source) {
Set<ManaType> manaTypes = new HashSet<>(6);
if (game == null || game.getPhase() == null || inManaTypeCalculation) {
return manaTypes;
}
inManaTypeCalculation = true;
Set<Card> cards =
game.getPlayer(source.getControllerId())
.getGraveyard()
.getCards(filter, game);
for (Card card : cards) {
ObjectColor cardColor = card.getColor(game);
if (cardColor.isBlack()) {
manaTypes.add(ManaType.BLACK);
}
if (cardColor.isBlue()) {
manaTypes.add(ManaType.BLUE);
}
if (cardColor.isGreen()) {
manaTypes.add(ManaType.GREEN);
}
if (cardColor.isRed()) {
manaTypes.add(ManaType.RED);
}
if (cardColor.isWhite()) {
manaTypes.add(ManaType.WHITE);
}
// If all types are already added, exit early
if (manaTypes.size() == 5) {
break;
}
}
inManaTypeCalculation = false;
return manaTypes;
}
@Override
public AnyColorCardInYourGraveyardManaEffect copy() {
return new AnyColorCardInYourGraveyardManaEffect(this);
}
}