Skip to content

Commit

Permalink
* Replaced some card.putOntoBattlefield by player.moveCard... methods (
Browse files Browse the repository at this point in the history
…#4866). Added new player.shuffleCardsToLibrary method.
  • Loading branch information
LevelX2 committed Jun 20, 2020
1 parent 52579fd commit 305dab9
Show file tree
Hide file tree
Showing 23 changed files with 217 additions and 306 deletions.
6 changes: 4 additions & 2 deletions Mage.Sets/src/mage/cards/a/Aethertow.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import mage.abilities.keyword.ConspireAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.common.FilterAttackingOrBlockingCreature;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetCreaturePermanent;

/**
Expand Down Expand Up @@ -58,9 +60,9 @@ class AethertowEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (targetCreature != null) {
targetCreature.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
return true;
return controller.putCardsOnTopOfLibrary(targetCreature, game, source, true);
}
return false;
}
Expand Down
3 changes: 1 addition & 2 deletions Mage.Sets/src/mage/cards/a/AmassTheComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ public boolean apply(Game game, Ability source) {
if (player.choose(Outcome.Detriment, player.getHand(), target, game)) {
Card card = player.getHand().get(target.getFirstTarget(), game);
if (card != null) {
player.removeFromHand(card, game);
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
return player.putCardsOnBottomOfLibrary(card, game, source, true);
}
}
}
Expand Down
10 changes: 3 additions & 7 deletions Mage.Sets/src/mage/cards/b/BrutalizerExarch.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ public BrutalizerExarchEffect2 copy() {
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
Player player = game.getPlayer(permanent.getOwnerId());
if (player == null) {
return false;
}

return permanent.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
Player controller = game.getPlayer(source.getControllerId());
if (permanent != null && controller != null) {
return controller.putCardsOnBottomOfLibrary(permanent, game, source, true);
}
return false;
}
Expand Down
11 changes: 6 additions & 5 deletions Mage.Sets/src/mage/cards/c/ConsignToDream.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;

/**
Expand Down Expand Up @@ -58,15 +59,15 @@ public ConsignToDreamEffect copy() {

@Override
public boolean apply(Game game, Ability source) {
boolean applied = false;
Permanent target = game.getPermanent(source.getFirstTarget());
if (target != null) {
Player controller = game.getPlayer(source.getControllerId());
if (target != null && controller != null) {
if (target.getColor(game).isRed() || target.getColor(game).isGreen()) {
applied = target.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
return controller.putCardsOnTopOfLibrary(target, game, source, true);
} else {
applied = target.moveToZone(Zone.HAND, source.getSourceId(), game, false);
return controller.moveCards(target, Zone.HAND, source, game);
}
}
return applied;
return false;
}
}
7 changes: 4 additions & 3 deletions Mage.Sets/src/mage/cards/d/DarkRevenant.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Outcome;
Expand Down Expand Up @@ -67,9 +68,9 @@ public DarkRevenantEffect copy() {
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId());
if (card != null && game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) {
Player owner = game.getPlayer(card.getOwnerId());
if(owner != null) {
return card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
Player controller = game.getPlayer(source.getControllerId());
if(controller != null) {
return controller.putCardsOnTopOfLibrary(card, game, source, true);
}
}
return true;
Expand Down
13 changes: 7 additions & 6 deletions Mage.Sets/src/mage/cards/d/DeadReckoning.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
Expand Down Expand Up @@ -59,22 +60,22 @@ public DeadReckoningEffect copy() {

@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
TargetCardInYourGraveyard target1 = new TargetCardInYourGraveyard(new FilterCreatureCard("creature card in your graveyard"));
TargetCreaturePermanent target2 = new TargetCreaturePermanent();

if (you != null) {
if (controller != null) {
if (target1.canChoose(source.getControllerId(), game)
&& you.choose(Outcome.Benefit, target1, source.getSourceId(), game)
&& controller.choose(Outcome.Benefit, target1, source.getSourceId(), game)
&& target2.canChoose(source.getControllerId(), game)
&& you.choose(Outcome.Damage, target2, source.getSourceId(), game)) {
&& controller.choose(Outcome.Damage, target2, source.getSourceId(), game)) {
Card creatureInGraveyard = game.getCard(target1.getFirstTarget());
if (creatureInGraveyard != null) {
if (creatureInGraveyard.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true)) {
if (controller.putCardsOnTopOfLibrary(creatureInGraveyard, game, source, true)) {
int power = creatureInGraveyard.getPower().getValue();
Permanent creature = game.getPermanent(target2.getFirstTarget());
if (creature != null) {
creature.damage(power, source.getSourceId(), game, true, true);
creature.damage(power, source.getSourceId(), game, false, true);
return true;
}
}
Expand Down
31 changes: 9 additions & 22 deletions Mage.Sets/src/mage/cards/d/DiminishingReturns.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.DrawCardAllEffect;
import mage.abilities.effects.common.ShuffleHandGraveyardAllEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
Expand All @@ -23,7 +24,8 @@ public DiminishingReturns(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.SORCERY},"{2}{U}{U}");

// Each player shuffles their hand and graveyard into their library. You exile the top ten cards of your library. Then each player draws up to seven cards.
this.getSpellAbility().addEffect(new DiminishingReturnsEffect());
this.getSpellAbility().addEffect(new ShuffleHandGraveyardAllEffect());
this.getSpellAbility().addEffect(new DiminishingReturnsEffect());
}

public DiminishingReturns(final DiminishingReturns card) {
Expand All @@ -40,7 +42,7 @@ class DiminishingReturnsEffect extends OneShotEffect {

public DiminishingReturnsEffect() {
super(Outcome.Neutral);
staticText = "Each player shuffles their hand and graveyard into their library. You exile the top ten cards of your library. Then each player draws up to seven cards.";
staticText = "You exile the top ten cards of your library. Then each player draws up to seven cards.";
}

public DiminishingReturnsEffect(final DiminishingReturnsEffect effect) {
Expand All @@ -51,28 +53,13 @@ public DiminishingReturnsEffect(final DiminishingReturnsEffect effect) {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.moveCards(controller.getLibrary().getTopCards(game, 10), Zone.EXILED, source, game);
game.getState().processAction(game);
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
for (Card card: player.getHand().getCards(game)) {
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
}
for (Card card: player.getGraveyard().getCards(game)) {
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
}
player.shuffleLibrary(source, game);
}
}

for (Card card: controller.getLibrary().getTopCards(game, 10)) {
controller.moveCardToExileWithInfo(card, null, "", source.getSourceId(), game, Zone.LIBRARY, true);
}

for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int cardsToDrawCount = player.getAmount(0, 7, "How many cards to draw (up to 7)?", game);
player.drawCards(cardsToDrawCount, source.getSourceId(), game);
player.drawCards(player.getAmount(0, 7, "How many cards to draw (up to 7)?", game),
source.getSourceId(), game);
}
}
}
Expand Down
43 changes: 10 additions & 33 deletions Mage.Sets/src/mage/cards/d/Doomsday.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,47 +58,24 @@ public DoomsdayEffect copy() {

@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player controller = game.getPlayer(source.getControllerId());

if (player != null) {
if (controller != null) {
//Search your library and graveyard for five cards
Cards allCards = new CardsImpl();
Cards cards = new CardsImpl();
allCards.addAll(player.getLibrary().getCardList());
allCards.addAll(player.getGraveyard());
allCards.addAll(controller.getLibrary().getCardList());
allCards.addAll(controller.getGraveyard());
int number = Math.min(5, allCards.size());
TargetCard target = new TargetCard(number, number, Zone.ALL, new FilterCard());

if (player.choose(Outcome.Benefit, allCards, target, game)) {
// exile the rest
for (UUID uuid : allCards) {
if (!target.getTargets().contains(uuid)) {
Card card = game.getCard(uuid);
if (card != null) {
card.moveToExile(null, "Doomsday", source.getSourceId(), game);
}
} else {
cards.add(uuid);
}

}
if (controller.choose(Outcome.Benefit, allCards, target, game)) {
Cards toLibrary = new CardsImpl(target.getTargets());
allCards.removeAll(toLibrary);
// Exile the rest
controller.moveCards(allCards, Zone.EXILED, source, game);
//Put the chosen cards on top of your library in any order
target = new TargetCard(Zone.ALL, new FilterCard("Card to put on top"));
while (cards.size() > 1 && player.canRespond()) {
player.choose(Outcome.Neutral, cards, target, game);
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
}
target.clearChosen();
}
if (cards.size() == 1) {
Card card = cards.get(cards.iterator().next(), game);
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
}
controller.putCardsOnTopOfLibrary(toLibrary, game, source, true);
}

return true;
}
return false;
Expand Down
21 changes: 4 additions & 17 deletions Mage.Sets/src/mage/cards/d/DwellOnThePast.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
Expand Down Expand Up @@ -61,23 +62,9 @@ public DwellOnThePastEffect copy() {

@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player != null) {
List<UUID> targets = source.getTargets().get(1).getTargets();
boolean shuffle = false;
for (UUID targetId : targets) {
Card card = game.getCard(targetId);
if (card != null) {
if (player.getGraveyard().contains(card.getId())) {
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
shuffle = true;
}
}
}
if (shuffle) {
player.shuffleLibrary(source, game);
}
return true;
Player controller = game.getPlayer(source.getFirstTarget());
if (controller != null) {
return controller.shuffleCardsToLibrary(new CardsImpl(source.getTargets().get(1).getTargets()), game, source);
}
return false;
}
Expand Down
11 changes: 6 additions & 5 deletions Mage.Sets/src/mage/cards/e/EpitaphGolem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.PutOnLibraryTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInYourGraveyard;

/**
Expand All @@ -32,7 +33,7 @@ public EpitaphGolem(UUID ownerId, CardSetInfo setInfo) {
// {2}: Put target card from your graveyard on the bottom of your library.
Ability ability = new SimpleActivatedAbility(
Zone.BATTLEFIELD,
new EpitaphGolemGraveyardToLibraryEffect(),
new PutOnLibraryTargetEffect(true),
new ManaCostsImpl("{2}"));
ability.addTarget(new TargetCardInYourGraveyard());
this.addAbility(ability);
Expand Down Expand Up @@ -66,9 +67,9 @@ public EpitaphGolemGraveyardToLibraryEffect copy() {

@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
return card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
return controller.putCardsOnBottomOfLibrary(game.getCard(getTargetPointer().getFirst(game, source)), game, source, true);
}
return false;
}
Expand Down
31 changes: 5 additions & 26 deletions Mage.Sets/src/mage/cards/g/GaeasBlessing.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

package mage.cards.g;

import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.ZoneChangeTriggeredAbility;
Expand All @@ -10,6 +9,7 @@
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.cards.CardsImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
Expand Down Expand Up @@ -68,23 +68,9 @@ public GaeasBlessingEffect copy() {

@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player != null) {
List<UUID> targets = source.getTargets().get(1).getTargets();
boolean shuffle = false;
for (UUID targetId : targets) {
Card card = game.getCard(targetId);
if (card != null) {
if (player.getGraveyard().contains(card.getId())) {
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
shuffle = true;
}
}
}
if (shuffle) {
player.shuffleLibrary(source, game);
}
return true;
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
return targetPlayer.shuffleCardsToLibrary(new CardsImpl(source.getTargets().get(1).getTargets()), game, source);
}
return false;
}
Expand Down Expand Up @@ -154,14 +140,7 @@ public GaeasBlessingGraveToLibraryEffect(final GaeasBlessingGraveToLibraryEffect
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
game.informPlayers(controller.getLogName() + " shuffle their graveyard into their library");
for (Card card : controller.getGraveyard().getCards(game)) {
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.GRAVEYARD, true, true);
}
controller.getLibrary().addAll(controller.getGraveyard().getCards(game), game);
controller.getGraveyard().clear();
controller.shuffleLibrary(source, game);
return true;
return controller.shuffleCardsToLibrary(controller.getGraveyard(), game, source);
}
return false;
}
Expand Down
Loading

0 comments on commit 305dab9

Please sign in to comment.