Skip to content

Commit

Permalink
Allow jumpstart/"nosell" cards to be sold for 0 credits
Browse files Browse the repository at this point in the history
  • Loading branch information
tehdiplomat committed Feb 2, 2025
1 parent eaf6f11 commit 6615090
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ public String getDescription(PointOfInterestChanges changes) {
description += "\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;
}
Expand Down
54 changes: 40 additions & 14 deletions forge-gui-mobile/src/forge/adventure/player/AdventurePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -908,14 +908,45 @@ public void renameDeck(String text) {
}

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();
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) {
float price = cardSellPrice(card) * result;
cards.remove(card, result);
addGold((int) price);
public int sellCard(PaperCard card, Integer result, boolean addGold) {
// When selling cards, always try to sell cards worth something before selling cards that aren't worth anything
if (result == null || result < 1) return 0;

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) {
Expand Down Expand Up @@ -1166,20 +1197,16 @@ public ItemPool<PaperCard> getSellableCards() {
ItemPool<PaperCard> sellableCards = new ItemPool<>(PaperCard.class);
sellableCards.addAllFlat(cards.toFlatList());

// 1. Remove cards you can't sell
sellableCards.removeAll(noSellCards);
// Nosell cards used to be filtered out here. Instead we're going to replace their value with 0

// 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

// 2. Count max cards across all decks in excess of unsellable
Map<PaperCard, Integer> maxCardCounts = new HashMap<>();
for (int i = 0; i < NUMBER_OF_DECKS; i++) {
for (final Map.Entry<PaperCard, Integer> cp : decks[i].getAllCardsInASinglePool()) {

int count = cp.getValue() - noSellCards.count(cp.getKey());

if (count <= 0) continue;

int count = cp.getValue();
if (count > maxCardCounts.getOrDefault(cp.getKey(), 0)) {
maxCardCounts.put(cp.getKey(), cp.getValue());
}
Expand Down Expand Up @@ -1213,9 +1240,8 @@ public void loadChanges(PointOfInterestChanges changes) {
public void doAutosell() {
int profit = 0;
for (PaperCard cardToSell : autoSellCards.toFlatList()) {
profit += AdventurePlayer.current().cardSellPrice(cardToSell);
profit += AdventurePlayer.current().sellOneCard(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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void run(Integer result) {
if (!cardManager.isInfinite()) {
removeCard(card, result);
}
AdventurePlayer.current().sellCard(card, result);
AdventurePlayer.current().sellCard(card, result, true);
lblGold.setText(String.valueOf(AdventurePlayer.current().getGold()));
}
});
Expand Down Expand Up @@ -601,7 +601,7 @@ protected void buildMenu() {
public void run(Boolean result) {
if (result) {
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();
lblGold.setText(String.valueOf(AdventurePlayer.current().getGold()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public AdventureEventData createEvent(EventStyle style, String pointID, int even

AdventureEventData e;

// TODO After a certain amount of wins, stop offering jump start events
if (random.nextInt(10) <= 2) {
e = new AdventureEventData(eventSeed, EventFormat.Jumpstart);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:DBCleanup:DB$ Cleanup | ClearChosenCard$ True
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.

0 comments on commit 6615090

Please sign in to comment.