From d7e63120e5e28ec2468c218a2c5d6a3bc32b8326 Mon Sep 17 00:00:00 2001 From: North Date: Sat, 3 Nov 2012 23:44:24 +0200 Subject: [PATCH] [CardRepository] replaced getCardNames, getCardNonLandNames and getCreatureTypes --- Mage.Sets/src/mage/cache/Cache.java | 36 ------ Mage.Sets/src/mage/cache/CacheDataHelper.java | 116 ------------------ Mage.Sets/src/mage/cache/CacheService.java | 114 ----------------- Mage.Sets/src/mage/cache/CacheTest.java | 46 ------- .../mage/cards/repository/CardRepository.java | 51 +++++++- Mage.Sets/src/mage/sets/Sets.java | 25 ---- .../sets/avacynrestored/CavernOfSouls.java | 4 +- .../sets/avacynrestored/RidersOfGavony.java | 4 +- .../CranialExtraction.java | 4 +- .../sets/championsofkamigawa/Mindblaze.java | 4 +- .../src/mage/sets/innistrad/Nevermore.java | 4 +- .../src/mage/sets/judgment/CabalTherapy.java | 4 +- .../mage/sets/magic2011/ConundrumSphinx.java | 4 +- .../sets/magic2012/AdaptiveAutomaton.java | 4 +- .../mirrodinbesieged/PhyrexianRevoker.java | 4 +- .../src/mage/sets/newphyrexia/Xenograft.java | 4 +- .../sets/returntoravnica/SlaughterGames.java | 4 +- .../sets/saviorsofkamigawa/PithingNeedle.java | 4 +- .../mage/sets/scarsofmirrodin/Memoricide.java | 4 +- .../src/mage/sets/tempest/CursedScroll.java | 4 +- .../sets/urzaslegacy/EngineeredPlague.java | 5 +- 21 files changed, 80 insertions(+), 369 deletions(-) delete mode 100644 Mage.Sets/src/mage/cache/Cache.java delete mode 100644 Mage.Sets/src/mage/cache/CacheDataHelper.java delete mode 100644 Mage.Sets/src/mage/cache/CacheService.java delete mode 100644 Mage.Sets/src/mage/cache/CacheTest.java diff --git a/Mage.Sets/src/mage/cache/Cache.java b/Mage.Sets/src/mage/cache/Cache.java deleted file mode 100644 index eb9c207b446..00000000000 --- a/Mage.Sets/src/mage/cache/Cache.java +++ /dev/null @@ -1,36 +0,0 @@ -package mage.cache; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -/** - * Cache model - * - * @author noxx - */ -public class Cache implements Serializable { - - private int version; - private String name; - private Map cacheObjects = new HashMap(); - - public Cache(String name, int version) { - this.name = name; - this.version = version; - } - - public int getVersion() { - return version; - } - - public String getName() { - return name; - } - - public Map getCacheObjects() { - return cacheObjects; - } - - private static final long serialVersionUID = 1L; -} diff --git a/Mage.Sets/src/mage/cache/CacheDataHelper.java b/Mage.Sets/src/mage/cache/CacheDataHelper.java deleted file mode 100644 index ff5145ab5a3..00000000000 --- a/Mage.Sets/src/mage/cache/CacheDataHelper.java +++ /dev/null @@ -1,116 +0,0 @@ -package mage.cache; - -import org.apache.log4j.Logger; - -import java.io.*; - -/** - * @author noxx - */ -public class CacheDataHelper { - - private static final Logger log = Logger.getLogger(CacheDataHelper.class); - - /** - * Save object on disk. - * - * @param cache Cache object to save. - * @param name Part of name that will be used to form original filename to save object to. - */ - public static void cacheObject(Cache cache, String name) { - ObjectOutputStream oos = null; - try { - File dir = new File("cache"); - if (!dir.exists() || dir.exists() && dir.isFile()) { - boolean bCreated = dir.mkdir(); - if (!bCreated) { - log.error("Couldn't create directory for cache."); - return; - } - } - File f = new File("cache" + File.separator + name + ".obj"); - if (!f.exists()) { - f.createNewFile(); - } - oos = new ObjectOutputStream(new FileOutputStream(f)); - oos.writeObject(cache); - oos.close(); - - } catch (FileNotFoundException e) { - log.error("Error while caching data: ", e); - return; - } catch (IOException io) { - log.error("Error while caching data: ", io); - return; - } - } - - /** - * Gets Cache object from cache folder. - * - * @param name - * @return - */ - public static Cache getCachedObject(String name) { - ObjectInputStream ois = null; - try { - File dir = new File("cache"); - if (!dir.exists() || dir.exists() && dir.isFile()) { - return null; - } - File f = new File("cache" + File.separator + name + ".obj"); - if (!f.exists()) { - log.warn("Couldn't find cache for name: " + name); - return null; - } - ois = new ObjectInputStream(new FileInputStream(f)); - Object object = ois.readObject(); - - if (!(object instanceof Cache)) { - log.error("Cached object has wrong type: " + object.getClass().getName()); - return null; - } - - return (Cache)object; - - } catch (FileNotFoundException e) { - log.error("Error while reading cached data: ", e); - return null; - } catch (IOException io) { - log.error("Error while reading cached data: ", io); - return null; - } catch (ClassNotFoundException e) { - log.error("Error while reading cached data: ", e); - return null; - } finally { - try { - if (ois != null) { - ois.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * Validates cache for being consistent. - * - * @param cache - * @return - */ - public static boolean validateCache(Cache cache, int cacheVersion, int cardCount, String countKey) { - if (cache == null || cache.getVersion() != cacheVersion) { - return false; - } - Object object = cache.getCacheObjects().get(countKey); - if (object == null || !(object instanceof Integer)) { - return false; - } - Integer count = (Integer) object; - if (!count.equals(cardCount)) { - return false; - } - return true; - } -} diff --git a/Mage.Sets/src/mage/cache/CacheService.java b/Mage.Sets/src/mage/cache/CacheService.java deleted file mode 100644 index bc7dbad9883..00000000000 --- a/Mage.Sets/src/mage/cache/CacheService.java +++ /dev/null @@ -1,114 +0,0 @@ -package mage.cache; - -import mage.Constants; -import mage.cards.Card; -import mage.cards.ExpansionSet; -import org.apache.log4j.Logger; - -import java.util.*; - -/** - * @author noxx - */ -public class CacheService { - - private static final Logger log = Logger.getLogger(CacheService.class); - - private static final String CARDS_CACHE_OBJECT_NAME = "cards"; - private static final String CARDS_KEY = "cards_key"; - private static final String NAMES_CACHE_OBJECT_NAME = "card_names"; - private static final String NAMES_KEY = "card_names_key"; - private static final String CARD_COUNT_KEY = "card_count_key"; - private static final String CREATURE_TYPES_CACHE_OBJECT_NAME = "creature_types"; - private static final String CREATURE_TYPES_KEY = "creature_types_key"; - private static final String NONLAND_NAMES_CACHE_OBJECT_NAME = "nonland_names"; - private static final String NONLAND_NAMES_KEY = "nonland_names_key"; - - private static final int CACHE_VERSION = 1; - - public static List loadCards(Collection sets) { - Cache cache = CacheDataHelper.getCachedObject(CARDS_CACHE_OBJECT_NAME); - List cards = new ArrayList(); - if (cache == null || cache.getVersion() != CACHE_VERSION) { - for (ExpansionSet set : sets) { - cards.addAll(set.getCards()); - } - cache = new Cache(CARDS_CACHE_OBJECT_NAME, CACHE_VERSION); - cache.getCacheObjects().put(CARDS_KEY, cards); - cache.getCacheObjects().put(CARD_COUNT_KEY, cards.size()); - CacheDataHelper.cacheObject(cache, CARDS_CACHE_OBJECT_NAME); - } else { - cards = (List) cache.getCacheObjects().get(CARDS_KEY); - log.debug("Loaded cards from cache."); - } - - return cards; - } - - public static Set loadCardNames(List cards) { - Cache cache = CacheDataHelper.getCachedObject(NAMES_CACHE_OBJECT_NAME); - Set names = new TreeSet(); - if (!CacheDataHelper.validateCache(cache, CACHE_VERSION, cards.size(), CARD_COUNT_KEY)) { - for (Card card : cards) { - names.add(card.getName()); - } - cache = new Cache(NAMES_CACHE_OBJECT_NAME, CACHE_VERSION); - cache.getCacheObjects().put(NAMES_KEY, names); - cache.getCacheObjects().put(CARD_COUNT_KEY, cards.size()); - CacheDataHelper.cacheObject(cache, NAMES_CACHE_OBJECT_NAME); - } else { - Set cachedNames = (Set) cache.getCacheObjects().get(NAMES_KEY); - names.addAll(cachedNames); - log.debug("Loaded card names from cache."); - } - - return names; - } - - public static Set loadCreatureTypes(List cards) { - Set creatureTypes = new TreeSet(); - Cache cache = CacheDataHelper.getCachedObject(CREATURE_TYPES_CACHE_OBJECT_NAME); - if (!CacheDataHelper.validateCache(cache, CACHE_VERSION, cards.size(), CARD_COUNT_KEY)) { - for (Card card : cards) { - if (card.getCardType().contains(Constants.CardType.CREATURE)) { - for (String type : card.getSubtype()) { - creatureTypes.add(type); - if (type.equals("")) { - throw new IllegalStateException("Card with empty subtype: " + card.getName()); - } - } - } - } - cache = new Cache(CREATURE_TYPES_CACHE_OBJECT_NAME, CACHE_VERSION); - cache.getCacheObjects().put(CREATURE_TYPES_KEY, creatureTypes); - cache.getCacheObjects().put(CARD_COUNT_KEY, cards.size()); - CacheDataHelper.cacheObject(cache, CREATURE_TYPES_CACHE_OBJECT_NAME); - } else { - Set cachedCreatureTypes = (Set) cache.getCacheObjects().get(CREATURE_TYPES_KEY); - creatureTypes.addAll(cachedCreatureTypes); - log.debug("Loaded creature types from cache."); - } - - return creatureTypes; - } - - public static Set loadNonLandNames(List cards) { - Set nonLandNames = new TreeSet(); - Cache cache = CacheDataHelper.getCachedObject(NONLAND_NAMES_CACHE_OBJECT_NAME); - if (!CacheDataHelper.validateCache(cache, CACHE_VERSION, cards.size(), CARD_COUNT_KEY)) { - for (Card card : cards) { - if (!card.getCardType().contains(Constants.CardType.LAND)) nonLandNames.add(card.getName()); - } - cache = new Cache(NONLAND_NAMES_CACHE_OBJECT_NAME, CACHE_VERSION); - cache.getCacheObjects().put(NONLAND_NAMES_KEY, nonLandNames); - cache.getCacheObjects().put(CARD_COUNT_KEY, cards.size()); - CacheDataHelper.cacheObject(cache, NONLAND_NAMES_CACHE_OBJECT_NAME); - } else { - Set cachedNonLandNames = (Set) cache.getCacheObjects().get(NONLAND_NAMES_KEY); - nonLandNames.addAll(cachedNonLandNames); - log.debug("Loaded non land names from cache."); - } - - return nonLandNames; - } -} diff --git a/Mage.Sets/src/mage/cache/CacheTest.java b/Mage.Sets/src/mage/cache/CacheTest.java deleted file mode 100644 index 28fef6f1181..00000000000 --- a/Mage.Sets/src/mage/cache/CacheTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package mage.cache; - -import mage.Constants; -import mage.cards.Card; -import mage.cards.ExpansionSet; -import mage.sets.Sets; -import org.junit.Assert; -import org.junit.Test; - -import java.util.Set; - -/** - * @author noxx - */ -public class CacheTest { - - /** - * In case this test fails, it does mean that you need to update cache version in Sets.java - */ - @Test - public void testCacheConsistency() { - Set names = Sets.getCardNames(); - Set nonLandNames = Sets.getNonLandCardNames(); - Set creatureTypes = Sets.getCreatureTypes(); - - for (ExpansionSet set : Sets.getInstance().values()) { - for (Card card : set.getCards()) { - if (card.getCardType().contains(Constants.CardType.CREATURE)) { - for (String type : card.getSubtype()) { - if (!creatureTypes.contains(type)) { - Assert.assertTrue("Couldn't find a creature type in the cache: " + type, false); - } - } - } - if (!names.contains(card.getName())) { - Assert.assertTrue("Couldn't find a card name in the cache: " + card.getName(), false); - } - if (!card.getCardType().contains(Constants.CardType.LAND)) { - if (!nonLandNames.contains(card.getName())) { - Assert.assertTrue("Couldn't find a non-land card name in the cache: " + card.getName(), false); - } - } - } - } - } -} diff --git a/Mage.Sets/src/mage/cards/repository/CardRepository.java b/Mage.Sets/src/mage/cards/repository/CardRepository.java index 471682a8aa2..6902be403bb 100644 --- a/Mage.Sets/src/mage/cards/repository/CardRepository.java +++ b/Mage.Sets/src/mage/cards/repository/CardRepository.java @@ -39,8 +39,10 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.Set; import java.util.TreeSet; import java.util.concurrent.Callable; +import mage.Constants.CardType; /** * @@ -52,7 +54,7 @@ public enum CardRepository { private static final String JDBC_URL = "jdbc:sqlite:db/cards.db"; private Random random = new Random(); private Dao cardDao; - private TreeSet classNames; + private Set classNames; private CardRepository() { File file = new File("db"); @@ -121,6 +123,53 @@ public enum CardRepository { } } + public Set getNames() { + Set names = new TreeSet(); + try { + QueryBuilder qb = cardDao.queryBuilder(); + qb.distinct().selectColumns("name"); + List results = cardDao.query(qb.prepare()); + for (CardInfo card : results) { + names.add(card.getName()); + } + } catch (SQLException ex) { + } finally { + return names; + } + } + + public Set getNonLandNames() { + Set names = new TreeSet(); + try { + QueryBuilder qb = cardDao.queryBuilder(); + qb.distinct().selectColumns("name"); + qb.where().not().like("types", new SelectArg('%' + CardType.LAND.name() + '%')); + List results = cardDao.query(qb.prepare()); + for (CardInfo card : results) { + names.add(card.getName()); + } + } catch (SQLException ex) { + } finally { + return names; + } + } + + public Set getCreatureTypes() { + TreeSet subtypes = new TreeSet(); + try { + QueryBuilder qb = cardDao.queryBuilder(); + qb.distinct().selectColumns("subtypes"); + qb.where().like("types", new SelectArg('%' + CardType.CREATURE.name() + '%')); + List results = cardDao.query(qb.prepare()); + for (CardInfo card : results) { + subtypes.addAll(card.getSubTypes()); + } + } catch (SQLException ex) { + } finally { + return subtypes; + } + } + public CardInfo findCard(String setCode, int cardNumber) { try { QueryBuilder queryBuilder = cardDao.queryBuilder(); diff --git a/Mage.Sets/src/mage/sets/Sets.java b/Mage.Sets/src/mage/sets/Sets.java index 88800cdeda8..d748a9fa035 100644 --- a/Mage.Sets/src/mage/sets/Sets.java +++ b/Mage.Sets/src/mage/sets/Sets.java @@ -31,7 +31,6 @@ package mage.sets; import mage.Constants.CardType; import mage.Constants.ColoredManaSymbol; import mage.Mana; -import mage.cache.CacheService; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.ExpansionSet; @@ -50,9 +49,6 @@ public class Sets extends HashMap { private final static Logger logger = Logger.getLogger(Sets.class); private static final Sets fINSTANCE = new Sets(); - private static Set names; - private static Set nonLandNames; - private static Set creatureTypes; private static List cards; protected static Random rnd = new Random(); @@ -63,10 +59,7 @@ public class Sets extends HashMap { } private Sets() { - names = new TreeSet(); - nonLandNames = new TreeSet(); cards = new ArrayList(); - creatureTypes = new TreeSet(); this.addSet(AlaraReborn.getInstance()); this.addSet(Alliances.getInstance()); this.addSet(Antiquities.getInstance()); @@ -156,30 +149,12 @@ public class Sets extends HashMap { for (ExpansionSet set : getInstance().values()) { cards.addAll(set.getCards()); } - names = CacheService.loadCardNames(cards); - creatureTypes = CacheService.loadCreatureTypes(cards); - nonLandNames = CacheService.loadNonLandNames(cards); loaded = true; } } } } - public static Set getCardNames() { - loadCards(); - return names; - } - - public static Set getNonLandCardNames() { - loadCards(); - return nonLandNames; - } - - public static Set getCreatureTypes() { - loadCards(); - return creatureTypes; - } - public static Card getRandomCard() { loadCards(); return cards.get(rnd.nextInt(cards.size())); diff --git a/Mage.Sets/src/mage/sets/avacynrestored/CavernOfSouls.java b/Mage.Sets/src/mage/sets/avacynrestored/CavernOfSouls.java index f586d48510f..2906477f438 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/CavernOfSouls.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/CavernOfSouls.java @@ -43,6 +43,7 @@ import mage.abilities.mana.ConditionalAnyColorManaAbility; import mage.abilities.mana.builder.ConditionalManaBuilder; import mage.abilities.mana.conditional.CreatureCastManaCondition; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; @@ -50,7 +51,6 @@ import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.game.stack.Spell; import mage.players.Player; -import mage.sets.Sets; import mage.watchers.WatcherImpl; import java.util.ArrayList; @@ -109,7 +109,7 @@ class CavernOfSoulsEffect extends OneShotEffect { if (player != null && permanent != null) { Choice typeChoice = new ChoiceImpl(true); typeChoice.setMessage("Choose creature type"); - typeChoice.setChoices(Sets.getCreatureTypes()); + typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!player.choose(Constants.Outcome.Benefit, typeChoice, game)) { game.debugMessage("player canceled choosing type. retrying."); } diff --git a/Mage.Sets/src/mage/sets/avacynrestored/RidersOfGavony.java b/Mage.Sets/src/mage/sets/avacynrestored/RidersOfGavony.java index 4ff140ba41b..9f3b452a7bc 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/RidersOfGavony.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/RidersOfGavony.java @@ -39,6 +39,7 @@ import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.ProtectionAbility; import mage.abilities.keyword.VigilanceAbility; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.filter.FilterPermanent; @@ -47,7 +48,6 @@ import mage.filter.predicate.mageobject.SubtypePredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.sets.Sets; import java.util.UUID; @@ -103,7 +103,7 @@ class RidersOfGavonyEffect extends OneShotEffect { if (player != null && permanent != null) { Choice typeChoice = new ChoiceImpl(true); typeChoice.setMessage("Choose creature type"); - typeChoice.setChoices(Sets.getCreatureTypes()); + typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!player.choose(Constants.Outcome.BoostCreature, typeChoice, game)) { game.debugMessage("player canceled choosing type. retrying."); } diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/CranialExtraction.java b/Mage.Sets/src/mage/sets/championsofkamigawa/CranialExtraction.java index 1a46b1a913f..cf9c3b2c37e 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/CranialExtraction.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/CranialExtraction.java @@ -37,11 +37,11 @@ import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardsImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; import mage.players.Player; -import mage.sets.Sets; import mage.target.TargetPlayer; /** @@ -90,7 +90,7 @@ class CranialExtractionEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (player != null && controller != null) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getNonLandCardNames()); + cardChoice.setChoices(CardRepository.instance.getNonLandNames()); cardChoice.clearChoice(); while (!controller.choose(Outcome.Exile, cardChoice, game)) { diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/Mindblaze.java b/Mage.Sets/src/mage/sets/championsofkamigawa/Mindblaze.java index 52b3d43b5c9..f7aac6bba63 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/Mindblaze.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/Mindblaze.java @@ -39,13 +39,13 @@ import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.cards.Cards; import mage.cards.CardsImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.filter.FilterCard; import mage.filter.predicate.mageobject.NamePredicate; import mage.game.Game; import mage.players.Player; -import mage.sets.Sets; import mage.target.TargetPlayer; @@ -95,7 +95,7 @@ class MindblazeEffect extends OneShotEffect { Player playerControls = game.getPlayer(source.getControllerId()); if (player != null && playerControls != null) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getNonLandCardNames()); + cardChoice.setChoices(CardRepository.instance.getNonLandNames()); cardChoice.clearChoice(); Choice numberChoice = new ChoiceImpl(); numberChoice.setMessage("Choose a number greater than 0"); diff --git a/Mage.Sets/src/mage/sets/innistrad/Nevermore.java b/Mage.Sets/src/mage/sets/innistrad/Nevermore.java index 0c26cc54314..28b56039879 100644 --- a/Mage.Sets/src/mage/sets/innistrad/Nevermore.java +++ b/Mage.Sets/src/mage/sets/innistrad/Nevermore.java @@ -40,13 +40,13 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.players.Player; -import mage.sets.Sets; /** * @@ -93,7 +93,7 @@ class NevermoreEffect1 extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getNonLandCardNames()); + cardChoice.setChoices(CardRepository.instance.getNonLandNames()); cardChoice.clearChoice(); while (!controller.choose(Outcome.Detriment, cardChoice, game)) { game.debugMessage("player canceled choosing name. retrying."); diff --git a/Mage.Sets/src/mage/sets/judgment/CabalTherapy.java b/Mage.Sets/src/mage/sets/judgment/CabalTherapy.java index 8c6b6627e3e..762ff96ce03 100644 --- a/Mage.Sets/src/mage/sets/judgment/CabalTherapy.java +++ b/Mage.Sets/src/mage/sets/judgment/CabalTherapy.java @@ -39,11 +39,11 @@ import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.FlashbackAbility; import mage.cards.Card; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; import mage.players.Player; -import mage.sets.Sets; import mage.target.TargetPlayer; import mage.target.common.TargetControlledCreaturePermanent; @@ -93,7 +93,7 @@ class CabalTherapyEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (player != null && controller != null) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getNonLandCardNames()); + cardChoice.setChoices(CardRepository.instance.getNonLandNames()); cardChoice.clearChoice(); while (!controller.choose(Outcome.Discard, cardChoice, game)) { diff --git a/Mage.Sets/src/mage/sets/magic2011/ConundrumSphinx.java b/Mage.Sets/src/mage/sets/magic2011/ConundrumSphinx.java index 4af7682eacc..3327f03529f 100644 --- a/Mage.Sets/src/mage/sets/magic2011/ConundrumSphinx.java +++ b/Mage.Sets/src/mage/sets/magic2011/ConundrumSphinx.java @@ -42,11 +42,11 @@ import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.Cards; import mage.cards.CardsImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; import mage.players.Player; -import mage.sets.Sets; /** * @@ -91,7 +91,7 @@ class ConundrumSphinxEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getCardNames()); + cardChoice.setChoices(CardRepository.instance.getNames()); for (Player player: game.getPlayers().values()) { if(player.getLibrary().size() > 0){ cardChoice.clearChoice(); diff --git a/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java b/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java index 366a4df198d..d63678941c7 100644 --- a/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java +++ b/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java @@ -38,13 +38,13 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.sets.Sets; import java.util.UUID; @@ -96,7 +96,7 @@ class AdaptiveAutomatonEffect extends OneShotEffect { Permanent permanent = game.getPermanent(source.getSourceId()); if (player != null && permanent != null) { Choice typeChoice = new ChoiceImpl(true); - typeChoice.setChoices(Sets.getCreatureTypes()); + typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!player.choose(Constants.Outcome.BoostCreature, typeChoice, game)) { game.debugMessage("player canceled choosing type. retrying."); } diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/PhyrexianRevoker.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/PhyrexianRevoker.java index a201d979b17..ce6ae257033 100644 --- a/Mage.Sets/src/mage/sets/mirrodinbesieged/PhyrexianRevoker.java +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/PhyrexianRevoker.java @@ -42,13 +42,13 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.players.Player; -import mage.sets.Sets; /** * @@ -97,7 +97,7 @@ class PhyrexianRevokerEffect1 extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getNonLandCardNames()); + cardChoice.setChoices(CardRepository.instance.getNonLandNames()); cardChoice.clearChoice(); while (!controller.choose(Outcome.Detriment, cardChoice, game)) { game.debugMessage("player canceled choosing name. retrying."); diff --git a/Mage.Sets/src/mage/sets/newphyrexia/Xenograft.java b/Mage.Sets/src/mage/sets/newphyrexia/Xenograft.java index c84ce54ed7c..bf24a1f64fe 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/Xenograft.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/Xenograft.java @@ -42,13 +42,13 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.sets.Sets; /** * @@ -95,7 +95,7 @@ class XenograftEffect extends OneShotEffect { Permanent permanent = game.getPermanent(source.getSourceId()); if (player != null && permanent != null) { Choice typeChoice = new ChoiceImpl(true); - typeChoice.setChoices(Sets.getCreatureTypes()); + typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!player.choose(Outcome.BoostCreature, typeChoice, game)) { game.debugMessage("player canceled choosing type. retrying."); } diff --git a/Mage.Sets/src/mage/sets/returntoravnica/SlaughterGames.java b/Mage.Sets/src/mage/sets/returntoravnica/SlaughterGames.java index ed8c97cda47..0d02d9e3cf1 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/SlaughterGames.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/SlaughterGames.java @@ -38,11 +38,11 @@ import mage.abilities.effects.common.CantCounterSourceEffect; import mage.abilities.effects.common.search.SearchTargetGraveyardHandLibraryForCardNameAndExileEffect; import mage.cards.Card; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; import mage.players.Player; -import mage.sets.Sets; import mage.target.common.TargetOpponent; /** @@ -93,7 +93,7 @@ class SlaughterGamesEffect extends SearchTargetGraveyardHandLibraryForCardNameAn Player controller = game.getPlayer(source.getControllerId()); if (player != null && controller != null) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getNonLandCardNames()); + cardChoice.setChoices(CardRepository.instance.getNonLandNames()); cardChoice.clearChoice(); cardChoice.setMessage("Name a nonland card"); diff --git a/Mage.Sets/src/mage/sets/saviorsofkamigawa/PithingNeedle.java b/Mage.Sets/src/mage/sets/saviorsofkamigawa/PithingNeedle.java index 71628965cfb..bbeca7d2f1b 100644 --- a/Mage.Sets/src/mage/sets/saviorsofkamigawa/PithingNeedle.java +++ b/Mage.Sets/src/mage/sets/saviorsofkamigawa/PithingNeedle.java @@ -38,12 +38,12 @@ import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; import mage.game.events.GameEvent; import mage.players.Player; -import mage.sets.Sets; /** * @@ -88,7 +88,7 @@ class NameCard extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getCardNames()); + cardChoice.setChoices(CardRepository.instance.getNames()); cardChoice.clearChoice(); while (!controller.choose(Constants.Outcome.Detriment, cardChoice, game)) { game.debugMessage("player canceled choosing name. retrying."); diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/Memoricide.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/Memoricide.java index 1645cabd5e4..cea75b67f11 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/Memoricide.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/Memoricide.java @@ -37,11 +37,11 @@ import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardsImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; import mage.players.Player; -import mage.sets.Sets; import mage.target.TargetPlayer; /** @@ -89,7 +89,7 @@ class MemoricideEffect extends OneShotEffect { Player controller = game.getPlayer(source.getControllerId()); if (player != null && controller != null) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getNonLandCardNames()); + cardChoice.setChoices(CardRepository.instance.getNonLandNames()); cardChoice.clearChoice(); while (!controller.choose(Outcome.Exile, cardChoice, game)) { diff --git a/Mage.Sets/src/mage/sets/tempest/CursedScroll.java b/Mage.Sets/src/mage/sets/tempest/CursedScroll.java index 1214a4cac11..704c8f06523 100644 --- a/Mage.Sets/src/mage/sets/tempest/CursedScroll.java +++ b/Mage.Sets/src/mage/sets/tempest/CursedScroll.java @@ -40,12 +40,12 @@ import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.Cards; import mage.cards.CardsImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.sets.Sets; import mage.target.common.TargetCreatureOrPlayer; /** @@ -91,7 +91,7 @@ class CursedScrollEffect extends OneShotEffect { Player you = game.getPlayer(source.getControllerId()); if (you != null) { Choice cardChoice = new ChoiceImpl(); - cardChoice.setChoices(Sets.getCardNames()); + cardChoice.setChoices(CardRepository.instance.getNames()); cardChoice.clearChoice(); while (!you.choose(Constants.Outcome.Damage, cardChoice, game)) { game.debugMessage("player canceled choosing name. retrying."); diff --git a/Mage.Sets/src/mage/sets/urzaslegacy/EngineeredPlague.java b/Mage.Sets/src/mage/sets/urzaslegacy/EngineeredPlague.java index ed3a2760145..059fd4f2be0 100644 --- a/Mage.Sets/src/mage/sets/urzaslegacy/EngineeredPlague.java +++ b/Mage.Sets/src/mage/sets/urzaslegacy/EngineeredPlague.java @@ -32,12 +32,12 @@ import mage.Constants; import mage.Constants.CardType; import mage.Constants.Rarity; import mage.abilities.Ability; -import mage.abilities.StaticAbility; import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continious.BoostAllEffect; import mage.cards.CardImpl; +import mage.cards.repository.CardRepository; import mage.choices.Choice; import mage.choices.ChoiceImpl; import mage.filter.common.FilterCreaturePermanent; @@ -45,7 +45,6 @@ import mage.filter.predicate.mageobject.SubtypePredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.sets.Sets; /** * @@ -96,7 +95,7 @@ public class EngineeredPlague extends CardImpl { if (player != null && permanent != null) { Choice typeChoice = new ChoiceImpl(true); typeChoice.setMessage("Choose creature type"); - typeChoice.setChoices(Sets.getCreatureTypes()); + typeChoice.setChoices(CardRepository.instance.getCreatureTypes()); while (!player.choose(Constants.Outcome.Detriment, typeChoice, game)) { game.debugMessage("player canceled choosing type. retrying."); }