This wiki is a read-only version of the Stardew Valley Wiki. The official editable wiki maintained by ConcernedApe can be found at stardewvalleywiki.com

Template talk:Qualityprice

From Stardew Valley Wiki
Jump to: navigation, search
This talk page is for discussing Template:Qualityprice.
  • Sign and date your posts by typing four tildes (~~~~).
  • Put new text below old text.
  • Be polite.
  • Assume good faith.
  • Don't delete discussions.

Fixing the values

Followup to discussions at Talk:Fish#Calling Qualityprice with wrong values, Talk:Cauliflower#Price Generation by Infobox Template, Template talk:Infobox#Pumpkin is broken

Basically, multiple values displayed on the wiki right now are incorrect because the Qualityprice template is messing up when there's both a profession-based bonus and a quality bonus. Measures have been taken to try to fix this (e.g., the Infobox template is truncating values before passing them to the Qualityprice template), but in fact they're only semi-effective (and are breaking as many values as they're fixing).

The game code calculates prices in Object::sellToStorePrice. This is used for everything (fish, artisan goods, crops, etc.). Basically it does truncation at every step:

price = trunc(profession_multiplier * trunc(quality_multiplier * trunc(base_price)))

But just as important is the order in which the multipliers are applied: quality is applied first THEN profession. That order is impossible the way the Qualityprice template is currently being used, because it's always being passed base_price*profession_multiplier. The only way to get the Qualityprice template to actually calculate the correct value in all cases is to pass the base price into the template and provide the profession_multiplier as a separate parameter.

I scanned all the game items to identify which ones have prices/professions where the truncation and/or order affect the final price. I found 83 cases where only truncating after all the multiplications gives the wrong value; 33 of those are fixed by double-truncation even if the multiplier order is done incorrectly; 50 of them require multipliers to be in the correct order and truncation to be done at both steps. (There are another 72 cases where the value is only wrong if double-truncation is done with the wrong multiplier order).

I found several of these cases that I could easily test in-game, and all in-game prices matched predicted values (with double-truncation and correct multiplier order):

  • Artisan + silver starfruit wine: 3936 (wiki says 3937)
  • Tiller + silver ancient fruit: 755 (wiki says 756)
  • Tiller + silver parsnip: 47 (wiki says 47, only because infobox is doing extra trunc but in wrong order)
  • Tiller + silver starfruit: 1030 (wiki says 1031)
  • Tiller + silver wheat: 34 (wiki says 33 because infobox template is doing wrong trunc order)
  • Fisher + gold eel: 158 (wiki says 159)
  • Fisher + silver sandfish: 116 (wiki says 117)
  • Fisher + iridium albacore: 187 (wiki correct; wrong trunc order would give 186)

So my plan is to change the template to accept prof_mult as an optional extra parameter, and then change the pages using the template for profession bonuses accordingly. Nebulous Maestress (talk) 05:31, 30 August 2020 (UTC)

 !Thank you! I was told years ago that it was something with the template that (mysteriously) could not be fixed. Hmmph. I tried, but I'm not particularly adept with template mechanics, so I didn't see what to do, only that I wasn't getting there. The problem occasionally had major impacts on my game play, when I had enough resources to buy something only within a few Gold.pngg and I had calculated it took selling items to come up with the scratch. Imagine my frustration when a stack of cauliflower was my key to success and then Pierre gave me ten less gold than I thought I had coming. A thing like that can change your whole game plan, because the timing of buying can be critical to the timing of doing, which can have rippling financial effects going forward, and it can even stymie certain plans. I created a whole spreadsheet containing every object type and its sell price under all circumstances just in order to have a convenient way to figure these things (and know with certainty the sums didn't have a calculation error in them). Debugging that spreadsheet proved surprisingly tricky, because the calculation method and order is so critical, and the items where discrepancies occur so apparently random. It's how I uncovered the formula in the first place, and the proof of wiki error. And now you have nailed the final piece into place and no one else will ever have to go to such lengths again. (Probably, no one else ever would. ;) But that's a different matter.) I for one am grateful. Butterbur (talk) 15:57, 31 August 2020 (UTC)
Nice work - I saw the template changes you made to accommodate this and it all looks great!! -- Katzeus (talk) 14:35, 4 September 2020 (UTC)
Ditto. And clearly you went way beyond just the quality price issue in your template work. Kudos on it all! Fine design principles! Butterbur (talk) 14:58, 4 September 2020 (UTC)
Thanks!
In case you missed it in the midst of the hundred other edits, I posted a bit of general background/rationale at User talk:Nebulous Maestress#Template Rewrites. And eventually I might even update a few articles to actually make use of some new features! Nebulous Maestress (talk) 15:25, 4 September 2020 (UTC)