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

@ -25,13 +25,14 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
@ -74,10 +75,7 @@ public class CascadeAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && spell.getSourceId().equals(this.getSourceId())) {
return true;
}
return false;
return spell != null && spell.getSourceId().equals(this.getSourceId());
}
@Override
@ -95,7 +93,6 @@ public class CascadeAbility extends TriggeredAbilityImpl {
}
// moved to static method because it's called also from class {link} MaelstromNexus
public static boolean applyCascade(Outcome outcome, Game game, Ability source) {
Card card;
Player player = game.getPlayer(source.getControllerId());
@ -109,31 +106,33 @@ public class CascadeAbility extends TriggeredAbilityImpl {
if (card == null) {
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);
player.getLibrary().reset();
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)) {
exile.remove(card.getId());
}
}
}
while (exile.size() > 0) {
card = exile.getRandom(game);
exile.remove(card.getId());
player.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.EXILED, false, false);
// Mobe the remaining cards to the buttom of the libraray in a random order
Cards cardsFromExile = new CardsImpl();
Cards cardsToLibrary = new CardsImpl();
cardsFromExile.addAll(exile);
while (cardsFromExile.size() > 0) {
card = cardsFromExile.getRandom(game);
cardsFromExile.remove(card.getId());
cardsToLibrary.add(card);
}
player.putCardsOnBottomOfLibrary(cardsToLibrary, game, source, true);
return true;
}
}
// !!! 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
class CascadeEffect extends OneShotEffect {
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);
GameEvent event = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, spell.getSpellAbility().getId(), spell.getSpellAbility().getSourceId(), playerId);
game.fireEvent(event);
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);
game.fireEvent(event);
if (!game.isSimulation()) {