mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
* Adventure cards - improved game logs (card hint works with adventure spell now, added original card info to cast's log);
This commit is contained in:
parent
713110eb03
commit
862fe69b53
9 changed files with 141 additions and 62 deletions
|
|
@ -99,6 +99,12 @@ public class AdventureCardSpellImpl extends CardImpl implements AdventureCardSpe
|
|||
public AdventureCard getParentCard() {
|
||||
return this.adventureCardParent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdName() {
|
||||
// id must send to main card (popup card hint in game logs)
|
||||
return getName() + " [" + adventureCardParent.getId().toString().substring(0, 3) + ']';
|
||||
}
|
||||
}
|
||||
|
||||
class AdventureCardSpellAbility extends SpellAbility {
|
||||
|
|
|
|||
|
|
@ -15,10 +15,7 @@ import mage.abilities.costs.mana.ManaCosts;
|
|||
import mage.abilities.keyword.BestowAbility;
|
||||
import mage.abilities.keyword.MorphAbility;
|
||||
import mage.abilities.text.TextPart;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.CardsImpl;
|
||||
import mage.cards.FrameStyle;
|
||||
import mage.cards.SplitCard;
|
||||
import mage.cards.*;
|
||||
import mage.constants.*;
|
||||
import mage.counters.Counter;
|
||||
import mage.counters.Counters;
|
||||
|
|
@ -168,6 +165,13 @@ public class Spell extends StackObjImpl implements Card {
|
|||
return "a card face down";
|
||||
}
|
||||
}
|
||||
|
||||
if (card instanceof AdventureCardSpell) {
|
||||
AdventureCard adventureCard = ((AdventureCardSpell) card).getParentCard();
|
||||
return GameLog.replaceNameByColoredName(card, getSpellAbility().toString(), adventureCard)
|
||||
+ " as Adventure spell of " + GameLog.getColoredObjectIdName(adventureCard);
|
||||
}
|
||||
|
||||
return GameLog.replaceNameByColoredName(card, getSpellAbility().toString());
|
||||
}
|
||||
|
||||
|
|
@ -421,7 +425,11 @@ public class Spell extends StackObjImpl implements Card {
|
|||
public String getIdName() {
|
||||
String idName;
|
||||
if (card != null) {
|
||||
idName = card.getId().toString().substring(0, 3);
|
||||
if (card instanceof AdventureCardSpell) {
|
||||
idName = ((AdventureCardSpell) card).getParentCard().getId().toString().substring(0, 3);
|
||||
} else {
|
||||
idName = card.getId().toString().substring(0, 3);
|
||||
}
|
||||
} else {
|
||||
idName = getId().toString().substring(0, 3);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
package mage.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import mage.MageObject;
|
||||
import mage.Mana;
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -17,6 +14,13 @@ import mage.game.permanent.Permanent;
|
|||
import mage.game.permanent.token.Token;
|
||||
import mage.util.functions.CopyTokenFunction;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author nantuko
|
||||
*/
|
||||
|
|
@ -25,10 +29,10 @@ 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"};
|
||||
|
||||
static final String[] ordinalStrings = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eightth", "ninth",
|
||||
"tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth"};
|
||||
"tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth"};
|
||||
|
||||
public static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
|
||||
|
||||
|
|
@ -143,8 +147,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();
|
||||
|
|
@ -329,7 +333,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) {
|
||||
|
|
@ -414,7 +418,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
|
||||
*/
|
||||
|
|
@ -449,9 +453,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) {
|
||||
|
|
@ -577,4 +581,28 @@ public final class CardUtil {
|
|||
Card card = game.getCard(objectId);
|
||||
return card != null ? card.getMainCard().getId() : objectId;
|
||||
}
|
||||
|
||||
public static String urlEncode(String data) {
|
||||
if (data.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
return URLEncoder.encode(data, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String urlDecode(String encodedData) {
|
||||
if (encodedData.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
try {
|
||||
return URLDecoder.decode(encodedData, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
|
||||
package mage.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public final class ClassScanner {
|
||||
|
|
@ -30,7 +27,7 @@ public final class ClassScanner {
|
|||
public static List<Class> findClasses(ClassLoader classLoader, List<String> packages, Class<?> type) {
|
||||
List<Class> cards = new ArrayList<>();
|
||||
try {
|
||||
if(classLoader == null) classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) classLoader = Thread.currentThread().getContextClassLoader();
|
||||
assert classLoader != null;
|
||||
|
||||
Map<String, String> dirs = new HashMap<>();
|
||||
|
|
@ -56,7 +53,7 @@ public final class ClassScanner {
|
|||
}
|
||||
|
||||
for (String filePath : jars) {
|
||||
File file = new File(URLDecoder.decode(filePath, "UTF-8"));
|
||||
File file = new File(CardUtil.urlDecode(filePath));
|
||||
cards.addAll(findClassesInJar(classLoader, file, packages, type));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
|
|
@ -82,7 +79,7 @@ public final class ClassScanner {
|
|||
if (!file.exists()) return cards;
|
||||
|
||||
|
||||
try(JarInputStream jarFile = new JarInputStream(new FileInputStream(file))) {
|
||||
try (JarInputStream jarFile = new JarInputStream(new FileInputStream(file))) {
|
||||
while (true) {
|
||||
JarEntry jarEntry = jarFile.getNextJarEntry();
|
||||
if (jarEntry == null) {
|
||||
|
|
|
|||
|
|
@ -33,32 +33,50 @@ public final class GameLog {
|
|||
return text.replaceAll(mageObject.getName(), getColoredObjectIdName(mageObject));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mageObject - original object name to replace
|
||||
* @param text - original text to insert object's html name
|
||||
* @param alternativeObject - alternative object (object to show in card's hint in GUI)
|
||||
* @return
|
||||
*/
|
||||
public static String replaceNameByColoredName(MageObject mageObject, String text, MageObject alternativeObject) {
|
||||
return text.replaceAll(mageObject.getName(), getColoredObjectIdName(mageObject, alternativeObject));
|
||||
}
|
||||
|
||||
public static String getColoredObjectName(MageObject mageObject) {
|
||||
return "<font color=\'" + getColorName(mageObject.getColor(null)) + "\'>" + mageObject.getName() + "</font>";
|
||||
return "<font color='" + getColorName(mageObject.getColor(null)) + "'>" + mageObject.getName() + "</font>";
|
||||
}
|
||||
|
||||
public static String getColoredObjectIdName(MageObject mageObject) {
|
||||
return "<font color=\'" + getColorName(mageObject.getColor(null)) + "\'>" + mageObject.getIdName() + "</font>";
|
||||
return getColoredObjectIdName(mageObject, null);
|
||||
}
|
||||
|
||||
public static String getColoredObjectIdName(MageObject mageObject, MageObject alternativeObject) {
|
||||
return "<font"
|
||||
+ " color='" + getColorName(mageObject.getColor(null)) + "'"
|
||||
+ " object_id='" + mageObject.getId() + "'"
|
||||
+ (alternativeObject == null ? "" : " alternative_name='" + CardUtil.urlEncode(alternativeObject.getName()) + "'")
|
||||
+ ">" + mageObject.getIdName() + "</font>";
|
||||
}
|
||||
|
||||
public static String getColoredObjectIdNameForTooltip(MageObject mageObject) {
|
||||
return "<font color=\'" + getTooltipColorName(mageObject.getColor(null)) + "\'>" + mageObject.getIdName() + "</font>";
|
||||
return "<font color='" + getTooltipColorName(mageObject.getColor(null)) + "'>" + mageObject.getIdName() + "</font>";
|
||||
}
|
||||
|
||||
public static String getNeutralColoredText(String text) {
|
||||
return "<font color=\'" + LOG_COLOR_NEUTRAL + "\'>" + text + "</font>";
|
||||
return "<font color='" + LOG_COLOR_NEUTRAL + "'>" + text + "</font>";
|
||||
}
|
||||
|
||||
public static String getColoredPlayerName(String name) {
|
||||
return "<font color=\'" + LOG_COLOR_PLAYER + "\'>" + name + "</font>";
|
||||
return "<font color='" + LOG_COLOR_PLAYER + "'>" + name + "</font>";
|
||||
}
|
||||
|
||||
public static String getPlayerRequestColoredText(String name) {
|
||||
return "<font color=\'" + LOG_COLOR_PLAYER_REQUEST + "\'>" + name + "</font>";
|
||||
return "<font color='" + LOG_COLOR_PLAYER_REQUEST + "'>" + name + "</font>";
|
||||
}
|
||||
|
||||
public static String getPlayerConfirmColoredText(String name) {
|
||||
return "<font color=\'" + LOG_COLOR_PLAYER_CONFIRM + "\'>" + name + "</font>";
|
||||
return "<font color='" + LOG_COLOR_PLAYER_CONFIRM + "'>" + name + "</font>";
|
||||
}
|
||||
|
||||
public static String getSmallSecondLineText(String text) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue