Difference between revisions of "Skull Cavern/Ore Distribution"

From Stardew Valley Wiki
Jump to navigation Jump to search
(moved from skull cavern page)
 
Line 3: Line 3:
 
[[File:Skull Cavern Gem.png|300px|thumb|right|Changing distribution of gemstone ore with level.]]
 
[[File:Skull Cavern Gem.png|300px|thumb|right|Changing distribution of gemstone ore with level.]]
 
[[File:Skull Cavern GemNodes.png|300px|thumb|right|Changing distribution of gem nodes with level and luck.]]
 
[[File:Skull Cavern GemNodes.png|300px|thumb|right|Changing distribution of gem nodes with level and luck.]]
Small minable stones and ores can appear as random stones throughout the level, or rarely as small clumps. These have different distributions<ref name="chooseStoneType" />.
+
Small minable stones and ores can appear as random stones throughout the level, or rarely as small clumps. These have different distributions<ref name="populateLevel" /><ref name="chooseStoneType" />.
On average there will be 0.66 small resource clumps on each level with neutral luck, and 0.97 for the largest possible luck. These clumps have a 25% chance to be a dark grey rock (stone ore), a 1.5% chance to be iridium, and a 73.5% chance to be gold.
+
On average there will be less than 0.67 small resource clumps on each level with neutral luck, and less than 1 for the largest possible luck. These clumps have a 25% chance to be a dark grey rock (stone ore), a 1.5% chance to be iridium, and a 73.5% chance to be gold.
  
 
The distribution for random stones is more complex and varies with depth and best understood in a few stages.
 
The distribution for random stones is more complex and varies with depth and best understood in a few stages.
Line 18: Line 18:
  
 
Dark grey rocks,  start with their maximum chance at level 1 (9.73% for dark grey rocks, 0.005% for mystic stones, 0.059% for gem nodes for best chances), and drop proportionally as ores take their place.
 
Dark grey rocks,  start with their maximum chance at level 1 (9.73% for dark grey rocks, 0.005% for mystic stones, 0.059% for gem nodes for best chances), and drop proportionally as ores take their place.
 +
 +
 +
==Code Details==
 +
The main code for populating the level is found in the function <code>StardewValley.Locations.MineShaft::populateLevel</code>. In setting up to populate the level, it initially defines stoneChance as a random number (double) in the range [10,30), and gemStoneChance as 0.003. It then calls <code>StardewValley.Locations.MineShaft::adjustLevelChances</code>, which will perform a few checks including setting the chance to find stone to 0 for infested floors and dividing gem stone chance by 2<ref name="adjustChances" />.
 +
After this setup, it will then iterate through every square of the level, and if it passes a few checks it will add a stone selected using the function <code>StardewValley.Locations.MineShaft::chooseStoneType</code>, passing the gemstone chance from above and the magic numbers 0.001 and 5e-5 for gem nodes (internally chanceForPurpleStone) and mystic stones (internally chanceForMysticStone). In the same sweep, if it does not add a stone there is a chance for it to add a large resource clump, which are 2 possible variants of a 2 by 2 boulder.
 +
 +
After iterating through every square, and performing a few other tasks, it will attempt to add ore clumps using the function <code>StardewValley.Locations.MineShaft::tryToAddOreClumps</code>.
 +
 +
===Ore Clumps===
 +
In the <code>StardewValley.Locations.MineShaft::tryToAddOreClumps</code><ref name="oreClumps" /> function, a try will only be made if a random number is less than 0.55 plus the average daily luck. The maximum possible average daily luck is 0.1 from random luck and 0.025 from the special charm<ref name="dailyLuck" />. This means with neutral luck there is a 55% chance to try, and with the best possible luck there is a 67.5% chance.
 +
It will try once, and then generate a random number and keep going if that random number is less than 0.25 plus the average daily luck.
 +
This means there will be 1 chance, plus a 25% chance with neutral luck or a 37.5% chance with best possible luck.
 +
 +
This gives an expected value of 1.3 recurring or 1.6 attempts to generate a clump, which when combined with the base chance to try gives an expected amount of 0.67 or 1.
 +
 +
However, each try chooses a random tile on the map and will only place an ore clump there if the tile is free, resulting in less than these numbers.
 +
 +
To choose which type of ore to add it calls the function <code>StardewValley.Locations.MineShaft::getAppropriateOre</code><ref name="whichOre" />, which just before returning has a 25% chance (if it is not in hard mode) to set the ore to 668 or 670, which are the dark grey rocks (stone ore). Otherwise, the ore is set as 764, gold ore, with a 2% chance to set it to 765, iridium ore.
 +
This results in total chances of 25% for dark grey rocks, 1.5% chance for iridium ore, and 73.5% for gold.
 +
 +
===Random ore placement (chooseStoneType)===
 +
This will first go through the different areas, and for skull cavern, it will set the base stone type to 32, 38, 40 or 42 (equally), and then calculate several variables, in a few stages to give different definitions for different floor ranges
 +
chanceForOre is defined in 2 parts, including using a min to give 3 different regions:
 +
 +
<code>double chanceForOre = 0.02 + (double)skullCavernMineLevel * 0.0005;
 +
if (this.mineLevel >= 130) {
 +
chanceForOre += 0.01 * (double)((float)(Math.Min(100, skullCavernMineLevel) - 10) / 10f);
 +
}</code>
 +
 +
This ends up being defined as either <code>0.02 + skullCavernMineLevel * 0.0005 </code> for floors 1-10, <code>0.01 + skullCavernMineLevel * 0.0015</code> for levels 10 to 100, and <code>0.11 + skullCavernMineLevel * 0.0005</code> for levels 100 and up. This means the chance for ore will increase by 0.05% for each floor, except between levels 10 and 100 where it increases by 0.15% each floor.
  
 
==References==
 
==References==
 
<references>
 
<references>
 +
<ref name="populateLevel">See <samp>MineShaft::populateLevel</samp> in the game code.</ref>
 +
<ref name="adjustChances">See <samp>MineShaft::adjustLevelChances</samp> in the game code.</ref>
 +
<ref name="oreClumps">See <samp>MineShaft::tryToAddOreClumps</samp> in the game code.</ref>
 +
<ref name="dailyLuck">See <samp>FarmerTeam::AverageDailyLuck</samp> in the game code.</ref>
 +
<ref name="whichOre">See <samp>FarmerTeam::getAppropriateOre</samp> in the game code.</ref>
 
<ref name="chooseStoneType">See <samp>MineShaft::chooseStoneType</samp> in the game code.</ref>
 
<ref name="chooseStoneType">See <samp>MineShaft::chooseStoneType</samp> in the game code.</ref>
 
</references>
 
</references>

Revision as of 22:55, 18 April 2023

Axe.png
Article Stub

This article is marked as a stub for the following reason:

  • Need info about how charts were generated, more supporting evidence for percentages and claims about luck
Changing distribution of metal ore with level.
Changing distribution of gemstone ore with level.
Changing distribution of gem nodes with level and luck.

Small minable stones and ores can appear as random stones throughout the level, or rarely as small clumps. These have different distributions[1][2]. On average there will be less than 0.67 small resource clumps on each level with neutral luck, and less than 1 for the largest possible luck. These clumps have a 25% chance to be a dark grey rock (stone ore), a 1.5% chance to be iridium, and a 73.5% chance to be gold.

The distribution for random stones is more complex and varies with depth and best understood in a few stages.

If a Qi quest is in progress which makes the mine more dangerous, there is a small chance for a stone to be replaced with a radioactive ore. This is very dependent upon luck, with the luck boost from the special charm being worth 192 levels, and the worst luck requiring a depth of level 550 to have any chance ore will drop. This is also dependent on luck buffs, with each level of luck worth 15 floors. This will replace any of the below stones.

The chance for a stone to be a metal ore (copper, iron, gold or iridium) will vary depending on floor, starting at 2% on floor 1, rapidly increasing to 16% on floor 100, and then increasing to 100% on floor 1780. Luck has no affect on this chance, or on the ore distribution. Copper and iron have the same distribution. From floor 2010 only gold and iridium ore will be found, and from floor 5700 only iridium ore will be found from this generation.

If the stone is not a metal ore, there is a chance for it to be a a gem stone ore (diamond, emerald, aquamarine, ruby, amethyst, topaz and jade), a gem node (the round purple stone), a mystic stone or a dark grey rock. This means that the chance can decrease as you go deeper as more of the stone is metal ore, and above floor 1780 these will not be found. Luck and mining level only play a significant role for mystic stones and gem nodes. For others the contribution is negligible.

For gem stone ores, diamond is slightly rarer than most, and jade is half as rare as most. The chance initially increases, peaking at a chance of ~0.35% (~0.18% for jade) at a depth of ~800, before dropping back down.

Dark grey rocks, start with their maximum chance at level 1 (9.73% for dark grey rocks, 0.005% for mystic stones, 0.059% for gem nodes for best chances), and drop proportionally as ores take their place.


Code Details

The main code for populating the level is found in the function StardewValley.Locations.MineShaft::populateLevel. In setting up to populate the level, it initially defines stoneChance as a random number (double) in the range [10,30), and gemStoneChance as 0.003. It then calls StardewValley.Locations.MineShaft::adjustLevelChances, which will perform a few checks including setting the chance to find stone to 0 for infested floors and dividing gem stone chance by 2[3]. After this setup, it will then iterate through every square of the level, and if it passes a few checks it will add a stone selected using the function StardewValley.Locations.MineShaft::chooseStoneType, passing the gemstone chance from above and the magic numbers 0.001 and 5e-5 for gem nodes (internally chanceForPurpleStone) and mystic stones (internally chanceForMysticStone). In the same sweep, if it does not add a stone there is a chance for it to add a large resource clump, which are 2 possible variants of a 2 by 2 boulder.

After iterating through every square, and performing a few other tasks, it will attempt to add ore clumps using the function StardewValley.Locations.MineShaft::tryToAddOreClumps.

Ore Clumps

In the StardewValley.Locations.MineShaft::tryToAddOreClumps[4] function, a try will only be made if a random number is less than 0.55 plus the average daily luck. The maximum possible average daily luck is 0.1 from random luck and 0.025 from the special charm[5]. This means with neutral luck there is a 55% chance to try, and with the best possible luck there is a 67.5% chance. It will try once, and then generate a random number and keep going if that random number is less than 0.25 plus the average daily luck. This means there will be 1 chance, plus a 25% chance with neutral luck or a 37.5% chance with best possible luck.

This gives an expected value of 1.3 recurring or 1.6 attempts to generate a clump, which when combined with the base chance to try gives an expected amount of 0.67 or 1.

However, each try chooses a random tile on the map and will only place an ore clump there if the tile is free, resulting in less than these numbers.

To choose which type of ore to add it calls the function StardewValley.Locations.MineShaft::getAppropriateOre[6], which just before returning has a 25% chance (if it is not in hard mode) to set the ore to 668 or 670, which are the dark grey rocks (stone ore). Otherwise, the ore is set as 764, gold ore, with a 2% chance to set it to 765, iridium ore. This results in total chances of 25% for dark grey rocks, 1.5% chance for iridium ore, and 73.5% for gold.

Random ore placement (chooseStoneType)

This will first go through the different areas, and for skull cavern, it will set the base stone type to 32, 38, 40 or 42 (equally), and then calculate several variables, in a few stages to give different definitions for different floor ranges chanceForOre is defined in 2 parts, including using a min to give 3 different regions:

double chanceForOre = 0.02 + (double)skullCavernMineLevel * 0.0005; if (this.mineLevel >= 130) { chanceForOre += 0.01 * (double)((float)(Math.Min(100, skullCavernMineLevel) - 10) / 10f); }

This ends up being defined as either 0.02 + skullCavernMineLevel * 0.0005 for floors 1-10, 0.01 + skullCavernMineLevel * 0.0015 for levels 10 to 100, and 0.11 + skullCavernMineLevel * 0.0005 for levels 100 and up. This means the chance for ore will increase by 0.05% for each floor, except between levels 10 and 100 where it increases by 0.15% each floor.

References

  1. See MineShaft::populateLevel in the game code.
  2. See MineShaft::chooseStoneType in the game code.
  3. See MineShaft::adjustLevelChances in the game code.
  4. See MineShaft::tryToAddOreClumps in the game code.
  5. See FarmerTeam::AverageDailyLuck in the game code.
  6. See FarmerTeam::getAppropriateOre in the game code.