Elin:Code Analysis/Fishing

From Ylvapedia
Revision as of 11:46, 28 November 2024 by OmegaPlatinum (talk | contribs) (Update number of fish table.)
Jump to navigation Jump to search

Calculations

Fish LV

The formula to calculate the fish LV that can be caught based on your fishing level:

fishLV = rnd(fishingLevel * 2) + 1
  • fishingLevel: Your current fishing skill level.
  • rnd: A random number between 0 and the value passed into the function.

Adjusted Fish LV

The adjusted fish LV is calculated during item creation. It uses multiple calls to the rnd function and adds a hardcoded value of +2 at the end. The final adjusted level becomes:

adjustedLV = fishLV + 2 + rnd(rnd(rnd(rnd(Mathf.Min(fishLV * 2, 20)) + 1) + 1) + 1)
  • The adjustment process involves:
    • Determining the base fishLV as rnd(fishingLevel * 2) + 1.
    • Applying multiple calls to the rnd function:
      • rnd generates a random number between 0 and (max - 1).
      • Each call depends on the result of the previous rnd, gradually narrowing down the possible range.
    • Adding a hardcoded +2 to ensure the adjusted LV always has an offset.
  • Note: While it’s rare, the final result of the multiple calls to rnd can theoretically be as high as 19, resulting in a significant boost to the adjusted LV.

Example

If your fishing level is 10:

  • Base LV:
    • fishLV = rnd(10 * 2) + 1 = rnd(20) + 1.
    • Example result: 10.
  • Adjustments:
    • First rnd(20) → Result = 7.
    • Second rnd(7 + 1) → Result = 3.
    • Third rnd(3 + 1) → Result = 2.
    • Fourth rnd(2 + 1) → Result = 0.
  • Final Adjusted LV:
    • adjustedLV = 10 + 2 + 0 = 12.

Fish LV Range Table

Fishing Level Minimum LV Maximum LV
1 3 4
2 3 6
3 3 8
4 3 10
5 3 12
6 3 14
7 3 16
8 3 18
9 3 20
10 3 22
11 3 24
12 3 26
13 3 28
14 3 30
15 3 32
16 3 34
17 3 36
18 3 38
19 3 40

Code (EA 23.41)

int num3 = EClass.rnd(num * 2) + 1;
thing = ThingGen.Create("fish", -1, num3);

lv = lv + 2 + EClass.rnd(EClass.rnd(EClass.rnd(EClass.rnd(Mathf.Min(lv * 2, 20)) + 1) + 1) + 1);

Number of Fish

The formula to calculate the number of fish you can catch based on your fishing level:

numberOfFish = rnd(fishingLevel / (fishLV + 10)) + 1
  • fishingLevel: Your current fishing skill level.
  • fishLV: The fish LV.
  • rnd: A random number between 0 and the value passed into the function.

Example

If your fishing level is 22, and the fish LV is determined to be 1, the potential number of fish is calculated as:

rnd(22 / (1 + 10)) + 1

This simplifies to:

rnd(22 / 11) + 1

The rnd(2) generates a random number between 0 and 1. Adding 1 ensures that you will catch at least 1 fish, and the number of fish can either be 1 or 2, depending on the random result.

Adding Land Feats

The initial chance of catching one extra fish starts at 5%.

If the land feats include:

  • Beach (3604): Adds 20% to the base chance.
  • Sea (3605): Adds 20% to the base chance.
  • Fishing Spot (3706): Adds 25% to the base chance.

Since only Sea (3605) or Beach (3604) can be present at the same time (not both), the total chance is calculated as:

chanceForOneMoreFish = 5
chanceForOneMoreFish += isBeach * 20 + isSea * 20 + isFishingSpot * 25

Where:

  • isBeach: A flag (either 0 or 1) indicating whether the land feat is a Beach (3604).
  • isSea: A flag (either 0 or 1) indicating whether the land feat is Sea (3605).
  • isFishingSpot: A flag (either 0 or 1) indicating whether the land feat is a Fishing Spot (3706).

For example:

  • If Sea (3605) is present, and Fishing Spot (3706) is also present:
chanceForOneMoreFish = 5 + 1 * 20 + 1 * 25 = 50
  • If Beach (3604) is present instead of Sea (3605):
chanceForOneMoreFish = 5 + 1 * 20 + 1 * 25 = 50

Checking the Chance to Increase the Number of Fish

The chanceForOneMoreFish value is compared to a random number generated by the rnd(100) function, which produces a number between 0 and 99 (inclusive).

If chanceForOneMoreFish is greater than or equal to the random number, the number of fish will increase by 1.

This check is implemented with:

if (chanceForOneMoreFish >= rnd(100))

For example:

  • If chanceForOneMoreFish = 50, and the random number generated by rnd(100) is 50 or less, you will catch an additional fish.

Example with Land Feats

Example 1: Fishing Spot (3706) and Sea (3605)

Let's say your fishing level is 22, and the fish LV is 1. The base number of fish is calculated as:

numberOfFish = rnd(22 / (1 + 10)) + 1 = rnd(2) + 1

This gives 1 or 2 fish, depending on the random result.

Now, evaluating the land feats:

  • Start with chanceForOneMoreFish = 5 (base chance).
  • Sea (3605) adds 20.
  • Fishing Spot (3706) adds 25.

The new chanceForOneMoreFish becomes:

chanceForOneMoreFish = 5 + 20 + 25 = 50

Next, the random chance is checked:

if (chanceForOneMoreFish >= rnd(100))

If the random number generated by rnd(100) is 50 or less, the number of fish will increase by 1. Thus:

  • numberOfFish = numberOfFish + 1 (if the random check passes).
  • If the random number exceeds 50, the number of fish remains unchanged.
Example 2: Fishing Spot (3706) and Beach (3604)

For the same fishing level and fish LV, the land feats contribute:

  • Beach (3604) adds 20.
  • Fishing Spot (3706) adds 25.

The total chanceForOneMoreFish remains:

chanceForOneMoreFish = 5 + 20 + 25 = 50

The random check behaves the same as above, with the same chance for an additional fish.

Number of Fish Table

Fish LV Minimum Fishing Level for 2 Fish Minimum Fishing Level for 3 Fish Minimum Fishing Level for 4+ Fish
1 22 33 44, etc.
5 30 45 60, etc.
10 40 60 80, etc.
15 50 75 100, etc.
20 60 90 120, etc.
25 70 105 140, etc.
30 80 120 160, etc.
35 90 135 180, etc.
40 100 150 200, etc.

Note: Values for 4+ fish follow the same progression pattern (incrementing by the same interval as earlier columns).

Code (EA 23.40)

num2 = EClass.rnd(num / (num3 + 10)) + 1;
int num4 = 5;
if (EClass.Branch != null)
{
    num4 += EClass.Branch.Evalue(3604) * 20 + EClass.Branch.Evalue(3605) * 20 + EClass.Branch.Evalue(3706) * 25;
}
if (num4 >= EClass.rnd(100))
{
    num2++;
}
if (thing != null)
{
    thing.SetNum(num2);
    thing.SetBlessedState(BlessedState.Normal);
}

Fishing Speed

The fishing process involves two key variables:

  • progress: Represents the overall duration or percentage of fishing completion, ranging from 0 to 100.
  • hit: Tracks the number of attempts made during the fishing fight. The following conditions apply:
    • Increase: hit increments on each attempt until either:
      • The fish is caught (when hit > random threshold).
      • Certain random conditions reset hit to 0.

Success

The formula to calculate the success threshold for catching a fish is:

successThreshold = Mathf.Clamp(10 - rnd(fishingLevel + 1) / 10, 5, 10)
  • fishingLevel: Your current fishing skill level.
  • rnd: A random number between 0 and the value passed into the function.
  • Clamp: Ensures the value stays between 5 (easiest) and 10 (hardest).

The actual success logic occurs as follows:

if (hit > rnd(successThreshold)) {
    hit = 100;
    progress = MaxProgress;
}
  • hit: Tracks the current number of attempts. The fish is caught if hit exceeds the random roll of the successThreshold.
  • progress: Automatically completes when success occurs.

Example

If your fishing level is 20, the calculation proceeds as follows:

  1. rnd(20 + 1) generates a random number between 0 and 20.
  2. This random number is divided by 10 and subtracted from 10.
  3. The result is clamped to the range [5, 10], determining the successThreshold.

For example:

  • If rnd(21) = 10, the calculation is:
successThreshold = Mathf.Clamp(10 - (10 / 10), 5, 10) = 9

A random roll of rnd(9) determines the threshold. If hit > rnd(9), the fish is caught.

Success Threshold Table

Fishing Level Min successThreshold Max successThreshold
1 10 10
5 10 10
10 9 10
15 9 10
20 8 10
25 8 10
30 7 10
35 7 10
40 6 10
45 6 10
50 5 10
55 5 10
60 5 10

Reset

The formula to determine whether hit resets is:

resetThreshold = Mathf.Clamp(10 - rnd(fishingLevel + 1) / 5, 2, 10)
  • fishingLevel: Your current fishing skill level.
  • rnd: A random number between 0 and the value passed into the function.
  • Clamp: Ensures the value stays between 2 (easiest threshold to reset) and 10 (hardest threshold to reset).

If rnd(resetThreshold) equals 0, and progress >= 10, the hit counter resets to 0.

Example

If your fishing level is 30, the calculation proceeds as follows:

  1. rnd(30 + 1) generates a random number between 0 and 30.
  2. This random number is divided by 5 and subtracted from 10.
  3. The result is clamped to the range [2, 10], determining the resetThreshold.

For example:

  • If rnd(31) = 10, the calculation is:
resetThreshold = Mathf.Clamp(10 - (10 / 5), 2, 10) = 8

A second random roll, rnd(8), is performed. If the result is 0, the hit counter resets.

Reset Threshold Table

Fishing Level Min resetThreshold Max resetThreshold
1 10 10
5 9 10
10 8 10
15 7 10
20 6 10
25 5 10
30 4 10
35 3 10
40 2 10
45 2 10
50 2 10

Code (EA 23.37)

public override void OnProgress()
{
	if (this.owner.IsPC && (this.owner.Tool == null || !this.owner.Tool.HasElement(245, 1)))
	{
		this.Cancel();
		return;
	}
	if (this.hit >= 0)
	{
		this.owner.renderer.PlayAnime(AnimeID.Fishing, default(Vector3), false);
		this.owner.PlaySound("fish_fight", 1f, true);
		this.Ripple();
		int a = Mathf.Clamp(10 - EClass.rnd(this.owner.Evalue(245) + 1) / 10, 5, 10);
		if (this.hit > EClass.rnd(a))
		{
			this.hit = 100;
			this.progress = this.MaxProgress;
		}
		this.hit++;
		return;
	}
	if (EClass.rnd(Mathf.Clamp(10 - EClass.rnd(this.owner.Evalue(245) + 1) / 5, 2, 10)) == 0 && this.progress >= 10)
	{
		this.hit = 0;
	}
	if (this.progress == 2 || (this.progress >= 8 && this.progress % 6 == 0 && EClass.rnd(3) == 0))
	{
		this.owner.renderer.PlayAnime(AnimeID.Shiver, default(Vector3), false);
		this.Ripple();
	}
}