* Maelstrom Nexus - Fixed that the compared casting cost was always 5 instead of the casting cost of the spell that got Cascade.

This commit is contained in:
LevelX2 2015-09-29 00:37:52 +02:00
parent 707358f875
commit 8f086c8c7e
3 changed files with 102 additions and 108 deletions

View file

@ -27,21 +27,28 @@
*/ */
package mage.sets.alarareborn; package mage.sets.alarareborn;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.keyword.CascadeAbility; import mage.abilities.keyword.CascadeAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Rarity; import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.constants.WatcherScope; import mage.constants.WatcherScope;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.stack.Spell; import mage.game.stack.Spell;
import mage.target.targetpointer.FixedTarget; import mage.game.stack.StackObject;
import mage.players.Player;
import mage.watchers.Watcher; import mage.watchers.Watcher;
/** /**
@ -55,7 +62,7 @@ public class MaelstromNexus extends CardImpl {
this.expansionSetCode = "ARB"; this.expansionSetCode = "ARB";
// The first spell you cast each turn has cascade. // The first spell you cast each turn has cascade.
this.addAbility(new MaelstromNexusTriggeredAbility(), new FirstSpellCastThisTurnWatcher()); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MaelstromNexusGainCascadeFirstSpellEffect()), new FirstSpellCastThisTurnWatcher());
} }
@ -69,52 +76,51 @@ public class MaelstromNexus extends CardImpl {
} }
} }
class MaelstromNexusTriggeredAbility extends TriggeredAbilityImpl { class MaelstromNexusGainCascadeFirstSpellEffect extends ContinuousEffectImpl {
public MaelstromNexusTriggeredAbility() { private Ability cascadeAbility = new CascadeAbility();
super(Zone.BATTLEFIELD, new CascadeEffect());
public MaelstromNexusGainCascadeFirstSpellEffect() {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
staticText = "The first spell you cast each turn has cascade";
} }
public MaelstromNexusTriggeredAbility(MaelstromNexusTriggeredAbility ability) { public MaelstromNexusGainCascadeFirstSpellEffect(final MaelstromNexusGainCascadeFirstSpellEffect effect) {
super(ability); super(effect);
} }
@Override @Override
public boolean checkEventType(GameEvent event, Game game) { public MaelstromNexusGainCascadeFirstSpellEffect copy() {
return event.getType() == GameEvent.EventType.SPELL_CAST; return new MaelstromNexusGainCascadeFirstSpellEffect(this);
} }
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(event.getTargetId()); Player controller = game.getPlayer(source.getControllerId());
FirstSpellCastThisTurnWatcher watcher = (FirstSpellCastThisTurnWatcher) game.getState().getWatchers().get("FirstSpellCastThisTurn", this.getSourceId()); if (controller != null) {
if (spell != null for (StackObject stackObject : game.getStack()) {
&& watcher != null // only spells cast, so no copies of spells
&& watcher.conditionMet()) { if ((stackObject instanceof Spell) && !stackObject.isCopy() && stackObject.getControllerId().equals(source.getControllerId())) {
this.getEffects().get(0).setTargetPointer(new FixedTarget(spell.getSourceId())); Spell spell = (Spell) stackObject;
FirstSpellCastThisTurnWatcher watcher = (FirstSpellCastThisTurnWatcher) game.getState().getWatchers().get("FirstSpellCastThisTurn");
if (watcher != null && spell.getId().equals(watcher.getIdOfFirstCastSpell(source.getControllerId()))) {
game.getState().addOtherAbility(spell.getCard(), cascadeAbility);
}
}
}
return true; return true;
} }
return false; return false;
} }
@Override
public MaelstromNexusTriggeredAbility copy() {
return new MaelstromNexusTriggeredAbility(this);
}
@Override
public String getRule() {
return "The first spell you cast each turn has cascade.";
}
} }
class FirstSpellCastThisTurnWatcher extends Watcher { class FirstSpellCastThisTurnWatcher extends Watcher {
int spellCount = 0; Map<UUID, UUID> playerFirstSpellCast = new HashMap<>();
Map<UUID, UUID> playerFirstCastSpell = new HashMap<>();
public FirstSpellCastThisTurnWatcher() { public FirstSpellCastThisTurnWatcher() {
super("FirstSpellCastThisTurn", WatcherScope.CARD); super("FirstSpellCastThisTurn", WatcherScope.GAME);
} }
public FirstSpellCastThisTurnWatcher(final FirstSpellCastThisTurnWatcher watcher) { public FirstSpellCastThisTurnWatcher(final FirstSpellCastThisTurnWatcher watcher) {
@ -123,16 +129,18 @@ class FirstSpellCastThisTurnWatcher extends Watcher {
@Override @Override
public void watch(GameEvent event, Game game) { public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getPlayerId() == controllerId) { switch (event.getType()) {
Spell spell = (Spell) game.getObject(event.getTargetId()); case SPELL_CAST:
if (spell != null) { case CAST_SPELL:
spellCount++; Spell spell = (Spell) game.getObject(event.getTargetId());
if (spellCount == 1) { if (spell != null && !playerFirstSpellCast.containsKey(spell.getControllerId())) {
condition = true; if (event.getType().equals(EventType.SPELL_CAST)) {
} else { playerFirstSpellCast.put(spell.getControllerId(), spell.getId());
condition = false; } else if (event.getType().equals(EventType.CAST_SPELL)) {
playerFirstCastSpell.put(spell.getControllerId(), spell.getId());
}
} }
}
} }
} }
@ -144,28 +152,15 @@ class FirstSpellCastThisTurnWatcher extends Watcher {
@Override @Override
public void reset() { public void reset() {
super.reset(); super.reset();
spellCount = 0; playerFirstSpellCast.clear();
playerFirstCastSpell.clear();
}
public UUID getIdOfFirstCastSpell(UUID playerId) {
if (playerFirstSpellCast.get(playerId) == null) {
return playerFirstCastSpell.get(playerId);
} else {
return playerFirstSpellCast.get(playerId);
}
} }
} }
class CascadeEffect extends OneShotEffect {
public CascadeEffect() {
super(Outcome.PutCardInPlay);
}
public CascadeEffect(CascadeEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
return CascadeAbility.applyCascade(outcome, game, source);
}
@Override
public CascadeEffect copy() {
return new CascadeEffect(this);
}
}

View file

@ -1,37 +1,38 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.abilities.keyword; package mage.abilities.keyword;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
@ -74,10 +75,7 @@ public class CascadeAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId()); Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && spell.getSourceId().equals(this.getSourceId())) { return spell != null && spell.getSourceId().equals(this.getSourceId());
return true;
}
return false;
} }
@Override @Override
@ -95,7 +93,6 @@ public class CascadeAbility extends TriggeredAbilityImpl {
} }
// moved to static method because it's called also from class {link} MaelstromNexus // moved to static method because it's called also from class {link} MaelstromNexus
public static boolean applyCascade(Outcome outcome, Game game, Ability source) { public static boolean applyCascade(Outcome outcome, Game game, Ability source) {
Card card; Card card;
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
@ -109,31 +106,33 @@ public class CascadeAbility extends TriggeredAbilityImpl {
if (card == null) { if (card == null) {
break; break;
} }
player.moveCardToExileWithInfo(card, exile.getId(), exile.getName(), source.getSourceId(), game, Zone.LIBRARY, true); player.moveCardsToExile(card, source, game, true, exile.getId(), exile.getName());
} while (player.isInGame() && card.getCardType().contains(CardType.LAND) || card.getManaCost().convertedManaCost() >= sourceCost); } while (player.isInGame() && card.getCardType().contains(CardType.LAND) || card.getManaCost().convertedManaCost() >= sourceCost);
player.getLibrary().reset(); player.getLibrary().reset();
if (card != null) { if (card != null) {
if (player.chooseUse(outcome, "Use cascade effect on " + card.getName() + "?", source, game)) { if (player.chooseUse(outcome, "Use cascade effect on " + card.getLogName() + "?", source, game)) {
if(player.cast(card.getSpellAbility(), game, true)){ if (player.cast(card.getSpellAbility(), game, true)) {
exile.remove(card.getId()); exile.remove(card.getId());
} }
} }
} }
// Mobe the remaining cards to the buttom of the libraray in a random order
while (exile.size() > 0) { Cards cardsFromExile = new CardsImpl();
card = exile.getRandom(game); Cards cardsToLibrary = new CardsImpl();
exile.remove(card.getId()); cardsFromExile.addAll(exile);
player.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.EXILED, false, false); while (cardsFromExile.size() > 0) {
card = cardsFromExile.getRandom(game);
cardsFromExile.remove(card.getId());
cardsToLibrary.add(card);
} }
player.putCardsOnBottomOfLibrary(cardsToLibrary, game, source, true);
return true; return true;
} }
} }
// !!! Changes to the cascade effect here have to be copied to the cascadeEffect of Maelstrom Nexus card eventually. // !!! Changes to the cascade effect here have to be copied to the cascadeEffect of Maelstrom Nexus card eventually.
// There is a functional copy of this effect // There is a functional copy of this effect
class CascadeEffect extends OneShotEffect { class CascadeEffect extends OneShotEffect {
public CascadeEffect() { public CascadeEffect() {
@ -185,5 +184,3 @@ class CascadeEffect extends OneShotEffect {
} }
} }

View file

@ -962,8 +962,10 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
} }
setCastSourceIdWithAlternateMana(null, null); setCastSourceIdWithAlternateMana(null, null);
GameEvent event = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, spell.getSpellAbility().getId(), spell.getSpellAbility().getSourceId(), playerId);
game.fireEvent(event);
if (spell.activate(game, noMana)) { if (spell.activate(game, noMana)) {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spell.getSpellAbility().getId(), spell.getSpellAbility().getSourceId(), playerId); event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spell.getSpellAbility().getId(), spell.getSpellAbility().getSourceId(), playerId);
event.setZone(fromZone); event.setZone(fromZone);
game.fireEvent(event); game.fireEvent(event);
if (!game.isSimulation()) { if (!game.isSimulation()) {