From 6b6f718bc47d208e96bf2d0c84fcf32b9aaffe83 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Sat, 23 Jun 2012 09:41:32 +0400 Subject: [PATCH] Fixing limited: removed card lazy loading --- Mage.Sets/src/mage/sets/Sets.java | 36 +++++++++++++++++++-------- Mage/src/mage/cards/ExpansionSet.java | 19 +++++++++----- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/Mage.Sets/src/mage/sets/Sets.java b/Mage.Sets/src/mage/sets/Sets.java index 40f6be3311f..262184416d3 100644 --- a/Mage.Sets/src/mage/sets/Sets.java +++ b/Mage.Sets/src/mage/sets/Sets.java @@ -120,9 +120,25 @@ public class Sets extends HashMap { private void addSet(ExpansionSet set) { this.put(set.getCode(), set); + cards.addAll(set.getCards()); + for (Card card : set.getCards()) { + names.add(card.getName()); + if (card.getCardType().contains(CardType.CREATURE)) { + for (String type : card.getSubtype()) { + creatureTypes.add(type); + if (type.equals("")) { + throw new IllegalStateException("Card with empty subtype: " + card.getName()); + } + } + } + if (!card.getCardType().contains(CardType.LAND)) nonLandNames.add(card.getName()); + } + if (creatureTypes.contains("")) { + creatureTypes.remove(""); + } } - private static void loadCards() { + /*private static void loadCards() { if (cards.isEmpty()) { System.out.println("Loading cards..."); long t1 = System.currentTimeMillis(); @@ -146,33 +162,33 @@ public class Sets extends HashMap { } System.out.println("It took " + (System.currentTimeMillis() - t1) / 1000 + " ms to load all cards."); } - } + }*/ public static Set getCardNames() { - if (names.isEmpty()) { + /*if (names.isEmpty()) { loadCards(); - } + }*/ return names; } public static Set getNonLandCardNames() { - if (nonLandNames.isEmpty()) { + /*if (nonLandNames.isEmpty()) { loadCards(); - } + }*/ return nonLandNames; } public static Set getCreatureTypes() { - if (creatureTypes.isEmpty()) { + /*if (creatureTypes.isEmpty()) { loadCards(); - } + }*/ return creatureTypes; } public static Card getRandomCard() { - if (cards.isEmpty()) { + /*if (cards.isEmpty()) { loadCards(); - } + }*/ return cards.get(rnd.nextInt(cards.size())); } diff --git a/Mage/src/mage/cards/ExpansionSet.java b/Mage/src/mage/cards/ExpansionSet.java index e2cb824cad0..01d229cf544 100644 --- a/Mage/src/mage/cards/ExpansionSet.java +++ b/Mage/src/mage/cards/ExpansionSet.java @@ -77,19 +77,19 @@ public abstract class ExpansionSet implements Serializable { this.releaseDate = releaseDate; this.setType = setType; this.packageName = packageName; - //this.cards = getCardClassesForPackage(packageName); - //this.rarities = getCardsByRarity(); + this.cards = getCardClassesForPackage(packageName); + this.rarities = getCardsByRarity(); } public List getCards() { - if (cards == null) { + /*if (cards == null) { synchronized (this) { if (cards == null) { this.cards = getCardClassesForPackage(packageName); this.rarities = getCardsByRarity(); } } - } + }*/ return cards; } @@ -301,7 +301,7 @@ public abstract class ExpansionSet implements Serializable { private Map> getCardsByRarity() { Map> cardsByRarity = new HashMap>(); - for (Card card : cards) { + for (Card card : getCards()) { if (!cardsByRarity.containsKey(card.getRarity())) cardsByRarity.put(card.getRarity(), new ArrayList()); cardsByRarity.get(card.getRarity()).add(card); @@ -426,7 +426,7 @@ public abstract class ExpansionSet implements Serializable { } protected Card getRandom(Rarity rarity) { - if (!rarities.containsKey(rarity)) + if (rarities.containsKey(rarity)) return null; int size = rarities.get(rarity).size(); if (size > 0) { @@ -452,4 +452,11 @@ public abstract class ExpansionSet implements Serializable { } return null; } + + public Map> getRarities() { + /*if (rarities == null) { + this.rarities = getCardsByRarity(); + }*/ + return rarities; + } }