diff --git a/forge-core/src/main/java/forge/item/PaperCard.java b/forge-core/src/main/java/forge/item/PaperCard.java index a09e0fd85e9..02116812ec6 100644 --- a/forge-core/src/main/java/forge/item/PaperCard.java +++ b/forge-core/src/main/java/forge/item/PaperCard.java @@ -54,13 +54,14 @@ public class PaperCard implements Comparable, InventoryItemFromSet, private final int artIndex; private final boolean foil; private Boolean hasImage; + private final boolean noSell; private String sortableName; private final String functionalVariant; // Calculated fields are below: private transient CardRarity rarity; // rarity is given in ctor when set is assigned // Reference to a new instance of Self, but foiled! - private transient PaperCard foiledVersion; + private transient PaperCard foiledVersion, noSellVersion; @Override public String getName() { @@ -137,6 +138,24 @@ public class PaperCard implements Comparable, InventoryItemFromSet, this.artIndex, false, String.valueOf(collectorNumber), this.artist, this.functionalVariant); return unFoiledVersion; } + public PaperCard getNoSellVersion() { + if (this.noSell) + return this; + + if (this.noSellVersion == null) { + this.noSellVersion = new PaperCard(this.rules, this.edition, this.rarity, + this.artIndex, this.foil, String.valueOf(collectorNumber), this.artist, this.functionalVariant, true); + } + return this.noSellVersion; + } + public PaperCard getSellable() { + if (!this.noSell) + return this; + + PaperCard sellable = new PaperCard(this.rules, this.edition, this.rarity, + this.artIndex, this.foil, String.valueOf(collectorNumber), this.artist, this.functionalVariant, false); + return sellable; + } @Override public String getItemType() { @@ -144,6 +163,9 @@ public class PaperCard implements Comparable, InventoryItemFromSet, return localizer.getMessage("lblCard"); } + public boolean isNoSell() { + return noSell; + } public boolean hasImage() { return hasImage(false); } @@ -162,6 +184,12 @@ public class PaperCard implements Comparable, InventoryItemFromSet, public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0, final int artIndex0, final boolean foil0, final String collectorNumber0, final String artist0, final String functionalVariant) { + this(rules0, edition0, rarity0, artIndex0, foil0, collectorNumber0, artist0, functionalVariant, false); + } + + public PaperCard(final CardRules rules0, final String edition0, final CardRarity rarity0, + final int artIndex0, final boolean foil0, final String collectorNumber0, + final String artist0, final String functionalVariant, final boolean noSell0) { if (rules0 == null || edition0 == null || rarity0 == null) { throw new IllegalArgumentException("Cannot create card without rules, edition or rarity"); } @@ -177,6 +205,7 @@ public class PaperCard implements Comparable, InventoryItemFromSet, // This is a good tradeoff sortableName = TextUtil.toSortableName(CardTranslation.getTranslatedName(rules0.getName())); this.functionalVariant = functionalVariant != null ? functionalVariant : IPaperCard.NO_FUNCTIONAL_VARIANT; + noSell = noSell0; } public static PaperCard FAKE_CARD = new PaperCard(CardRules.getUnsupportedCardNamed("Fake Card"), "Fake Edition", CardRarity.Common); diff --git a/forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java b/forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java index 0b8df107dbc..3b0a1bfa567 100644 --- a/forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java +++ b/forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java @@ -473,7 +473,8 @@ public class AdventurePlayer implements Serializable, SaveFileContent { if (data.containsKey("noSellCards")) { PaperCard[] items = (PaperCard[]) data.readObject("noSellCards"); for (PaperCard item : items) { - noSellCards.add(item); + if (item != null) + noSellCards.add(item.getNoSellVersion()); } } if (data.containsKey("autoSellCards")) { @@ -636,7 +637,7 @@ public class AdventurePlayer implements Serializable, SaveFileContent { autoSellCards.add(reward.getCard()); refreshEditor(); } else if (reward.isNoSell()) { - noSellCards.add(reward.getCard()); + noSellCards.add(reward.getCard().getNoSellVersion()); refreshEditor(); } break; diff --git a/forge-gui-mobile/src/forge/adventure/scene/DeckEditScene.java b/forge-gui-mobile/src/forge/adventure/scene/DeckEditScene.java index 6315979fe7d..cc0115b6cc6 100644 --- a/forge-gui-mobile/src/forge/adventure/scene/DeckEditScene.java +++ b/forge-gui-mobile/src/forge/adventure/scene/DeckEditScene.java @@ -2,8 +2,6 @@ package forge.adventure.scene; import com.badlogic.gdx.scenes.scene2d.Stage; import forge.adventure.data.AdventureEventData; -import forge.adventure.player.AdventurePlayer; -import forge.item.PaperCard; import forge.screens.FScreen; /** @@ -61,12 +59,4 @@ public class DeckEditScene extends ForgeScene { } return screen; } - - public boolean isAutoSell(PaperCard pc) { - return AdventurePlayer.current().getAutoSellCards().contains(pc); - } - - public boolean isNoSell(PaperCard pc) { - return AdventurePlayer.current().getNoSellCards().contains(pc); - } } diff --git a/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java b/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java index 9d7fa4d7fd5..b7961a2a31c 100644 --- a/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java +++ b/forge-gui-mobile/src/forge/adventure/stage/ConsoleCommandInterpreter.java @@ -222,8 +222,8 @@ public class ConsoleCommandInterpreter { if (s.length < 1) return "Command needs 1 parameter: Card name."; PaperCard card = StaticData.instance().getCommonCards().getCard(s[0]); if (card == null) return "Cannot find card: " + s[0]; - Current.player().addCard(card); - Current.player().noSellCards.add(card); + Current.player().addCard(card.getNoSellVersion()); + Current.player().noSellCards.add(card.getNoSellVersion()); return "Added card: " + s[0]; }); registerCommand(new String[]{"give", "item"}, s -> { diff --git a/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java b/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java index 500c77245df..ca347f33524 100644 --- a/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java +++ b/forge-gui-mobile/src/forge/itemmanager/views/ImageView.java @@ -1126,13 +1126,11 @@ public class ImageView extends ItemView { if (cardPrice == null) cardPrice = ((ShopScene) Forge.getCurrentScene()).getCardPrice((PaperCard) item); drawCardLabel(g, "$" + cardPrice, Color.GOLD, x, y ,w ,h); - } /*else if (Forge.getCurrentScene() instanceof DeckEditScene) { - if (((DeckEditScene) Forge.getCurrentScene()).isAutoSell((PaperCard) item)) { - drawCardLabel(g, Forge.getLocalizer().getMessage("lblAutoSell"), Color.GREEN, x, y, w, h); - } else if (((DeckEditScene) Forge.getCurrentScene()).isNoSell((PaperCard) item)) { + } else { + if (((PaperCard) item).isNoSell()) { drawCardLabel(g, Forge.getLocalizer().getMessage("lblNoSell"), Color.RED, x, y, w, h); } - }*///TODO FIX Distinction + } } } else if (item instanceof ConquestCommander) { CardRenderer.drawCard(g, ((ConquestCommander) item).getCard(), x, y, w, h, pos);