mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
[CardRepository] replaced getCardNames, getCardNonLandNames and getCreatureTypes
This commit is contained in:
parent
e5f91ef244
commit
d7e63120e5
21 changed files with 80 additions and 369 deletions
36
Mage.Sets/src/mage/cache/Cache.java
vendored
36
Mage.Sets/src/mage/cache/Cache.java
vendored
|
@ -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<String, Object> cacheObjects = new HashMap<String, Object>();
|
||||
|
||||
public Cache(String name, int version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Map<String, Object> getCacheObjects() {
|
||||
return cacheObjects;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
116
Mage.Sets/src/mage/cache/CacheDataHelper.java
vendored
116
Mage.Sets/src/mage/cache/CacheDataHelper.java
vendored
|
@ -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;
|
||||
}
|
||||
}
|
114
Mage.Sets/src/mage/cache/CacheService.java
vendored
114
Mage.Sets/src/mage/cache/CacheService.java
vendored
|
@ -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<Card> loadCards(Collection<ExpansionSet> sets) {
|
||||
Cache cache = CacheDataHelper.getCachedObject(CARDS_CACHE_OBJECT_NAME);
|
||||
List<Card> cards = new ArrayList<Card>();
|
||||
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<Card>) cache.getCacheObjects().get(CARDS_KEY);
|
||||
log.debug("Loaded cards from cache.");
|
||||
}
|
||||
|
||||
return cards;
|
||||
}
|
||||
|
||||
public static Set<String> loadCardNames(List<Card> cards) {
|
||||
Cache cache = CacheDataHelper.getCachedObject(NAMES_CACHE_OBJECT_NAME);
|
||||
Set<String> names = new TreeSet<String>();
|
||||
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<String> cachedNames = (Set<String>) cache.getCacheObjects().get(NAMES_KEY);
|
||||
names.addAll(cachedNames);
|
||||
log.debug("Loaded card names from cache.");
|
||||
}
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
public static Set<String> loadCreatureTypes(List<Card> cards) {
|
||||
Set<String> creatureTypes = new TreeSet<String>();
|
||||
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<String> cachedCreatureTypes = (Set<String>) cache.getCacheObjects().get(CREATURE_TYPES_KEY);
|
||||
creatureTypes.addAll(cachedCreatureTypes);
|
||||
log.debug("Loaded creature types from cache.");
|
||||
}
|
||||
|
||||
return creatureTypes;
|
||||
}
|
||||
|
||||
public static Set<String> loadNonLandNames(List<Card> cards) {
|
||||
Set<String> nonLandNames = new TreeSet<String>();
|
||||
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<String> cachedNonLandNames = (Set<String>) cache.getCacheObjects().get(NONLAND_NAMES_KEY);
|
||||
nonLandNames.addAll(cachedNonLandNames);
|
||||
log.debug("Loaded non land names from cache.");
|
||||
}
|
||||
|
||||
return nonLandNames;
|
||||
}
|
||||
}
|
46
Mage.Sets/src/mage/cache/CacheTest.java
vendored
46
Mage.Sets/src/mage/cache/CacheTest.java
vendored
|
@ -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<String> names = Sets.getCardNames();
|
||||
Set<String> nonLandNames = Sets.getNonLandCardNames();
|
||||
Set<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<CardInfo, Object> cardDao;
|
||||
private TreeSet<String> classNames;
|
||||
private Set<String> classNames;
|
||||
|
||||
private CardRepository() {
|
||||
File file = new File("db");
|
||||
|
@ -121,6 +123,53 @@ public enum CardRepository {
|
|||
}
|
||||
}
|
||||
|
||||
public Set<String> getNames() {
|
||||
Set<String> names = new TreeSet<String>();
|
||||
try {
|
||||
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
|
||||
qb.distinct().selectColumns("name");
|
||||
List<CardInfo> results = cardDao.query(qb.prepare());
|
||||
for (CardInfo card : results) {
|
||||
names.add(card.getName());
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} finally {
|
||||
return names;
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getNonLandNames() {
|
||||
Set<String> names = new TreeSet<String>();
|
||||
try {
|
||||
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
|
||||
qb.distinct().selectColumns("name");
|
||||
qb.where().not().like("types", new SelectArg('%' + CardType.LAND.name() + '%'));
|
||||
List<CardInfo> results = cardDao.query(qb.prepare());
|
||||
for (CardInfo card : results) {
|
||||
names.add(card.getName());
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
} finally {
|
||||
return names;
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> getCreatureTypes() {
|
||||
TreeSet<String> subtypes = new TreeSet<String>();
|
||||
try {
|
||||
QueryBuilder<CardInfo, Object> qb = cardDao.queryBuilder();
|
||||
qb.distinct().selectColumns("subtypes");
|
||||
qb.where().like("types", new SelectArg('%' + CardType.CREATURE.name() + '%'));
|
||||
List<CardInfo> 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<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
|
||||
|
|
|
@ -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<String, ExpansionSet> {
|
|||
|
||||
private final static Logger logger = Logger.getLogger(Sets.class);
|
||||
private static final Sets fINSTANCE = new Sets();
|
||||
private static Set<String> names;
|
||||
private static Set<String> nonLandNames;
|
||||
private static Set<String> creatureTypes;
|
||||
private static List<Card> cards;
|
||||
protected static Random rnd = new Random();
|
||||
|
||||
|
@ -63,10 +59,7 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
}
|
||||
|
||||
private Sets() {
|
||||
names = new TreeSet<String>();
|
||||
nonLandNames = new TreeSet<String>();
|
||||
cards = new ArrayList<Card>();
|
||||
creatureTypes = new TreeSet<String>();
|
||||
this.addSet(AlaraReborn.getInstance());
|
||||
this.addSet(Alliances.getInstance());
|
||||
this.addSet(Antiquities.getInstance());
|
||||
|
@ -156,30 +149,12 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
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<String> getCardNames() {
|
||||
loadCards();
|
||||
return names;
|
||||
}
|
||||
|
||||
public static Set<String> getNonLandCardNames() {
|
||||
loadCards();
|
||||
return nonLandNames;
|
||||
}
|
||||
|
||||
public static Set<String> getCreatureTypes() {
|
||||
loadCards();
|
||||
return creatureTypes;
|
||||
}
|
||||
|
||||
public static Card getRandomCard() {
|
||||
loadCards();
|
||||
return cards.get(rnd.nextInt(cards.size()));
|
||||
|
|
|
@ -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<CavernOfSoulsEffect> {
|
|||
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.");
|
||||
}
|
||||
|
|
|
@ -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<RidersOfGavonyEffect> {
|
|||
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.");
|
||||
}
|
||||
|
|
|
@ -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<CranialExtractionEffect> {
|
|||
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)) {
|
||||
|
|
|
@ -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<MindblazeEffect> {
|
|||
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");
|
||||
|
|
|
@ -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<NevermoreEffect1> {
|
|||
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.");
|
||||
|
|
|
@ -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<CabalTherapyEffect> {
|
|||
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)) {
|
||||
|
|
|
@ -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<ConundrumSphinxEffect> {
|
|||
@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();
|
||||
|
|
|
@ -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<AdaptiveAutomatonEffect> {
|
|||
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.");
|
||||
}
|
||||
|
|
|
@ -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<PhyrexianRevokerEffect1> {
|
|||
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.");
|
||||
|
|
|
@ -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<XenograftEffect> {
|
|||
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.");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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<NameCard> {
|
|||
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.");
|
||||
|
|
|
@ -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<MemoricideEffect> {
|
|||
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)) {
|
||||
|
|
|
@ -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<CursedScrollEffect> {
|
|||
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.");
|
||||
|
|
|
@ -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<EngineeredPlague> {
|
|||
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.");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue