Changes

Jump to navigation Jump to search
4,422 bytes added ,  04:14, 20 November 2021
Saloon rotating dish investigation
{{talkheader}}

== Rotating Saloon Dish ==

Hello there. Some days ago [https://stardewvalleywiki.com/mediawiki/index.php?title=The_Stardrop_Saloon&curid=1424&oldid=130569 Revision as of 19:43, 16 November 2021 by GamingWithMaxJ] said the rotating dish was defined according to the number of step the player has made. Out of curiosity, I wanted to check that. It is a bit (a lot) more complicated than that, but steps count indeed. Investigation.

The rotating dish is set in <code>Utility::getSaloonStock</code>, using <samp>Game1.dishOfTheDay</samp>. This variable value is redefined each day at <code>Game1::_newDayAfterFade</code>:

<syntaxhighlight lang="C#">
dishOfTheDay = new Object(Vector2.Zero, num2, initialStack);
</syntaxhighlight>

With <samp>num2</samp> being defined as such:

<syntaxhighlight lang="C#">
int num2 = random.Next(194, 240);
while (Utility.getForbiddenDishesOfTheDay().Contains(num2))
{
num2 = random.Next(194, 240);
}
</syntaxhighlight>

So one index is pseudo-randomly picked from 194 (included) to 240 (excluded). Indexes correspond to food as specified in <code>Content\Data\ObjectInformation.xnb</code>. For instance 194 is ''Fried Egg'' and 240 is ''Farmer's Lunch''. <code>Utility::getForbiddenDishesOfTheDay</code> is just to exclude dishes that Gus already normally sells, as we can see:

<syntaxhighlight lang="C#">
public static int[] getForbiddenDishesOfTheDay()
{
return new int[7] { 346, 196, 216, 224, 206, 395, 217 };
}
</syntaxhighlight>

This <samp>int</samp> array refers to ''Beer, Salad, Bread, Spaghetti, Pizza'' and ''Coffee'' (the 217 is not defined).

More interestingly for our investigation, <samp>random.Next(int minValue, int maxValue)</samp> is a base C# function, building pseudo-random numbers from a pseudo-random seed. The function is defined in [https://referencesource.microsoft.com/#mscorlib/system/random.cs mscorlib/system/random.cs] if you want to dig that.

The first random seed taken for random functions is a timestamp get at game launch, as we can see in the <code>Game1</code> constructor:

<syntaxhighlight lang="C#">
public static Random random = new Random(DateTime.Now.Millisecond);
</syntaxhighlight>

This is the random seed used for the dish chosen on a new game creation (see <samp>Game1::loadForNewGame</samp>).

But the randomness seed is then re-defined each day in the <code>Game1::_newDayAfterFade</code> function:

<syntaxhighlight lang="C#">
random = new Random(num);
for (int i = 0; i < dayOfMonth; i++)
{
random.Next();
}
</syntaxhighlight>

With <samp>num</samp> being defined as such:

<syntaxhighlight lang="C#">
num = (int)uniqueIDForThisGame / 100 + (int)(stats.DaysPlayed * 10) + 1 + (int)stats.StepsTaken;
</syntaxhighlight>

So stats, including steps taken, are taken into account here to build the new seed that is sent to the random number generator.

There also is <samp>uniqueIDForThisGame</samp>. If I'm not mistaken, the value is defined at game launch (<samp>Game1</samp> constructor), or when returning to title (<samp>Game1::CleanupReturningToTitle</samp>), and specified once and for all in the save game if no custom seed is entered (see <samp>Game1::loadForNewGame</samp> and <samp>SaveGame::getSaveEnumerator</samp> and <samp>SaveGame::getLoadEnumerator</samp>), calculated from <code>Utility::NewUniqueIdForThisGame</code>:

<syntaxhighlight lang="C#">
public static ulong NewUniqueIdForThisGame()
{
DateTime dateTime = new DateTime(2012, 6, 22);
return (ulong)(long)(DateTime.UtcNow - dateTime).TotalSeconds;
}
</syntaxhighlight>

Finally, calling <samp>random.Next()</samp> (also from [https://referencesource.microsoft.com/#mscorlib/system/random.cs mscorlib/system/random.cs])" moves the cursor" in the random numbers array generated from the seed by the random function (and also recalculate new values for values passed). To put it more simply, calling the function changes the output number obtained the next time a random method will be called, so <samp>dayOfMonth</samp> also matters.

To conclude, it would be more accurate to say Gus daily dish is set according to:
* Save game seed (by default, generated from time parameters)
* Steps taken
* Days played
* Day of the month
* Complex calculations from those

I hope I did not make a mistake in reading the code, and that my writing is not too confusing...!

- [[User:Charly|Charly]] ([[User talk:Charly|talk]]) 04:14, 20 November 2021 (UTC)
255

edits

Navigation menu