Files
forge/forge-m-base/src/forge/quest/QuestUtil.java
2014-04-06 20:23:03 +00:00

175 lines
5.6 KiB
Java

/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.quest;
import forge.card.CardDb.SetPreference;
import forge.card.CardEdition;
import forge.card.CardRules;
import forge.game.card.Card;
import forge.item.IPaperCard;
import forge.item.PaperToken;
import forge.model.FModel;
import forge.quest.bazaar.QuestPetController;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* QuestUtil class.
* </p>
* MODEL - Static utility methods to help with minor tasks around Quest.
*
* @author Forge
* @version $Id: QuestUtil.java 24769 2014-02-09 13:56:04Z Hellfish $
*/
public class QuestUtil {
/**
* <p>
* getComputerStartingCards.
* </p>
*
* @param qd
* a {@link forge.quest.data.QuestData} object.
* @return a {@link forge.CardList} object.
*/
public static List<Card> getComputerStartingCards() {
return new ArrayList<Card>();
}
/**
* <p>
* getComputerStartingCards.
* </p>
* Returns new card instances of extra AI cards in play at start of event.
*
* @param qd
* a {@link forge.quest.data.QuestData} object.
* @param qe
* a {@link forge.quest.QuestEvent} object.
* @return a {@link forge.CardList} object.
*/
public static List<IPaperCard> getComputerStartingCards(final QuestEvent qe) {
final List<IPaperCard> list = new ArrayList<IPaperCard>();
for (final String s : qe.getAiExtraCards()) {
list.add(QuestUtil.readExtraCard(s));
}
return list;
}
/**
* <p>
* getHumanStartingCards.
* </p>
* Returns list of current plant/pet configuration only.
* @param human
*
* @param qd
* a {@link forge.quest.data.QuestData} object.
* @return a {@link forge.CardList} object.
*/
public static List<IPaperCard> getHumanStartingCards(final QuestController qc) {
final List<IPaperCard> list = new ArrayList<IPaperCard>();
for (int iSlot = 0; iSlot < QuestController.MAX_PET_SLOTS; iSlot++) {
String petName = qc.getSelectedPet(iSlot);
QuestPetController pet = qc.getPetsStorage().getPet(petName);
if (pet != null) {
IPaperCard c = pet.getPetCard(qc.getAssets());
if (c != null) {
list.add(c);
}
}
}
return list;
}
/**
* <p>
* getHumanStartingCards.
* </p>
* Returns new card instances of extra human cards, including current
* plant/pet configuration, and cards in play at start of quest.
*
* @param qd
* a {@link forge.quest.data.QuestData} object.
* @param qe
* a {@link forge.quest.QuestEvent} object.
* @return a {@link forge.CardList} object.
*/
public static List<IPaperCard> getHumanStartingCards(final QuestController qc, final QuestEvent qe) {
final List<IPaperCard> list = QuestUtil.getHumanStartingCards(qc);
for (final String s : qe.getHumanExtraCards()) {
list.add(QuestUtil.readExtraCard(s));
}
return list;
}
/**
* <p>
* createToken.
* </p>
* Creates a card instance for token defined by property string.
*
* @param s
* Properties string of token
* (TOKEN;W;1;1;sheep;type;type;type...)
* @return token Card
*/
public static PaperToken createToken(final String s) {
final String[] properties = s.split(";", 6);
List<String> script = new ArrayList<String>();
script.add("Name:" + properties[4]);
script.add("Colors:" + properties[1]);
script.add("PT:"+ properties[2] + "/" + properties[3]);
script.add("Types:" + properties[5].replace(';', ' '));
script.add("Oracle:"); // tokens don't have texts yet
String fileName = PaperToken.makeTokenFileName(properties[1], properties[2], properties[3], properties[4]);
final PaperToken c = new PaperToken(CardRules.fromScript(script), CardEdition.UNKNOWN, fileName);
return c;
}
/**
* <p>
* readExtraCard.
* </p>
* Creates single card for a string read from unique event properties.
*
* @param name
* the name
* @param owner
* the owner
* @return the card
*/
public static IPaperCard readExtraCard(final String name) {
// Token card creation
IPaperCard tempcard;
if (name.startsWith("TOKEN")) {
tempcard = QuestUtil.createToken(name);
return tempcard;
}
// Standard card creation
return FModel.getMagicDb().getCommonCards().getCardFromEdition(name, SetPreference.Latest);
}
} // QuestUtil