mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
* Guardian Angel - Fixed activated action.
This commit is contained in:
parent
8e51e3a2bf
commit
25c9a28184
1 changed files with 108 additions and 17 deletions
|
@ -28,19 +28,27 @@
|
|||
package mage.cards.g;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.DelayedTriggeredAbility;
|
||||
import mage.abilities.SpecialAction;
|
||||
import mage.abilities.costs.mana.GenericManaCost;
|
||||
import mage.abilities.dynamicvalue.common.ManacostVariableValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect;
|
||||
import mage.abilities.effects.common.CreateSpecialActionEffect;
|
||||
import mage.abilities.effects.common.PreventDamageToTargetEffect;
|
||||
import mage.abilities.effects.common.RemoveSpecialActionEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.TimingRule;
|
||||
import mage.constants.Zone;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCreatureOrPlayer;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -50,20 +58,10 @@ public class GuardianAngel extends CardImpl {
|
|||
|
||||
public GuardianAngel(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{X}{W}");
|
||||
|
||||
|
||||
// Prevent the next X damage that would be dealt to target creature or player this turn. Until end of turn, you may pay {1} any time you could cast an instant. If you do, prevent the next 1 damage that would be dealt to that creature or player this turn.
|
||||
ManacostVariableValue manaX = new ManacostVariableValue();
|
||||
Effect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, false, true, manaX);
|
||||
effect.setText("Prevent the next X damage that would be dealt to target creature or player this turn.");
|
||||
this.getSpellAbility().addEffect(effect);
|
||||
this.getSpellAbility().addEffect(new GuardianAngelEffect());
|
||||
this.getSpellAbility().addTarget(new TargetCreatureOrPlayer());
|
||||
Effect effect2 = new PreventDamageToTargetEffect(Duration.EndOfTurn, 1);
|
||||
effect2.setTargetPointer(new FixedTarget(this.getSpellAbility().getFirstTarget()));
|
||||
effect2.setText(" Until end of turn, you may pay {1} any time you could cast an instant. If you do, prevent the next 1 damage that would be dealt to that creature or player this turn.");
|
||||
SimpleActivatedAbility ability = new SimpleActivatedAbility(Zone.ALL, effect2, new GenericManaCost(1));
|
||||
ability.setTiming(TimingRule.INSTANT);
|
||||
this.addAbility(ability);
|
||||
}
|
||||
|
||||
public GuardianAngel(final GuardianAngel card) {
|
||||
|
@ -75,3 +73,96 @@ public class GuardianAngel extends CardImpl {
|
|||
return new GuardianAngel(this);
|
||||
}
|
||||
}
|
||||
|
||||
class GuardianAngelEffect extends OneShotEffect {
|
||||
|
||||
public GuardianAngelEffect() {
|
||||
super(Outcome.Benefit);
|
||||
this.staticText = "Prevent the next X damage that would be dealt to target creature or player this turn. Until end of turn, you may pay {1} any time you could cast an instant. If you do, prevent the next 1 damage that would be dealt to that creature or player this turn";
|
||||
}
|
||||
|
||||
public GuardianAngelEffect(final GuardianAngelEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuardianAngelEffect copy() {
|
||||
return new GuardianAngelEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
String targetName = "";
|
||||
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
|
||||
if (targetPlayer == null) {
|
||||
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
|
||||
if (targetPermanent == null) {
|
||||
return true;
|
||||
}
|
||||
targetName = targetPermanent.getIdName();
|
||||
} else {
|
||||
targetName = "player " + targetPlayer.getName();
|
||||
}
|
||||
ContinuousEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, source.getManaCostsToPay().getX(), false);
|
||||
effect.setTargetPointer(getTargetPointer());
|
||||
game.addEffect(effect, source);
|
||||
SpecialAction specialAction = new GuardianAngelAction();
|
||||
specialAction.getEffects().get(0).setTargetPointer(getTargetPointer());
|
||||
specialAction.getEffects().get(0).setText("Prevent the next 1 damage that would be dealt to target creature or player this turn (" + targetName + ").");
|
||||
new CreateSpecialActionEffect(specialAction).apply(game, source);
|
||||
// Create a hidden delayed triggered ability to remove the special action at end of turn.
|
||||
new CreateDelayedTriggeredAbilityEffect(new GuardianAngelDelayedTriggeredAbility(specialAction.getId()), false).apply(game, source);
|
||||
return true;
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
class GuardianAngelAction extends SpecialAction {
|
||||
|
||||
GuardianAngelAction() {
|
||||
super();
|
||||
this.addCost(new GenericManaCost(1));
|
||||
this.addEffect(new PreventDamageToTargetEffect(Duration.EndOfTurn, 1));
|
||||
}
|
||||
|
||||
GuardianAngelAction(final GuardianAngelAction ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuardianAngelAction copy() {
|
||||
return new GuardianAngelAction(this);
|
||||
}
|
||||
}
|
||||
|
||||
class GuardianAngelDelayedTriggeredAbility extends DelayedTriggeredAbility {
|
||||
|
||||
GuardianAngelDelayedTriggeredAbility(UUID specialActionId) {
|
||||
super(new RemoveSpecialActionEffect(specialActionId), Duration.OneUse);
|
||||
this.usesStack = false;
|
||||
this.setRuleVisible(false);
|
||||
}
|
||||
|
||||
GuardianAngelDelayedTriggeredAbility(GuardianAngelDelayedTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuardianAngelDelayedTriggeredAbility copy() {
|
||||
return new GuardianAngelDelayedTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == EventType.CLEANUP_STEP_PRE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue