common base class for booster and starter,

the deck you load in deckeditor is not modified if you choose not to save
This commit is contained in:
Maxmtg
2012-02-25 14:28:34 +00:00
parent 455555be82
commit 66aabc0910
7 changed files with 129 additions and 265 deletions

1
.gitattributes vendored
View File

@@ -11391,6 +11391,7 @@ src/main/java/forge/item/InventoryItem.java -text
src/main/java/forge/item/InventoryItemFromSet.java -text
src/main/java/forge/item/ItemPool.java -text
src/main/java/forge/item/ItemPoolView.java -text
src/main/java/forge/item/OpenablePack.java -text
src/main/java/forge/item/PreconDeck.java -text
src/main/java/forge/item/TournamentPack.java -text
src/main/java/forge/item/package-info.java -text

View File

@@ -153,9 +153,12 @@ public class DeckController<T extends DeckBase> implements IDeckController<T> {
*
* @see forge.gui.deckeditor.IDeckController#load(java.lang.String)
*/
@SuppressWarnings("unchecked")
@Override
public void load(final String name) {
this.setModel(this.folder.get(name), true);
T newModel = this.folder.get(name);
if (null != newModel)
this.setModel((T)newModel.copyTo(name), true);
}
/*

View File

@@ -48,6 +48,7 @@ import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.ItemPool;
import forge.item.ItemPoolView;
import forge.item.OpenablePack;
import forge.item.PreconDeck;
import forge.item.TournamentPack;
import forge.quest.ReadPriceList;
@@ -330,23 +331,16 @@ public final class QuestCardShop extends DeckEditorBase<InventoryItem, Object> {
this.getBottomTableWithCards().addCard(card);
this.questData.getCards().buyCard(card, value);
} else if (item instanceof BoosterPack) {
} else if (item instanceof OpenablePack) {
this.getTopTableWithCards().removeCard(item);
final BoosterPack booster = (BoosterPack) ((BoosterPack) item).clone();
this.questData.getCards().buyBooster(booster, value);
final List<CardPrinted> newCards = booster.getCards();
for (final CardPrinted card : newCards) {
this.getBottomTableWithCards().addCard(card);
OpenablePack booster = null;
if (item instanceof BoosterPack) {
booster = (BoosterPack) ((BoosterPack) item).clone();
} else if (item instanceof TournamentPack) {
booster = (TournamentPack) ((TournamentPack) item).clone();
}
final CardListViewer c = new CardListViewer(booster.getName(),
"You have found the following cards inside:", newCards);
c.show();
} else if (item instanceof TournamentPack) {
this.getTopTableWithCards().removeCard(item);
final TournamentPack booster = (TournamentPack) ((TournamentPack) item).clone();
this.questData.getCards().buyTournamentPack(booster, value);
this.questData.getCards().buyPack(booster, value);
final List<CardPrinted> newCards = booster.getCards();
for (final CardPrinted card : newCards) {
this.getBottomTableWithCards().addCard(card);

View File

@@ -33,7 +33,7 @@ import forge.util.Predicate;
* TODO Write javadoc for this type.
*
*/
public class BoosterPack implements InventoryItemFromSet {
public class BoosterPack extends OpenablePack {
/** The Constant fnFromSet. */
public static final Lambda1<BoosterPack, CardEdition> FN_FROM_SET = new Lambda1<BoosterPack, CardEdition>() {
@@ -44,12 +44,6 @@ public class BoosterPack implements InventoryItemFromSet {
}
};
private final BoosterData contents;
private final String name;
private List<CardPrinted> cards = null;
/**
* Instantiates a new booster pack.
*
@@ -57,38 +51,7 @@ public class BoosterPack implements InventoryItemFromSet {
* the set
*/
public BoosterPack(final String name0, final BoosterData boosterData) {
this.contents = boosterData;
this.name = name0;
}
/*
* (non-Javadoc)
*
* @see forge.item.InventoryItemFromSet#getSet()
*/
/**
* Gets the sets the.
*
* @return String
*/
@Override
public final String getEdition() {
return this.contents.getEdition();
}
/*
* (non-Javadoc)
*
* @see forge.item.InventoryItemFromSet#getName()
*/
/**
* Gets the name.
*
* @return String
*/
@Override
public final String getName() {
return this.name + " " + this.getType();
super(name0, boosterData);
}
/*
@@ -125,83 +88,20 @@ public class BoosterPack implements InventoryItemFromSet {
return this.getRandomBasicLand(Singletons.getModel().getEditions().get("M12"));
}
private void generate() {
protected List<CardPrinted> generate() {
final BoosterGenerator gen = new BoosterGenerator(this.contents.getEditionFilter());
this.cards = gen.getBoosterPack(this.contents);
List<CardPrinted> myCards = gen.getBoosterPack(this.contents);
final int cntLands = this.contents.getLand();
if (cntLands > 0) {
this.cards.add(this.getLandFromNearestSet());
myCards.add(this.getLandFromNearestSet());
}
return myCards;
}
/**
* Gets the cards.
*
* @return the cards
*/
public final List<CardPrinted> getCards() {
if (null == this.cards) {
this.generate();
}
return this.cards;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
/**
* Hash code.
*
* @return int
*/
@Override
public final int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + ((this.contents == null) ? 0 : this.contents.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public final boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
final BoosterPack other = (BoosterPack) obj;
if (this.contents == null) {
if (other.contents != null) {
return false;
}
} else if (!this.contents.equals(other.contents)) {
return false;
}
return true;
}
/*
* (non-Javadoc)
*
* @see forge.item.InventoryItem#getType()
*/
/**
* Gets the type.
*
* @return String
*/
@Override
public final String getType() {
return "Booster Pack";
@@ -222,12 +122,5 @@ public class BoosterPack implements InventoryItemFromSet {
return new BoosterPack(name, contents);
}
/**
* TODO: Write javadoc for this method.
* @return
*/
public int getTotalCards() {
return contents.getTotal();
}
}

View File

@@ -0,0 +1,98 @@
package forge.item;
import java.util.List;
import forge.card.BoosterData;
import forge.card.BoosterGenerator;
/**
* TODO: Write javadoc for this type.
*/
public abstract class OpenablePack implements InventoryItemFromSet {
protected final BoosterData contents;
protected final String name;
private List<CardPrinted> cards = null;
public OpenablePack(final String name0, final BoosterData boosterData) {
this.contents = boosterData;
this.name = name0;
}
@Override
public final String getName() {
return this.name + " " + this.getType();
}
@Override
public final String getEdition() {
return this.contents.getEdition();
}
protected abstract List<CardPrinted> generate();
/**
* Gets the cards.
*
* @return the cards
*/
public final List<CardPrinted> getCards() {
if (null == this.cards) {
cards = this.generate();
}
return this.cards;
}
public int getTotalCards() {
return contents.getTotal();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public final boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
final OpenablePack other = (OpenablePack) obj;
if (this.contents == null) {
if (other.contents != null) {
return false;
}
} else if (!this.contents.equals(other.contents)) {
return false;
}
return true;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
/**
* Hash code.
*
* @return int
*/
@Override
public final int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + ((this.contents == null) ? 0 : this.contents.hashCode());
return result;
}
}

View File

@@ -29,7 +29,7 @@ import forge.card.CardEdition;
* TODO Write javadoc for this type.
*
*/
public class TournamentPack implements InventoryItemFromSet {
public class TournamentPack extends OpenablePack {
/** The Constant fnFromSet. */
public static final Lambda1<TournamentPack, CardEdition> FN_FROM_SET = new Lambda1<TournamentPack, CardEdition>() {
@@ -40,11 +40,6 @@ public class TournamentPack implements InventoryItemFromSet {
}
};
private final BoosterData contents;
private final String name;
private List<CardPrinted> cards = null;
/**
* Instantiates a new booster pack.
*
@@ -52,132 +47,26 @@ public class TournamentPack implements InventoryItemFromSet {
* the set
*/
public TournamentPack(final String name0, final BoosterData boosterData) {
this.contents = boosterData;
this.name = name0;
super(name0, boosterData);
}
/*
* (non-Javadoc)
*
* @see forge.item.InventoryItemFromSet#getSet()
*/
/**
* Gets the sets the.
*
* @return String
*/
@Override
public final String getEdition() {
return this.contents.getEdition();
}
/*
* (non-Javadoc)
*
* @see forge.item.InventoryItemFromSet#getName()
*/
/**
* Gets the name.
*
* @return String
*/
@Override
public final String getName() {
return this.name + " " + this.getType();
}
/*
* (non-Javadoc)
*
* @see forge.item.InventoryItemFromSet#getImageFilename()
*/
/**
* Gets the image filename.
*
* @return String
*/
@Override
public final String getImageFilename() {
return "tournamentpacks/" + this.contents.getEdition() + ".png";
}
private void generate() {
final BoosterGenerator gen = new BoosterGenerator(this.contents.getEditionFilter());
this.cards = gen.getBoosterPack(this.contents);
}
/**
* Gets the cards.
*
* @return the cards
*/
public final List<CardPrinted> getCards() {
if (null == this.cards) {
this.generate();
}
return this.cards;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
/**
* Hash code.
*
* @return int
*/
@Override
public final int hashCode() {
final int prime = 31;
int result = 1;
result = (prime * result) + ((this.contents == null) ? 0 : this.contents.hashCode());
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public final boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (this.getClass() != obj.getClass()) {
return false;
}
final TournamentPack other = (TournamentPack) obj;
if (this.contents == null) {
if (other.contents != null) {
return false;
}
} else if (!this.contents.equals(other.contents)) {
return false;
}
return true;
}
/*
* (non-Javadoc)
*
* @see forge.item.InventoryItem#getType()
*/
/**
* Gets the type.
*
* @return String
*/
@Override
public final String getType() {
return "Tournament Pack";
}
protected List<CardPrinted> generate() {
final BoosterGenerator gen = new BoosterGenerator(this.contents.getEditionFilter());
return gen.getBoosterPack(this.contents);
}
/*
* (non-Javadoc)
*
@@ -193,13 +82,5 @@ public class TournamentPack implements InventoryItemFromSet {
return new TournamentPack(name, contents);
}
/**
* TODO: Write javadoc for this method.
*
* @return
*/
public int getTotalCards() {
return contents.getTotal();
}
}

View File

@@ -33,6 +33,7 @@ import forge.item.CardPrinted;
import forge.item.InventoryItem;
import forge.item.ItemPool;
import forge.item.ItemPoolView;
import forge.item.OpenablePack;
import forge.item.PreconDeck;
import forge.item.TournamentPack;
import forge.quest.BoosterUtils;
@@ -200,7 +201,7 @@ public final class QuestUtilCards {
* @param value
* the value
*/
public void buyBooster(final BoosterPack booster, final int value) {
public void buyPack(final OpenablePack booster, final int value) {
if (this.q.getCredits() >= value) {
this.q.setCredits(this.q.getCredits() - value);
this.q.getShopList().remove(booster);
@@ -208,13 +209,6 @@ public final class QuestUtilCards {
}
}
public void buyTournamentPack(final TournamentPack booster, final int value) {
if (this.q.getCredits() >= value) {
this.q.setCredits(this.q.getCredits() - value);
this.q.getShopList().remove(booster);
this.addAllCards(booster.getCards());
}
}
/**
* Buy precon deck.