mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
* Some rework of card moving after spell countering.
This commit is contained in:
parent
3de7ff6808
commit
39762e5bf5
1 changed files with 4 additions and 104 deletions
|
@ -28,28 +28,17 @@
|
|||
package mage.sets.commander;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.abilities.effects.common.ReturnToLibrarySpellEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.PhaseStep;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetSpell;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -63,7 +52,7 @@ public class SpellCrumple extends CardImpl {
|
|||
|
||||
// Counter target spell. If that spell is countered this way, put it on the bottom of its owner's library instead of into that player's graveyard. Put Spell Crumple on the bottom of its owner's library.
|
||||
this.getSpellAbility().addTarget(new TargetSpell());
|
||||
this.getSpellAbility().addEffect(new SpellCrumpleCounterEffect());
|
||||
this.getSpellAbility().addEffect(new SpellCrumpleCounterEffect());
|
||||
this.getSpellAbility().addEffect(new ReturnToLibrarySpellEffect(false));
|
||||
}
|
||||
|
||||
|
@ -95,99 +84,10 @@ class SpellCrumpleCounterEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
UUID objectId = source.getFirstTarget();
|
||||
UUID sourceId = source.getSourceId();
|
||||
// counter code from SpellStack
|
||||
StackObject stackObject = game.getStack().getStackObject(objectId);
|
||||
MageObject sourceObject = game.getObject(sourceId);
|
||||
if (stackObject != null && sourceObject != null) {
|
||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER, objectId, sourceId, stackObject.getControllerId()))) {
|
||||
if ( stackObject instanceof Spell ) {
|
||||
game.rememberLKI(objectId, Zone.STACK, (Spell)stackObject);
|
||||
}
|
||||
// Spell Crumple specific code
|
||||
ReplacementEffectImpl effect = new SpellCrumpleReplacementEffect();
|
||||
effect.setTargetPointer(new FixedTarget(stackObject.getId()));
|
||||
game.addEffect(effect, source);
|
||||
// Spell Crumple specific code end
|
||||
game.informPlayers(new StringBuilder(stackObject.getName()).append(" is countered by ").append(sourceObject.getLogName()).toString());
|
||||
game.getStack().remove(stackObject);
|
||||
stackObject.counter(sourceId, game); // tries to move to graveyard
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTERED, objectId, sourceId, stackObject.getControllerId()));
|
||||
} else {
|
||||
game.informPlayers(new StringBuilder(stackObject.getName()).append(" could not be countered by ").append(sourceObject.getLogName()).toString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// counter code from SpellStack end
|
||||
}
|
||||
}
|
||||
|
||||
class SpellCrumpleReplacementEffect extends ReplacementEffectImpl {
|
||||
|
||||
private PhaseStep phaseStep;
|
||||
|
||||
public SpellCrumpleReplacementEffect() {
|
||||
super(Duration.OneUse, Outcome.Benefit);
|
||||
staticText = "If that spell is countered this way, put it on the bottom of its owner's library instead of into that player's graveyard";
|
||||
phaseStep = null;
|
||||
}
|
||||
|
||||
public SpellCrumpleReplacementEffect(final SpellCrumpleReplacementEffect effect) {
|
||||
super(effect);
|
||||
phaseStep = effect.phaseStep;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpellCrumpleReplacementEffect copy() {
|
||||
return new SpellCrumpleReplacementEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInactive(Ability source, Game game) {
|
||||
if (!game.getPhase().getStep().getType().equals(phaseStep)) {
|
||||
return true;
|
||||
}
|
||||
return super.isInactive(source, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Ability source, Game game) {
|
||||
phaseStep = game.getPhase().getStep().getType();
|
||||
super.init(source, game);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
MageObject targetObject = game.getObject(event.getTargetId());
|
||||
if (targetObject instanceof Card) {
|
||||
Card card = (Card) targetObject;
|
||||
if (card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false, event.getAppliedEffects())) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
game.informPlayers(controller.getLogName() + " has put " + card.getName() + " on the bottom of the library.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
return event.getType() == EventType.ZONE_CHANGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (((ZoneChangeEvent)event).getToZone().equals(Zone.GRAVEYARD)) {
|
||||
MageObject mageObject = game.getLastKnownInformation(getTargetPointer().getFirst(game, source), Zone.STACK);
|
||||
if (mageObject instanceof Spell) {
|
||||
return ((Spell)mageObject).getSourceId().equals(event.getTargetId());
|
||||
}
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
return game.getStack().counter(targetPointer.getFirst(game, source), source.getSourceId(), game, Zone.LIBRARY, false, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue