Merge remote-tracking branch 'upstream/master' into collector-number-in-card-list-and-card-db-refactoring

This commit is contained in:
leriomaggio
2021-07-23 22:38:23 +01:00
299 changed files with 3647 additions and 1286 deletions

View File

@@ -661,6 +661,14 @@ public class DeckProxy implements InventoryItem {
return decks;
}
public static List<DeckProxy> getNetArchivePauperDecks(final NetDeckArchivePauper category) {
final List<DeckProxy> decks = new ArrayList<>();
if (category != null) {
addDecksRecursivelly("Constructed", GameType.Constructed, decks, "", category, null);
}
return decks;
}
public static List<DeckProxy> getNetArchiveLegacyDecks(final NetDeckArchiveLegacy category) {
final List<DeckProxy> decks = new ArrayList<>();
if (category != null) {
@@ -677,7 +685,7 @@ public class DeckProxy implements InventoryItem {
return decks;
}
public static List<DeckProxy> getNetArchiveBlockecks(final NetDeckArchiveBlock category) {
public static List<DeckProxy> getNetArchiveBlockDecks(final NetDeckArchiveBlock category) {
final List<DeckProxy> decks = new ArrayList<>();
if (category != null) {
addDecksRecursivelly("Constructed", GameType.Constructed, decks, "", category, null);

View File

@@ -35,6 +35,7 @@ public enum DeckType {
NET_ARCHIVE_STANDARD_DECK("lblNetArchiveStandardDecks"),
NET_ARCHIVE_PIONEER_DECK("lblNetArchivePioneerDecks"),
NET_ARCHIVE_MODERN_DECK("lblNetArchiveModernDecks"),
NET_ARCHIVE_PAUPER_DECK("lblNetArchivePauperDecks"),
NET_ARCHIVE_LEGACY_DECK("lblNetArchiveLegacyDecks"),
NET_ARCHIVE_VINTAGE_DECK("lblNetArchiveVintageDecks"),
NET_ARCHIVE_BLOCK_DECK("lblNetArchiveBlockDecks");
@@ -63,6 +64,7 @@ public enum DeckType {
DeckType.NET_ARCHIVE_STANDARD_DECK,
DeckType.NET_ARCHIVE_PIONEER_DECK,
DeckType.NET_ARCHIVE_MODERN_DECK,
DeckType.NET_ARCHIVE_PAUPER_DECK,
DeckType.NET_ARCHIVE_LEGACY_DECK,
DeckType.NET_ARCHIVE_VINTAGE_DECK,
DeckType.NET_ARCHIVE_BLOCK_DECK
@@ -81,8 +83,10 @@ public enum DeckType {
DeckType.NET_ARCHIVE_STANDARD_DECK,
DeckType.NET_ARCHIVE_PIONEER_DECK,
DeckType.NET_ARCHIVE_MODERN_DECK,
DeckType.NET_ARCHIVE_PAUPER_DECK,
DeckType.NET_ARCHIVE_LEGACY_DECK,
DeckType.NET_ARCHIVE_VINTAGE_DECK
DeckType.NET_ARCHIVE_VINTAGE_DECK,
DeckType.NET_ARCHIVE_BLOCK_DECK
};
}
}

View File

@@ -0,0 +1,122 @@
package forge.deck;
import forge.deck.io.DeckSerializer;
import forge.deck.io.DeckStorage;
import forge.game.GameType;
import forge.gui.GuiBase;
import forge.gui.download.GuiDownloadZipService;
import forge.gui.util.SGuiChoose;
import forge.localinstance.properties.ForgeConstants;
import forge.util.FileUtil;
import forge.util.WaitCallback;
import forge.util.storage.StorageBase;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
public class NetDeckArchivePauper extends StorageBase<Deck> {
public static final String PREFIX = "NET_ARCHIVE_PAUPER_DECK";
private static Map<String, NetDeckArchivePauper> constructed, commander, brawl;
private static Map<String, NetDeckArchivePauper> loadCategories(String filename) {
Map<String, NetDeckArchivePauper> categories = new TreeMap<>();
if (FileUtil.doesFileExist(filename)) {
List<String> lines = FileUtil.readFile(filename);
for (String line : lines) {
int idx = line.indexOf('|');
if (idx != -1) {
String name = line.substring(0, idx).trim();
String url = line.substring(idx + 1).trim();
categories.put(name, new NetDeckArchivePauper(name, url));
}
}
}
return categories;
}
public static NetDeckArchivePauper selectAndLoad(GameType gameType) {
return selectAndLoad(gameType, null);
}
public static NetDeckArchivePauper selectAndLoad(GameType gameType, String name) {
Map<String, NetDeckArchivePauper> categories;
switch (gameType) {
case Constructed:
case Gauntlet:
if (constructed == null) {
constructed = loadCategories(ForgeConstants.NET_ARCHIVE_PAUPER_DECKS_LIST_FILE);
}
categories = constructed;
break;
default:
return null;
}
if (name != null) {
NetDeckArchivePauper category = categories.get(name);
if (category != null && category.map.isEmpty()) {
//if name passed in, try to load decks from current cached files
File downloadDir = new File(category.getFullPath());
if (downloadDir.exists()) {
for (File file : downloadDir.listFiles(DeckStorage.DCK_FILE_FILTER)) {
Deck deck = DeckSerializer.fromFile(file);
if (deck != null) {
category.map.put(deck.getName(), deck);
}
}
}
}
return category;
}
List<NetDeckArchivePauper> category = new ArrayList<>(categories.values());
Collections.reverse(category);
final NetDeckArchivePauper c = SGuiChoose.oneOrNone("Select a Net Deck Archive Pauper category", category);
if (c == null) { return null; }
if (c.map.isEmpty()) { //only download decks once per session
WaitCallback<Boolean> callback = new WaitCallback<Boolean>() {
@Override
public void run() {
String downloadLoc = c.getFullPath();
GuiBase.getInterface().download(new GuiDownloadZipService(c.getName(), "decks", c.getUrl(), downloadLoc, downloadLoc, null) {
@Override
protected void copyInputStream(InputStream in, String outPath) throws IOException {
super.copyInputStream(in, outPath);
Deck deck = DeckSerializer.fromFile(new File(outPath));
if (deck != null) {
c.map.put(deck.getName(), deck);
}
}
}, this);
}
};
if (!callback.invokeAndWait()) { return null; } //wait for download to finish
}
return c;
}
private final String url;
private NetDeckArchivePauper(String name0, String url0) {
super(name0, ForgeConstants.DECK_NET_ARCHIVE_DIR + name0, new HashMap<>());
url = url0;
}
public String getUrl() {
return url;
}
public String getDeckType() {
return "Net Archive Pauper Decks - " + name;
}
@Override
public String toString() {
return name;
}
}

View File

@@ -84,7 +84,7 @@ public class LimitedDeckBuilder extends DeckGeneratorBase {
// remove Unplayables
final Iterable<PaperCard> playables = Iterables.filter(availableList,
Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_DECKS, PaperCard.FN_GET_RULES));
Predicates.compose(CardRulesPredicates.IS_KEPT_IN_AI_LIMITED_DECKS, PaperCard.FN_GET_RULES));
this.aiPlayables = Lists.newArrayList(playables);
this.availableList.removeAll(aiPlayables);

View File

@@ -106,6 +106,8 @@ public enum ItemManagerConfig {
null, null, 3, 0),
NET_ARCHIVE_MODERN_DECKS(SColumnUtil.getDecksDefaultColumns(false, false), false, false, false,
null, null, 3, 0),
NET_ARCHIVE_PAUPER_DECKS(SColumnUtil.getDecksDefaultColumns(false, false), false, false, false,
null, null, 3, 0),
NET_ARCHIVE_LEGACY_DECKS(SColumnUtil.getDecksDefaultColumns(false, false), false, false, false,
null, null, 3, 0),
NET_ARCHIVE_VINTAGE_DECKS(SColumnUtil.getDecksDefaultColumns(false, false), false, false, false,

View File

@@ -56,6 +56,7 @@ public final class ForgeConstants {
public static final String NET_ARCHIVE_STANDARD_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-standard.txt";
public static final String NET_ARCHIVE_PIONEER_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-pioneer.txt";
public static final String NET_ARCHIVE_MODERN_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-modern.txt";
public static final String NET_ARCHIVE_PAUPER_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-pauper.txt";
public static final String NET_ARCHIVE_LEGACY_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-legacy.txt";
public static final String NET_ARCHIVE_VINTAGE_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-vintage.txt";
public static final String NET_ARCHIVE_BLOCK_DECKS_LIST_FILE = LISTS_DIR + "net-decks-archive-block.txt";

View File

@@ -468,8 +468,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
if (cost.isMandatory()) {
return chooseNumber(ability, localizer.getMessage("lblChooseAnnounceForCard", announce,
CardTranslation.getTranslatedName(ability.getHostCard().getName())) , min, max);
}
else {
} else {
return getGui().getInteger(localizer.getMessage("lblChooseAnnounceForCard", announce,
CardTranslation.getTranslatedName(ability.getHostCard().getName())) , min, max, min + 9);
}
@@ -497,8 +496,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
String inpMessage = null;
if (min == 0) {
inpMessage = localizer.getMessage("lblSelectUpToNumTargetToAction", message, action);
}
else {
} else {
inpMessage = localizer.getMessage("lblSelectNumTargetToAction", message, action);
}
@@ -816,8 +814,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
String prompt = null;
if (isFirstGame) {
prompt = localizer.getMessage("lblYouHaveWonTheCoinToss", player.getName());
}
else {
} else {
prompt = localizer.getMessage("lblYouLostTheLastGame", player.getName());
}
prompt += "\n\n" + localizer.getMessage("lblWouldYouLiketoPlayorDraw");
@@ -828,8 +825,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
String prompt = null;
if (isFirstGame) {
prompt = localizer.getMessage("lblYouHaveWonTheCoinToss", player.getName());
}
else {
} else {
prompt = localizer.getMessage("lblYouLostTheLastGame", player.getName());
}
prompt += "\n\n" + localizer.getMessage("lblWhoWouldYouLiketoStartthisGame");
@@ -1323,14 +1319,17 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
if (sa.hasParam("TokenScript")) {
sa.setActivatingPlayer(player);
Card protoType = TokenInfo.getProtoType(sa.getParam("TokenScript"), sa, null);
for (String type : protoType.getType().getCreatureTypes()) {
Integer count = typesInDeck.get(type);
if (count == null) {
count = 0;
for (String token : sa.getParam("TokenScript").split(",")) {
Card protoType = TokenInfo.getProtoType(token, sa, null);
for (String type : protoType.getType().getCreatureTypes()) {
Integer count = typesInDeck.get(type);
if (count == null) {
count = 0;
}
typesInDeck.put(type, count + 1);
}
typesInDeck.put(type, count + 1);
}
}
}
// same for Trigger that does make Tokens
@@ -1339,13 +1338,15 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
if (sa != null) {
if (sa.hasParam("TokenScript")) {
sa.setActivatingPlayer(player);
Card protoType = TokenInfo.getProtoType(sa.getParam("TokenScript"), sa, null);
for (String type : protoType.getType().getCreatureTypes()) {
Integer count = typesInDeck.get(type);
if (count == null) {
count = 0;
for (String token : sa.getParam("TokenScript").split(",")) {
Card protoType = TokenInfo.getProtoType(token, sa, null);
for (String type : protoType.getType().getCreatureTypes()) {
Integer count = typesInDeck.get(type);
if (count == null) {
count = 0;
}
typesInDeck.put(type, count + 1);
}
typesInDeck.put(type, count + 1);
}
}
}
@@ -2679,12 +2680,10 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
String message = null;
if (targetZone != ZoneType.Battlefield) {
message = localizer.getMessage("lblPutCardInWhichPlayerZone", targetZone.getTranslatedName().toLowerCase());
}
else {
} else {
if (noTriggers) {
message = localizer.getMessage("lblPutCardInWhichPlayerBattlefield");
}
else {
} else {
message = localizer.getMessage("lblPutCardInWhichPlayerPlayOrStack");
}
}