Allow jumpstart/"nosell" cards to be sold for 0 credits

This commit is contained in:
Chris H
2025-01-29 23:01:11 -05:00
parent eaf6f117a2
commit 6615090bda
5 changed files with 45 additions and 18 deletions

View File

@@ -606,7 +606,7 @@ public class AdventureEventData implements Serializable {
description += "\n"; description += "\n";
} }
description += "Prizes\n3 round wins: 500 gold\n2 round wins: 200 gold\n1 round win: 100 gold\n"; description += "Prizes\n3 round wins: 500 gold\n2 round wins: 200 gold\n1 round win: 100 gold\n";
description += "Finishing event will award an unsellable copy of each card in your Jumpstart deck."; description += "Participating in this event will award a valueless copy of each card in your Jumpstart deck.";
} }
return description; return description;
} }

View File

@@ -908,14 +908,45 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
} }
public int cardSellPrice(PaperCard card) { public int cardSellPrice(PaperCard card) {
int valuable = cards.count(card) - noSellCards.count(card);
if (valuable == 0) {
return 0;
}
int basePrice = (int) (CardUtil.getCardPrice(card) * difficultyData.sellFactor);
float townPriceModifier = currentLocationChanges == null ? 1f : currentLocationChanges.getTownPriceModifier(); float townPriceModifier = currentLocationChanges == null ? 1f : currentLocationChanges.getTownPriceModifier();
return (int) (CardUtil.getCardPrice(card) * difficultyData.sellFactor * (2.0f - townPriceModifier)); return (int) (basePrice * difficultyData.sellFactor * (2.0f - townPriceModifier));
} }
public void sellCard(PaperCard card, Integer result) { public int sellCard(PaperCard card, Integer result, boolean addGold) {
float price = cardSellPrice(card) * result; // When selling cards, always try to sell cards worth something before selling cards that aren't worth anything
cards.remove(card, result); if (result == null || result < 1) return 0;
addGold((int) price);
float earned = 0;
int valuableCount = cards.count(card) - noSellCards.count(card);
int noValueToSell = result - valuableCount;
int amountValuableToSell = Math.min(result, valuableCount);
if (amountValuableToSell > 0) {
earned += cardSellPrice(card) * amountValuableToSell;
cards.remove(card, amountValuableToSell);
}
if (noValueToSell > 0) {
cards.remove(card, noValueToSell);
noSellCards.remove(card, noValueToSell);
}
if (addGold) {
addGold((int) earned);
}
return (int) earned;
}
public int sellOneCard(PaperCard card) {
return sellCard(card, 1, false);
} }
public void removeItem(String name) { public void removeItem(String name) {
@@ -1166,8 +1197,8 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
ItemPool<PaperCard> sellableCards = new ItemPool<>(PaperCard.class); ItemPool<PaperCard> sellableCards = new ItemPool<>(PaperCard.class);
sellableCards.addAllFlat(cards.toFlatList()); sellableCards.addAllFlat(cards.toFlatList());
// 1. Remove cards you can't sell // Nosell cards used to be filtered out here. Instead we're going to replace their value with 0
sellableCards.removeAll(noSellCards);
// 1a. Potentially return here if we want to give config option to sell cards from decks // 1a. Potentially return here if we want to give config option to sell cards from decks
// but would need to update the decks on sell, not just the catalog // but would need to update the decks on sell, not just the catalog
@@ -1175,11 +1206,7 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
Map<PaperCard, Integer> maxCardCounts = new HashMap<>(); Map<PaperCard, Integer> maxCardCounts = new HashMap<>();
for (int i = 0; i < NUMBER_OF_DECKS; i++) { for (int i = 0; i < NUMBER_OF_DECKS; i++) {
for (final Map.Entry<PaperCard, Integer> cp : decks[i].getAllCardsInASinglePool()) { for (final Map.Entry<PaperCard, Integer> cp : decks[i].getAllCardsInASinglePool()) {
int count = cp.getValue();
int count = cp.getValue() - noSellCards.count(cp.getKey());
if (count <= 0) continue;
if (count > maxCardCounts.getOrDefault(cp.getKey(), 0)) { if (count > maxCardCounts.getOrDefault(cp.getKey(), 0)) {
maxCardCounts.put(cp.getKey(), cp.getValue()); maxCardCounts.put(cp.getKey(), cp.getValue());
} }
@@ -1213,9 +1240,8 @@ public class AdventurePlayer implements Serializable, SaveFileContent {
public void doAutosell() { public void doAutosell() {
int profit = 0; int profit = 0;
for (PaperCard cardToSell : autoSellCards.toFlatList()) { for (PaperCard cardToSell : autoSellCards.toFlatList()) {
profit += AdventurePlayer.current().cardSellPrice(cardToSell); profit += AdventurePlayer.current().sellOneCard(cardToSell);
autoSellCards.remove(cardToSell); autoSellCards.remove(cardToSell);
cards.remove(cardToSell, 1);
} }
addGold(profit); //do this as one transaction so as not to get multiple copies of sound effect addGold(profit); //do this as one transaction so as not to get multiple copies of sound effect
} }

View File

@@ -151,7 +151,7 @@ public class AdventureDeckEditor extends TabPageScreen<AdventureDeckEditor> {
if (!cardManager.isInfinite()) { if (!cardManager.isInfinite()) {
removeCard(card, result); removeCard(card, result);
} }
AdventurePlayer.current().sellCard(card, result); AdventurePlayer.current().sellCard(card, result, true);
lblGold.setText(String.valueOf(AdventurePlayer.current().getGold())); lblGold.setText(String.valueOf(AdventurePlayer.current().getGold()));
} }
}); });
@@ -601,7 +601,7 @@ public class AdventureDeckEditor extends TabPageScreen<AdventureDeckEditor> {
public void run(Boolean result) { public void run(Boolean result) {
if (result) { if (result) {
for (Map.Entry<PaperCard, Integer> entry : catalogPage.cardManager.getFilteredItems()) { for (Map.Entry<PaperCard, Integer> entry : catalogPage.cardManager.getFilteredItems()) {
AdventurePlayer.current().sellCard(entry.getKey(), entry.getValue()); AdventurePlayer.current().sellCard(entry.getKey(), entry.getValue(), true);
} }
catalogPage.refresh(); catalogPage.refresh();
lblGold.setText(String.valueOf(AdventurePlayer.current().getGold())); lblGold.setText(String.valueOf(AdventurePlayer.current().getGold()));

View File

@@ -98,6 +98,7 @@ public class AdventureEventController implements Serializable {
AdventureEventData e; AdventureEventData e;
// TODO After a certain amount of wins, stop offering jump start events
if (random.nextInt(10) <= 2) { if (random.nextInt(10) <= 2) {
e = new AdventureEventData(eventSeed, EventFormat.Jumpstart); e = new AdventureEventData(eventSeed, EventFormat.Jumpstart);
} else { } else {

View File

@@ -10,4 +10,4 @@ SVar:DBChoose:DB$ ChooseCard | AtRandom$ True | Choices$ Creature.nonToken+OppCt
SVar:DBCopy:DB$ CopyPermanent | Defined$ ChosenCard | AddTypes$ Sliver | SubAbility$ DBCleanup SVar:DBCopy:DB$ CopyPermanent | Defined$ ChosenCard | AddTypes$ Sliver | SubAbility$ DBCleanup
SVar:DBCleanup:DB$ Cleanup | ClearChosenCard$ True SVar:DBCleanup:DB$ Cleanup | ClearChosenCard$ True
SVar:DBSeek:DB$ Seek | Type$ Card.Sliver | SpellDescription$ Seek a Sliver card. SVar:DBSeek:DB$ Seek | Type$ Card.Sliver | SpellDescription$ Seek a Sliver card.
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. 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.