Elin:Code Analysis/Hearthstone growth: Difference between revisions

(Page Creation, Code Analysis/Hearthstone growth)
 
(Recalculate the number to account for float to int conversion)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:Code Analysis/Hearthstone growth}}
{{Spoiler}}
{{Spoiler}}


Line 31: Line 32:
Every alive resident that is not livestock has 1 in 3 chance of giving out 1 xp of hearthstone level every day.
Every alive resident that is not livestock has 1 in 3 chance of giving out 1 xp of hearthstone level every day.


If they have a Pioneer job, they are guaranteed to provide 3 additional points of xp everyday.
If they have a Pioneer job, they are guaranteed to provide 3 additional points of xp everyday on top of the normal random chance one.


==Shipping EXP==
==Shipping EXP==
Line 71: Line 72:
That is to say, for the purpose of Hearthstone growth, any item with a shipping price more than 9985 is considered the same.
That is to say, for the purpose of Hearthstone growth, any item with a shipping price more than 9985 is considered the same.


At the same time, every item, '''even if it is sold for nothing''', will also have the minimum exp of '''1.15''' thanks to the +15 of the price in the formula and +1 at the end of it.
At the same time, every item, '''even if it is sold for nothing''', will also have the minimum exp of '''1.15''' (Which will be rounded down to 1 due to being int value) thanks to the +15 of the price in the formula and +1 at the end of it.


But keep in mind, due to the order of operation, the +1 at the end is only applied '''once per type of item'''.
But keep in mind, due to the order of operation, the +1 at the end is only applied '''once per type of item'''.
Line 82: Line 83:
return a / 2 + Rand.rnd(a / 2);
return a / 2 + Rand.rnd(a / 2);
}
}
</syntaxhighlight>In essence, it returns the value at 50-100% of the input. So for an item with 0 selling price, it can now yield anywhere between 0.575 and 1.15 xp.
</syntaxhighlight>In essence, it returns the value at 50-100% of the input rounding down again.


<code>num2 = num2 / 2 + 1;</code>
<code>num2 = num2 / 2 + 1;</code>


Now dividing the value by 2 and plus 1 to it. The 0 sell value item xp is now between 1.2875 - 1.575
Now dividing the value by 2 and plus 1 to it, rounding down for the third time.


This time, the plus one is only applied '''once per shipment''' of item.
This time, the plus one is only applied '''once per shipment''' of item.
Line 114: Line 115:
}
}


</syntaxhighlight>It essentially multiplies the EXP by 1.5 and randomly add 0-1 to it.
</syntaxhighlight>It essentially multiplies the EXP by 1.5 and randomly add 0-1 to it. Rounding down again down to being an int.


==EXP require for each level==
==EXP require for each level==
Line 166: Line 167:
! colspan="2" |Worst Rng
! colspan="2" |Worst Rng
Max Sell value item
Max Sell value item
! colspan="2" |Medium Rng
! colspan="2" |Average Rng
Max Sell value item
Max Sell value item
! colspan="2" |Best Rng
! colspan="2" |Best Rng
Line 187: Line 188:
| rowspan="6" |LV
| rowspan="6" |LV
|1 > 2
|1 > 2
|3,523
|3,540
|5,300
|5,300
|2,340
|2,634
|3,532
|3,974
|1,759
|1,754
|2,647
|2,647
|6
|6
Line 201: Line 202:
|-
|-
|2 > 3
|2 > 3
|8,856
|8,874
|13,300
|13,300
|5,896
|6,634
|8,865
|9,974
|4,416
|4,420
|6,647
|6,647
|14
|14
|18
|20
|9
|10
|14
|15
|7
|7
|10
|10
|-
|-
|3 > 4
|3 > 4
|17,745
|17,754
|26,634
|26,634
|11,822
|13,314
|17,754
|19,974
|8,860
|8,860
|13,314
|13,314
|27
|27
|40
|40
|18
|20
|27
|30
|14
|14
|20
|20
|-
|-
|4 > 5
|4 > 5
|30,189
|30,207
|45,300
|45,300
|20,117
|22,634
|30,198
|33,974
|15,083
|15,087
|22,647
|22,647
|46
|46
|68
|68
|31
|31
|46
|51
|23
|23
|34
|34
|-
|-
|5 > 6
|5 > 6
|46,189
|51,540
|69,300
|77,300
|30,785
|38,634
|46,198
|57,974
|23,083
|25,754
|34,647
|38,647
|70
|78
|104
|116
|47
|58
|70
|87
|34
|39
|52
|58
|-
|-
|6 > 7
|6 > 7
|65,745
|98,634
|43,822
|65,754
|65,754
|98,647
|49,314
|73,974
|32,860
|32,860
|49,314
|49,314
|99
|99
|148
|148
|66
|74
|99
|111
|50
|50
|74
|74
|-
|-
| colspan="2" |Total
| colspan="2" |Total
|172,246
|177,669
|258,468
|266,481
|114,781
|133,164
|172,301
|199,844
|86,061
|88,735
|129,216
|133,216
|262
|270
|386
|400
|175
|197
|262
|300
|131
|136
|194
|200
|}<!-- Someone please peer-review this. Math is my worst subject -->
|}<!-- Someone please peer-review this. Math is my worst subject -->
{{DEFAULTSORT:Code_Analysis/Hearthstone_growth}}
[[Category:Elin Spoiler]]
[[Category:EN]]

Latest revision as of 23:36, 23 June 2025



Residents EXP

From FactionBranch.cs

public void OnAdvanceDay()
	{
		int num = 0;
		foreach (Chara member in members)
		{
			if (member.IsPC || member.isDead)
			{
				continue;
			}
			...
			if (member.memberType == FactionMemberType.Default)
			{
				if (EClass.rnd(3) == 0)
				{
					num++;
				}
				if (member.GetWork("Pioneer") != null)
				{
					num += 3;
				}
			}
		}
		ModExp(num);
	}

Analysis:

Every alive resident that is not livestock has 1 in 3 chance of giving out 1 xp of hearthstone level every day.

If they have a Pioneer job, they are guaranteed to provide 3 additional points of xp everyday on top of the normal random chance one.

Shipping EXP

From GameDate.cs

public void ShipGoods()
	{
		...
		int num2 = 0;
		...
		foreach (Thing thing3 in container_shipping.things)
		{
			if (thing3.trait.CanBeShipped)
			{
				int price = thing3.GetPrice(CurrencyType.Money, sell: true, PriceType.Shipping);
				...
				num2 += EClass.rndHalf(thing3.Num * Mathf.Min(15 + price, 10000) / 100 + 1);
	            ...
			}
		}
		...
		num2 = num2 / 2 + 1;
		if (zone.branch.policies.IsActive(2515))
		{
			num2 = 0;
		}
		...
		zone.branch.ModExp(num2);
	    ...
	}

Analysis:

int price = thing3.GetPrice(CurrencyType.Money, sell: true, PriceType.Shipping);

num += thing3.Num;
num2 += EClass.rndHalf(thing3.Num * Mathf.Min(15 + price, 10000) / 100 + 1);

The bases of shipping xp is the price of item sold by shipping.

There's a maximum price of an item when used to determine the exp gain due to Mathf.Min() functions.

That is to say, for the purpose of Hearthstone growth, any item with a shipping price more than 9985 is considered the same.

At the same time, every item, even if it is sold for nothing, will also have the minimum exp of 1.15 (Which will be rounded down to 1 due to being int value) thanks to the +15 of the price in the formula and +1 at the end of it.

But keep in mind, due to the order of operation, the +1 at the end is only applied once per type of item.

So it incentivizes shipping many kinds of items to reap more hearthstone exp.

Now, we must look at what EClass.rndHalf() do.

public static int rndHalf(int a)
	{
		return a / 2 + Rand.rnd(a / 2);
	}

In essence, it returns the value at 50-100% of the input rounding down again.

num2 = num2 / 2 + 1;

Now dividing the value by 2 and plus 1 to it, rounding down for the third time.

This time, the plus one is only applied once per shipment of item.

Which means that technically speaking, you’ll get more hearthstone exp from the same number of items by shipping items every day

rather than shipping in a big batch at once from time to time.

if (zone.branch.policies.IsActive(2515))
	{
		num2 = 0;
	}

Growth Suppression policy effect will set the xp to 0 if it is turned on.

Growth Boost Policy

When the Hearthstone gains EXP from the above pathways, the EXP number will further increase by the Growth Boost policy if you have it enabled.

From FactionBranch.cs

public void ModExp(int a)
{
    	...
    	if (policies.IsActive(2516))
    	{
        	        	a = a * 150 / 100 + EClass.rnd(2);
    	}
    	exp += a;
    	...
}

It essentially multiplies the EXP by 1.5 and randomly add 0-1 to it. Rounding down again down to being an int.

EXP require for each level

Dictated by the following formula in FactionBranch.cs:

public int GetNextExp(int _lv = -1)
	{
		if (_lv == -1)
		{
			_lv = lv;
		}
		return _lv * _lv * 100 + 100;
	}

Which mean the require exp for each of hearthstone are:

Level EXP require
1 > 2 200
2 > 3 500
3 > 4 1000
4 > 5 1700
5 > 6 2600
6 > 7 3700

Amount of items require to level up

With all the aforementioned code analyzed, we can calculate the theoretical ceiling and floor of the amount of item required to be shipped to level up each hearthstone level in one go, using a singular type of item. The result is the following table.

As a reminder, Max sell value is something that can be sold for 9985 oren or more.

Scenario Worst Rng

0 sell value item

Average Rng

0 Sell value item

Best Rng

0 Sell value item

Worst Rng

Max Sell value item

Average Rng

Max Sell value item

Best Rng

Max Sell value item

Growth boost
LV 1 > 2 3,540 5,300 2,634 3,974 1,754 2,647 6 8 4 6 3 4
2 > 3 8,874 13,300 6,634 9,974 4,420 6,647 14 20 10 15 7 10
3 > 4 17,754 26,634 13,314 19,974 8,860 13,314 27 40 20 30 14 20
4 > 5 30,207 45,300 22,634 33,974 15,087 22,647 46 68 31 51 23 34
5 > 6 51,540 77,300 38,634 57,974 25,754 38,647 78 116 58 87 39 58
6 > 7 65,754 98,647 49,314 73,974 32,860 49,314 99 148 74 111 50 74
Total 177,669 266,481 133,164 199,844 88,735 133,216 270 400 197 300 136 200