mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
Some fixes to putOnTop/buttomOfLibrary of player to handle cards and permanents.
This commit is contained in:
parent
f9f6fd2d2d
commit
d4044536cb
2 changed files with 41 additions and 36 deletions
|
@ -110,7 +110,11 @@ public class PutOnLibraryTargetEffect extends OneShotEffect {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, onTop);
|
if (onTop) {
|
||||||
|
owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
|
||||||
|
} else {
|
||||||
|
owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!permanents.isEmpty()) {
|
while (!permanents.isEmpty()) {
|
||||||
|
@ -125,7 +129,11 @@ public class PutOnLibraryTargetEffect extends OneShotEffect {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, onTop);
|
if (onTop) {
|
||||||
|
owner.putCardsOnTopOfLibrary(cardsPlayer, game, source, true);
|
||||||
|
} else {
|
||||||
|
owner.putCardsOnBottomOfLibrary(cardsPlayer, game, source, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -819,13 +819,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
public boolean putCardsOnBottomOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder) {
|
public boolean putCardsOnBottomOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder) {
|
||||||
if (cards.size() != 0) {
|
if (cards.size() != 0) {
|
||||||
if (!anyOrder) {
|
if (!anyOrder) {
|
||||||
for (UUID cardId : cards) {
|
for (UUID objectId : cards) {
|
||||||
Card card =game.getCard(cardId);
|
moveObjectToLibrary(objectId, source.getSourceId(), game, false, false);
|
||||||
|
|
||||||
if (card != null) {
|
|
||||||
Zone fromZone = game.getState().getZone(cardId);
|
|
||||||
this.moveCardToLibraryWithInfo(card, source.getSourceId(), game, fromZone, false, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library (last one chosen will be bottommost)"));
|
TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library (last one chosen will be bottommost)"));
|
||||||
|
@ -835,32 +830,36 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
Card chosenCard = cards.get(target.getFirstTarget(), game);
|
Card chosenCard = cards.get(target.getFirstTarget(), game);
|
||||||
if (chosenCard != null) {
|
if (chosenCard != null) {
|
||||||
cards.remove(chosenCard);
|
cards.remove(chosenCard);
|
||||||
Zone fromZone = game.getState().getZone(chosenCard.getId());
|
moveObjectToLibrary(chosenCard.getId(), source.getSourceId(), game, false, false);
|
||||||
this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, false, false);
|
|
||||||
}
|
}
|
||||||
target.clearChosen();
|
target.clearChosen();
|
||||||
}
|
}
|
||||||
if (cards.size() == 1) {
|
if (cards.size() == 1) {
|
||||||
Card chosenCard = cards.get(cards.iterator().next(), game);
|
Card chosenCard = cards.get(cards.iterator().next(), game);
|
||||||
Zone fromZone = game.getState().getZone(chosenCard.getId());
|
moveObjectToLibrary(chosenCard.getId(), source.getSourceId(), game, false, false);
|
||||||
this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, false, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Can be cards or permanents that go to library
|
||||||
|
*
|
||||||
|
* @param cards
|
||||||
|
* @param game
|
||||||
|
* @param source
|
||||||
|
* @param anyOrder
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean putCardsOnTopOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder) {
|
public boolean putCardsOnTopOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder) {
|
||||||
if (cards.size() != 0) {
|
if (cards.size() != 0) {
|
||||||
if (!anyOrder) {
|
if (!anyOrder) {
|
||||||
for (UUID cardId : cards) {
|
for (UUID cardId : cards) {
|
||||||
Card card =game.getCard(cardId);
|
moveObjectToLibrary(cardId, source.getSourceId(), game, true, false);
|
||||||
|
|
||||||
if (card != null) {
|
|
||||||
Zone fromZone = game.getState().getZone(cardId);
|
|
||||||
this.moveCardToLibraryWithInfo(card, source.getSourceId(), game, fromZone, true, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the top of your library (last one chosen will be topmost)"));
|
TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the top of your library (last one chosen will be topmost)"));
|
||||||
|
@ -870,33 +869,31 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
Card chosenCard = cards.get(target.getFirstTarget(), game);
|
Card chosenCard = cards.get(target.getFirstTarget(), game);
|
||||||
if (chosenCard != null) {
|
if (chosenCard != null) {
|
||||||
cards.remove(chosenCard);
|
cards.remove(chosenCard);
|
||||||
Zone fromZone = game.getState().getZone(chosenCard.getId());
|
moveObjectToLibrary(chosenCard.getId(), source.getSourceId(), game, true, false);
|
||||||
if (fromZone.equals(Zone.BATTLEFIELD)) {
|
|
||||||
Permanent permanent = game.getPermanent(chosenCard.getId());
|
|
||||||
this.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, fromZone, true, false);
|
|
||||||
} else {
|
|
||||||
this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, true, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
target.clearChosen();
|
target.clearChosen();
|
||||||
}
|
}
|
||||||
if (cards.size() == 1) {
|
if (cards.size() == 1) {
|
||||||
// Card chosenCard = cards.get(cards.iterator().next(), game);
|
moveObjectToLibrary(cards.iterator().next(), source.getSourceId(), game, true, false);
|
||||||
UUID cardId = cards.iterator().next();
|
|
||||||
Zone fromZone = game.getState().getZone(cardId);
|
|
||||||
if (fromZone.equals(Zone.BATTLEFIELD)) {
|
|
||||||
Permanent permanent = game.getPermanent(cardId);
|
|
||||||
this.moveCardToLibraryWithInfo(permanent, source.getSourceId(), game, fromZone, true, false);
|
|
||||||
} else {
|
|
||||||
Card chosenCard = cards.get(cardId, game);
|
|
||||||
this.moveCardToLibraryWithInfo(chosenCard, source.getSourceId(), game, fromZone, true, false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean moveObjectToLibrary(UUID objectId, UUID sourceId, Game game, boolean toTop, boolean withName) {
|
||||||
|
MageObject mageObject =game.getObject(objectId);
|
||||||
|
if (mageObject != null) {
|
||||||
|
Zone fromZone = game.getState().getZone(objectId);
|
||||||
|
if ((mageObject instanceof Permanent)) {
|
||||||
|
return this.moveCardToLibraryWithInfo((Permanent) mageObject, sourceId, game, fromZone, toTop, withName);
|
||||||
|
} else if (mageObject instanceof Card) {
|
||||||
|
return this.moveCardToLibraryWithInfo((Card) mageObject, sourceId, game, fromZone, toTop, withName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCastSourceIdWithoutMana(UUID sourceId) {
|
public void setCastSourceIdWithoutMana(UUID sourceId) {
|
||||||
castSourceIdWithoutMana = sourceId;
|
castSourceIdWithoutMana = sourceId;
|
||||||
|
|
Loading…
Reference in a new issue