mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
Implement Chaos battles
This commit is contained in:
@@ -81,13 +81,14 @@ public class ConquestController {
|
||||
return decks;
|
||||
}
|
||||
|
||||
public void launchEvent(ConquestCommander commander, ConquestEvent event) {
|
||||
public void launchEvent(ConquestEvent event) {
|
||||
if (activeEvent != null) { return; }
|
||||
|
||||
//determine game variants
|
||||
Set<GameType> variants = new HashSet<GameType>();
|
||||
event.addVariants(variants);
|
||||
|
||||
final ConquestCommander commander = model.getSelectedCommander();
|
||||
final RegisteredPlayer humanStart = new RegisteredPlayer(commander.getDeck());
|
||||
final RegisteredPlayer aiStart = new RegisteredPlayer(event.getOpponentDeck());
|
||||
|
||||
@@ -122,7 +123,7 @@ public class ConquestController {
|
||||
rp.setRandomFoil(useRandomFoil);
|
||||
}
|
||||
final GameRules rules = new GameRules(GameType.PlanarConquest);
|
||||
rules.setGamesPerMatch(1); //only play one game at a time
|
||||
rules.setGamesPerMatch(event.gamesPerMatch());
|
||||
rules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
||||
rules.setCanCloneUseTargetsImage(FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE));
|
||||
final HostedMatch hostedMatch = GuiBase.getInterface().hostMatch();
|
||||
@@ -170,23 +171,13 @@ public class ConquestController {
|
||||
}
|
||||
|
||||
public void showGameOutcome(final GameView game, final IWinLoseView<? extends IButton> view) {
|
||||
if (game.isMatchWonBy(humanPlayer)) {
|
||||
view.getBtnRestart().setVisible(false);
|
||||
view.getBtnQuit().setText("Great!");
|
||||
model.addWin(activeEvent);
|
||||
}
|
||||
else {
|
||||
view.getBtnRestart().setVisible(true);
|
||||
view.getBtnRestart().setText("Retry");
|
||||
view.getBtnQuit().setText("Quit");
|
||||
model.addLoss(activeEvent);
|
||||
}
|
||||
|
||||
model.saveData();
|
||||
FModel.getConquestPreferences().save();
|
||||
activeEvent.showGameOutcome(model, game, humanPlayer, view);
|
||||
}
|
||||
|
||||
public void finishEvent() {
|
||||
public void finishEvent(final IWinLoseView<? extends IButton> view) {
|
||||
if (activeEvent == null) { return; }
|
||||
|
||||
activeEvent.onFinished(model, view);
|
||||
activeEvent = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ public final class ConquestData {
|
||||
|
||||
private final File directory;
|
||||
private final String xmlFilename;
|
||||
private final ConquestRecord chaosBattleRecord;
|
||||
private final EnumMap<ConquestPlane, ConquestPlaneData> planeDataMap = new EnumMap<ConquestPlane, ConquestPlaneData>(ConquestPlane.class);
|
||||
private final HashSet<PaperCard> unlockedCards = new HashSet<PaperCard>();
|
||||
private final List<ConquestCommander> commanders = new ArrayList<ConquestCommander>();
|
||||
@@ -81,6 +82,7 @@ public final class ConquestData {
|
||||
unlockCard(card);
|
||||
}
|
||||
}
|
||||
chaosBattleRecord = new ConquestRecord();
|
||||
}
|
||||
|
||||
public ConquestData(File directory0) {
|
||||
@@ -88,6 +90,7 @@ public final class ConquestData {
|
||||
directory = directory0;
|
||||
xmlFilename = directory.getPath() + ForgeConstants.PATH_SEPARATOR + XML_FILE;
|
||||
|
||||
ConquestRecord chaosBattleRecord0 = null;
|
||||
try {
|
||||
XmlReader xml = new XmlReader(xmlFilename);
|
||||
CardDb cardDb = FModel.getMagicDb().getCommonCards();
|
||||
@@ -95,6 +98,7 @@ public final class ConquestData {
|
||||
aetherShards = xml.read("aetherShards", aetherShards);
|
||||
currentLocation = xml.read("currentLocation", ConquestLocation.class);
|
||||
selectedCommanderIndex = xml.read("selectedCommanderIndex", selectedCommanderIndex);
|
||||
chaosBattleRecord0 = xml.read("chaosBattleRecord", ConquestRecord.class);
|
||||
xml.read("unlockedCards", unlockedCards, cardDb);
|
||||
xml.read("newCards", newCards, cardDb);
|
||||
xml.read("commanders", commanders, ConquestCommander.class);
|
||||
@@ -103,6 +107,10 @@ public final class ConquestData {
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (chaosBattleRecord0 == null) {
|
||||
chaosBattleRecord0 = new ConquestRecord();
|
||||
}
|
||||
chaosBattleRecord = chaosBattleRecord0;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -224,6 +232,10 @@ public final class ConquestData {
|
||||
return Math.round(100f * (float)conquered / (float)total) + "%";
|
||||
}
|
||||
|
||||
public ConquestRecord getChaosBattleRecord() {
|
||||
return chaosBattleRecord;
|
||||
}
|
||||
|
||||
public void saveData() {
|
||||
FileUtil.ensureDirectoryExists(directory);
|
||||
|
||||
|
||||
@@ -2,8 +2,12 @@ package forge.planarconquest;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import forge.LobbyPlayer;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.game.GameView;
|
||||
import forge.interfaces.IButton;
|
||||
import forge.interfaces.IWinLoseView;
|
||||
import forge.util.XmlReader;
|
||||
import forge.util.XmlWriter;
|
||||
import forge.util.XmlWriter.IXmlWritable;
|
||||
@@ -41,6 +45,28 @@ public abstract class ConquestEvent {
|
||||
conquered = conquered0;
|
||||
}
|
||||
|
||||
public int gamesPerMatch() {
|
||||
return 1; //events are one game by default
|
||||
}
|
||||
|
||||
public void showGameOutcome(final ConquestData model, final GameView game, final LobbyPlayer humanPlayer, final IWinLoseView<? extends IButton> view) {
|
||||
if (game.isMatchWonBy(humanPlayer)) {
|
||||
view.getBtnRestart().setVisible(false);
|
||||
view.getBtnQuit().setText("Great!");
|
||||
model.addWin(this);
|
||||
}
|
||||
else {
|
||||
view.getBtnRestart().setVisible(true);
|
||||
view.getBtnRestart().setText("Retry");
|
||||
view.getBtnQuit().setText("Quit");
|
||||
model.addLoss(this);
|
||||
}
|
||||
model.saveData();
|
||||
}
|
||||
|
||||
public void onFinished(final ConquestData model, final IWinLoseView<? extends IButton> view) {
|
||||
}
|
||||
|
||||
protected abstract Deck buildOpponentDeck();
|
||||
public abstract void addVariants(Set<GameType> variants);
|
||||
public abstract String getEventName();
|
||||
|
||||
@@ -37,7 +37,11 @@ public class ConquestPreferences extends PreferencesStore<ConquestPreferences.CQ
|
||||
BOOSTER_COMMONS("11"),
|
||||
BOOSTER_UNCOMMONS("3"),
|
||||
BOOSTER_RARES("1"),
|
||||
BOOSTERS_PER_MYTHIC("8");
|
||||
BOOSTERS_PER_MYTHIC("8"),
|
||||
|
||||
CHAOS_BATTLE_WINS_MEDIUMAI("2"),
|
||||
CHAOS_BATTLE_WINS_HARDAI("5"),
|
||||
CHAOS_BATTLE_WINS_EXPERTAI("10");
|
||||
|
||||
private final String strDefaultVal;
|
||||
|
||||
|
||||
@@ -47,13 +47,16 @@ public class QuestEventDuelManager {
|
||||
public QuestEventDuelManager(final File dir) {
|
||||
allDuels = new StorageBase<QuestEventDuel>("Quest duels", new QuestDuelReader(dir));
|
||||
assembleDuelDifficultyLists();
|
||||
} // End assembleAllEvents()
|
||||
}
|
||||
|
||||
/** @return List<QuestEventDuel> */
|
||||
public Iterable<QuestEventDuel> getAllDuels() {
|
||||
return allDuels;
|
||||
}
|
||||
|
||||
public Iterable<QuestEventDuel> getDuels(QuestEventDifficulty difficulty) {
|
||||
return sortedDuels.get(difficulty);
|
||||
}
|
||||
|
||||
// define fallback orders if there aren't enough opponents defined for a particular difficultly level
|
||||
private static List<QuestEventDifficulty> _easyOrder = Arrays.asList(QuestEventDifficulty.EASY, QuestEventDifficulty.MEDIUM, QuestEventDifficulty.HARD, QuestEventDifficulty.EXPERT);
|
||||
private static List<QuestEventDifficulty> _mediumOrder = Arrays.asList(QuestEventDifficulty.MEDIUM, QuestEventDifficulty.HARD, QuestEventDifficulty.EASY, QuestEventDifficulty.EXPERT);
|
||||
|
||||
Reference in New Issue
Block a user