Fixed handling of cards that exist multiple times for Unstable.

This commit is contained in:
LevelX2 2017-12-30 18:35:47 +01:00
parent 48e6b475f3
commit 88b06137be
4 changed files with 32 additions and 29 deletions

View file

@ -4,7 +4,6 @@ import java.io.File;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.HashMap;
import java.util.Objects;
import java.util.prefs.Preferences;
import mage.client.MageFrame;
import mage.client.constants.Constants;
@ -122,17 +121,17 @@ public final class CardImageUtils {
return set;
}
public static String prepareCardNameForFile(String cardName){
public static String prepareCardNameForFile(String cardName) {
return cardName.replace(":", "").replace("\"", "").replace("//", "-");
}
public static String getImagesDir(){
public static String getImagesDir() {
// return real images dir (path without separator)
String path = null;
// user path
if (!PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true").equals("true")){
if (!PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true").equals("true")) {
path = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
}
@ -141,8 +140,7 @@ public final class CardImageUtils {
path = Constants.IO.DEFAULT_IMAGES_DIR;
}
while(path.endsWith(File.separator))
{
while (path.endsWith(File.separator)) {
path = path.substring(0, path.length() - 1);
}
@ -152,7 +150,6 @@ public final class CardImageUtils {
public static String buildImagePathToTokens() {
String imagesPath = getImagesDir() + File.separator;
if (PreferencesDialog.isSaveImagesToZip()) {
return imagesPath + "TOK.zip" + File.separator;
} else {
@ -198,20 +195,25 @@ public final class CardImageUtils {
String setPath = buildImagePathToSet(card);
String prefixType = "";
if(card.getType() != 0){
if (card.getType() != 0) {
prefixType = " " + Integer.toString(card.getType());
}
String cardName = card.getFileName();
if (cardName.isEmpty()){
if (cardName.isEmpty()) {
cardName = prepareCardNameForFile(card.getName());
}
String finalFileName = "";
if (card.getUsesVariousArt()){
if (card.getUsesVariousArt()) {
finalFileName = cardName + '.' + card.getCollectorId() + ".full.jpg";
}else{
finalFileName = cardName + prefixType + ".full.jpg";
} else {
int len = card.getCollectorId().length();
if (Character.isLetter(card.getCollectorId().charAt(len - 1))) {
finalFileName = cardName + card.getCollectorId().charAt(len - 1) + ".full.jpg";
} else {
finalFileName = cardName + prefixType + ".full.jpg";
}
}
// if image file exists, correct name (for case sensitive systems)
@ -219,17 +221,17 @@ public final class CardImageUtils {
TFile dirFile = new TFile(setPath);
TFile imageFile = new TFile(setPath + finalFileName);
// warning, zip files can be broken
try{
try {
if (dirFile.exists() && !imageFile.exists()) {
// search like names
for (String fileName: dirFile.list()) {
for (String fileName : dirFile.list()) {
if (fileName.toLowerCase().equals(finalFileName.toLowerCase())) {
finalFileName = fileName;
break;
}
}
}
}catch (Exception ex) {
} catch (Exception ex) {
log.error("Can't read card name from file, may be it broken: " + setPath);
}

View file

@ -37,6 +37,7 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.CounterPredicate;
import mage.game.Game;
@ -48,12 +49,12 @@ import mage.players.Player;
*
* @author spjspj
*/
public class GarbageElemental extends CardImpl {
public class GarbageElementalC extends CardImpl {
public GarbageElemental(UUID ownerId, CardSetInfo setInfo) {
public GarbageElementalC(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{4}{R}");
this.subtype.add("Elemental");
this.subtype.add(SubType.ELEMENTAL);
this.power = new MageInt(3);
this.toughness = new MageInt(2);
@ -68,13 +69,13 @@ public class GarbageElemental extends CardImpl {
}
public GarbageElemental(final GarbageElemental card) {
public GarbageElementalC(final GarbageElementalC card) {
super(card);
}
@Override
public GarbageElemental copy() {
return new GarbageElemental(this);
public GarbageElementalC copy() {
return new GarbageElementalC(this);
}
}
@ -106,7 +107,7 @@ class GarbageElementalEffect extends OneShotEffect {
if (controller != null) {
int thisRoll = controller.rollDice(game, 6);
int thatRoll = controller.rollDice(game, 6);
Token token = new GoblinToken();
return token.putOntoBattlefield(Math.abs(thatRoll - thisRoll), game, source.getSourceId(), source.getControllerId());
}

View file

@ -59,7 +59,7 @@ import mage.target.common.TargetCreaturePermanent;
*
* @author spjspj
*/
public class VeryCrypticCommand extends CardImpl {
public class VeryCrypticCommandD extends CardImpl {
private static final FilterStackObject filter = new FilterStackObject("spell or ability with a single target");
private static final FilterCreaturePermanent filter2 = new FilterCreaturePermanent("nontoken creature");
@ -69,7 +69,7 @@ public class VeryCrypticCommand extends CardImpl {
filter2.add(Predicates.not(new TokenPredicate()));
}
public VeryCrypticCommand(UUID ownerId, CardSetInfo setInfo) {
public VeryCrypticCommandD(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{U}{U}{U}");
// Choose two -
@ -101,13 +101,13 @@ public class VeryCrypticCommand extends CardImpl {
this.getSpellAbility().getModes().addMode(mode);
}
public VeryCrypticCommand(final VeryCrypticCommand card) {
public VeryCrypticCommandD(final VeryCrypticCommandD card) {
super(card);
}
@Override
public VeryCrypticCommand copy() {
return new VeryCrypticCommand(this);
public VeryCrypticCommandD copy() {
return new VeryCrypticCommandD(this);
}
}

View file

@ -60,7 +60,7 @@ public class Unstable extends ExpansionSet {
cards.add(new SetCardInfo("Earl of Squirrel", 108, Rarity.RARE, mage.cards.e.EarlOfSquirrel.class));
cards.add(new SetCardInfo("Forest", 216, Rarity.LAND, mage.cards.basiclands.Forest.class, new CardGraphicInfo(FrameStyle.UNH_FULL_ART_BASIC, false)));
cards.add(new SetCardInfo("GO TO JAIL", 8, Rarity.COMMON, mage.cards.g.GOTOJAIL.class));
cards.add(new SetCardInfo("Garbage Elemental", 82, Rarity.UNCOMMON, mage.cards.g.GarbageElemental.class));
cards.add(new SetCardInfo("Garbage Elemental", "82c", Rarity.UNCOMMON, mage.cards.g.GarbageElementalC.class));
cards.add(new SetCardInfo("Ground Pounder", 110, Rarity.COMMON, mage.cards.g.GroundPounder.class));
cards.add(new SetCardInfo("Hammer Helper", 85, Rarity.COMMON, mage.cards.h.HammerHelper.class));
cards.add(new SetCardInfo("Hydradoodle", 112, Rarity.RARE, mage.cards.h.Hydradoodle.class));
@ -81,7 +81,7 @@ public class Unstable extends ExpansionSet {
cards.add(new SetCardInfo("Sword of Dungeons & Dragons", 1, Rarity.MYTHIC, mage.cards.s.SwordOfDungeonsAndDragons.class));
cards.add(new SetCardInfo("Target Minotaur", 98, Rarity.COMMON, mage.cards.t.TargetMinotaur.class));
cards.add(new SetCardInfo("Time Out", 48, Rarity.COMMON, mage.cards.t.TimeOut.class));
cards.add(new SetCardInfo("Very Cryptic Command", 49, Rarity.RARE, mage.cards.v.VeryCrypticCommand.class));
cards.add(new SetCardInfo("Very Cryptic Command", "49d", Rarity.RARE, mage.cards.v.VeryCrypticCommandD.class));
cards.add(new SetCardInfo("Willing Test Subject", 126, Rarity.COMMON, mage.cards.w.WillingTestSubject.class));
cards.add(new SetCardInfo("capital offense", 52, Rarity.COMMON, mage.cards.c.CapitalOffense.class));
}