Rework Spell.counter using PutCards and reimplement Desertion. Fixes #9299

This commit is contained in:
Alex W. Jackson 2022-10-10 21:21:31 -04:00
parent cbe610d339
commit e40934921f
27 changed files with 124 additions and 251 deletions

View file

@ -413,47 +413,46 @@ public class Spell extends StackObjectImpl implements Card {
@Override
public void counter(Ability source, Game game) {
this.counter(source, game, Zone.GRAVEYARD, false, ZoneDetail.NONE);
this.counter(source, game, PutCards.GRAVEYARD);
}
@Override
public void counter(Ability source, Game game, Zone zone, boolean owner, ZoneDetail zoneDetail) {
public void counter(Ability source, Game game, PutCards zone) {
// source can be null for fizzled spells, don't use that code in your ZONE_CHANGE watchers/triggers:
// event.getSourceId().equals
// TODO: so later it must be replaced to another technics with non null source
UUID counteringSourceId = (source == null ? null : source.getSourceId());
// TODO: fizzled spells are no longer considered "countered" as of current rules; may need refactor
this.countered = true;
if (!isCopy()) {
Player player = game.getPlayer(game.getControllerId(counteringSourceId));
if (player == null) {
player = game.getPlayer(getControllerId());
}
if (player != null) {
Ability counteringAbility = null;
MageObject counteringObject = game.getObject(counteringSourceId);
if (counteringObject instanceof StackObject) {
counteringAbility = ((StackObject) counteringObject).getStackAbility();
}
if (zone == Zone.LIBRARY) {
if (zoneDetail == ZoneDetail.CHOOSE) {
if (player.chooseUse(Outcome.Detriment, "Move countered spell to the top of the library? (otherwise it goes to the bottom)", counteringAbility, game)) {
zoneDetail = ZoneDetail.TOP;
} else {
zoneDetail = ZoneDetail.BOTTOM;
}
}
if (zoneDetail == ZoneDetail.TOP) {
player.putCardsOnTopOfLibrary(new CardsImpl(card), game, counteringAbility, false);
} else {
player.putCardsOnBottomOfLibrary(new CardsImpl(card), game, counteringAbility, false);
}
} else {
player.moveCards(card, zone, counteringAbility, game, false, false, owner, null);
}
}
} else {
if (isCopy()) {
// copied spell, only remove from stack
game.getStack().remove(this, game);
return;
}
Player player = game.getPlayer(source == null ? getControllerId() : source.getControllerId());
if (player != null) {
switch (zone) {
case TOP_OR_BOTTOM:
if (player.chooseUse(Outcome.Detriment,
"Put the countered spell on the top or bottom of its owner's library?",
null, "Top", "Bottom", source, game
)) {
player.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, false);
} else {
player.putCardsOnBottomOfLibrary(new CardsImpl(card), game, source, false);
}
break;
case TOP_ANY:
player.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, false);
break;
case BOTTOM_ANY:
case BOTTOM_RANDOM:
player.putCardsOnBottomOfLibrary(new CardsImpl(card), game, source, false);
break;
case BATTLEFIELD_TAPPED:
player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
break;
default:
player.moveCards(card, zone.getZone(), source, game);
}
}
}

View file

@ -6,8 +6,7 @@ import java.util.Date;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.constants.Zone;
import mage.constants.ZoneDetail;
import mage.constants.PutCards;
import mage.game.Game;
import mage.game.events.GameEvent;
import org.apache.log4j.Logger;
@ -60,13 +59,10 @@ public class SpellStack extends ArrayDeque<StackObject> {
}
public boolean counter(UUID objectId, Ability source, Game game) {
return counter(objectId, source, game, Zone.GRAVEYARD, false, ZoneDetail.TOP);
return counter(objectId, source, game, PutCards.GRAVEYARD);
}
public boolean counter(UUID objectId, Ability source, Game game, Zone zone, boolean owner, ZoneDetail zoneDetail) {
// the counter logic is copied by some spells to handle replacement effects of the countered spell
// so if logic is changed here check those spells for needed changes too
// Concerned cards to check: Hinder, Spell Crumple
public boolean counter(UUID objectId, Ability source, Game game, PutCards zone) {
StackObject stackObject = getStackObject(objectId);
MageObject sourceObject = game.getObject(source);
if (stackObject != null && sourceObject != null) {
@ -86,7 +82,7 @@ public class SpellStack extends ArrayDeque<StackObject> {
if (!(stackObject instanceof Spell)) { // spells are removed from stack by the card movement
this.remove(stackObject, game);
}
stackObject.counter(source, game, zone, owner, zoneDetail);
stackObject.counter(source, game, zone);
if (!game.isSimulation()) {
game.informPlayers(counteredObjectName + " is countered by " + sourceObject.getLogName());
}

View file

@ -104,12 +104,12 @@ public class StackAbility extends StackObjectImpl implements Ability {
@Override
public void counter(Ability source, Game game) {
// zone, owner, top ignored
this.counter(source, game, Zone.GRAVEYARD, true, ZoneDetail.TOP);
// zone ignored
this.counter(source, game, PutCards.GRAVEYARD);
}
@Override
public void counter(Ability source, Game game, Zone zone, boolean owner, ZoneDetail zoneDetail) {
public void counter(Ability source, Game game, PutCards zone) {
//20100716 - 603.8
if (ability instanceof StateTriggeredAbility) {
((StateTriggeredAbility) ability).counter(game);

View file

@ -3,8 +3,7 @@ package mage.game.stack;
import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability;
import mage.constants.Zone;
import mage.constants.ZoneDetail;
import mage.constants.PutCards;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.mageobject.MageObjectReferencePredicate;
import mage.game.Controllable;
@ -25,7 +24,7 @@ public interface StackObject extends MageObject, Controllable {
*/
void counter(Ability source, Game game);
void counter(Ability source, Game game, Zone zone, boolean owner, ZoneDetail zoneDetail);
void counter(Ability source, Game game, PutCards zone);
Ability getStackAbility();