Improved CreatureEntersBattlefieldTriggeredAbility: if a target is required for the effect then that target must be added in the constructor.

This commit is contained in:
North 2011-05-18 20:57:16 +03:00
parent 3e3957e323
commit 0e7ef05c5d
2 changed files with 25 additions and 6 deletions

View file

@ -34,6 +34,7 @@ import mage.MageInt;
import mage.abilities.common.CreatureEntersBattlefieldTriggeredAbility;
import mage.abilities.effects.common.LoseLifeTargetEffect;
import mage.cards.CardImpl;
import mage.target.TargetPlayer;
/**
*
@ -51,7 +52,7 @@ public class BloodSeeker extends CardImpl<BloodSeeker> {
this.power = new MageInt(1);
this.toughness = new MageInt(1);
this.addAbility(new CreatureEntersBattlefieldTriggeredAbility(new LoseLifeTargetEffect(1), true, true));
this.addAbility(new CreatureEntersBattlefieldTriggeredAbility(new LoseLifeTargetEffect(1), true, true, new TargetPlayer()));
}
public BloodSeeker(final BloodSeeker card) {

View file

@ -36,7 +36,9 @@ import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.TargetPlayer;
import mage.target.common.TargetCreaturePermanent;
/**
*
@ -76,7 +78,19 @@ public class CreatureEntersBattlefieldTriggeredAbility extends TriggeredAbilityI
public CreatureEntersBattlefieldTriggeredAbility(Effect effect, boolean optional, boolean opponentController) {
super(Zone.BATTLEFIELD, effect, optional);
this.opponentController = opponentController;
this.addTarget(new TargetPlayer());
}
/**
*
* @param effect
* @param optional
* @param opponentController
* @param target - needed if the ability targets a player or a creature
*/
public CreatureEntersBattlefieldTriggeredAbility(Effect effect, boolean optional, boolean opponentController, Target target) {
super(Zone.BATTLEFIELD, effect, optional);
this.opponentController = opponentController;
this.addTarget(target);
}
public CreatureEntersBattlefieldTriggeredAbility(CreatureEntersBattlefieldTriggeredAbility ability) {
@ -90,10 +104,14 @@ public class CreatureEntersBattlefieldTriggeredAbility extends TriggeredAbilityI
if (((ZoneChangeEvent) event).getToZone() == Zone.BATTLEFIELD
&& permanent.getCardType().contains(CardType.CREATURE)
&& (permanent.getControllerId().equals(this.controllerId) ^ opponentController)) {
if (opponentController) {
this.getTargets().get(0).add(permanent.getControllerId(), game);
} else {
this.getTargets().remove(0);
if (!this.getTargets().isEmpty()) {
Target target = this.getTargets().get(0);
if (target instanceof TargetPlayer) {
target.add(permanent.getControllerId(), game);
}
if (target instanceof TargetCreaturePermanent) {
target.add(event.getTargetId(), game);
}
}
return true;
}