mirror of
https://github.com/magefree/mage.git
synced 2026-01-25 12:49:39 -08:00
Merge branch 'CardRepository'
This commit is contained in:
commit
f64149971a
79 changed files with 1811 additions and 2686 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.sets.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class DckDeckImporter extends DeckImporterImpl {
|
||||
|
||||
private static final Pattern pattern = Pattern.compile("(SB:)?\\s*(\\d*)\\s*\\[([a-zA-Z0-9]{3}):(\\d*)\\].*");
|
||||
|
||||
@Override
|
||||
protected void readLine(String line, DeckCardLists deckList) {
|
||||
|
||||
if (line.length() == 0 || line.startsWith("#")) {
|
||||
return;
|
||||
}
|
||||
|
||||
Matcher m = pattern.matcher(line);
|
||||
if (m.matches()) {
|
||||
boolean sideboard = false;
|
||||
if ("SB:".equals(m.group(1))) {
|
||||
sideboard = true;
|
||||
}
|
||||
int count = Integer.parseInt(m.group(2));
|
||||
String setCode = m.group(3);
|
||||
int cardNum = Integer.parseInt(m.group(4));
|
||||
ExpansionSet set = Sets.findSet(setCode);
|
||||
String card = null;
|
||||
if (set != null) {
|
||||
card = set.findCardName(cardNum);
|
||||
}
|
||||
if (card != null) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (!sideboard) {
|
||||
deckList.getCards().add(card);
|
||||
} else {
|
||||
deckList.getSideboard().add(card);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sbMessage.append("Could not find card '").append("' at line ").append(lineCount).append(": ").append(line).append("\n");
|
||||
}
|
||||
} else if (line.startsWith("NAME:")) {
|
||||
deckList.setName(line.substring(5, line.length()));
|
||||
} else if (line.startsWith("AUTHOR:")) {
|
||||
deckList.setAuthor(line.substring(7, line.length()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.sets.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class DecDeckImporter extends DeckImporterImpl {
|
||||
|
||||
@Override
|
||||
protected void readLine(String line, DeckCardLists deckList) {
|
||||
if (line.length() == 0 || line.startsWith("//")) return;
|
||||
boolean sideboard = false;
|
||||
if (line.startsWith("SB:")) {
|
||||
line = line.substring(3).trim();
|
||||
sideboard = true;
|
||||
}
|
||||
int delim = line.indexOf(' ');
|
||||
String lineNum = line.substring(0, delim).trim();
|
||||
String lineName = line.substring(delim).trim();
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum);
|
||||
Card card = Sets.findCard(lineName);
|
||||
if (card == null)
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
else {
|
||||
String cardName = card.getClass().getCanonicalName();
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (!sideboard)
|
||||
deckList.getCards().add(cardName);
|
||||
else
|
||||
deckList.getSideboard().add(cardName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
sbMessage.append("Invalid number: ").append(lineNum).append(" at line ").append(lineCount).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public interface DeckImporter {
|
||||
|
||||
public DeckCardLists importDeck(String file);
|
||||
public String getErrors();
|
||||
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Scanner;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public abstract class DeckImporterImpl implements DeckImporter {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(DeckImporterImpl.class);
|
||||
protected StringBuilder sbMessage = new StringBuilder();
|
||||
protected int lineCount;
|
||||
|
||||
@Override
|
||||
public DeckCardLists importDeck(String file) {
|
||||
File f = new File(file);
|
||||
DeckCardLists deckList = new DeckCardLists();
|
||||
lineCount = 0;
|
||||
sbMessage.setLength(0);
|
||||
try {
|
||||
Scanner scanner = new Scanner(f);
|
||||
try {
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine().trim();
|
||||
lineCount++;
|
||||
readLine(line, deckList);
|
||||
}
|
||||
if (sbMessage.length() > 0) {
|
||||
logger.fatal(sbMessage);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
logger.fatal(null, ex);
|
||||
}
|
||||
finally {
|
||||
scanner.close();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
logger.fatal(null, ex);
|
||||
}
|
||||
return deckList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrors(){
|
||||
return sbMessage.toString();
|
||||
}
|
||||
|
||||
protected abstract void readLine(String line, DeckCardLists deckList);
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class DeckImporterUtil {
|
||||
|
||||
public static DeckImporter getDeckImporter(String file) {
|
||||
if (file.toLowerCase().endsWith("dec")) {
|
||||
return new DecDeckImporter();
|
||||
} else if (file.toLowerCase().endsWith("mwdeck")) {
|
||||
return new MWSDeckImporter();
|
||||
} else if (file.toLowerCase().endsWith("txt")) {
|
||||
return new TxtDeckImporter();
|
||||
} else if (file.toLowerCase().endsWith("dck")) {
|
||||
return new DckDeckImporter();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static DeckCardLists importDeck(String file) {
|
||||
DeckImporter deckImporter = getDeckImporter(file);
|
||||
if (deckImporter != null) {
|
||||
return deckImporter.importDeck(file);
|
||||
} else {
|
||||
return new DeckCardLists();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.ExpansionSet;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.sets.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class MWSDeckImporter extends DeckImporterImpl {
|
||||
|
||||
@Override
|
||||
protected void readLine(String line, DeckCardLists deckList) {
|
||||
if (line.length() == 0 || line.startsWith("//")) return;
|
||||
boolean sideboard = false;
|
||||
if (line.startsWith("SB:")) {
|
||||
line = line.substring(3).trim();
|
||||
sideboard = true;
|
||||
}
|
||||
int delim = line.indexOf(' ');
|
||||
String lineNum = line.substring(0, delim).trim();
|
||||
String setCode = "";
|
||||
if (line.indexOf('[') != -1 ) {
|
||||
int setStart = line.indexOf('[') + 1;
|
||||
int setEnd = line.indexOf(']');
|
||||
setCode = line.substring(setStart, setEnd).trim();
|
||||
delim = setEnd;
|
||||
}
|
||||
String lineName = line.substring(delim + 1).trim();
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum);
|
||||
ExpansionSet set = null;
|
||||
if (setCode.length() > 0)
|
||||
set = Sets.findSet(setCode);
|
||||
Card card;
|
||||
if (set != null) {
|
||||
card = set.findCard(lineName);
|
||||
}
|
||||
else {
|
||||
card = Sets.findCard(lineName);
|
||||
}
|
||||
if (card == null)
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
else {
|
||||
String cardName = card.getClass().getCanonicalName();
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (!sideboard)
|
||||
deckList.getCards().add(cardName);
|
||||
else
|
||||
deckList.getSideboard().add(cardName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
sbMessage.append("Invalid number: ").append(lineNum).append(" at line ").append(lineCount).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.cards.decks.importer;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.sets.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class TxtDeckImporter extends DeckImporterImpl {
|
||||
|
||||
private boolean sideboard = false;
|
||||
|
||||
@Override
|
||||
protected void readLine(String line, DeckCardLists deckList) {
|
||||
if (line.length() == 0 || line.startsWith("//")) return;
|
||||
if (line.startsWith("Sideboard")) {
|
||||
sideboard = true;
|
||||
return;
|
||||
}
|
||||
int delim = line.indexOf(' ');
|
||||
String lineNum = line.substring(0, delim).trim();
|
||||
String lineName = line.substring(delim).trim();
|
||||
try {
|
||||
int num = Integer.parseInt(lineNum);
|
||||
Card card = Sets.findCard(lineName);
|
||||
if (card == null)
|
||||
sbMessage.append("Could not find card: '").append(lineName).append("' at line ").append(lineCount).append("\n");
|
||||
else {
|
||||
String cardName = card.getClass().getCanonicalName();
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (!sideboard)
|
||||
deckList.getCards().add(cardName);
|
||||
else
|
||||
deckList.getSideboard().add(cardName);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException nfe) {
|
||||
sbMessage.append("Invalid number: ").append(lineNum).append(" at line ").append(lineCount).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,397 +0,0 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
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;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
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;
|
||||
private static Map<String, Card> cardMap;
|
||||
protected static Random rnd = new Random();
|
||||
|
||||
private static boolean loaded;
|
||||
|
||||
public static Sets getInstance() {
|
||||
return fINSTANCE;
|
||||
}
|
||||
|
||||
private Sets() {
|
||||
names = new TreeSet<String>();
|
||||
nonLandNames = new TreeSet<String>();
|
||||
cards = new ArrayList<Card>();
|
||||
cardMap = new HashMap<String, Card>();
|
||||
creatureTypes = new TreeSet<String>();
|
||||
this.addSet(AlaraReborn.getInstance());
|
||||
this.addSet(Alliances.getInstance());
|
||||
this.addSet(Antiquities.getInstance());
|
||||
this.addSet(Apocalypse.getInstance());
|
||||
this.addSet(ArabianNights.getInstance());
|
||||
this.addSet(AvacynRestored.getInstance());
|
||||
this.addSet(BetrayersOfKamigawa.getInstance());
|
||||
this.addSet(ChampionsOfKamigawa.getInstance());
|
||||
this.addSet(Coldsnap.getInstance());
|
||||
this.addSet(Conflux.getInstance());
|
||||
this.addSet(DarkAscension.getInstance());
|
||||
this.addSet(Darksteel.getInstance());
|
||||
this.addSet(Dissension.getInstance());
|
||||
this.addSet(EighthEdition.getInstance());
|
||||
this.addSet(ElspethvsTezzeret.getInstance());
|
||||
this.addSet(Eventide.getInstance());
|
||||
this.addSet(Exodus.getInstance());
|
||||
this.addSet(FifthDawn.getInstance());
|
||||
this.addSet(FifthEdition.getInstance());
|
||||
this.addSet(FallenEmpires.getInstance());
|
||||
this.addSet(FourthEdition.getInstance());
|
||||
this.addSet(FutureSight.getInstance());
|
||||
this.addSet(Guildpact.getInstance());
|
||||
this.addSet(Guru.getInstance());
|
||||
this.addSet(Homelands.getInstance());
|
||||
this.addSet(IceAge.getInstance());
|
||||
this.addSet(Innistrad.getInstance());
|
||||
this.addSet(Invasion.getInstance());
|
||||
this.addSet(Judgment.getInstance());
|
||||
this.addSet(Legends.getInstance());
|
||||
this.addSet(Legions.getInstance());
|
||||
this.addSet(Lorwyn.getInstance());
|
||||
this.addSet(Magic2010.getInstance());
|
||||
this.addSet(Magic2011.getInstance());
|
||||
this.addSet(Magic2012.getInstance());
|
||||
this.addSet(Magic2013.getInstance());
|
||||
this.addSet(MagicPlayerRewards.getInstance());
|
||||
this.addSet(MercadianMasques.getInstance());
|
||||
this.addSet(Mirage.getInstance());
|
||||
this.addSet(Mirrodin.getInstance());
|
||||
this.addSet(MirrodinBesieged.getInstance());
|
||||
this.addSet(Morningtide.getInstance());
|
||||
this.addSet(Nemesis.getInstance());
|
||||
this.addSet(NewPhyrexia.getInstance());
|
||||
this.addSet(NinthEdition.getInstance());
|
||||
this.addSet(Odyssey.getInstance());
|
||||
this.addSet(Onslaught.getInstance());
|
||||
this.addSet(PlanarChaos.getInstance());
|
||||
this.addSet(Planechase.getInstance());
|
||||
this.addSet(Planeshift.getInstance());
|
||||
this.addSet(Prophecy.getInstance());
|
||||
this.addSet(RavnicaCityOfGuilds.getInstance());
|
||||
this.addSet(ReturnToRavnica.getInstance());
|
||||
this.addSet(RiseOfTheEldrazi.getInstance());
|
||||
this.addSet(SaviorsOfKamigawa.getInstance());
|
||||
this.addSet(ScarsOfMirrodin.getInstance());
|
||||
this.addSet(Scourge.getInstance());
|
||||
this.addSet(SeventhEdition.getInstance());
|
||||
this.addSet(ShardsOfAlara.getInstance());
|
||||
this.addSet(Shadowmoor.getInstance());
|
||||
this.addSet(SixthEdition.getInstance());
|
||||
this.addSet(Stronghold.getInstance());
|
||||
this.addSet(Tenth.getInstance());
|
||||
this.addSet(Tempest.getInstance());
|
||||
this.addSet(TheDark.getInstance());
|
||||
this.addSet(TimeSpiral.getInstance());
|
||||
this.addSet(TimeSpiralTimeshifted.getInstance());
|
||||
this.addSet(Torment.getInstance());
|
||||
this.addSet(UrzasSaga.getInstance());
|
||||
this.addSet(UrzasLegacy.getInstance());
|
||||
this.addSet(UrzasDestiny.getInstance());
|
||||
this.addSet(Visions.getInstance());
|
||||
this.addSet(Weatherlight.getInstance());
|
||||
this.addSet(Worldwake.getInstance());
|
||||
this.addSet(Zendikar.getInstance());
|
||||
}
|
||||
|
||||
private void addSet(ExpansionSet set) {
|
||||
this.put(set.getCode(), set);
|
||||
//cards.addAll(set.getCards());
|
||||
}
|
||||
|
||||
private static void loadCards() {
|
||||
if (!loaded) {
|
||||
synchronized (Sets.class) {
|
||||
if (!loaded) {
|
||||
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()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates card pool of cardsCount cards that have manacost of allowed colors.
|
||||
*
|
||||
* @param cardsCount
|
||||
* @param allowedColors
|
||||
* @return
|
||||
*/
|
||||
public static List<Card> generateRandomCardPool(int cardsCount, List<ColoredManaSymbol> allowedColors) {
|
||||
List<Card> cardPool = new ArrayList<Card>();
|
||||
|
||||
int count = 0;
|
||||
int tries = 0;
|
||||
while (count < cardsCount) {
|
||||
Card card = getRandomCard();
|
||||
if (!card.getCardType().contains(CardType.LAND)) {
|
||||
if (cardFitsChosenColors(card, allowedColors)) {
|
||||
cardPool.add(card);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
tries++;
|
||||
if (tries > 4096) { // to avoid infinite loop
|
||||
throw new IllegalStateException("Not enough cards for chosen colors to generate deck: " + allowedColors);
|
||||
}
|
||||
}
|
||||
|
||||
return cardPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that card can be played using chosen (allowed) colors.
|
||||
*
|
||||
* @param card
|
||||
* @param allowedColors
|
||||
* @return
|
||||
*/
|
||||
private static boolean cardFitsChosenColors(Card card, List<ColoredManaSymbol> allowedColors) {
|
||||
if (card.getCardType().contains(CardType.LAND)) {
|
||||
if (!card.getSupertype().contains("Basic")) {
|
||||
int score = 0;
|
||||
for (Mana mana : card.getMana()) {
|
||||
for (ColoredManaSymbol color : allowedColors) {
|
||||
score += mana.getColor(color);
|
||||
}
|
||||
}
|
||||
if (score > 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (String symbol : card.getManaCost().getSymbols()) {
|
||||
boolean found = false;
|
||||
symbol = symbol.replace("{", "").replace("}", "");
|
||||
if (isColoredMana(symbol)) {
|
||||
for (ColoredManaSymbol allowed : allowedColors) {
|
||||
if (allowed.toString().equals(symbol)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static boolean isColoredMana(String symbol) {
|
||||
return symbol.equals("W") || symbol.equals("G") || symbol.equals("U") || symbol.equals("B") || symbol.equals("R");
|
||||
}
|
||||
|
||||
public static Deck generateDeck() {
|
||||
List<ColoredManaSymbol> allowedColors = new ArrayList<ColoredManaSymbol>();
|
||||
int numColors = rnd.nextInt(2) + 1;
|
||||
int cardPoolSize = 60;
|
||||
if (numColors > 2) {
|
||||
cardPoolSize += 20;
|
||||
}
|
||||
Deck deck = new Deck();
|
||||
|
||||
return deck;
|
||||
}
|
||||
|
||||
public static Card findCard(String name) {
|
||||
for (ExpansionSet set: fINSTANCE.values()) {
|
||||
Card card = set.findCard(name);
|
||||
if (card != null)
|
||||
return card;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Card findCard(String name, boolean random) {
|
||||
if (!random) {
|
||||
return findCard(name);
|
||||
} else {
|
||||
List<Card> cardsFound = new ArrayList<Card>();
|
||||
for (ExpansionSet set: fINSTANCE.values()) {
|
||||
Card card = set.findCard(name, true);
|
||||
if (card != null) {
|
||||
cardsFound.add(card);
|
||||
}
|
||||
}
|
||||
if (cardsFound.size() > 0) {
|
||||
Card card = cardsFound.get(rnd.nextInt(cardsFound.size()));
|
||||
String cardClassName = card.getClass().getName();
|
||||
return CardImpl.createCard(cardClassName);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Card findCard(String expansionsetCode, int cardNum) {
|
||||
if (cardMap.containsKey(expansionsetCode + Integer.toString(cardNum))) {
|
||||
return cardMap.get(expansionsetCode + Integer.toString(cardNum));
|
||||
}
|
||||
if (fINSTANCE.containsKey(expansionsetCode)) {
|
||||
ExpansionSet set = fINSTANCE.get(expansionsetCode);
|
||||
Card card = set.findCard(cardNum);
|
||||
if (card != null) {
|
||||
cardMap.put(expansionsetCode + Integer.toString(cardNum), card);
|
||||
return card;
|
||||
}
|
||||
}
|
||||
logger.warn("Could not find card: set=" + expansionsetCode + "cardNum=" + Integer.toString(cardNum));
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
public static Card createCard(Class clazz) {
|
||||
try {
|
||||
Constructor<?> con = clazz.getConstructor(new Class[]{UUID.class});
|
||||
Card card = (Card) con.newInstance(new Object[] {null});
|
||||
card.build();
|
||||
return card;
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("Error creating card:" + clazz.getName(), ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static ExpansionSet findSet(String code) {
|
||||
if (fINSTANCE.containsKey(code))
|
||||
return fINSTANCE.get(code);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void saveDeck(String file, DeckCardLists deck) throws FileNotFoundException {
|
||||
PrintWriter out = new PrintWriter(file);
|
||||
Map<String, Integer> deckCards = new HashMap<String, Integer>();
|
||||
Map<String, Integer> sideboard = new HashMap<String, Integer>();
|
||||
try {
|
||||
if (deck.getName() != null && deck.getName().length() > 0)
|
||||
out.println("NAME:" + deck.getName());
|
||||
if (deck.getAuthor() != null && deck.getAuthor().length() > 0)
|
||||
out.println("AUTHOR:" + deck.getAuthor());
|
||||
for (String cardClass: deck.getCards()) {
|
||||
if (deckCards.containsKey(cardClass)) {
|
||||
deckCards.put(cardClass, deckCards.get(cardClass) + 1);
|
||||
}
|
||||
else {
|
||||
deckCards.put(cardClass, 1);
|
||||
}
|
||||
}
|
||||
for (String cardClass: deck.getSideboard()) {
|
||||
if (sideboard.containsKey(cardClass)) {
|
||||
sideboard.put(cardClass, sideboard.get(cardClass) + 1);
|
||||
}
|
||||
else {
|
||||
sideboard.put(cardClass, 1);
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry: deckCards.entrySet()) {
|
||||
Card card = CardImpl.createCard(entry.getKey());
|
||||
if (card != null) {
|
||||
out.printf("%d [%s:%d] %s%n", entry.getValue(), card.getExpansionSetCode(), card.getCardNumber(), card.getName());
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Integer> entry: sideboard.entrySet()) {
|
||||
Card card = CardImpl.createCard(entry.getKey());
|
||||
if (card != null) {
|
||||
out.printf("SB: %d [%s:%d] %s%n", entry.getValue(), card.getExpansionSetCode(), card.getCardNumber(), card.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
public ExpansionSet[] getSortedByReleaseDate() {
|
||||
ExpansionSet[] sets = Sets.getInstance().values().toArray(new ExpansionSet[0]);
|
||||
Arrays.sort(sets, new Comparator<ExpansionSet>() {
|
||||
@Override
|
||||
public int compare(ExpansionSet o1, ExpansionSet o2) {
|
||||
return o2.getReleaseDate().compareTo(o1.getReleaseDate());
|
||||
}
|
||||
});
|
||||
return sets;
|
||||
}
|
||||
}
|
||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue