Thorinair / Stardew-Profits

A Stardew Valley crop profits calculator and visualizer. Link: https://thorinair.github.io/Stardew-Profits/
MIT License
153 stars 74 forks source link

Keg "sell excess" calculations does not account crop quality #79

Open jaimeiturriaga opened 5 days ago

jaimeiturriaga commented 5 days ago

There are cases where adding kegs as an option results in less profit than just selling the crops outright image image This is because the keg calculations are not considering crop quality and are instead using the base price of the crop.

My suggestion is to replace

var cropPrice = 0;
if (options.sellExcess)
    cropPrice = options.skills.till ? crop.produce.price * 1.1 : crop.produce.price;
netIncome += cropsLeft * cropPrice;

with

if (options.sellExcess) {
  var rawIncome = 0
  rawIncome += crop.produce.price * crops_left * ratioN;
  rawIncome += Math.trunc(crop.produce.price * 1.25) * crops_left * ratioS;
  rawIncome += Math.trunc(crop.produce.price * 1.5) * crops_left * ratioG;
  rawIncome += crop.produce.price * 2 * crops_left * ratioI;
  if (options.skills.till) {
      rawIncome *= 1.1;
  }
  netIncome += rawIncome 
}

Fyi this is a hacky solution. A DRYer one would be splitting out the crop selling logic so it can be reused.

doodlebunnyhops commented 5 days ago

I've actually been taking a harder look at how quality is distributed - it's also why I didn't include the math for selling excess by quality and defaulted excess to normal quality when I worked on this with @Thorinair.

Backing up for a moment on the original ask here - @Thorinair I'd be happy to re-work the logic on quality outcome. The issue is it uses probability and not event driven conditional probability. Then apply quality to all produce results. Any thoughts takeaways?

Thorinair commented 5 days ago

@doodlebunnyhops it is indeed quite a messy problem. Making it event driven would be messy as it would require simulation day-by-day, and would also result in random results each time, and not a proper average. I think the cleanest solution would be to keep it as averages, and implement the existing code into the remaining crops calculation.

Complication here is that we cannot just put the excess into the formula. Most players would first process the normal value crop, and sell the higher valuable ones, as that makes most sense for profit. This means we first need to calculate the amounts of crops (maybe whole numbers?) and then "spend them" on making the artisan goods. Essentially, the whole code would have to be reworked...

The only solution I see here is to either keep the excess sold to just normal, or do a compromise and process it with the existing code anyway.