mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
* Some more fixed/reworked card movement handling.
This commit is contained in:
parent
d07209c33b
commit
dcd3e7c039
34 changed files with 253 additions and 436 deletions
|
|
@ -135,26 +135,17 @@ public class Library implements Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
public void putCardThirdFromTheTop(Card card, Game game) {
|
||||
if (card != null) {
|
||||
if (card.getOwnerId().equals(playerId)) {
|
||||
Card cardTop = null;
|
||||
Card cardSecond = null;
|
||||
if (hasCards()) {
|
||||
cardTop = removeFromTop(game);
|
||||
}
|
||||
if (hasCards()) {
|
||||
cardSecond = removeFromTop(game);
|
||||
}
|
||||
putOnTop(card, game);
|
||||
if (cardSecond != null) {
|
||||
putOnTop(cardSecond, game);
|
||||
}
|
||||
if (cardTop != null) {
|
||||
putOnTop(cardTop, game);
|
||||
}
|
||||
} else {
|
||||
game.getPlayer(card.getOwnerId()).getLibrary().putCardThirdFromTheTop(card, game);
|
||||
public void putCardToTopXPos(Card card, int pos, Game game) {
|
||||
if (card != null && pos > -1) {
|
||||
LinkedList<Card> save = new LinkedList<>();
|
||||
int idx = 1;
|
||||
while (hasCards() && idx < pos) {
|
||||
idx++;
|
||||
save.add(removeFromTop(game));
|
||||
}
|
||||
putOnTop(card, game);
|
||||
while (!save.isEmpty()) {
|
||||
putOnTop(save.removeLast(), game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -562,6 +562,17 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
*/
|
||||
boolean putCardsOnBottomOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder);
|
||||
|
||||
/**
|
||||
* Moves the card to the top x position of the library
|
||||
*
|
||||
* @param card
|
||||
* @param game
|
||||
* @param source
|
||||
* @param xFromTheTop
|
||||
* @return
|
||||
*/
|
||||
boolean putCardOnTopXOfLibrary(Card card, Game game, Ability source, int xFromTheTop);
|
||||
|
||||
/**
|
||||
* Moves the cards from cards to the top of players library.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ import mage.game.events.ZoneChangeEvent;
|
|||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
import mage.game.permanent.PermanentToken;
|
||||
import mage.game.permanent.token.SquirrelToken;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.game.stack.StackAbility;
|
||||
|
|
@ -894,6 +895,26 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean putCardOnTopXOfLibrary(Card card, Game game, Ability source, int xFromTheTop) {
|
||||
if (card.getOwnerId().equals(getId())) {
|
||||
if (library.size() + 1 < xFromTheTop) {
|
||||
putCardsOnBottomOfLibrary(new CardsImpl(card), game, source, true);
|
||||
} else {
|
||||
if (card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true) && !(card instanceof PermanentToken) && !card.isCopy()) {
|
||||
card = getLibrary().removeFromTop(game);
|
||||
getLibrary().putCardToTopXPos(card, xFromTheTop, game);
|
||||
game.informPlayers(card.getLogName() + " is put into " + getLogName() + "'s library " + CardUtil.numberToOrdinalText(xFromTheTop) + " from the top");
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return game.getPlayer(card.getOwnerId()).putCardOnTopXOfLibrary(card, game, source, xFromTheTop);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be cards or permanents that go to library
|
||||
*
|
||||
|
|
@ -1840,6 +1861,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
return gainLife(amount, game, source.getSourceId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int gainLife(int amount, Game game, UUID sourceId) {
|
||||
if (!canGainLife || amount == 0) {
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -51,6 +51,9 @@ public final class CardUtil {
|
|||
static final String[] numberStrings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
|
||||
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"};
|
||||
|
||||
static final String[] ordinalStrings = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eightth", "ninth",
|
||||
"tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth"};
|
||||
|
||||
/**
|
||||
* Increase spell or ability cost to be paid.
|
||||
*
|
||||
|
|
@ -363,6 +366,13 @@ public final class CardUtil {
|
|||
return number;
|
||||
}
|
||||
|
||||
public static String numberToOrdinalText(int number) {
|
||||
if (number >= 1 && number < 21) {
|
||||
return ordinalStrings[number - 1];
|
||||
}
|
||||
return Integer.toString(number) + "th";
|
||||
}
|
||||
|
||||
public static String replaceSourceName(String message, String sourceName) {
|
||||
message = message.replace("{this}", sourceName);
|
||||
message = message.replace("{source}", sourceName);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue