Implemented Vivien's Invocation

This commit is contained in:
Evan Kranzler 2018-06-12 20:26:55 -04:00
parent 6073139e45
commit 57e9f0eb93
2 changed files with 171 additions and 0 deletions

View file

@ -0,0 +1,170 @@
package mage.cards.v;
import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.SendOptionUsedEventEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.common.FilterCreatureCard;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetCard;
import mage.target.common.TargetOpponentsCreaturePermanent;
/**
*
* @author TheElk801
*/
public final class ViviensInvocation extends CardImpl {
public ViviensInvocation(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{5}{G}{G}");
// Look at the top seven cards of your library. You may put a creature card from among them onto the battlefield. Put the rest on the bottom of your library in a random order. When a creature is put onto the battlefield this way, it deals damage equals to its power to target creature an opponent controls.
this.getSpellAbility().addEffect(new ViviensInvocationEffect());
}
public ViviensInvocation(final ViviensInvocation card) {
super(card);
}
@Override
public ViviensInvocation copy() {
return new ViviensInvocation(this);
}
}
class ViviensInvocationEffect extends OneShotEffect {
public ViviensInvocationEffect(final ViviensInvocationEffect effect) {
super(effect);
}
public ViviensInvocationEffect() {
super(Outcome.PutCreatureInPlay);
this.staticText = "Look at the top seven cards of your library. "
+ "You may put a creature card from among them onto the battlefield. "
+ "Put the rest on the bottom of your library in a random order. "
+ "When a creature is put onto the battlefield this way, "
+ "it deals damage equal to its power to target creature an opponent controls";
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
cards.addAll(controller.getLibrary().getTopCards(game, 7));
if (!cards.isEmpty()) {
TargetCard target = new TargetCard(
Zone.LIBRARY,
new FilterCreatureCard("creature card to put on the battlefield")
);
if (controller.choose(Outcome.PutCreatureInPlay, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
game.addDelayedTriggeredAbility(
new ViviensInvocationReflexiveTriggeredAbility(
new MageObjectReference(permanent, game)
), source);
new SendOptionUsedEventEffect().apply(game, source);
}
}
}
if (!cards.isEmpty()) {
controller.putCardsOnBottomOfLibrary(cards, game, source, false);
}
}
return true;
}
@Override
public ViviensInvocationEffect copy() {
return new ViviensInvocationEffect(this);
}
}
class ViviensInvocationReflexiveTriggeredAbility extends DelayedTriggeredAbility {
public ViviensInvocationReflexiveTriggeredAbility(MageObjectReference mor) {
super(new ViviensInvocationDamageEffect(mor), Duration.OneUse, false);
this.addTarget(new TargetOpponentsCreaturePermanent());
}
public ViviensInvocationReflexiveTriggeredAbility(final ViviensInvocationReflexiveTriggeredAbility ability) {
super(ability);
}
@Override
public ViviensInvocationReflexiveTriggeredAbility copy() {
return new ViviensInvocationReflexiveTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.OPTION_USED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
return event.getPlayerId().equals(this.getControllerId())
&& event.getSourceId().equals(this.getSourceId());
}
@Override
public String getRule() {
return "When a creature is put onto the battlefield with {this}, "
+ "it deals damage equal to its power to target creature an opponent controls";
}
}
class ViviensInvocationDamageEffect extends OneShotEffect {
private final MageObjectReference mor;
public ViviensInvocationDamageEffect(MageObjectReference mor) {
super(Outcome.Benefit);
this.mor = mor;
}
public ViviensInvocationDamageEffect(final ViviensInvocationDamageEffect effect) {
super(effect);
mor = effect.mor;
}
@Override
public ViviensInvocationDamageEffect copy() {
return new ViviensInvocationDamageEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
if (mor == null) {
return false;
}
Permanent creature = game.getPermanent(source.getFirstTarget());
Permanent permanent = mor.getPermanent(game);
if (creature == null || permanent == null) {
return false;
}
return creature.damage(permanent.getPower().getValue(), permanent.getId(), game, false, true) > 0;
}
}

View file

@ -125,6 +125,7 @@ public final class CoreSet2019 extends ExpansionSet {
cards.add(new SetCardInfo("Ursine Champion", 304, Rarity.COMMON, mage.cards.u.UrsineChampion.class));
cards.add(new SetCardInfo("Vampire Sovereign", 125, Rarity.UNCOMMON, mage.cards.v.VampireSovereign.class));
cards.add(new SetCardInfo("Vivien Reid", 208, Rarity.MYTHIC, mage.cards.v.VivienReid.class));
cards.add(new SetCardInfo("Vivien's Invocation", 209, Rarity.RARE, mage.cards.v.ViviensInvocation.class));
cards.add(new SetCardInfo("Volcanic Dragon", 167, Rarity.UNCOMMON, mage.cards.v.VolcanicDragon.class));
cards.add(new SetCardInfo("Walking Corpse", 126, Rarity.COMMON, mage.cards.w.WalkingCorpse.class));
cards.add(new SetCardInfo("Wall of Mist", 83, Rarity.COMMON, mage.cards.w.WallOfMist.class));