forked from External/mage
* Fixed some card movement (fixes #4910).
This commit is contained in:
parent
7b4ca412b8
commit
df987049c0
43 changed files with 481 additions and 548 deletions
|
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue