From f69a8af83fbe467b53923f6c6b4fe467708cac45 Mon Sep 17 00:00:00 2001 From: austinio7116 Date: Sat, 14 Apr 2018 18:41:37 +0100 Subject: [PATCH] Added new RestrictedLegendary option to formats to enable blanket restriction on legendary cards --- .../src/main/java/forge/game/GameFormat.java | 25 ++++++++++++++----- .../forge/quest/data/GameFormatQuest.java | 3 ++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/forge-game/src/main/java/forge/game/GameFormat.java b/forge-game/src/main/java/forge/game/GameFormat.java index 28dc2060842..98f3c0b19cf 100644 --- a/forge-game/src/main/java/forge/game/GameFormat.java +++ b/forge-game/src/main/java/forge/game/GameFormat.java @@ -57,6 +57,7 @@ public class GameFormat implements Comparable { protected final List bannedCardNames; protected final List restrictedCardNames; protected final List additionalCardNames; // for cards that are legal but not reprinted in any of the allowed Sets + protected boolean restrictedLegendary = false; protected final transient List allowedSetCodes_ro; protected final transient List bannedCardNames_ro; @@ -69,13 +70,13 @@ public class GameFormat implements Comparable { private final int index; public GameFormat(final String fName, final Iterable sets, final List bannedCards) { - this(fName, sets, bannedCards, null, null, null, 0, FormatType.Custom, FormatSubType.Custom); + this(fName, sets, bannedCards, null, false, null, null, 0, FormatType.Custom, FormatSubType.Custom); } - public static final GameFormat NoFormat = new GameFormat("(none)", null, null, null, null, null, Integer.MAX_VALUE, FormatType.Custom, FormatSubType.Custom); + public static final GameFormat NoFormat = new GameFormat("(none)", null, null, null, false, null, null, Integer.MAX_VALUE, FormatType.Custom, FormatSubType.Custom); public GameFormat(final String fName, final Iterable sets, final List bannedCards, - final List restrictedCards, final List additionalCards, + final List restrictedCards, Boolean restrictedLegendary, final List additionalCards, final List rarities, int compareIdx, FormatType formatType, FormatSubType formatSubType) { this.index = compareIdx; this.formatType = formatType; @@ -99,6 +100,7 @@ public class GameFormat implements Comparable { bannedCardNames = bannedCards == null ? new ArrayList() : Lists.newArrayList(bannedCards); restrictedCardNames = restrictedCards == null ? new ArrayList() : Lists.newArrayList(restrictedCards); + this.restrictedLegendary = restrictedLegendary; additionalCardNames = additionalCards == null ? new ArrayList() : Lists.newArrayList(additionalCards); allowedRarities = rarities == null ? Lists.newArrayList() : rarities; @@ -162,6 +164,10 @@ public class GameFormat implements Comparable { return restrictedCardNames_ro; } + public Boolean isRestrictedLegendary() { + return restrictedLegendary; + } + public List getAdditionalCards() { return additionalCardNames_ro; } @@ -208,9 +214,10 @@ public class GameFormat implements Comparable { } } - if(!restrictedCardNames_ro.isEmpty() ) { + if(!restrictedCardNames_ro.isEmpty() || restrictedLegendary ) { for (Entry poolEntry : allCards) { - if( poolEntry.getValue().intValue() > 1 && restrictedCardNames_ro.contains(poolEntry.getKey().getName())) + if( poolEntry.getValue().intValue() > 1 && (restrictedCardNames_ro.contains(poolEntry.getKey().getName()) + || poolEntry.getKey().getRules().getType().isLegendary() && restrictedLegendary)) return false; } } @@ -266,6 +273,7 @@ public class GameFormat implements Comparable { List sets = null; // default: all sets allowed List bannedCards = null; // default: nothing banned List restrictedCards = null; // default: nothing restricted + Boolean restrictedLegendary = false; List additionalCards = null; // default: nothing additional List rarities = null; FileSection section = FileSection.parse(contents.get("format"), ":"); @@ -297,6 +305,11 @@ public class GameFormat implements Comparable { restrictedCards = Arrays.asList(strCars.split("; ")); } + Boolean strRestrictedLegendary = section.getBoolean("restrictedlegendary"); + if ( strRestrictedLegendary != null ) { + restrictedLegendary = strRestrictedLegendary; + } + strCars = section.get("additional"); if ( strCars != null ) { additionalCards = Arrays.asList(strCars.split("; ")); @@ -314,7 +327,7 @@ public class GameFormat implements Comparable { } } - GameFormat result = new GameFormat(title, sets, bannedCards, restrictedCards, additionalCards, rarities, idx, formatType,formatsubType); + GameFormat result = new GameFormat(title, sets, bannedCards, restrictedCards, restrictedLegendary, additionalCards, rarities, idx, formatType,formatsubType); naturallyOrdered.add(result); return result; } diff --git a/forge-gui/src/main/java/forge/quest/data/GameFormatQuest.java b/forge-gui/src/main/java/forge/quest/data/GameFormatQuest.java index a1916ea0c77..51c117bf1ea 100644 --- a/forge-gui/src/main/java/forge/quest/data/GameFormatQuest.java +++ b/forge-gui/src/main/java/forge/quest/data/GameFormatQuest.java @@ -63,7 +63,8 @@ public final class GameFormatQuest extends GameFormat { */ public GameFormatQuest(final GameFormat toCopy, boolean allowSetUnlocks) { super(toCopy.getName(), toCopy.getAllowedSetCodes(), toCopy.getBannedCardNames(), toCopy.getRestrictedCards(), - toCopy.getAdditionalCards(), toCopy.getAllowedRarities(), toCopy.getIndex(), FormatType.Custom, FormatSubType.Custom); + toCopy.isRestrictedLegendary(),toCopy.getAdditionalCards(), toCopy.getAllowedRarities(), + toCopy.getIndex(), FormatType.Custom, FormatSubType.Custom); allowUnlocks = allowSetUnlocks; }