reimplement with common class

This commit is contained in:
xenohedron 2023-09-21 01:36:05 -04:00
parent d83d27dfa3
commit 0cbee152d2
3 changed files with 42 additions and 160 deletions

View file

@ -1,11 +1,9 @@
package mage.cards.f;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.EntersBattlefieldOrAttacksSourceTriggeredAbility;
import mage.abilities.common.SourceBecomesTargetTriggeredAbility;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.common.CounterUnlessPaysEffect;
import mage.abilities.effects.common.DontUntapInControllersNextUntapStepTargetEffect;
@ -13,13 +11,12 @@ import mage.abilities.effects.common.TapTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SetTargetPointer;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.filter.StaticFilters;
import mage.target.TargetPermanent;
import mage.target.TargetStackObject;
import java.util.UUID;
/**
*
@ -35,7 +32,10 @@ public final class FrostTitan extends CardImpl {
this.toughness = new MageInt(6);
// Whenever Frost Titan becomes the target of a spell or ability an opponent controls, counter that spell or ability unless its controller pays 2.
this.addAbility(new FrostTitanAbility());
this.addAbility(new SourceBecomesTargetTriggeredAbility(
new CounterUnlessPaysEffect(new GenericManaCost(2)).setText("counter that spell or ability unless its controller pays {2}"),
StaticFilters.FILTER_SPELL_OR_ABILITY_OPPONENTS, SetTargetPointer.SPELL, false
));
// Whenever Frost Titan enters the battlefield or attacks, tap target permanent. It doesn't untap during its controller's next untap step.
Ability ability = new EntersBattlefieldOrAttacksSourceTriggeredAbility(new TapTargetEffect());
@ -54,42 +54,3 @@ public final class FrostTitan extends CardImpl {
}
}
class FrostTitanAbility extends TriggeredAbilityImpl {
public FrostTitanAbility() {
super(Zone.BATTLEFIELD, new CounterUnlessPaysEffect(new GenericManaCost(2)), false);
}
private FrostTitanAbility(final FrostTitanAbility ability) {
super(ability);
}
@Override
public FrostTitanAbility copy() {
return new FrostTitanAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TARGETED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getTargetId().equals(this.getSourceId()) && game.getOpponents(this.controllerId).contains(event.getPlayerId())) {
this.getTargets().clear();
TargetStackObject target = new TargetStackObject();
target.add(event.getSourceId(), game);
this.addTarget(target);
return true;
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} becomes the target of a spell or ability an opponent controls, counter that spell or ability unless its controller pays {2}.";
}
}

View file

@ -1,34 +1,30 @@
package mage.cards.o;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.common.SourceBecomesTargetTriggeredAbility;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.StackObject;
import mage.filter.FilterSpell;
import java.util.UUID;
/**
*
* @author anonymous
* @author xenohedron
*/
public final class OpalineSliver extends CardImpl {
private static final FilterPermanent filter = new FilterPermanent("All Slivers");
private static final FilterPermanent filterSliver = new FilterPermanent("All Slivers");
private static final FilterSpell filterSpell = new FilterSpell("a spell an opponent controls");
static {
filter.add(SubType.SLIVER.getPredicate());
filterSliver.add(SubType.SLIVER.getPredicate());
filterSpell.add(TargetController.OPPONENT.getControllerPredicate());
}
public OpalineSliver(UUID ownerId, CardSetInfo setInfo) {
@ -38,9 +34,12 @@ public final class OpalineSliver extends CardImpl {
this.toughness = new MageInt(2);
// All Slivers have "Whenever this permanent becomes the target of a spell an opponent controls, you may draw a card."
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAllEffect(
new OpalineSliverTriggeredAbility(), Duration.WhileOnBattlefield,
filter, "All Slivers have \"Whenever this permanent becomes the target of a spell an opponent controls, you may draw a card.\"")));
Ability gainedTriggeredAbility = new SourceBecomesTargetTriggeredAbility(
new DrawCardSourceControllerEffect(1), filterSpell, SetTargetPointer.NONE, true)
.setTriggerPhrase("Whenever this permanent becomes the target of a spell an opponent controls, ");
this.addAbility(new SimpleStaticAbility(new GainAbilityAllEffect(
gainedTriggeredAbility, Duration.WhileOnBattlefield, filterSliver,
"All Slivers have \"Whenever this permanent becomes the target of a spell an opponent controls, you may draw a card.\"")));
}
private OpalineSliver(final OpalineSliver card) {
@ -52,43 +51,3 @@ public final class OpalineSliver extends CardImpl {
return new OpalineSliver(this);
}
}
class OpalineSliverTriggeredAbility extends TriggeredAbilityImpl {
public OpalineSliverTriggeredAbility() {
super(Zone.BATTLEFIELD, new DrawCardSourceControllerEffect(1), false);
}
private OpalineSliverTriggeredAbility(final OpalineSliverTriggeredAbility ability) {
super(ability);
}
@Override
public OpalineSliverTriggeredAbility copy() {
return new OpalineSliverTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TARGETED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
StackObject spell = game.getStack().getStackObject(event.getSourceId());
if (spell == null) {
return false;
} else {
return event.getTargetId().equals(this.getSourceId())
&& game.getOpponents(this.controllerId).contains(event.getPlayerId())
&& StaticFilters.FILTER_SPELL_A.match(spell, getControllerId(), this, game);
}
}
@Override
public String getRule() {
return "Whenever this permanent becomes the target of a spell an opponent controls, you may draw a card.";
}
}

View file

@ -1,9 +1,7 @@
package mage.cards.r;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SourceBecomesTargetTriggeredAbility;
import mage.abilities.costs.common.DiscardCardCost;
import mage.abilities.effects.common.CounterUnlessPaysEffect;
import mage.abilities.keyword.HasteAbility;
@ -11,21 +9,24 @@ import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SetTargetPointer;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.target.targetpointer.FixedTarget;
import mage.constants.TargetController;
import mage.filter.FilterSpell;
import java.util.UUID;
/**
*
* @author LevelX2
* @author LevelX2, xenohedron
*/
public final class RealitySmasher extends CardImpl {
private static final FilterSpell filter = new FilterSpell("a spell an opponent controls");
static {
filter.add(TargetController.OPPONENT.getControllerPredicate());
}
public RealitySmasher(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{C}");
this.subtype.add(SubType.ELDRAZI);
@ -37,7 +38,10 @@ public final class RealitySmasher extends CardImpl {
// Haste
this.addAbility(HasteAbility.getInstance());
// Whenever Reality Smasher becomes the target of a spell an opponent controls, counter that spell unless its controller discards a card.
this.addAbility(new RealitySmasherTriggeredAbility());
this.addAbility(new SourceBecomesTargetTriggeredAbility(
new CounterUnlessPaysEffect(new DiscardCardCost()).setText("counter that spell unless its controller discards a card"),
filter, SetTargetPointer.SPELL, false
));
}
private RealitySmasher(final RealitySmasher card) {
@ -49,45 +53,3 @@ public final class RealitySmasher extends CardImpl {
return new RealitySmasher(this);
}
}
class RealitySmasherTriggeredAbility extends TriggeredAbilityImpl {
public RealitySmasherTriggeredAbility() {
super(Zone.BATTLEFIELD, new CounterUnlessPaysEffect(new DiscardCardCost()), false);
}
private RealitySmasherTriggeredAbility(final RealitySmasherTriggeredAbility ability) {
super(ability);
}
@Override
public RealitySmasherTriggeredAbility copy() {
return new RealitySmasherTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.TARGETED;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
StackObject spell = game.getStack().getStackObject(event.getSourceId());
if (!(spell instanceof Spell)) {
return false;
} else {
if (event.getTargetId().equals(this.getSourceId())
&& game.getOpponents(this.controllerId).contains(event.getPlayerId())) {
getEffects().setTargetPointer(new FixedTarget(spell.getId()));
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever {this} becomes the target of a spell an opponent controls, counter that spell unless its controller discards a card.";
}
}