From ecc3c8b1e4de6918b0089310ce67958e9eb32e1d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 9 Mar 2015 01:03:21 +0100 Subject: [PATCH] * Daretti, Scrap Savant - Fixed a bug that the game is locked if multiple delayed triggered abilities from the emlem trigger. --- Mage.Common/src/mage/view/AbilityView.java | 6 ++++ Mage.Common/src/mage/view/CardsView.java | 34 ++++++++++++------- .../commander2014/DarettiScrapSavant.java | 5 +-- ...nOfNextEndStepDelayedTriggeredAbility.java | 9 +++-- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Mage.Common/src/mage/view/AbilityView.java b/Mage.Common/src/mage/view/AbilityView.java index c26ae5a300..16492d7a6c 100644 --- a/Mage.Common/src/mage/view/AbilityView.java +++ b/Mage.Common/src/mage/view/AbilityView.java @@ -63,4 +63,10 @@ public class AbilityView extends CardView { public CardView getSourceCard() { return this.sourceCard; } + + public void setName(String name) { + this.name = name; + } + + } diff --git a/Mage.Common/src/mage/view/CardsView.java b/Mage.Common/src/mage/view/CardsView.java index ff83aa18ee..7285357e28 100644 --- a/Mage.Common/src/mage/view/CardsView.java +++ b/Mage.Common/src/mage/view/CardsView.java @@ -46,6 +46,7 @@ import static mage.constants.Zone.GRAVEYARD; import static mage.constants.Zone.STACK; import mage.game.Game; import mage.game.GameState; +import mage.game.command.Emblem; import mage.game.permanent.Permanent; import mage.target.targetpointer.TargetPointer; @@ -65,32 +66,41 @@ public class CardsView extends LinkedHashMap { public CardsView ( Collection abilities, Game game ) { for ( Ability ability : abilities ) { - Card sourceCard = null; + MageObject sourceObject = null; + AbilityView abilityView = null; switch ( ability.getZone() ) { case ALL: case EXILED: case GRAVEYARD: - sourceCard = game.getCard(ability.getSourceId()); + sourceObject = game.getCard(ability.getSourceId()); break; case BATTLEFIELD: - sourceCard = game.getPermanent(ability.getSourceId()); - if (sourceCard == null) { - sourceCard = (Permanent)game.getLastKnownInformation(ability.getSourceId(), Zone.BATTLEFIELD); + sourceObject = game.getPermanent(ability.getSourceId()); + if (sourceObject == null) { + sourceObject = (Permanent)game.getLastKnownInformation(ability.getSourceId(), Zone.BATTLEFIELD); } break; case STACK: - sourceCard = game.getCard(ability.getSourceId()); + sourceObject = game.getObject(ability.getSourceId()); break; case COMMAND: - sourceCard = game.getCard(ability.getSourceId()); - if (sourceCard == null) { - ability.newId(); - this.put(ability.getId(), new AbilityView(ability, "Emblem", new CardView("Emblem"))); + sourceObject = game.getObject(ability.getSourceId()); + if (sourceObject instanceof Emblem) { + Card planeswalkerCard = game.getCard(((Emblem)sourceObject).getSourceId()); + if (planeswalkerCard != null) { + abilityView = new AbilityView(ability, "Emblem " + planeswalkerCard.getName(), new CardView(sourceObject)); + abilityView.setName("Emblem " + planeswalkerCard.getName()); + abilityView.setExpansionSetCode(planeswalkerCard.getExpansionSetCode()); + } else { + throw new IllegalArgumentException("Source card for emblem not found."); + } } break; } - if (sourceCard != null) { - AbilityView abilityView = new AbilityView(ability, sourceCard.getLogName(), new CardView(sourceCard)); + if (sourceObject != null) { + if (abilityView == null) { + abilityView = new AbilityView(ability, sourceObject.getLogName(), new CardView(sourceObject)); + } if (ability.getTargets().size() > 0) { abilityView.setTargets(ability.getTargets()); } else { diff --git a/Mage.Sets/src/mage/sets/commander2014/DarettiScrapSavant.java b/Mage.Sets/src/mage/sets/commander2014/DarettiScrapSavant.java index 9209840698..79fcd51022 100644 --- a/Mage.Sets/src/mage/sets/commander2014/DarettiScrapSavant.java +++ b/Mage.Sets/src/mage/sets/commander2014/DarettiScrapSavant.java @@ -45,6 +45,7 @@ import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; +import mage.constants.TargetController; import mage.constants.Zone; import mage.counters.CounterType; import mage.filter.FilterCard; @@ -180,7 +181,7 @@ class DarettiSacrificeEffect extends OneShotEffect { class DarettiScrapSavantEmblem extends Emblem { // You get an emblem with "Whenever an artifact is put into your graveyard from the battlefield, return that card to the battlefield at the beginning of the next end step." public DarettiScrapSavantEmblem() { - this.setName("EMBLEM: Daretti, Scrap Savant"); + this.setName("Emblem - Daretti"); this.getAbilities().add(new DarettiScrapSavantTriggeredAbility()); } } @@ -246,7 +247,7 @@ class DarettiScrapSavantEffect extends OneShotEffect { Effect effect = new ReturnFromGraveyardToBattlefieldTargetEffect(); effect.setTargetPointer(new FixedTarget(card.getId())); effect.setText("return that card to the battlefield at the beginning of the next end step"); - DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect); + DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(Zone.COMMAND, effect, TargetController.ANY); delayedAbility.setSourceId(source.getSourceId()); delayedAbility.setControllerId(source.getControllerId()); delayedAbility.setSourceObject(source.getSourceObject(game)); diff --git a/Mage/src/mage/abilities/common/delayed/AtTheBeginOfNextEndStepDelayedTriggeredAbility.java b/Mage/src/mage/abilities/common/delayed/AtTheBeginOfNextEndStepDelayedTriggeredAbility.java index 0809123568..8c911e984e 100644 --- a/Mage/src/mage/abilities/common/delayed/AtTheBeginOfNextEndStepDelayedTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/delayed/AtTheBeginOfNextEndStepDelayedTriggeredAbility.java @@ -34,9 +34,9 @@ import static mage.constants.TargetController.ANY; import static mage.constants.TargetController.CONTROLLER_ATTACHED_TO; import static mage.constants.TargetController.OPPONENT; import static mage.constants.TargetController.YOU; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.permanent.Permanent; /** @@ -52,11 +52,16 @@ public class AtTheBeginOfNextEndStepDelayedTriggeredAbility extends DelayedTrigg } public AtTheBeginOfNextEndStepDelayedTriggeredAbility(Effect effect, TargetController targetController) { + this(Zone.ALL, effect, targetController); + } + + public AtTheBeginOfNextEndStepDelayedTriggeredAbility(Zone zone, Effect effect, TargetController targetController) { super(effect); + this.zone = zone; this.targetController = targetController; } - public AtTheBeginOfNextEndStepDelayedTriggeredAbility(AtTheBeginOfNextEndStepDelayedTriggeredAbility ability) { + public AtTheBeginOfNextEndStepDelayedTriggeredAbility(final AtTheBeginOfNextEndStepDelayedTriggeredAbility ability) { super(ability); this.targetController = ability.targetController; }