mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
a few more card refactors for card.moveToZone
This commit is contained in:
parent
bb04962144
commit
adc945748b
5 changed files with 54 additions and 68 deletions
|
@ -2,10 +2,11 @@ package mage.abilities.effects.common;
|
|||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.StaticFilters;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetCardInYourGraveyard;
|
||||
|
@ -17,7 +18,8 @@ import java.util.UUID;
|
|||
* @author LevelX2
|
||||
*/
|
||||
public class ExileCardFromOwnGraveyardControllerEffect extends OneShotEffect {
|
||||
private int amount;
|
||||
|
||||
private final int amount;
|
||||
|
||||
public ExileCardFromOwnGraveyardControllerEffect(int amount) {
|
||||
super(Outcome.Exile);
|
||||
|
@ -25,7 +27,7 @@ public class ExileCardFromOwnGraveyardControllerEffect extends OneShotEffect {
|
|||
this.staticText = setText();
|
||||
}
|
||||
|
||||
public ExileCardFromOwnGraveyardControllerEffect(final ExileCardFromOwnGraveyardControllerEffect effect) {
|
||||
private ExileCardFromOwnGraveyardControllerEffect(final ExileCardFromOwnGraveyardControllerEffect effect) {
|
||||
super(effect);
|
||||
this.amount = effect.amount;
|
||||
}
|
||||
|
@ -38,19 +40,21 @@ public class ExileCardFromOwnGraveyardControllerEffect extends OneShotEffect {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(Math.min(amount, player.getGraveyard().size()), new FilterCard());
|
||||
if (player.chooseTarget(outcome, target, source, game)) {
|
||||
for (UUID targetId : target.getTargets()) {
|
||||
Card card = player.getGraveyard().get(targetId, game);
|
||||
if (card != null) {
|
||||
card.moveToZone(Zone.EXILED, source, game, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (player == null || player.getGraveyard().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(Math.min(
|
||||
amount, player.getGraveyard().size()
|
||||
), StaticFilters.FILTER_CARD);
|
||||
target.setNotTarget(true);
|
||||
if (!player.chooseTarget(outcome, target, source, game)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
Cards cards = new CardsImpl();
|
||||
for (UUID targetId : target.getTargets()) {
|
||||
cards.add(player.getGraveyard().get(targetId, game));
|
||||
}
|
||||
return player.moveCards(cards, Zone.EXILED, source, game);
|
||||
}
|
||||
|
||||
private String setText() {
|
||||
|
@ -63,5 +67,4 @@ public class ExileCardFromOwnGraveyardControllerEffect extends OneShotEffect {
|
|||
sb.append("from your graveyard");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.MageObject;
|
||||
|
@ -7,19 +6,16 @@ import mage.abilities.Mode;
|
|||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class PutOnLibrarySourceEffect extends OneShotEffect {
|
||||
|
||||
boolean onTop;
|
||||
private final boolean onTop;
|
||||
|
||||
public PutOnLibrarySourceEffect(boolean onTop) {
|
||||
super(Outcome.ReturnToHand);
|
||||
|
@ -44,22 +40,15 @@ public class PutOnLibrarySourceEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
|
||||
if (sourceObject == null) {
|
||||
if (player == null || !(sourceObject instanceof Card)) {
|
||||
return false;
|
||||
}
|
||||
if (sourceObject instanceof Permanent) {
|
||||
((Permanent) sourceObject).moveToZone(Zone.LIBRARY, source, game, onTop);
|
||||
return true;
|
||||
} else if (sourceObject instanceof Card && game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
|
||||
for (Player player : game.getPlayers().values()) {
|
||||
if (player.getGraveyard().contains(sourceObject.getId())) {
|
||||
((Card) sourceObject).moveToZone(Zone.LIBRARY, source, game, onTop);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (onTop) {
|
||||
return player.putCardsOnTopOfLibrary((Card) sourceObject, game, source, false);
|
||||
}
|
||||
return false;
|
||||
return player.putCardsOnBottomOfLibrary((Card) sourceObject, game, source, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -73,6 +62,5 @@ public class PutOnLibrarySourceEffect extends OneShotEffect {
|
|||
sb.append(onTop ? "top" : "the bottom").append(" of its owner's library");
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.constants.Outcome;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeff
|
||||
*/
|
||||
public class ReturnToHandAttachedEffect extends OneShotEffect {
|
||||
|
@ -30,17 +30,15 @@ public class ReturnToHandAttachedEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Object object = getValue("attachedTo");
|
||||
if (object instanceof Permanent) {
|
||||
Card card = game.getCard(((Permanent) object).getId());
|
||||
if (card != null
|
||||
&& getValue("zcc").equals(game.getState().getZoneChangeCounter(card.getId()))) { // Necrogenesis, etc.
|
||||
if (card.moveToZone(Zone.HAND, source, game, false)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Player player = game.getPlayer(source.getSourceId());
|
||||
Permanent permanent = (Permanent) getValue("attachedTo");
|
||||
if (player == null || permanent == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
Card card = permanent.getMainCard();
|
||||
if (permanent.getZoneChangeCounter(game) != card.getZoneChangeCounter(game) + 1) {
|
||||
return false;
|
||||
}
|
||||
return player.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@ public class WishEffect extends OneShotEffect {
|
|||
if (topOfLibrary) {
|
||||
controller.putCardsOnTopOfLibrary(card, game, source, true);
|
||||
} else {
|
||||
card.moveToZone(Zone.HAND, source, game, false);
|
||||
controller.moveCards(card, Zone.HAND, source, game);
|
||||
}
|
||||
if (reveal) {
|
||||
Cards revealCard = new CardsImpl();
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
|
||||
|
||||
package mage.game.permanent.token;
|
||||
import java.util.UUID;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleActivatedAbility;
|
||||
|
@ -12,7 +8,9 @@ import mage.abilities.costs.mana.ManaCostsImpl;
|
|||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Zone;
|
||||
import mage.filter.FilterCard;
|
||||
import mage.filter.predicate.mageobject.NamePredicate;
|
||||
|
@ -22,7 +20,6 @@ import mage.target.Target;
|
|||
import mage.target.common.TargetCardInExile;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author spjspj
|
||||
*/
|
||||
public final class SengirNosferatuBatToken extends TokenImpl {
|
||||
|
@ -59,11 +56,11 @@ class ReturnSengirNosferatuEffect extends OneShotEffect {
|
|||
filter.add(new NamePredicate("Sengir Nosferatu"));
|
||||
}
|
||||
|
||||
public ReturnSengirNosferatuEffect() {
|
||||
ReturnSengirNosferatuEffect() {
|
||||
super(Outcome.Benefit);
|
||||
}
|
||||
|
||||
public ReturnSengirNosferatuEffect(final ReturnSengirNosferatuEffect effect) {
|
||||
private ReturnSengirNosferatuEffect(final ReturnSengirNosferatuEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
|
@ -74,20 +71,20 @@ class ReturnSengirNosferatuEffect extends OneShotEffect {
|
|||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
UUID controllerId = source.getControllerId();
|
||||
Target target = new TargetCardInExile(filter);
|
||||
target.setNotTarget(true);
|
||||
if (!target.canChoose(source.getSourceId(), controllerId, game)) {
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
Player player = game.getPlayer(controllerId);
|
||||
if (player != null) {
|
||||
player.chooseTarget(Outcome.PutCreatureInPlay, target, source, game);
|
||||
Card card = game.getCard(target.getTargets().get(0));
|
||||
if (card != null) {
|
||||
return card.moveToZone(Zone.BATTLEFIELD, source, game, false);
|
||||
}
|
||||
Target target = new TargetCardInExile(filter);
|
||||
target.setNotTarget(true);
|
||||
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
player.chooseTarget(Outcome.PutCreatureInPlay, target, source, game);
|
||||
Card card = game.getCard(target.getFirstTarget());
|
||||
return card != null && player.moveCards(
|
||||
card, Zone.BATTLEFIELD, source, game, false,
|
||||
false, true, null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue