mirror of
https://github.com/magefree/mage.git
synced 2026-01-09 20:32:06 -08:00
Rework Spell.counter using PutCards and reimplement Desertion. Fixes #9299
This commit is contained in:
parent
cbe610d339
commit
e40934921f
27 changed files with 124 additions and 251 deletions
|
|
@ -1,12 +1,10 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.Mode;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.constants.ZoneDetail;
|
||||
import mage.constants.PutCards;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
|
||||
|
|
@ -15,29 +13,20 @@ import mage.players.Player;
|
|||
*/
|
||||
public class CounterTargetWithReplacementEffect extends OneShotEffect {
|
||||
|
||||
private Zone targetZone;
|
||||
private ZoneDetail zoneDetail;
|
||||
|
||||
public CounterTargetWithReplacementEffect(Zone targetZone) {
|
||||
this(targetZone, ZoneDetail.NONE);
|
||||
}
|
||||
private final PutCards putIt;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param targetZone
|
||||
* @param zoneDetail use to specify when moving card to library <ul><li>true
|
||||
* = put on top</li><li>false = put on bottom</li></ul>
|
||||
* @param putIt
|
||||
*/
|
||||
public CounterTargetWithReplacementEffect(Zone targetZone, ZoneDetail zoneDetail) {
|
||||
public CounterTargetWithReplacementEffect(PutCards putIt) {
|
||||
super(Outcome.Detriment);
|
||||
this.targetZone = targetZone;
|
||||
this.zoneDetail = zoneDetail;
|
||||
this.putIt = putIt;
|
||||
}
|
||||
|
||||
public CounterTargetWithReplacementEffect(final CounterTargetWithReplacementEffect effect) {
|
||||
super(effect);
|
||||
this.targetZone = effect.targetZone;
|
||||
this.zoneDetail = effect.zoneDetail;
|
||||
this.putIt = effect.putIt;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -49,41 +38,26 @@ public class CounterTargetWithReplacementEffect extends OneShotEffect {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
return game.getStack().counter(targetPointer.getFirst(game, source), source, game, targetZone, false, zoneDetail);
|
||||
return game.getStack().counter(getTargetPointer().getFirst(game, source), source, game, putIt);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Mode mode) {
|
||||
StringBuilder sb = new StringBuilder("Counter target ");
|
||||
sb.append(mode.getTargets().get(0).getTargetName());
|
||||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("counter ");
|
||||
sb.append(getTargetPointer().describeTargets(mode.getTargets(), "it"));
|
||||
sb.append(". If that spell is countered this way, ");
|
||||
if (targetZone == Zone.EXILED) {
|
||||
if (putIt == PutCards.EXILED) {
|
||||
sb.append("exile it instead of putting it into its owner's graveyard");
|
||||
} else {
|
||||
sb.append(putIt == PutCards.TOP_OR_BOTTOM ? "put that card " : "put it ");
|
||||
sb.append(putIt.getMessage(true, false));
|
||||
sb.append(" instead of into that player's graveyard");
|
||||
}
|
||||
if (targetZone == Zone.HAND) {
|
||||
sb.append("put it into its owner's hand instead of into that player's graveyard");
|
||||
}
|
||||
if (targetZone == Zone.LIBRARY) {
|
||||
sb.append("put it on ");
|
||||
switch (zoneDetail) {
|
||||
case BOTTOM:
|
||||
sb.append("the bottom");
|
||||
break;
|
||||
case TOP:
|
||||
sb.append("top");
|
||||
break;
|
||||
case CHOOSE:
|
||||
sb.append("top or bottom");
|
||||
break;
|
||||
case NONE:
|
||||
sb.append("<not allowed value>");
|
||||
break;
|
||||
}
|
||||
sb.append(" of its owner's library instead of into that player's graveyard");
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ import mage.abilities.costs.mana.ManaCost;
|
|||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.constants.ZoneDetail;
|
||||
import mage.constants.PutCards;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
|
|
@ -88,11 +87,7 @@ public class CounterUnlessPaysEffect extends OneShotEffect {
|
|||
if (!(player.chooseUse(Outcome.Benefit, message, source, game)
|
||||
&& costToPay.pay(source, game, source, spell.getControllerId(), false, null))) {
|
||||
game.informPlayers(player.getLogName() + " chooses not to pay " + costValueMessage + " to prevent the counter effect");
|
||||
if (exile) {
|
||||
game.getStack().counter(spell.getId(), source, game, Zone.EXILED, false, ZoneDetail.NONE);
|
||||
} else {
|
||||
return game.getStack().counter(spell.getId(), source, game);
|
||||
}
|
||||
game.getStack().counter(spell.getId(), source, game, exile ? PutCards.EXILED : PutCards.GRAVEYARD);
|
||||
}
|
||||
game.informPlayers(player.getLogName() + " chooses to pay " + costValueMessage + " to prevent the counter effect");
|
||||
return true;
|
||||
|
|
@ -103,13 +98,8 @@ public class CounterUnlessPaysEffect extends OneShotEffect {
|
|||
if (staticText != null && !staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (mode.getTargets().isEmpty()) {
|
||||
sb.append("counter it");
|
||||
} else {
|
||||
sb.append("counter target ").append(mode.getTargets().get(0).getTargetName());
|
||||
}
|
||||
StringBuilder sb = new StringBuilder("counter ");
|
||||
sb.append(getTargetPointer().describeTargets(mode.getTargets(), "it"));
|
||||
sb.append(" unless its controller pays ");
|
||||
if (cost != null) {
|
||||
sb.append(cost.getText());
|
||||
|
|
@ -121,9 +111,8 @@ public class CounterUnlessPaysEffect extends OneShotEffect {
|
|||
sb.append(genericMana.getMessage());
|
||||
}
|
||||
if (exile) {
|
||||
sb.append(". If that spell is countered this way, exile it instead of putting it into its owner's graveyard.");
|
||||
sb.append(". If that spell is countered this way, exile it instead of putting it into its owner's graveyard");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
|
||||
package mage.constants;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public enum ZoneDetail {
|
||||
|
||||
NONE,
|
||||
TOP,
|
||||
BOTTOM,
|
||||
CHOOSE
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue