* Fixed some card movement (fixes #4910).

This commit is contained in:
LevelX2 2018-05-08 18:01:15 +02:00
parent 7b4ca412b8
commit df987049c0
43 changed files with 481 additions and 548 deletions

View file

@ -54,6 +54,12 @@ public class CardsImpl extends LinkedHashSet<UUID> implements Cards, Serializabl
}
}
public CardsImpl(Set<Card> cards) {
for (Card card : cards) {
this.add(card.getId());
}
}
public CardsImpl(Collection<UUID> cardIds) {
if (cardIds != null) {
this.addAll(cardIds);

View file

@ -136,24 +136,26 @@ public class Library implements Serializable {
}
public void putCardThirdFromTheTop(Card card, Game game) {
if (card != null && card.getOwnerId().equals(playerId)) {
Card cardTop = null;
Card cardSecond = null;
if (hasCards()) {
cardTop = removeFromTop(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);
}
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);
}
}
@ -190,6 +192,12 @@ public class Library implements Serializable {
return new ArrayList<>(library);
}
/**
* Returns the cards of the library in a list ordered from top to buttom
*
* @param game
* @return
*/
public List<Card> getCards(Game game) {
return library.stream().map(game::getCard).collect(Collectors.toList());
}

View file

@ -474,14 +474,41 @@ public interface Player extends MageItem, Copyable<Player> {
void resetStoredBookmark(Game game);
void revealCards(Ability source, Cards cards, Game game);
void revealCards(String name, Cards cards, Game game);
void revealCards(Ability source, String name, Cards cards, Game game);
void revealCards(String name, Cards cards, Game game, boolean postToLog);
/**
* Adds the cards to the reveal window and adds the source object's id name
* to the title bar of the revealed cards window
*
* @param source
* @param name
* @param cards
* @param game
* @param postToLog
*/
void revealCards(Ability source, String name, Cards cards, Game game, boolean postToLog);
void lookAtCards(String name, Card card, Game game);
void lookAtCards(String name, Cards cards, Game game);
/**
* Adds the cards to the look window and adds the source object's id name to
* the title bar of the lookedAt window
*
* @param source
* @param name
* @param cards
* @param game
*/
void lookAtCards(Ability source, String name, Cards cards, Game game);
@Override
Player copy();

View file

@ -1474,16 +1474,34 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public void revealCards(String name, Cards cards, Game game) {
revealCards(name, cards, game, true);
public void revealCards(Ability source, Cards cards, Game game) {
revealCards(source, null, cards, game, true);
}
@Override
public void revealCards(String name, Cards cards, Game game, boolean postToLog) {
public void revealCards(String titleSuffix, Cards cards, Game game) {
revealCards(titleSuffix, cards, game, true);
}
@Override
public void revealCards(String titleSuffix, Cards cards, Game game, boolean postToLog) {
revealCards(null, titleSuffix, cards, game, postToLog);
}
@Override
public void revealCards(Ability source, String titleSuffix, Cards cards, Game game) {
revealCards(source, titleSuffix, cards, game, true);
}
@Override
public void revealCards(Ability source, String titleSuffix, Cards cards, Game game, boolean postToLog) {
if (cards == null || cards.isEmpty()) {
return;
}
if (postToLog) {
game.getState().getRevealed().add(name, cards);
game.getState().getRevealed().add(CardUtil.createObjectRealtedWindowTitle(source, game, titleSuffix), cards);
} else {
game.getState().getRevealed().update(name, cards);
game.getState().getRevealed().update(CardUtil.createObjectRealtedWindowTitle(source, game, titleSuffix), cards);
}
if (postToLog && !game.isSimulation()) {
StringBuilder sb = new StringBuilder(getLogName()).append(" reveals ");
@ -1500,14 +1518,19 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public void lookAtCards(String name, Card card, Game game) {
game.getState().getLookedAt(this.playerId).add(name, card);
public void lookAtCards(String titleSuffix, Card card, Game game) {
game.getState().getLookedAt(this.playerId).add(titleSuffix, card);
game.fireUpdatePlayersEvent();
}
@Override
public void lookAtCards(String name, Cards cards, Game game) {
game.getState().getLookedAt(this.playerId).add(name, cards);
public void lookAtCards(String titleSuffix, Cards cards, Game game) {
this.lookAtCards(null, titleSuffix, cards, game);
}
@Override
public void lookAtCards(Ability source, String titleSuffix, Cards cards, Game game) {
game.getState().getLookedAt(this.playerId).add(CardUtil.createObjectRealtedWindowTitle(source, game, titleSuffix), cards);
game.fireUpdatePlayersEvent();
}

View file

@ -7,9 +7,11 @@ package mage.target.targetpointer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.cards.Cards;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -46,6 +48,14 @@ public class FixedTargets implements TargetPointer {
this.initialized = true;
}
public FixedTargets(Set<Card> cards, Game game) {
for (Card card : cards) {
MageObjectReference mor = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game), game);
targets.add(mor);
}
this.initialized = true;
}
private FixedTargets(final FixedTargets fixedTargets) {
this.targets.addAll(fixedTargets.targets);
this.targetsNotInitialized.addAll(fixedTargets.targetsNotInitialized);

View file

@ -27,6 +27,7 @@
*/
package mage.util;
import java.util.UUID;
import mage.MageObject;
import mage.Mana;
import mage.abilities.Ability;
@ -37,22 +38,18 @@ import mage.abilities.costs.mana.*;
import mage.cards.Card;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.TokenImpl;
import mage.game.permanent.token.Token;
import mage.util.functions.CopyTokenFunction;
import java.util.UUID;
/**
* @author nantuko
*/
public final class CardUtil {
private static final String SOURCE_EXILE_ZONE_TEXT = "SourceExileZone";
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"};
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"};
/**
* Increase spell or ability cost to be paid.
@ -133,7 +130,6 @@ public final class CardUtil {
return adjustedCost;
}
public static void reduceCost(SpellAbility spellAbility, ManaCosts<ManaCost> manaCostsToReduce) {
adjustCost(spellAbility, manaCostsToReduce, true);
}
@ -154,8 +150,8 @@ public final class CardUtil {
*
* @param spellAbility
* @param manaCostsToReduce costs to reduce
* @param convertToGeneric colored mana does reduce generic mana if no
* appropriate colored mana is in the costs included
* @param convertToGeneric colored mana does reduce generic mana if no
* appropriate colored mana is in the costs included
*/
public static void adjustCost(SpellAbility spellAbility, ManaCosts<ManaCost> manaCostsToReduce, boolean convertToGeneric) {
ManaCosts<ManaCost> previousCost = spellAbility.getManaCostsToPay();
@ -340,7 +336,7 @@ public final class CardUtil {
*
* @param number number to convert to text
* @param forOne if the number is 1, this string will be returnedinstead of
* "one".
* "one".
* @return
*/
public static String numberToText(int number, String forOne) {
@ -383,21 +379,22 @@ public final class CardUtil {
return true;
}
/**
* Parse card number as int (support base [123] and alternative numbers [123b]).
* Parse card number as int (support base [123] and alternative numbers
* [123b]).
*
* @param cardNumber origin card number
* @return int
*/
public static int parseCardNumberAsInt(String cardNumber){
public static int parseCardNumberAsInt(String cardNumber) {
if (cardNumber.isEmpty()){ throw new IllegalArgumentException("Card number is empty.");}
if (cardNumber.isEmpty()) {
throw new IllegalArgumentException("Card number is empty.");
}
if(Character.isDigit(cardNumber.charAt(cardNumber.length() - 1)))
{
if (Character.isDigit(cardNumber.charAt(cardNumber.length() - 1))) {
return Integer.parseInt(cardNumber);
}else{
} else {
return Integer.parseInt(cardNumber.substring(0, cardNumber.length() - 1));
}
}
@ -405,7 +402,7 @@ public final class CardUtil {
/**
* Creates and saves a (card + zoneChangeCounter) specific exileId.
*
* @param game the current game
* @param game the current game
* @param source source ability
* @return the specific UUID
*/
@ -440,9 +437,9 @@ public final class CardUtil {
* be specific to a permanent instance. So they won't match, if a permanent
* was e.g. exiled and came back immediately.
*
* @param text short value to describe the value
* @param text short value to describe the value
* @param cardId id of the card
* @param game the game
* @param game the game
* @return
*/
public static String getCardZoneString(String text, UUID cardId, Game game) {
@ -513,9 +510,9 @@ public final class CardUtil {
public static int addWithOverflowCheck(int base, int increment) {
long result = ((long) base) + increment;
if (result > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
return Integer.MAX_VALUE;
} else if (result < Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
return Integer.MIN_VALUE;
}
return base + increment;
}
@ -523,11 +520,28 @@ public final class CardUtil {
public static int subtractWithOverflowCheck(int base, int decrement) {
long result = ((long) base) - decrement;
if (result > Integer.MAX_VALUE) {
return Integer.MAX_VALUE;
return Integer.MAX_VALUE;
} else if (result < Integer.MIN_VALUE) {
return Integer.MIN_VALUE;
return Integer.MIN_VALUE;
}
return base - decrement;
}
public static String createObjectRealtedWindowTitle(Ability source, Game game, String textSuffix) {
String title;
if (source != null) {
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null) {
title = sourceObject.getIdName()
+ " [" + source.getSourceObjectZoneChangeCounter() + "]"
+ (textSuffix == null ? "" : " " + textSuffix);
} else {
title = textSuffix == null ? "" : textSuffix;
}
} else {
title = textSuffix == null ? "" : textSuffix;;
}
return title;
}
}