diff --git a/Mage.Sets/src/mage/cards/h/HandOfVecna.java b/Mage.Sets/src/mage/cards/h/HandOfVecna.java new file mode 100644 index 0000000000..cc4dcb9d48 --- /dev/null +++ b/Mage.Sets/src/mage/cards/h/HandOfVecna.java @@ -0,0 +1,127 @@ +package mage.cards.h; + +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfCombatTriggeredAbility; +import mage.abilities.costs.common.PayLifeCost; +import mage.abilities.dynamicvalue.common.CardsInControllerHandCount; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continuous.BoostTargetEffect; +import mage.abilities.keyword.EquipAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterControlledCreaturePermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.MageObjectReferencePredicate; +import mage.filter.predicate.mageobject.NamePredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetPermanent; +import mage.target.targetpointer.FixedTarget; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * @author TheElk801 + */ +public final class HandOfVecna extends CardImpl { + + public HandOfVecna(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.EQUIPMENT); + + // At the beginning of combat on your turn, equipped creature or a creature you control named Vecna gets +X/+X until end of turn, where X is the number of cards in your hand. + this.addAbility(new BeginningOfCombatTriggeredAbility( + new HandOfVecnaEffect(), TargetController.YOU, false + )); + + // Equip—Pay 1 life for each card in your hand. + this.addAbility(new EquipAbility(Outcome.Benefit, new PayLifeCost( + CardsInControllerHandCount.instance, "1 life for each card in your hand" + ))); + + // Equip {2} + this.addAbility(new EquipAbility(2)); + } + + private HandOfVecna(final HandOfVecna card) { + super(card); + } + + @Override + public HandOfVecna copy() { + return new HandOfVecna(this); + } +} + +class HandOfVecnaEffect extends OneShotEffect { + + private static final FilterPermanent filter = new FilterControlledCreaturePermanent("creature you control named Vecna"); + + static { + filter.add(new NamePredicate("Vecna")); + } + + HandOfVecnaEffect() { + super(Outcome.Benefit); + staticText = "equipped creature or a creature you control " + + "named Vecna gets +X/+X until end of turn, " + + "where X is the number of cards in your hand"; + } + + private HandOfVecnaEffect(final HandOfVecnaEffect effect) { + super(effect); + } + + @Override + public HandOfVecnaEffect copy() { + return new HandOfVecnaEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null || player.getHand().size() < 1) { + return false; + } + Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); + Permanent equipped = game.getPermanent(sourcePermanent != null ? sourcePermanent.getAttachedTo() : null); + List<Permanent> chooseable = game.getBattlefield().getActivePermanents( + filter, source.getControllerId(), source.getSourceId(), game + ); + if (equipped != null) { + chooseable.add(equipped); + } + Permanent toBoost; + switch (chooseable.size()) { + case 0: + return false; + case 1: + toBoost = chooseable.get(0); + break; + default: + FilterPermanent filter = new FilterPermanent("a creature to give +X/+X to"); + filter.add(Predicates.or( + chooseable + .stream() + .map(permanent -> new MageObjectReferencePredicate(permanent, game)) + .collect(Collectors.toList()) + )); + TargetPermanent target = new TargetPermanent(filter); + target.setNotTarget(true); + player.choose(outcome, target, source.getSourceId(), game); + toBoost = game.getPermanent(target.getFirstTarget()); + } + int xValue = player.getHand().size(); + game.addEffect(new BoostTargetEffect( + xValue, xValue, Duration.EndOfTurn + ).setTargetPointer(new FixedTarget(toBoost, game)), source); + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java index bd816ecb51..ac39bd7ed3 100644 --- a/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java +++ b/Mage.Sets/src/mage/sets/AdventuresInTheForgottenRealms.java @@ -108,6 +108,7 @@ public final class AdventuresInTheForgottenRealms extends ExpansionSet { cards.add(new SetCardInfo("Half-Elf Monk", 19, Rarity.COMMON, mage.cards.h.HalfElfMonk.class)); cards.add(new SetCardInfo("Hall of Storm Giants", 257, Rarity.RARE, mage.cards.h.HallOfStormGiants.class)); cards.add(new SetCardInfo("Hama Pashar, Ruin Seeker", 224, Rarity.UNCOMMON, mage.cards.h.HamaPasharRuinSeeker.class)); + cards.add(new SetCardInfo("Hand of Vecna", 246, Rarity.RARE, mage.cards.h.HandOfVecna.class)); cards.add(new SetCardInfo("Herald of Hadar", 108, Rarity.COMMON, mage.cards.h.HeraldOfHadar.class)); cards.add(new SetCardInfo("Hill Giant Herdgorger", 187, Rarity.COMMON, mage.cards.h.HillGiantHerdgorger.class)); cards.add(new SetCardInfo("Hired Hexblade", 109, Rarity.COMMON, mage.cards.h.HiredHexblade.class)); diff --git a/Mage/src/main/java/mage/filter/predicate/mageobject/MageObjectReferencePredicate.java b/Mage/src/main/java/mage/filter/predicate/mageobject/MageObjectReferencePredicate.java index 36c6d76210..f438b24e95 100644 --- a/Mage/src/main/java/mage/filter/predicate/mageobject/MageObjectReferencePredicate.java +++ b/Mage/src/main/java/mage/filter/predicate/mageobject/MageObjectReferencePredicate.java @@ -15,6 +15,10 @@ public class MageObjectReferencePredicate implements Predicate<MageItem> { private final MageObjectReference mor; + public MageObjectReferencePredicate(MageObject mageObject, Game game) { + this(new MageObjectReference(mageObject, game)); + } + public MageObjectReferencePredicate(MageObjectReference mor) { this.mor = mor; }