Implement rewards for Chaos battles

This commit is contained in:
drdev
2016-01-18 01:00:24 +00:00
parent 58328d6ebc
commit 1dd033b238
7 changed files with 113 additions and 111 deletions

View File

@@ -23,7 +23,9 @@ import com.google.common.base.Predicates;
import com.google.common.collect.Lists;
import forge.StaticData;
import forge.card.CardDb;
import forge.card.CardEdition;
import forge.card.CardEdition.CardInSet;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.item.IPaperCard;
@@ -42,10 +44,6 @@ import java.util.Map.Entry;
import java.util.Set;
/**
* TODO: Write javadoc for this type.
*
*/
public class GameFormat implements Comparable<GameFormat> {
private final String name;
// contains allowed sets, when empty allows all sets
@@ -61,18 +59,8 @@ public class GameFormat implements Comparable<GameFormat> {
protected final transient Predicate<PaperCard> filterRules;
protected final transient Predicate<PaperCard> filterPrinted;
private final int index;
/**
* Instantiates a new game format.
*
* @param fName
* the f name
* @param sets
* the sets
* @param bannedCards
* the banned cards
*/
private final int index;
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) {
this(fName, sets, bannedCards, null, 0);
}
@@ -110,63 +98,49 @@ public class GameFormat implements Comparable<GameFormat> {
return Predicates.and(banNames, StaticData.instance().getCommonCards().wasPrintedInSets(this.allowedSetCodes_ro));
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return this.name;
}
/**
* Gets the set list (for GameFormatQuest).
*
* @return list of allowed set codes
*/
public List<String> getAllowedSetCodes() {
return this.allowedSetCodes_ro;
}
/**
* Gets the banned cards (for GameFormatQuest).
*
* @return list of banned card names
*/
public List<String> getBannedCardNames() {
return this.bannedCardNames_ro;
}
public List<String> getRestrictedCards() {
// TODO Auto-generated method stub
return restrictedCardNames_ro;
}
/**
* Gets the filter rules.
*
* @return the filter rules
*/
public List<PaperCard> getAllCards() {
List<PaperCard> cards = new ArrayList<PaperCard>();
CardDb commonCards = StaticData.instance().getCommonCards();
for (String setCode : allowedSetCodes_ro) {
CardEdition edition = StaticData.instance().getEditions().get(setCode);
if (edition != null) {
for (CardInSet card : edition.getCards()) {
if (!bannedCardNames_ro.contains(card.name)) {
PaperCard pc = commonCards.getCard(card.name, setCode);
if (pc != null) {
cards.add(pc);
}
}
}
}
}
return cards;
}
public Predicate<PaperCard> getFilterRules() {
return this.filterRules;
}
/**
* Gets the filter printed.
*
* @return the filter printed
*/
public Predicate<PaperCard> getFilterPrinted() {
return this.filterPrinted;
}
/**
* Checks if is sets the legal.
*
* @param setCode
* the set code
* @return true, if is sets the legal
*/
public boolean isSetLegal(final String setCode) {
return this.allowedSetCodes_ro.isEmpty() || this.allowedSetCodes_ro.contains(setCode);
}
@@ -191,11 +165,6 @@ public class GameFormat implements Comparable<GameFormat> {
return isPoolLegal(deck.getAllCardsInASinglePool());
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return this.name;
@@ -208,10 +177,6 @@ public class GameFormat implements Comparable<GameFormat> {
}
};
/* (non-Javadoc)
* just used for ordering -- comparing the name is sufficient
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@Override
public int compareTo(GameFormat other) {
if (null == other) {
@@ -224,9 +189,6 @@ public class GameFormat implements Comparable<GameFormat> {
return index;
}
/**
* Instantiates a new format utils.
*/
public static class Reader extends StorageReaderFileSections<GameFormat> {
List<GameFormat> naturallyOrdered = new ArrayList<GameFormat>();
@@ -324,8 +286,7 @@ public class GameFormat implements Comparable<GameFormat> {
return result;
}
}
// declared here because
public final Predicate<CardEdition> editionLegalPredicate = new Predicate<CardEdition>() {
@Override
public boolean apply(final CardEdition subject) {

View File

@@ -27,6 +27,7 @@ public class ConquestEventScreen extends LaunchScreen {
//when returning to this screen from launched event, close it immediately and call callback
Forge.back();
callback.run(event);
launchedEvent = false;
}
}

View File

@@ -25,9 +25,11 @@ import forge.planarconquest.ConquestChaosBattle;
import forge.planarconquest.ConquestEvent;
import forge.planarconquest.ConquestLocation;
import forge.planarconquest.ConquestPlane;
import forge.planarconquest.ConquestPlane.AwardPool;
import forge.planarconquest.ConquestPlane.Region;
import forge.planarconquest.ConquestPreferences.CQPref;
import forge.planarconquest.ConquestPlaneData;
import forge.planarconquest.ConquestReward;
import forge.screens.FScreen;
import forge.screens.LoadingOverlay;
import forge.toolbox.FDisplayObject;
@@ -43,16 +45,26 @@ public class ConquestMultiverseScreen extends FScreen {
private final PlaneGrid planeGrid;
private ConquestData model;
private ConquestChaosBattle chaosBattle;
public ConquestMultiverseScreen() {
super("", ConquestMenu.getMenu());
planeGrid = add(new PlaneGrid());
}
@Override
public void onActivate() {
update();
if (chaosBattle == null) {
update();
}
else if (chaosBattle.isFinished()) {
//when returning to this screen from launched chaos battle, award boosters if it was conquered
if (chaosBattle.wasConquered()) {
awardBoosters(chaosBattle.getAwardPool(), 3);
}
chaosBattle = null;
}
}
@Override
@@ -61,7 +73,10 @@ public class ConquestMultiverseScreen extends FScreen {
}
public void update() {
model = FModel.getConquest().getModel();
ConquestData model0 = FModel.getConquest().getModel();
if (model == model0) { return; }
model = model0;
setHeaderCaption(model.getName() + "\nPlane - " + model.getCurrentPlane().getName());
planeGrid.revalidate();
@@ -94,10 +109,10 @@ public class ConquestMultiverseScreen extends FScreen {
public void run(ChaosWheelOutcome outcome) {
switch (outcome) {
case BOOSTER:
awardBooster(false);
awardBoosters(model.getCurrentPlane().getAwardPool(), 1);
break;
case DOUBLE_BOOSTER:
awardBooster(true);
awardBoosters(model.getCurrentPlane().getAwardPool(), 2);
break;
case SHARDS:
awardShards(FModel.getConquestPreferences().getPrefInt(CQPref.AETHER_WHEEL_SHARDS), false);
@@ -116,29 +131,43 @@ public class ConquestMultiverseScreen extends FScreen {
});
}
private void awardBooster(final boolean bonusBooster) {
final int shardsBefore = model.getAEtherShards();
ConquestRewardDialog.show("Received Booster Pack" + (bonusBooster ? "\n(1 of 2)" : ""),
FModel.getConquest().awardBooster(), new Runnable() {
@Override
public void run() {
final Runnable alertShardsFromDuplicates = new Runnable() {
@Override
public void run() {
final int shardsReceived = model.getAEtherShards() - shardsBefore;
if (shardsReceived > 0) {
awardShards(shardsReceived, true);
}
}
};
if (bonusBooster) {
ConquestRewardDialog.show("Received Booster Pack\n(2 of 2)", FModel.getConquest().awardBooster(), alertShardsFromDuplicates);
}
else {
alertShardsFromDuplicates.run();
private void awardBoosters(AwardPool pool, int totalCount) {
AwardBoosterHelper helper = new AwardBoosterHelper(pool, totalCount);
helper.run();
}
private class AwardBoosterHelper implements Runnable {
private final AwardPool pool;
private final int totalCount;
private final int shardsBefore;
private int number;
private AwardBoosterHelper(AwardPool pool0, int totalCount0) {
pool = pool0;
number = 1;
totalCount = totalCount0;
shardsBefore = model.getAEtherShards();
}
@Override
public void run() {
if (number > totalCount) {
//show total shards received from all boosters once all boosters shown
final int shardsReceived = model.getAEtherShards() - shardsBefore;
if (shardsReceived > 0) {
awardShards(shardsReceived, true);
}
return;
}
});
String title = "Received Booster Pack";
if (totalCount > 1) {
title += String.format("\n(%d of %d)", number, totalCount);
}
number++;
List<ConquestReward> rewards = FModel.getConquest().awardBooster(pool);
ConquestRewardDialog.show(title, rewards, this);
}
}
private static final FImage SHARD_IMAGE = new FImage() {
@@ -180,7 +209,8 @@ public class ConquestMultiverseScreen extends FScreen {
LoadingOverlay.show("Chaos approaching...", new Runnable() {
@Override
public void run() {
FModel.getConquest().launchEvent(new ConquestChaosBattle());
chaosBattle = new ConquestChaosBattle();
FModel.getConquest().launchEvent(chaosBattle);
}
});
}

View File

@@ -11,6 +11,7 @@ import forge.interfaces.IButton;
import forge.interfaces.IGuiGame;
import forge.interfaces.IWinLoseView;
import forge.model.FModel;
import forge.planarconquest.ConquestPlane.AwardPool;
import forge.planarconquest.ConquestPreferences.CQPref;
import forge.properties.ForgeConstants;
import forge.quest.QuestEventDifficulty;
@@ -22,6 +23,8 @@ import forge.util.Aggregates;
public class ConquestChaosBattle extends ConquestEvent {
private final QuestWorld world;
private final QuestEventDuel duel;
private AwardPool awardPool;
private boolean finished;
public ConquestChaosBattle() {
super(null, 0);
@@ -86,6 +89,7 @@ public class ConquestChaosBattle extends ConquestEvent {
if (game.isMatchWonBy(humanPlayer)) {
view.getBtnQuit().setText("Great!");
model.getChaosBattleRecord().addWin();
setConquered(true);
}
else {
view.getBtnQuit().setText("OK");
@@ -107,5 +111,17 @@ public class ConquestChaosBattle extends ConquestEvent {
model.getChaosBattleRecord().addLoss();
model.saveData();
}
finished = true;
}
public AwardPool getAwardPool() {
if (awardPool == null) { //delay initializing until needed
awardPool = new AwardPool(world.getAllCards());
}
return awardPool;
}
public boolean isFinished() {
return finished;
}
}

View File

@@ -183,8 +183,7 @@ public class ConquestController {
activeEvent = null;
}
public List<ConquestReward> awardBooster() {
AwardPool pool = FModel.getConquest().getModel().getCurrentPlane().getAwardPool();
public List<ConquestReward> awardBooster(AwardPool pool) {
ConquestPreferences prefs = FModel.getConquestPreferences();
List<PaperCard> rewards = new ArrayList<PaperCard>();
int boostersPerMythic = prefs.getPrefInt(CQPref.BOOSTERS_PER_MYTHIC);

View File

@@ -545,18 +545,16 @@ public enum ConquestPlane {
public AwardPool getAwardPool() {
if (awardPool == null) { //delay initializing until needed
awardPool = new AwardPool();
awardPool = new AwardPool(cardPool.getAllCards());
}
return awardPool;
}
public class AwardPool {
public static class AwardPool {
private final BoosterPool commons, uncommons, rares, mythics;
private final int commonValue, uncommonValue, rareValue, mythicValue;
private AwardPool() {
Iterable<PaperCard> cards = cardPool.getAllCards();
public AwardPool(Iterable<PaperCard> cards) {
ConquestPreferences prefs = FModel.getConquestPreferences();
commons = new BoosterPool();

View File

@@ -78,29 +78,26 @@ public class QuestWorld implements Comparable<QuestWorld>{
return dir == null ? null : dir + "/challenges";
}
/**
* The quest world format if specified.
* @return GameFormatQuest, the format
*/
public GameFormatQuest getFormat() {
return format;
}
/**
* <p>
* toString.
* </p>
*
* @return a {@link java.lang.String} object.
*/
public List<PaperCard> getAllCards() {
GameFormat format0 = format;
if (format0 == null) {
format0 = FModel.getQuest().getMainFormat();
}
if (format0 != null) {
return format0.getAllCards();
}
return FModel.getMagicDb().getCommonCards().getAllCards();
}
@Override
public final String toString() {
return this.getName();
}
/**
* FN_GET_NAME for reader.
*/
public static final Function<QuestWorld, String> FN_GET_NAME = new Function<QuestWorld, String>() {
@Override