Fix various target notTarget issues

This commit is contained in:
Alex W. Jackson 2022-07-24 23:11:14 -04:00
parent cc6936387e
commit fc39f320f0
9 changed files with 113 additions and 170 deletions

View file

@ -4,25 +4,19 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.costs.mana.ColoredManaCost;
import mage.abilities.effects.PreventionEffectImpl;
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.game.Game;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
import mage.game.events.PreventDamageEvent;
import mage.game.events.PreventedDamageEvent;
import mage.target.TargetSource;
import java.util.UUID;
/**
* @author BetaSteward_at_googlemail.com
* @author awjackson
*/
public final class AuriokReplica extends CardImpl {
@ -33,8 +27,7 @@ public final class AuriokReplica extends CardImpl {
this.toughness = new MageInt(2);
// {W}, Sacrifice Auriok Replica: Prevent all damage a source of your choice would deal to you this turn.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new AuriokReplicaEffect(), new ManaCostsImpl<>("{W}"));
ability.addTarget(new TargetSource());
Ability ability = new SimpleActivatedAbility(new AuriokReplicaEffect(), new ColoredManaCost(ColoredManaSymbol.W));
ability.addCost(new SacrificeSourceCost());
this.addAbility(ability);
}
@ -47,18 +40,21 @@ public final class AuriokReplica extends CardImpl {
public AuriokReplica copy() {
return new AuriokReplica(this);
}
}
class AuriokReplicaEffect extends PreventionEffectImpl {
private final TargetSource target;
public AuriokReplicaEffect() {
super(Duration.EndOfTurn);
staticText = "Prevent all damage a source of your choice would deal to you this turn";
this.staticText = "prevent all damage a source of your choice would deal to you this turn";
this.target = new TargetSource();
}
public AuriokReplicaEffect(final AuriokReplicaEffect effect) {
super(effect);
this.target = effect.target.copy();
}
@Override
@ -67,27 +63,16 @@ class AuriokReplicaEffect extends PreventionEffectImpl {
}
@Override
public boolean apply(Game game, Ability source) {
return true;
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
event.setAmount(0);
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
}
return true;
public void init(Ability source, Game game) {
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), source, game);
super.init(source, game);
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (super.applies(event, source, game)) {
return event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(this.getTargetPointer().getFirst(game, source));
}
return false;
return (super.applies(event, source, game)
&& event.getTargetId().equals(source.getControllerId())
&& event.getSourceId().equals(target.getFirstTarget())
);
}
}
}

View file

@ -6,7 +6,7 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.costs.mana.ColoredManaCost;
import mage.abilities.effects.common.continuous.BoostAllEffect;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.cards.CardImpl;
@ -14,7 +14,7 @@ import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.target.common.TargetCreaturePermanent;
import mage.target.TargetPermanent;
/**
*
@ -22,28 +22,26 @@ import mage.target.common.TargetCreaturePermanent;
*/
public final class BalthorTheStout extends CardImpl {
private static final FilterCreaturePermanent filter1 = new FilterCreaturePermanent("Barbarian creatures");
private static final FilterCreaturePermanent filter2 = new FilterCreaturePermanent("another target Barbarian");
private static final FilterCreaturePermanent filter1 = new FilterCreaturePermanent(SubType.BARBARIAN, "Barbarian creatures");
private static final FilterCreaturePermanent filter2 = new FilterCreaturePermanent(SubType.BARBARIAN, "another target Barbarian creature");
static {
filter1.add(SubType.BARBARIAN.getPredicate());
filter2.add(AnotherPredicate.instance);
filter2.add(SubType.BARBARIAN.getPredicate());
}
public BalthorTheStout(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{R}{R}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{R}{R}");
addSuperType(SuperType.LEGENDARY);
this.subtype.add(SubType.DWARF, SubType.BARBARIAN);
this.power = new MageInt(2);
this.toughness = new MageInt(2);
// Other Barbarian creatures get +1/+1.
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filter1, true)));
this.addAbility(new SimpleStaticAbility(new BoostAllEffect(1, 1, Duration.WhileOnBattlefield, filter1, true)));
// {R}: Another target Barbarian creature gets +1/+0 until end of turn.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostTargetEffect(1, 0, Duration.EndOfTurn),new ManaCostsImpl<>("{R}"));
ability.addTarget(new TargetCreaturePermanent(1, 1, filter2, true));
Ability ability = new SimpleActivatedAbility(new BoostTargetEffect(1, 0, Duration.EndOfTurn), new ColoredManaCost(ColoredManaSymbol.R));
ability.addTarget(new TargetPermanent(filter2));
this.addAbility(ability);
}

View file

@ -5,7 +5,7 @@ import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.PreventionEffectData;
import mage.abilities.effects.PreventionEffectImpl;
import mage.cards.Card;
@ -13,6 +13,7 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
@ -21,7 +22,7 @@ import mage.target.TargetSource;
/**
*
* @author jeffwadsworth
* @author awjackson
*/
public final class BoneMask extends CardImpl {
@ -29,11 +30,9 @@ public final class BoneMask extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{4}");
// {2}, {tap}: The next time a source of your choice would deal damage to you this turn, prevent that damage. Exile cards from the top of your library equal to the damage prevented this way.
Ability ability = new SimpleActivatedAbility(new BoneMaskEffect(), new ManaCostsImpl<>("{2}"));
Ability ability = new SimpleActivatedAbility(new BoneMaskEffect(), new GenericManaCost(2));
ability.addCost(new TapSourceCost());
ability.addTarget(new TargetSource());
this.addAbility(ability);
}
private BoneMask(final BoneMask card) {
@ -48,14 +47,18 @@ public final class BoneMask extends CardImpl {
class BoneMaskEffect extends PreventionEffectImpl {
private final TargetSource target;
public BoneMaskEffect() {
super(Duration.EndOfTurn, Integer.MAX_VALUE, false, false);
super(Duration.EndOfTurn);
this.staticText = "The next time a source of your choice would deal damage to you this turn, prevent that damage. "
+ "Exile cards from the top of your library equal to the damage prevented this way.";
this.target = new TargetSource();
}
public BoneMaskEffect(final BoneMaskEffect effect) {
super(effect);
this.target = effect.target.copy();
}
@Override
@ -64,31 +67,32 @@ class BoneMaskEffect extends PreventionEffectImpl {
}
@Override
public boolean apply(Game game, Ability source) {
return true;
public void init(Ability source, Game game) {
this.target.choose(Outcome.PreventDamage, source.getControllerId(), source.getSourceId(), source, game);
super.init(source, game);
}
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
this.used = true;
this.discard();
if (preventionData.getPreventedDamage() > 0) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Card> cards = controller.getLibrary().getTopCards(game, preventionData.getPreventedDamage());
controller.moveCards(cards, Zone.EXILED, source, game);
}
}
return false;
}
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (!this.used
&& super.applies(event, source, game)) {
if (event.getTargetId().equals(source.getControllerId())
&& event.getSourceId().equals(source.getFirstTarget())) {
PreventionEffectData preventionData = preventDamageAction(event, source, game);
this.used = true;
this.discard();
if (preventionData.getPreventedDamage() > 0) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Card> cardsToMoveToExileFromTopOfLibrary = controller.getLibrary().getTopCards(
game,
preventionData.getPreventedDamage());
controller.moveCards(cardsToMoveToExileFromTopOfLibrary, Zone.EXILED, source, game);
}
}
}
return true;
}
return false;
return (!this.used
&& super.applies(event, source, game)
&& event.getTargetId().equals(source.getControllerId())
&& event.getSourceId().equals(target.getFirstTarget())
);
}
}

View file

@ -5,19 +5,19 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.constants.SubType;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.TargetPermanent;
/**
*
* @author TheElk801
* @author awjackson
*/
public final class HeavenlyQilin extends CardImpl {
@ -38,13 +38,8 @@ public final class HeavenlyQilin extends CardImpl {
this.addAbility(FlyingAbility.getInstance());
// Whenenver Heavenly Qilin attacks, another target creature you control gains flying until end of turn.
Ability ability = new AttacksTriggeredAbility(
new GainAbilityTargetEffect(
FlyingAbility.getInstance(),
Duration.EndOfTurn
), false
);
ability.addTarget(new TargetControlledCreaturePermanent(1, 1, filter, true));
Ability ability = new AttacksTriggeredAbility(new GainAbilityTargetEffect(FlyingAbility.getInstance(), Duration.EndOfTurn));
ability.addTarget(new TargetPermanent(filter));
this.addAbility(ability);
}

View file

@ -1,4 +1,3 @@
package mage.cards.h;
import java.util.UUID;
@ -12,19 +11,12 @@ import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.keyword.ShroudAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.TargetPermanent;
/**
@ -32,10 +24,15 @@ import mage.target.common.TargetControlledCreaturePermanent;
*/
public final class HisokasGuard extends CardImpl {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature you control other than Hisoka's Guard");
static {
filter.add(AnotherPredicate.instance);
}
public HisokasGuard(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{1}{U}");
this.subtype.add(SubType.HUMAN);
this.subtype.add(SubType.WIZARD);
this.subtype.add(SubType.HUMAN, SubType.WIZARD);
this.power = new MageInt(1);
this.toughness = new MageInt(1);
@ -44,14 +41,10 @@ public final class HisokasGuard extends CardImpl {
this.addAbility(new SkipUntapOptionalAbility());
// {1}{U}, {T}: Target creature you control other than Hisoka's Guard has shroud for as long as Hisoka's Guard remains tapped. (It can't be the target of spells or abilities.)
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(AnotherPredicate.instance);
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new HisokasGuardGainAbilityTargetEffect(), new ManaCostsImpl<>("{1}{U}"));
Ability ability = new SimpleActivatedAbility(new HisokasGuardGainAbilityTargetEffect(), new ManaCostsImpl<>("{1}{U}"));
ability.addCost(new TapSourceCost());
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
ability.addTarget(target);
ability.addTarget(new TargetPermanent(filter));
this.addAbility(ability);
}
private HisokasGuard(final HisokasGuard card) {

View file

@ -1,12 +1,11 @@
package mage.cards.l;
import mage.MageInt;
import mage.MageObjectReference;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.abilities.keyword.TrampleAbility;
@ -16,17 +15,14 @@ import mage.constants.*;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.events.DamagedPlayerEvent;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.common.TargetLandPermanent;
import mage.target.TargetPermanent;
import java.util.Iterator;
import java.util.UUID;
/**
* @author Loki
* @author awjackson
*/
public final class LiegeOfTheTangle extends CardImpl {
@ -36,8 +32,19 @@ public final class LiegeOfTheTangle extends CardImpl {
this.power = new MageInt(8);
this.toughness = new MageInt(8);
// Trample
this.addAbility(TrampleAbility.getInstance());
this.addAbility(new LiegeOfTheTangleTriggeredAbility());
// Whenever Liege of the Tangle deals combat damage to a player, you may choose any number of target lands you control
// and put an awakening counter on each of them. Each of those lands is an 8/8 green Elemental creature
// for as long as it has an awakening counter on it. They're still lands.
Effect effect = new AddCountersTargetEffect(CounterType.AWAKENING.createInstance());
effect.setText("you may choose any number of target lands you control and put an awakening counter on each of them");
Ability ability = new DealsCombatDamageToAPlayerTriggeredAbility(effect, false);
ability.addEffect(new LiegeOfTheTangleEffect());
ability.addTarget(new TargetPermanent(0, Integer.MAX_VALUE, StaticFilters.FILTER_CONTROLLED_PERMANENT_LANDS));
this.addAbility(ability);
}
private LiegeOfTheTangle(final LiegeOfTheTangle card) {
@ -50,45 +57,11 @@ public final class LiegeOfTheTangle extends CardImpl {
}
}
class LiegeOfTheTangleTriggeredAbility extends TriggeredAbilityImpl {
LiegeOfTheTangleTriggeredAbility() {
super(Zone.BATTLEFIELD, new AddCountersTargetEffect(CounterType.AWAKENING.createInstance()));
this.addEffect(new LiegeOfTheTangleEffect());
Target target = new TargetLandPermanent(0, Integer.MAX_VALUE, StaticFilters.FILTER_LANDS, true);
this.addTarget(target);
}
public LiegeOfTheTangleTriggeredAbility(final LiegeOfTheTangleTriggeredAbility ability) {
super(ability);
}
@Override
public LiegeOfTheTangleTriggeredAbility copy() {
return new LiegeOfTheTangleTriggeredAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DAMAGED_PLAYER;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
Permanent p = game.getPermanent(event.getSourceId());
return damageEvent.isCombatDamage() && p != null && p.getId().equals(this.getSourceId());
}
@Override
public String getRule() {
return "Whenever {this} deals combat damage to a player, you may choose any number of target lands you control and put an awakening counter on each of them. Each of those lands is an 8/8 green Elemental creature for as long as it has an awakening counter on it. They're still lands.";
}
}
class LiegeOfTheTangleEffect extends ContinuousEffectImpl {
public LiegeOfTheTangleEffect() {
super(Duration.EndOfGame, Outcome.BecomeCreature);
staticText = "each of those lands is an 8/8 green Elemental creature for as long as it has an awakening counter on it. They're still lands";
}
public LiegeOfTheTangleEffect(final LiegeOfTheTangleEffect effect) {

View file

@ -1,37 +1,36 @@
package mage.cards.m;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.constants.SubType;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.target.Target;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.TargetPermanent;
/**
*
* @author L_J
* @author awjackson
*/
public final class MajesticHeliopterus extends CardImpl {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("another target Dinosaur you control");
private static final FilterControlledPermanent filter = new FilterControlledPermanent(SubType.DINOSAUR, "another target Dinosaur you control");
static {
filter.add(AnotherPredicate.instance);
filter.add(SubType.DINOSAUR.getPredicate());
}
public MajesticHeliopterus(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{3}{W}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}");
this.subtype.add(SubType.DINOSAUR);
this.power = new MageInt(2);
this.toughness = new MageInt(2);
@ -39,10 +38,8 @@ public final class MajesticHeliopterus extends CardImpl {
this.addAbility(FlyingAbility.getInstance());
// Whenever Majestic Heliopterus attacks, another target Dinosaur you control gains flying until end of turn.
Effect effect = new GainAbilityTargetEffect(FlyingAbility.getInstance(), Duration.EndOfTurn);
Ability ability = new AttacksTriggeredAbility(effect, false);
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
ability.addTarget(target);
Ability ability = new AttacksTriggeredAbility(new GainAbilityTargetEffect(FlyingAbility.getInstance(), Duration.EndOfTurn));
ability.addTarget(new TargetPermanent(filter));
this.addAbility(ability);
}

View file

@ -51,7 +51,7 @@ class RoguesGalleryTarget extends TargetCardInYourGraveyard {
}
RoguesGalleryTarget() {
super(0, Integer.MAX_VALUE, filter, true);
super(0, Integer.MAX_VALUE, filter);
}
private RoguesGalleryTarget(final RoguesGalleryTarget target) {

View file

@ -1,35 +1,34 @@
package mage.cards.t;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.AttacksTriggeredAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration;
import mage.constants.SubType;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.target.Target;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.TargetPermanent;
/**
*
* @author LevelX2
* @author awjackson
*/
public final class TrainedCondor extends CardImpl {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("another target creature you control");
static {
filter.add(AnotherPredicate.instance);
}
public TrainedCondor(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{U}");
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{U}");
this.subtype.add(SubType.BIRD);
this.power = new MageInt(2);
@ -37,11 +36,10 @@ public final class TrainedCondor extends CardImpl {
// Flying
this.addAbility(FlyingAbility.getInstance());
// Whenever Trained Condor attacks, another target creature you control gains flying until end of turn.
Effect effect = new GainAbilityTargetEffect(FlyingAbility.getInstance(), Duration.EndOfTurn);
Ability ability = new AttacksTriggeredAbility(effect, false);
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
ability.addTarget(target);
Ability ability = new AttacksTriggeredAbility(new GainAbilityTargetEffect(FlyingAbility.getInstance(), Duration.EndOfTurn));
ability.addTarget(new TargetPermanent(filter));
this.addAbility(ability);
}