mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
Implement rewards for Chaos battles
This commit is contained in:
@@ -23,7 +23,9 @@ import com.google.common.base.Predicates;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
|
import forge.card.CardDb;
|
||||||
import forge.card.CardEdition;
|
import forge.card.CardEdition;
|
||||||
|
import forge.card.CardEdition.CardInSet;
|
||||||
import forge.deck.CardPool;
|
import forge.deck.CardPool;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
@@ -42,10 +44,6 @@ import java.util.Map.Entry;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: Write javadoc for this type.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class GameFormat implements Comparable<GameFormat> {
|
public class GameFormat implements Comparable<GameFormat> {
|
||||||
private final String name;
|
private final String name;
|
||||||
// contains allowed sets, when empty allows all sets
|
// contains allowed sets, when empty allows all sets
|
||||||
@@ -63,16 +61,6 @@ public class GameFormat implements Comparable<GameFormat> {
|
|||||||
|
|
||||||
private final int index;
|
private final int index;
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new game format.
|
|
||||||
*
|
|
||||||
* @param fName
|
|
||||||
* the f name
|
|
||||||
* @param sets
|
|
||||||
* the sets
|
|
||||||
* @param bannedCards
|
|
||||||
* the banned cards
|
|
||||||
*/
|
|
||||||
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) {
|
public GameFormat(final String fName, final Iterable<String> sets, final List<String> bannedCards) {
|
||||||
this(fName, sets, bannedCards, null, 0);
|
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));
|
return Predicates.and(banNames, StaticData.instance().getCommonCards().wasPrintedInSets(this.allowedSetCodes_ro));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the name.
|
|
||||||
*
|
|
||||||
* @return the name
|
|
||||||
*/
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the set list (for GameFormatQuest).
|
|
||||||
*
|
|
||||||
* @return list of allowed set codes
|
|
||||||
*/
|
|
||||||
public List<String> getAllowedSetCodes() {
|
public List<String> getAllowedSetCodes() {
|
||||||
return this.allowedSetCodes_ro;
|
return this.allowedSetCodes_ro;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the banned cards (for GameFormatQuest).
|
|
||||||
*
|
|
||||||
* @return list of banned card names
|
|
||||||
*/
|
|
||||||
public List<String> getBannedCardNames() {
|
public List<String> getBannedCardNames() {
|
||||||
return this.bannedCardNames_ro;
|
return this.bannedCardNames_ro;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getRestrictedCards() {
|
public List<String> getRestrictedCards() {
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return restrictedCardNames_ro;
|
return restrictedCardNames_ro;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public List<PaperCard> getAllCards() {
|
||||||
* Gets the filter rules.
|
List<PaperCard> cards = new ArrayList<PaperCard>();
|
||||||
*
|
CardDb commonCards = StaticData.instance().getCommonCards();
|
||||||
* @return the filter rules
|
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() {
|
public Predicate<PaperCard> getFilterRules() {
|
||||||
return this.filterRules;
|
return this.filterRules;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the filter printed.
|
|
||||||
*
|
|
||||||
* @return the filter printed
|
|
||||||
*/
|
|
||||||
public Predicate<PaperCard> getFilterPrinted() {
|
public Predicate<PaperCard> getFilterPrinted() {
|
||||||
return this.filterPrinted;
|
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) {
|
public boolean isSetLegal(final String setCode) {
|
||||||
return this.allowedSetCodes_ro.isEmpty() || this.allowedSetCodes_ro.contains(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());
|
return isPoolLegal(deck.getAllCardsInASinglePool());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
*
|
|
||||||
* @see java.lang.Object#toString()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name;
|
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
|
@Override
|
||||||
public int compareTo(GameFormat other) {
|
public int compareTo(GameFormat other) {
|
||||||
if (null == other) {
|
if (null == other) {
|
||||||
@@ -224,9 +189,6 @@ public class GameFormat implements Comparable<GameFormat> {
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Instantiates a new format utils.
|
|
||||||
*/
|
|
||||||
public static class Reader extends StorageReaderFileSections<GameFormat> {
|
public static class Reader extends StorageReaderFileSections<GameFormat> {
|
||||||
List<GameFormat> naturallyOrdered = new ArrayList<GameFormat>();
|
List<GameFormat> naturallyOrdered = new ArrayList<GameFormat>();
|
||||||
|
|
||||||
@@ -325,7 +287,6 @@ public class GameFormat implements Comparable<GameFormat> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// declared here because
|
|
||||||
public final Predicate<CardEdition> editionLegalPredicate = new Predicate<CardEdition>() {
|
public final Predicate<CardEdition> editionLegalPredicate = new Predicate<CardEdition>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final CardEdition subject) {
|
public boolean apply(final CardEdition subject) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class ConquestEventScreen extends LaunchScreen {
|
|||||||
//when returning to this screen from launched event, close it immediately and call callback
|
//when returning to this screen from launched event, close it immediately and call callback
|
||||||
Forge.back();
|
Forge.back();
|
||||||
callback.run(event);
|
callback.run(event);
|
||||||
|
launchedEvent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ import forge.planarconquest.ConquestChaosBattle;
|
|||||||
import forge.planarconquest.ConquestEvent;
|
import forge.planarconquest.ConquestEvent;
|
||||||
import forge.planarconquest.ConquestLocation;
|
import forge.planarconquest.ConquestLocation;
|
||||||
import forge.planarconquest.ConquestPlane;
|
import forge.planarconquest.ConquestPlane;
|
||||||
|
import forge.planarconquest.ConquestPlane.AwardPool;
|
||||||
import forge.planarconquest.ConquestPlane.Region;
|
import forge.planarconquest.ConquestPlane.Region;
|
||||||
import forge.planarconquest.ConquestPreferences.CQPref;
|
import forge.planarconquest.ConquestPreferences.CQPref;
|
||||||
import forge.planarconquest.ConquestPlaneData;
|
import forge.planarconquest.ConquestPlaneData;
|
||||||
|
import forge.planarconquest.ConquestReward;
|
||||||
import forge.screens.FScreen;
|
import forge.screens.FScreen;
|
||||||
import forge.screens.LoadingOverlay;
|
import forge.screens.LoadingOverlay;
|
||||||
import forge.toolbox.FDisplayObject;
|
import forge.toolbox.FDisplayObject;
|
||||||
@@ -43,6 +45,7 @@ public class ConquestMultiverseScreen extends FScreen {
|
|||||||
|
|
||||||
private final PlaneGrid planeGrid;
|
private final PlaneGrid planeGrid;
|
||||||
private ConquestData model;
|
private ConquestData model;
|
||||||
|
private ConquestChaosBattle chaosBattle;
|
||||||
|
|
||||||
public ConquestMultiverseScreen() {
|
public ConquestMultiverseScreen() {
|
||||||
super("", ConquestMenu.getMenu());
|
super("", ConquestMenu.getMenu());
|
||||||
@@ -52,7 +55,16 @@ public class ConquestMultiverseScreen extends FScreen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivate() {
|
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
|
@Override
|
||||||
@@ -61,7 +73,10 @@ public class ConquestMultiverseScreen extends FScreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
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());
|
setHeaderCaption(model.getName() + "\nPlane - " + model.getCurrentPlane().getName());
|
||||||
|
|
||||||
planeGrid.revalidate();
|
planeGrid.revalidate();
|
||||||
@@ -94,10 +109,10 @@ public class ConquestMultiverseScreen extends FScreen {
|
|||||||
public void run(ChaosWheelOutcome outcome) {
|
public void run(ChaosWheelOutcome outcome) {
|
||||||
switch (outcome) {
|
switch (outcome) {
|
||||||
case BOOSTER:
|
case BOOSTER:
|
||||||
awardBooster(false);
|
awardBoosters(model.getCurrentPlane().getAwardPool(), 1);
|
||||||
break;
|
break;
|
||||||
case DOUBLE_BOOSTER:
|
case DOUBLE_BOOSTER:
|
||||||
awardBooster(true);
|
awardBoosters(model.getCurrentPlane().getAwardPool(), 2);
|
||||||
break;
|
break;
|
||||||
case SHARDS:
|
case SHARDS:
|
||||||
awardShards(FModel.getConquestPreferences().getPrefInt(CQPref.AETHER_WHEEL_SHARDS), false);
|
awardShards(FModel.getConquestPreferences().getPrefInt(CQPref.AETHER_WHEEL_SHARDS), false);
|
||||||
@@ -116,29 +131,43 @@ public class ConquestMultiverseScreen extends FScreen {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void awardBooster(final boolean bonusBooster) {
|
private void awardBoosters(AwardPool pool, int totalCount) {
|
||||||
final int shardsBefore = model.getAEtherShards();
|
AwardBoosterHelper helper = new AwardBoosterHelper(pool, totalCount);
|
||||||
ConquestRewardDialog.show("Received Booster Pack" + (bonusBooster ? "\n(1 of 2)" : ""),
|
helper.run();
|
||||||
FModel.getConquest().awardBooster(), new Runnable() {
|
}
|
||||||
@Override
|
|
||||||
public void run() {
|
private class AwardBoosterHelper implements Runnable {
|
||||||
final Runnable alertShardsFromDuplicates = new Runnable() {
|
private final AwardPool pool;
|
||||||
@Override
|
private final int totalCount;
|
||||||
public void run() {
|
private final int shardsBefore;
|
||||||
final int shardsReceived = model.getAEtherShards() - shardsBefore;
|
private int number;
|
||||||
if (shardsReceived > 0) {
|
|
||||||
awardShards(shardsReceived, true);
|
private AwardBoosterHelper(AwardPool pool0, int totalCount0) {
|
||||||
}
|
pool = pool0;
|
||||||
}
|
number = 1;
|
||||||
};
|
totalCount = totalCount0;
|
||||||
if (bonusBooster) {
|
shardsBefore = model.getAEtherShards();
|
||||||
ConquestRewardDialog.show("Received Booster Pack\n(2 of 2)", FModel.getConquest().awardBooster(), alertShardsFromDuplicates);
|
}
|
||||||
}
|
|
||||||
else {
|
@Override
|
||||||
alertShardsFromDuplicates.run();
|
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() {
|
private static final FImage SHARD_IMAGE = new FImage() {
|
||||||
@@ -180,7 +209,8 @@ public class ConquestMultiverseScreen extends FScreen {
|
|||||||
LoadingOverlay.show("Chaos approaching...", new Runnable() {
|
LoadingOverlay.show("Chaos approaching...", new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
FModel.getConquest().launchEvent(new ConquestChaosBattle());
|
chaosBattle = new ConquestChaosBattle();
|
||||||
|
FModel.getConquest().launchEvent(chaosBattle);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import forge.interfaces.IButton;
|
|||||||
import forge.interfaces.IGuiGame;
|
import forge.interfaces.IGuiGame;
|
||||||
import forge.interfaces.IWinLoseView;
|
import forge.interfaces.IWinLoseView;
|
||||||
import forge.model.FModel;
|
import forge.model.FModel;
|
||||||
|
import forge.planarconquest.ConquestPlane.AwardPool;
|
||||||
import forge.planarconquest.ConquestPreferences.CQPref;
|
import forge.planarconquest.ConquestPreferences.CQPref;
|
||||||
import forge.properties.ForgeConstants;
|
import forge.properties.ForgeConstants;
|
||||||
import forge.quest.QuestEventDifficulty;
|
import forge.quest.QuestEventDifficulty;
|
||||||
@@ -22,6 +23,8 @@ import forge.util.Aggregates;
|
|||||||
public class ConquestChaosBattle extends ConquestEvent {
|
public class ConquestChaosBattle extends ConquestEvent {
|
||||||
private final QuestWorld world;
|
private final QuestWorld world;
|
||||||
private final QuestEventDuel duel;
|
private final QuestEventDuel duel;
|
||||||
|
private AwardPool awardPool;
|
||||||
|
private boolean finished;
|
||||||
|
|
||||||
public ConquestChaosBattle() {
|
public ConquestChaosBattle() {
|
||||||
super(null, 0);
|
super(null, 0);
|
||||||
@@ -86,6 +89,7 @@ public class ConquestChaosBattle extends ConquestEvent {
|
|||||||
if (game.isMatchWonBy(humanPlayer)) {
|
if (game.isMatchWonBy(humanPlayer)) {
|
||||||
view.getBtnQuit().setText("Great!");
|
view.getBtnQuit().setText("Great!");
|
||||||
model.getChaosBattleRecord().addWin();
|
model.getChaosBattleRecord().addWin();
|
||||||
|
setConquered(true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
view.getBtnQuit().setText("OK");
|
view.getBtnQuit().setText("OK");
|
||||||
@@ -107,5 +111,17 @@ public class ConquestChaosBattle extends ConquestEvent {
|
|||||||
model.getChaosBattleRecord().addLoss();
|
model.getChaosBattleRecord().addLoss();
|
||||||
model.saveData();
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,8 +183,7 @@ public class ConquestController {
|
|||||||
activeEvent = null;
|
activeEvent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ConquestReward> awardBooster() {
|
public List<ConquestReward> awardBooster(AwardPool pool) {
|
||||||
AwardPool pool = FModel.getConquest().getModel().getCurrentPlane().getAwardPool();
|
|
||||||
ConquestPreferences prefs = FModel.getConquestPreferences();
|
ConquestPreferences prefs = FModel.getConquestPreferences();
|
||||||
List<PaperCard> rewards = new ArrayList<PaperCard>();
|
List<PaperCard> rewards = new ArrayList<PaperCard>();
|
||||||
int boostersPerMythic = prefs.getPrefInt(CQPref.BOOSTERS_PER_MYTHIC);
|
int boostersPerMythic = prefs.getPrefInt(CQPref.BOOSTERS_PER_MYTHIC);
|
||||||
|
|||||||
@@ -545,18 +545,16 @@ public enum ConquestPlane {
|
|||||||
|
|
||||||
public AwardPool getAwardPool() {
|
public AwardPool getAwardPool() {
|
||||||
if (awardPool == null) { //delay initializing until needed
|
if (awardPool == null) { //delay initializing until needed
|
||||||
awardPool = new AwardPool();
|
awardPool = new AwardPool(cardPool.getAllCards());
|
||||||
}
|
}
|
||||||
return awardPool;
|
return awardPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AwardPool {
|
public static class AwardPool {
|
||||||
private final BoosterPool commons, uncommons, rares, mythics;
|
private final BoosterPool commons, uncommons, rares, mythics;
|
||||||
private final int commonValue, uncommonValue, rareValue, mythicValue;
|
private final int commonValue, uncommonValue, rareValue, mythicValue;
|
||||||
|
|
||||||
private AwardPool() {
|
public AwardPool(Iterable<PaperCard> cards) {
|
||||||
Iterable<PaperCard> cards = cardPool.getAllCards();
|
|
||||||
|
|
||||||
ConquestPreferences prefs = FModel.getConquestPreferences();
|
ConquestPreferences prefs = FModel.getConquestPreferences();
|
||||||
|
|
||||||
commons = new BoosterPool();
|
commons = new BoosterPool();
|
||||||
|
|||||||
@@ -78,29 +78,26 @@ public class QuestWorld implements Comparable<QuestWorld>{
|
|||||||
return dir == null ? null : dir + "/challenges";
|
return dir == null ? null : dir + "/challenges";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The quest world format if specified.
|
|
||||||
* @return GameFormatQuest, the format
|
|
||||||
*/
|
|
||||||
public GameFormatQuest getFormat() {
|
public GameFormatQuest getFormat() {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public List<PaperCard> getAllCards() {
|
||||||
* <p>
|
GameFormat format0 = format;
|
||||||
* toString.
|
if (format0 == null) {
|
||||||
* </p>
|
format0 = FModel.getQuest().getMainFormat();
|
||||||
*
|
}
|
||||||
* @return a {@link java.lang.String} object.
|
if (format0 != null) {
|
||||||
*/
|
return format0.getAllCards();
|
||||||
|
}
|
||||||
|
return FModel.getMagicDb().getCommonCards().getAllCards();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final String toString() {
|
public final String toString() {
|
||||||
return this.getName();
|
return this.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* FN_GET_NAME for reader.
|
|
||||||
*/
|
|
||||||
public static final Function<QuestWorld, String> FN_GET_NAME = new Function<QuestWorld, String>() {
|
public static final Function<QuestWorld, String> FN_GET_NAME = new Function<QuestWorld, String>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user