Re: Help implementing a card
There is probably a really simple answer to this, but I've been stuck on mystic remora for a few days. Here is what I came up with:
- Code: Select all
package mage. sets. iceage;
import java. util. UUID;
import mage. abilities. costs. mana. ManaCostsImpl;
import mage. abilities. keyword. CumulativeUpkeepAbility;
import mage. game. stack. Spell;
import mage. constants. CardType;
import mage. constants. Rarity;
import mage. abilities. Ability;
import mage. abilities. TriggeredAbilityImpl;
import mage. abilities. costs. mana. GenericManaCost;
import mage. abilities. effects. OneShotEffect;
import mage. abilities. effects. common. DrawCardSourceControllerEffect;
import mage. cards. CardImpl;
import mage. constants. Outcome;
import mage. constants. Zone;
import mage. game. Game;
import mage. game. events. GameEvent;
import mage. players. Player;
import mage. target. targetpointer. FixedTarget;
/**
*
* @author TGower
*/
public class MysticRemora extends CardImpl {
public MysticRemora(UUID ownerId) {
super(ownerId, 87, "Mystic Remora", Rarity. COMMON, new CardType[]{CardType. ENCHANTMENT}, "{U}");
this. expansionSetCode = "ICE";
// Cumulative upkeep {1}
this. addAbility(new CumulativeUpkeepAbility(new ManaCostsImpl("{1}")));
// Whenever an opponent casts a noncreature spell, you may draw a card unless that player pays {4}.
this. addAbility(new MysticRemoraTriggeredAbility());
}
public MysticRemora(final MysticRemora card) {
super(card);
}
@Override
public MysticRemora copy() {
return new MysticRemora(this);
}
}
class MysticRemoraTriggeredAbility extends TriggeredAbilityImpl {
public MysticRemoraTriggeredAbility() {
super(Zone. BATTLEFIELD, new MysticRemoraEffect(), false);
}
public MysticRemoraTriggeredAbility(final MysticRemoraTriggeredAbility ability) {
super(ability);
}
@Override
public MysticRemoraTriggeredAbility copy() {
return new MysticRemoraTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event. getType() == GameEvent. EventType. SPELL_CAST;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (game. getOpponents(controllerId). contains(event. getPlayerId())) {
if (event. getType() == GameEvent. EventType. SPELL_CAST) {
Spell spell = game. getStack(). getSpell(event. getTargetId());
if (spell != null && !spell. getCardType(). contains(CardType. CREATURE)) {
Player controller = game. getPlayer(game. getControllerId(this. controllerId));
Player player = game. getPlayer(spell. getControllerId());
if (controller != player) {
this. getEffects(). get(0). setTargetPointer(new FixedTarget(event. getPlayerId()));
}
return true;
}
}
}
return false;
}
@Override
public String getRule() {
return "Whenever an opponent casts a noncreature spell, you may draw a card unless that player pays {4}. ";
}
}
class MysticRemoraEffect extends OneShotEffect {
public MysticRemoraEffect() {
super(Outcome. DrawCard);
this. staticText = "you may draw a card unless that player pays {4}";
}
public MysticRemoraEffect(final MysticRemoraEffect effect) {
super(effect);
}
@Override
public MysticRemoraEffect copy() {
return new MysticRemoraEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game. getPlayer(targetPointer. getFirst(game, source));
Player controller = game. getPlayer(source. getControllerId());
if (player != null) {
GenericManaCost cost = new GenericManaCost(4);
if (!cost. pay(source, game, player. getId(), player. getId(), false)) {
controller. drawCards(1, game);
}
return true;
}
return false;
}
}
. Ex. If
{G}{G},