Imporved setTargetPointer of EntersBattlefieldAllTriggeredAbility.

This commit is contained in:
LevelX2 2014-12-12 14:24:59 +01:00
parent 1ed1bc2e0d
commit 00281f0b10
16 changed files with 84 additions and 64 deletions

View file

@ -39,6 +39,7 @@ import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SetTargetPointer;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterSpell; import mage.filter.FilterSpell;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterControlledCreaturePermanent;
@ -88,7 +89,7 @@ public class RikuOfTwoReflections extends CardImpl {
// Whenever another nontoken creature enters the battlefield under your control, you may pay {G}{U}. If you do, put a token that's a copy of that creature onto the battlefield. // Whenever another nontoken creature enters the battlefield under your control, you may pay {G}{U}. If you do, put a token that's a copy of that creature onto the battlefield.
Ability ability = new EntersBattlefieldAllTriggeredAbility( Ability ability = new EntersBattlefieldAllTriggeredAbility(
Zone.BATTLEFIELD, new RikuOfTwoReflectionsCopyTokenEffect(),filterPermanent, false, true, Zone.BATTLEFIELD, new RikuOfTwoReflectionsCopyTokenEffect(),filterPermanent, false, SetTargetPointer.PERMANENT,
"Whenever another nontoken creature enters the battlefield under your control, you may pay {G}{U}. If you do, put a token that's a copy of that creature onto the battlefield.", "Whenever another nontoken creature enters the battlefield under your control, you may pay {G}{U}. If you do, put a token that's a copy of that creature onto the battlefield.",
true); true);
ability.addCost(new ManaCostsImpl("{G}{U}")); ability.addCost(new ManaCostsImpl("{G}{U}"));

View file

@ -36,6 +36,7 @@ import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SetTargetPointer;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
@ -78,7 +79,7 @@ class GenesisChamberTriggeredAbility extends EntersBattlefieldAllTriggeredAbilit
private static final String rule = "Whenever a nontoken creature enters the battlefield, if {this} is untapped, that creature's controller puts a 1/1 colorless Myr artifact creature token onto the battlefield"; private static final String rule = "Whenever a nontoken creature enters the battlefield, if {this} is untapped, that creature's controller puts a 1/1 colorless Myr artifact creature token onto the battlefield";
public GenesisChamberTriggeredAbility(Effect effect, FilterPermanent filter) public GenesisChamberTriggeredAbility(Effect effect, FilterPermanent filter)
{ {
super(Zone.BATTLEFIELD, effect, filter, false, true, rule); super(Zone.BATTLEFIELD, effect, filter, false, SetTargetPointer.PERMANENT, rule);
} }
public GenesisChamberTriggeredAbility(final GenesisChamberTriggeredAbility ability) { public GenesisChamberTriggeredAbility(final GenesisChamberTriggeredAbility ability) {

View file

@ -37,6 +37,7 @@ import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SetTargetPointer;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.common.FilterControlledPermanent; import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.mageobject.CardTypePredicate;
@ -67,7 +68,9 @@ public class AjanisChosen extends CardImpl {
this.toughness = new MageInt(3); this.toughness = new MageInt(3);
// Whenever an enchantment enters the battlefield under your control, put a 2/2 white Cat creature token onto the battlefield. If that enchantment is an Aura, you may attach it to the token. // Whenever an enchantment enters the battlefield under your control, put a 2/2 white Cat creature token onto the battlefield. If that enchantment is an Aura, you may attach it to the token.
this.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new AjanisChosenEffect(), filter, false, true, "Whenever an enchantment enters the battlefield under your control, put a 2/2 white Cat creature token onto the battlefield. If that enchantment is an Aura, you may attach it to the token")); this.addAbility(new EntersBattlefieldAllTriggeredAbility(
Zone.BATTLEFIELD, new AjanisChosenEffect(), filter, false, SetTargetPointer.PERMANENT,
"Whenever an enchantment enters the battlefield under your control, put a 2/2 white Cat creature token onto the battlefield. If that enchantment is an Aura, you may attach it to the token"));
} }
public AjanisChosen(final AjanisChosen card) { public AjanisChosen(final AjanisChosen card) {

View file

@ -35,6 +35,7 @@ import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SetTargetPointer;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.constants.Zone; import mage.constants.Zone;
import mage.counters.CounterType; import mage.counters.CounterType;
@ -61,7 +62,7 @@ public class OathOfTheAncientWood extends CardImpl {
// Whenever Oath of the Ancient Wood or another enchantment enters the battlefield under your control, you may put a +1/+1 counter on target creature. // Whenever Oath of the Ancient Wood or another enchantment enters the battlefield under your control, you may put a +1/+1 counter on target creature.
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance()); Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance());
Ability ability = new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, effect, filter, true, false, null, true); Ability ability = new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, effect, filter, true, SetTargetPointer.PERMANENT, null, true);
ability.addTarget(new TargetCreaturePermanent()); ability.addTarget(new TargetCreaturePermanent());
this.addAbility(ability); this.addAbility(ability);
} }

View file

@ -38,6 +38,7 @@ import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SetTargetPointer;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
@ -70,7 +71,7 @@ public class OgreBattledriver extends CardImpl {
this.toughness = new MageInt(3); this.toughness = new MageInt(3);
// Whenever another creature enters the battlefield under your control, that creature gets +2/+0 and gains haste until end of turn. // Whenever another creature enters the battlefield under your control, that creature gets +2/+0 and gains haste until end of turn.
Ability ability = new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new BoostTargetEffect(2, 0, Duration.EndOfTurn), filter, false, true, rule, true); Ability ability = new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new BoostTargetEffect(2, 0, Duration.EndOfTurn), filter, false, SetTargetPointer.PERMANENT, rule, true);
ability.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn)); ability.addEffect(new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn));
this.addAbility(ability); this.addAbility(ability);

View file

@ -43,6 +43,7 @@ import mage.abilities.effects.common.continious.GainAbilityAttachedEffect;
import mage.abilities.keyword.EquipAbility; import mage.abilities.keyword.EquipAbility;
import mage.abilities.keyword.ShroudAbility; import mage.abilities.keyword.ShroudAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.SetTargetPointer;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
@ -71,7 +72,7 @@ public class CloakAndDagger extends CardImpl {
// Whenever a Rogue creature enters the battlefield, you may attach Cloak and Dagger to it. // Whenever a Rogue creature enters the battlefield, you may attach Cloak and Dagger to it.
this.addAbility(new EntersBattlefieldAllTriggeredAbility( this.addAbility(new EntersBattlefieldAllTriggeredAbility(
Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"), Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"),
filter, true, true, null)); filter, true, SetTargetPointer.PERMANENT, null));
// Equip {3} // Equip {3}
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3))); this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3)));
} }

View file

@ -49,6 +49,7 @@ import mage.abilities.effects.common.continious.GainAbilitySourceEffect;
import mage.abilities.keyword.EquipAbility; import mage.abilities.keyword.EquipAbility;
import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.SetTargetPointer;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
@ -85,7 +86,7 @@ public class DivinersWand extends CardImpl {
// Whenever a Wizard creature enters the battlefield, you may attach Diviner's Wand to it. // Whenever a Wizard creature enters the battlefield, you may attach Diviner's Wand to it.
this.addAbility(new EntersBattlefieldAllTriggeredAbility( this.addAbility(new EntersBattlefieldAllTriggeredAbility(
Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"), Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"),
filter, true, true, null)); filter, true, SetTargetPointer.PERMANENT, null));
// Equip {3} // Equip {3}
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3))); this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3)));
} }

View file

@ -43,6 +43,7 @@ import mage.abilities.effects.common.continious.GainAbilityAttachedEffect;
import mage.abilities.keyword.EquipAbility; import mage.abilities.keyword.EquipAbility;
import mage.abilities.keyword.HasteAbility; import mage.abilities.keyword.HasteAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.SetTargetPointer;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
@ -71,7 +72,7 @@ public class ObsidianBattleAxe extends CardImpl {
// Whenever a Warrior creature enters the battlefield, you may attach Obsidian Battle-Axe to it. // Whenever a Warrior creature enters the battlefield, you may attach Obsidian Battle-Axe to it.
this.addAbility(new EntersBattlefieldAllTriggeredAbility( this.addAbility(new EntersBattlefieldAllTriggeredAbility(
Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"), Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"),
filter, true, true, null)); filter, true, SetTargetPointer.PERMANENT, null));
// Equip {3} // Equip {3}
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3))); this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(3)));
} }

View file

@ -47,6 +47,7 @@ import mage.abilities.effects.common.UntapSourceEffect;
import mage.abilities.effects.common.continious.GainAbilityAttachedEffect; import mage.abilities.effects.common.continious.GainAbilityAttachedEffect;
import mage.abilities.keyword.EquipAbility; import mage.abilities.keyword.EquipAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.SetTargetPointer;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
@ -83,7 +84,7 @@ public class ThornbiteStaff extends CardImpl {
// Whenever a Shaman creature enters the battlefield, you may attach Thornbite Staff to it. // Whenever a Shaman creature enters the battlefield, you may attach Thornbite Staff to it.
this.addAbility(new EntersBattlefieldAllTriggeredAbility( this.addAbility(new EntersBattlefieldAllTriggeredAbility(
Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"), Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"),
filter, true, true, null)); filter, true, SetTargetPointer.PERMANENT, null));
// Equip {4} // Equip {4}
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(4))); this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(4)));
} }

View file

@ -47,6 +47,7 @@ import mage.abilities.effects.common.continious.BoostSourceEffect;
import mage.abilities.effects.common.continious.GainAbilityAttachedEffect; import mage.abilities.effects.common.continious.GainAbilityAttachedEffect;
import mage.abilities.keyword.EquipAbility; import mage.abilities.keyword.EquipAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.SetTargetPointer;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate; import mage.filter.predicate.mageobject.SubtypePredicate;
@ -79,7 +80,8 @@ public class VeteransArmaments extends CardImpl {
// Whenever a Soldier creature enters the battlefield, you may attach Veteran's Armaments to it. // Whenever a Soldier creature enters the battlefield, you may attach Veteran's Armaments to it.
this.addAbility(new EntersBattlefieldAllTriggeredAbility( this.addAbility(new EntersBattlefieldAllTriggeredAbility(
Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"), Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"),
filter, true, true, null)); filter, true, SetTargetPointer.PERMANENT, null));
// Equip {2} // Equip {2}
this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(2))); this.addAbility(new EquipAbility(Outcome.AddAbility, new GenericManaCost(2)));
} }

View file

@ -40,6 +40,7 @@ import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.continious.BoostEquippedEffect; import mage.abilities.effects.common.continious.BoostEquippedEffect;
import mage.abilities.keyword.EquipAbility; import mage.abilities.keyword.EquipAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.SetTargetPointer;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.ControllerPredicate; import mage.filter.predicate.permanent.ControllerPredicate;
@ -65,8 +66,7 @@ public class SaiOfTheShinobi extends CardImpl {
// Whenever a creature enters the battlefield under your control, you may attach Sai of the Shinobi to it. // Whenever a creature enters the battlefield under your control, you may attach Sai of the Shinobi to it.
this.addAbility(new EntersBattlefieldAllTriggeredAbility( this.addAbility(new EntersBattlefieldAllTriggeredAbility(
Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"), Zone.BATTLEFIELD, new AttachEffect(Outcome.Detriment, "attach {source} to it"),
filter, true, true, filter, true, SetTargetPointer.PERMANENT, null, true));
null, true));
// Equip {2} // Equip {2}
this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(2))); this.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(2)));
} }

View file

@ -30,15 +30,16 @@ package mage.sets.ravnika;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldAllTriggeredAbility; import mage.abilities.common.EntersBattlefieldAllTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SetTargetPointer;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates; import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate; import mage.filter.predicate.mageobject.CardTypePredicate;
@ -66,7 +67,7 @@ public class CloudstoneCurio extends CardImpl {
this.expansionSetCode = "RAV"; this.expansionSetCode = "RAV";
// Whenever a nonartifact permanent enters the battlefield under your control, you may return another permanent you control that shares a card type with it to its owner's hand. // Whenever a nonartifact permanent enters the battlefield under your control, you may return another permanent you control that shares a card type with it to its owner's hand.
this.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new CloudstoneCurioEffect(), filter, true, true, "", true)); this.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new CloudstoneCurioEffect(), filter, true, SetTargetPointer.PERMANENT, "", true));
} }
@ -99,34 +100,31 @@ class CloudstoneCurioEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent triggeringCreature = game.getPermanent(getTargetPointer().getFirst(game, source)); Player controller = game.getPlayer(source.getControllerId());
if (triggeringCreature == null) { if (controller != null) {
triggeringCreature = (Permanent) game.getLastKnownInformation(getTargetPointer().getFirst(game, source), Zone.BATTLEFIELD); Permanent triggeringCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
} if (triggeringCreature == null) {
if (triggeringCreature != null) { triggeringCreature = (Permanent) game.getLastKnownInformation(getTargetPointer().getFirst(game, source), Zone.BATTLEFIELD);
FilterPermanent filter = new FilterPermanent("another permanent you control that shares a card type with " + triggeringCreature.getName());
filter.add(Predicates.not(new PermanentIdPredicate(triggeringCreature.getId())));
filter.add(new ControllerPredicate(TargetController.YOU));
Set<CardTypePredicate> cardTypes = new HashSet<CardTypePredicate>();
for (CardType cardType :triggeringCreature.getCardType()) {
cardTypes.add(new CardTypePredicate(cardType));
} }
filter.add(Predicates.or(cardTypes)); if (triggeringCreature != null) {
TargetPermanent target = new TargetPermanent(1,1,filter, true); FilterPermanent filter = new FilterPermanent("another permanent you control that shares a card type with " + triggeringCreature.getName());
Player controller = game.getPlayer(source.getControllerId()); filter.add(Predicates.not(new PermanentIdPredicate(triggeringCreature.getId())));
if (controller != null) { filter.add(new ControllerPredicate(TargetController.YOU));
Set<CardTypePredicate> cardTypes = new HashSet<>();
for (CardType cardType : triggeringCreature.getCardType()) {
cardTypes.add(new CardTypePredicate(cardType));
}
filter.add(Predicates.or(cardTypes));
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
if (target.canChoose(controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) { if (target.canChoose(controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
Permanent returningCreature = game.getPermanent(target.getFirstTarget()); Permanent returningCreature = game.getPermanent(target.getFirstTarget());
if (returningCreature != null) { if (returningCreature != null) {
if (returningCreature.moveToZone(Zone.HAND, source.getSourceId(), game, true)) { controller.moveCardToHandWithInfo(returningCreature, source.getSourceId(), game, Zone.BATTLEFIELD);
game.informPlayers(new StringBuilder("Cloudstone Curio: Returning ").append(returningCreature.getName()).append(" to owner's hand").toString());
return true;
}
} }
} }
} }
return true;
} }
return false; return false;
} }

View file

@ -35,12 +35,12 @@ import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SetTargetPointer;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.common.FilterLandPermanent; import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.permanent.ControllerPredicate; import mage.filter.predicate.permanent.ControllerPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
/** /**
@ -64,7 +64,7 @@ public class PollutedBonds extends CardImpl {
this.color.setBlack(true); this.color.setBlack(true);
// Whenever a land enters the battlefield under an opponent's control, that player loses 2 life and you gain 2 life. // Whenever a land enters the battlefield under an opponent's control, that player loses 2 life and you gain 2 life.
this.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new PollutedBondsEffect(), filter, false, true, rule, true)); this.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new PollutedBondsEffect(), filter, false, SetTargetPointer.PLAYER, rule, true));
} }
@ -96,18 +96,15 @@ class PollutedBondsEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Player opponent = null; if (controller != null) {
Permanent land = game.getPermanent(targetPointer.getFirst(game, source)); Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (land != null) { if (opponent != null) {
opponent = game.getPlayer(land.getControllerId()); opponent.loseLife(2, game);
}
controller.gainLife(2, game);
return true;
} }
if (opponent != null) { return false;
opponent.loseLife(2, game);
}
if (you != null) {
you.gainLife(2, game);
}
return true;
} }
} }

View file

@ -41,6 +41,7 @@ import mage.abilities.effects.common.combat.CantBlockAttackActivateAttachedEffec
import mage.abilities.keyword.EnchantAbility; import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SetTargetPointer;
import mage.constants.TargetController; import mage.constants.TargetController;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
@ -82,7 +83,7 @@ public class PrisonTerm extends CardImpl {
// Whenever a creature enters the battlefield under an opponent's control, you may attach Prison Term to that creature. // Whenever a creature enters the battlefield under an opponent's control, you may attach Prison Term to that creature.
this.addAbility(new EntersBattlefieldAllTriggeredAbility( this.addAbility(new EntersBattlefieldAllTriggeredAbility(
Zone.BATTLEFIELD, new PrisonTermEffect(), filter, true, true, "Whenever a creature enters the battlefield under an opponent's control, you may attach Prison Term to that creature.")); Zone.BATTLEFIELD, new PrisonTermEffect(), filter, true, SetTargetPointer.PERMANENT, "Whenever a creature enters the battlefield under an opponent's control, you may attach Prison Term to that creature."));
} }
public PrisonTerm(final PrisonTerm card) { public PrisonTerm(final PrisonTerm card) {

View file

@ -28,9 +28,11 @@
package mage.abilities.common; package mage.abilities.common;
import java.util.UUID; import java.util.UUID;
import mage.constants.Zone;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.constants.SetTargetPointer;
import static mage.constants.SetTargetPointer.PERMANENT;
import mage.constants.Zone;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -46,7 +48,7 @@ public class EntersBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
protected FilterPermanent filter; protected FilterPermanent filter;
protected String rule; protected String rule;
protected boolean controlled; protected boolean controlled;
protected boolean setTargetPointer; protected SetTargetPointer setTargetPointer;
/** /**
* zone = BATTLEFIELD optional = false * zone = BATTLEFIELD optional = false
@ -63,7 +65,7 @@ public class EntersBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
} }
public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional) { public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional) {
this(zone, effect, filter, optional, false, null, false); this(zone, effect, filter, optional, SetTargetPointer.NONE, null, false);
} }
public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, String rule) { public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, String rule) {
@ -71,14 +73,14 @@ public class EntersBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
} }
public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, String rule, boolean controlled) { public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, String rule, boolean controlled) {
this(zone, effect, filter, optional, false, rule, controlled); this(zone, effect, filter, optional, SetTargetPointer.NONE, rule, controlled);
} }
public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, boolean setTargetPointer, String rule) { public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, SetTargetPointer setTargetPointer, String rule) {
this(zone, effect, filter, optional, setTargetPointer, rule, false); this(zone, effect, filter, optional, setTargetPointer, rule, false);
} }
public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, boolean setTargetPointer, String rule, boolean controlled) { public EntersBattlefieldAllTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, SetTargetPointer setTargetPointer, String rule, boolean controlled) {
super(zone, effect, optional); super(zone, effect, optional);
this.filter = filter; this.filter = filter;
this.rule = rule; this.rule = rule;
@ -100,9 +102,17 @@ public class EntersBattlefieldAllTriggeredAbility extends TriggeredAbilityImpl {
UUID targetId = event.getTargetId(); UUID targetId = event.getTargetId();
Permanent permanent = game.getPermanent(targetId); Permanent permanent = game.getPermanent(targetId);
if (permanent != null && filter.match(permanent, getSourceId(), getControllerId(), game)) { if (permanent != null && filter.match(permanent, getSourceId(), getControllerId(), game)) {
if (setTargetPointer) { if (!setTargetPointer.equals(SetTargetPointer.NONE)) {
for (Effect effect : this.getEffects()) { for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId())); switch(setTargetPointer) {
case PERMANENT:
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
break;
case PLAYER:
effect.setTargetPointer(new FixedTarget(permanent.getControllerId()));
break;
}
} }
} }
return true; return true;

View file

@ -29,6 +29,7 @@
package mage.abilities.common; package mage.abilities.common;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.constants.SetTargetPointer;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.game.Game; import mage.game.Game;
@ -63,10 +64,10 @@ public class EntersBattlefieldControlledTriggeredAbility extends EntersBattlefie
} }
public EntersBattlefieldControlledTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, String rule) { public EntersBattlefieldControlledTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, String rule) {
this(zone, effect, filter, optional, false, rule); this(zone, effect, filter, optional, SetTargetPointer.NONE, rule);
} }
public EntersBattlefieldControlledTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, boolean setTargetPointer, String rule) { public EntersBattlefieldControlledTriggeredAbility(Zone zone, Effect effect, FilterPermanent filter, boolean optional, SetTargetPointer setTargetPointer, String rule) {
super(zone, effect, filter, optional, setTargetPointer, rule, true); super(zone, effect, filter, optional, setTargetPointer, rule, true);
} }