Skip to content

Commit 6615090

Browse files
committed
Allow jumpstart/"nosell" cards to be sold for 0 credits
1 parent eaf6f11 commit 6615090

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

forge-gui-mobile/src/forge/adventure/data/AdventureEventData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ public String getDescription(PointOfInterestChanges changes) {
606606
description += "\n";
607607
}
608608
description += "Prizes\n3 round wins: 500 gold\n2 round wins: 200 gold\n1 round win: 100 gold\n";
609-
description += "Finishing event will award an unsellable copy of each card in your Jumpstart deck.";
609+
description += "Participating in this event will award a valueless copy of each card in your Jumpstart deck.";
610610
}
611611
return description;
612612
}

forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -908,14 +908,45 @@ public void renameDeck(String text) {
908908
}
909909

910910
public int cardSellPrice(PaperCard card) {
911+
int valuable = cards.count(card) - noSellCards.count(card);
912+
if (valuable == 0) {
913+
return 0;
914+
}
915+
916+
int basePrice = (int) (CardUtil.getCardPrice(card) * difficultyData.sellFactor);
917+
911918
float townPriceModifier = currentLocationChanges == null ? 1f : currentLocationChanges.getTownPriceModifier();
912-
return (int) (CardUtil.getCardPrice(card) * difficultyData.sellFactor * (2.0f - townPriceModifier));
919+
return (int) (basePrice * difficultyData.sellFactor * (2.0f - townPriceModifier));
913920
}
914921

915-
public void sellCard(PaperCard card, Integer result) {
916-
float price = cardSellPrice(card) * result;
917-
cards.remove(card, result);
918-
addGold((int) price);
922+
public int sellCard(PaperCard card, Integer result, boolean addGold) {
923+
// When selling cards, always try to sell cards worth something before selling cards that aren't worth anything
924+
if (result == null || result < 1) return 0;
925+
926+
float earned = 0;
927+
928+
int valuableCount = cards.count(card) - noSellCards.count(card);
929+
int noValueToSell = result - valuableCount;
930+
int amountValuableToSell = Math.min(result, valuableCount);
931+
932+
if (amountValuableToSell > 0) {
933+
earned += cardSellPrice(card) * amountValuableToSell;
934+
cards.remove(card, amountValuableToSell);
935+
}
936+
if (noValueToSell > 0) {
937+
cards.remove(card, noValueToSell);
938+
noSellCards.remove(card, noValueToSell);
939+
}
940+
941+
if (addGold) {
942+
addGold((int) earned);
943+
}
944+
945+
return (int) earned;
946+
}
947+
948+
public int sellOneCard(PaperCard card) {
949+
return sellCard(card, 1, false);
919950
}
920951

921952
public void removeItem(String name) {
@@ -1166,20 +1197,16 @@ public ItemPool<PaperCard> getSellableCards() {
11661197
ItemPool<PaperCard> sellableCards = new ItemPool<>(PaperCard.class);
11671198
sellableCards.addAllFlat(cards.toFlatList());
11681199

1169-
// 1. Remove cards you can't sell
1170-
sellableCards.removeAll(noSellCards);
1200+
// Nosell cards used to be filtered out here. Instead we're going to replace their value with 0
1201+
11711202
// 1a. Potentially return here if we want to give config option to sell cards from decks
11721203
// but would need to update the decks on sell, not just the catalog
11731204

11741205
// 2. Count max cards across all decks in excess of unsellable
11751206
Map<PaperCard, Integer> maxCardCounts = new HashMap<>();
11761207
for (int i = 0; i < NUMBER_OF_DECKS; i++) {
11771208
for (final Map.Entry<PaperCard, Integer> cp : decks[i].getAllCardsInASinglePool()) {
1178-
1179-
int count = cp.getValue() - noSellCards.count(cp.getKey());
1180-
1181-
if (count <= 0) continue;
1182-
1209+
int count = cp.getValue();
11831210
if (count > maxCardCounts.getOrDefault(cp.getKey(), 0)) {
11841211
maxCardCounts.put(cp.getKey(), cp.getValue());
11851212
}
@@ -1213,9 +1240,8 @@ public void loadChanges(PointOfInterestChanges changes) {
12131240
public void doAutosell() {
12141241
int profit = 0;
12151242
for (PaperCard cardToSell : autoSellCards.toFlatList()) {
1216-
profit += AdventurePlayer.current().cardSellPrice(cardToSell);
1243+
profit += AdventurePlayer.current().sellOneCard(cardToSell);
12171244
autoSellCards.remove(cardToSell);
1218-
cards.remove(cardToSell, 1);
12191245
}
12201246
addGold(profit); //do this as one transaction so as not to get multiple copies of sound effect
12211247
}

forge-gui-mobile/src/forge/adventure/scene/AdventureDeckEditor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void run(Integer result) {
151151
if (!cardManager.isInfinite()) {
152152
removeCard(card, result);
153153
}
154-
AdventurePlayer.current().sellCard(card, result);
154+
AdventurePlayer.current().sellCard(card, result, true);
155155
lblGold.setText(String.valueOf(AdventurePlayer.current().getGold()));
156156
}
157157
});
@@ -601,7 +601,7 @@ protected void buildMenu() {
601601
public void run(Boolean result) {
602602
if (result) {
603603
for (Map.Entry<PaperCard, Integer> entry : catalogPage.cardManager.getFilteredItems()) {
604-
AdventurePlayer.current().sellCard(entry.getKey(), entry.getValue());
604+
AdventurePlayer.current().sellCard(entry.getKey(), entry.getValue(), true);
605605
}
606606
catalogPage.refresh();
607607
lblGold.setText(String.valueOf(AdventurePlayer.current().getGold()));

forge-gui-mobile/src/forge/adventure/util/AdventureEventController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public AdventureEventData createEvent(EventStyle style, String pointID, int even
9898

9999
AdventureEventData e;
100100

101+
// TODO After a certain amount of wins, stop offering jump start events
101102
if (random.nextInt(10) <= 2) {
102103
e = new AdventureEventData(eventSeed, EventFormat.Jumpstart);
103104
} else {

forge-gui/res/adventure/common/custom_cards/sliver_queen_boss_effect.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ SVar:DBChoose:DB$ ChooseCard | AtRandom$ True | Choices$ Creature.nonToken+OppCt
1010
SVar:DBCopy:DB$ CopyPermanent | Defined$ ChosenCard | AddTypes$ Sliver | SubAbility$ DBCleanup
1111
SVar:DBCleanup:DB$ Cleanup | ClearChosenCard$ True
1212
SVar:DBSeek:DB$ Seek | Type$ Card.Sliver | SpellDescription$ Seek a Sliver card.
13-
Oracle:{4}: Create a 1/1 colorless Sliver creature token. Every player may activate this ability but only once each turn. \n At the gebinning of your upkeep, choose one at random\n• Create a 1/1 colorless Sliver creature token.\nCreate a token of a random nontoken creature your opponent controls. That creature becomes a Sliver in addition to its other types.\n• Seek a Sliver card.
13+
Oracle:{4}: Create a 1/1 colorless Sliver creature token. Every player may activate this ability but only once each turn. \n At the beginning of your upkeep, choose one at random\n• Create a 1/1 colorless Sliver creature token.\nCreate a token of a random nontoken creature your opponent controls. That creature becomes a Sliver in addition to its other types.\n• Seek a Sliver card.

0 commit comments

Comments
 (0)