[AFC] Implemented Mantle of the Ancients

This commit is contained in:
Evan Kranzler 2021-08-25 08:11:54 -04:00
parent 40cf802d6b
commit 12219cff01
3 changed files with 179 additions and 16 deletions

View file

@ -0,0 +1,168 @@
package mage.cards.m;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.continuous.BoostEnchantedEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.cards.*;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetCard;
import mage.target.TargetPermanent;
import mage.target.common.TargetCardInYourGraveyard;
import mage.target.common.TargetControlledCreaturePermanent;
import java.util.Objects;
import java.util.UUID;
/**
* @author TheElk801
*/
public final class MantleOfTheAncients extends CardImpl {
public MantleOfTheAncients(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}{W}");
this.subtype.add(SubType.AURA);
// Enchant creature you control
TargetPermanent auraTarget = new TargetControlledCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
Ability ability = new EnchantAbility(auraTarget.getTargetName());
this.addAbility(ability);
// When Mantle of the Ancients enters the battlefield, return any number of target Aura and/or Equipment cards from your graveyard to the battlefield attached to enchanted creature.
this.addAbility(new EntersBattlefieldTriggeredAbility(new MantleOfTheAncientsEffect()));
// Enchanted creature gets +1/+1 for each Aura and Equipment attached to it.
this.addAbility(new SimpleStaticAbility(new BoostEnchantedEffect(
MantleOfTheAncientsValue.instance, MantleOfTheAncientsValue.instance
)));
}
private MantleOfTheAncients(final MantleOfTheAncients card) {
super(card);
}
@Override
public MantleOfTheAncients copy() {
return new MantleOfTheAncients(this);
}
}
class MantleOfTheAncientsEffect extends OneShotEffect {
MantleOfTheAncientsEffect() {
super(Outcome.Benefit);
staticText = "return any number of target Aura and/or Equipment cards " +
"that could be attached to enchanted creature from your graveyard " +
"to the battlefield attached to enchanted creature";
}
private MantleOfTheAncientsEffect(final MantleOfTheAncientsEffect effect) {
super(effect);
}
@Override
public MantleOfTheAncientsEffect copy() {
return new MantleOfTheAncientsEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = source.getSourcePermanentOrLKI(game);
if (player == null || sourcePermanent == null) {
return false;
}
Permanent permanent = game.getPermanent(sourcePermanent.getAttachedTo());
if (permanent == null) {
return false;
}
FilterCard filter = new FilterCard("Aura or Equipment card that can be attached to " + permanent.getName());
filter.add(new MantleOfTheAncientsPredicate(permanent));
TargetCard target = new TargetCardInYourGraveyard(0, Integer.MAX_VALUE, filter, true);
player.choose(outcome, target, source.getSourceId(), game);
Cards cards = new CardsImpl(target.getTargets());
if (cards.isEmpty()) {
return false;
}
cards.getCards(game)
.stream()
.forEach(card -> game.getState().setValue("attachTo:" + card.getId(), permanent));
player.moveCards(cards, Zone.BATTLEFIELD, source, game);
for (UUID cardId : cards) {
permanent.addAttachment(cardId, source, game);
}
return true;
}
}
class MantleOfTheAncientsPredicate implements Predicate<Card> {
private final Permanent permanent;
MantleOfTheAncientsPredicate(Permanent permanent) {
this.permanent = permanent;
}
@Override
public boolean apply(Card input, Game game) {
if (input.hasSubtype(SubType.AURA, game)) {
return input
.getSpellAbility()
.getTargets()
.stream()
.anyMatch(target -> target.getFilter().match(permanent, game));
}
return input.hasSubtype(SubType.EQUIPMENT, game);
}
}
enum MantleOfTheAncientsValue implements DynamicValue {
instance;
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
Permanent permanent = sourceAbility.getSourcePermanentOrLKI(game);
if (permanent == null) {
return 0;
}
return permanent
.getAttachments()
.stream()
.map(game::getPermanentOrLKIBattlefield)
.filter(Objects::nonNull)
.map(p -> p.hasSubtype(SubType.EQUIPMENT, game) || p.hasSubtype(SubType.AURA, game))
.mapToInt(b -> b ? 1 : 0)
.sum();
}
@Override
public MantleOfTheAncientsValue copy() {
return instance;
}
@Override
public String getMessage() {
return "Aura and Equipment attached to it";
}
@Override
public String toString() {
return "1";
}
}

View file

@ -152,6 +152,7 @@ public final class ForgottenRealmsCommander extends ExpansionSet {
cards.add(new SetCardInfo("Lumbering Falls", 247, Rarity.RARE, mage.cards.l.LumberingFalls.class)); cards.add(new SetCardInfo("Lumbering Falls", 247, Rarity.RARE, mage.cards.l.LumberingFalls.class));
cards.add(new SetCardInfo("Maddening Hex", 32, Rarity.RARE, mage.cards.m.MaddeningHex.class)); cards.add(new SetCardInfo("Maddening Hex", 32, Rarity.RARE, mage.cards.m.MaddeningHex.class));
cards.add(new SetCardInfo("Magmaquake", 133, Rarity.RARE, mage.cards.m.Magmaquake.class)); cards.add(new SetCardInfo("Magmaquake", 133, Rarity.RARE, mage.cards.m.Magmaquake.class));
cards.add(new SetCardInfo("Mantle of the Ancients", 8, Rarity.RARE, mage.cards.m.MantleOfTheAncients.class));
cards.add(new SetCardInfo("Marionette Master", 102, Rarity.RARE, mage.cards.m.MarionetteMaster.class)); cards.add(new SetCardInfo("Marionette Master", 102, Rarity.RARE, mage.cards.m.MarionetteMaster.class));
cards.add(new SetCardInfo("Masterwork of Ingenuity", 209, Rarity.RARE, mage.cards.m.MasterworkOfIngenuity.class)); cards.add(new SetCardInfo("Masterwork of Ingenuity", 209, Rarity.RARE, mage.cards.m.MasterworkOfIngenuity.class));
cards.add(new SetCardInfo("Merfolk Looter", 86, Rarity.UNCOMMON, mage.cards.m.MerfolkLooter.class)); cards.add(new SetCardInfo("Merfolk Looter", 86, Rarity.UNCOMMON, mage.cards.m.MerfolkLooter.class));

View file

@ -1,15 +1,13 @@
package mage.filter.predicate.card; package mage.filter.predicate.card;
import java.util.UUID;
import mage.cards.Card; import mage.cards.Card;
import mage.filter.Filter;
import mage.filter.predicate.Predicate; import mage.filter.predicate.Predicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.Target;
import java.util.UUID;
/** /**
*
* @author jeffwadsworth * @author jeffwadsworth
*/ */
// Use this predicate if a aura card comes into play attached to a permanent without targeting // Use this predicate if a aura card comes into play attached to a permanent without targeting
@ -23,20 +21,16 @@ public class AuraCardCanAttachToPermanentId implements Predicate<Card> {
@Override @Override
public boolean apply(Card input, Game game) { public boolean apply(Card input, Game game) {
final Permanent permanent = game.getPermanent(toBeCheckedPermanentId); Permanent permanent = game.getPermanent(toBeCheckedPermanentId);
Filter filter; if (permanent == null || input == null || !input.isEnchantment(game)) {
if (permanent != null
&& input != null
&& input.isEnchantment(game)) {
for (Target target : input.getSpellAbility().getTargets()) {
filter = target.getFilter();
if (filter.match(permanent, game)) {
return true;
}
}
}
return false; return false;
} }
return input
.getSpellAbility()
.getTargets()
.stream()
.anyMatch(target -> target.getFilter().match(permanent, game));
}
@Override @Override
public String toString() { public String toString() {