Elin:Code Analysis/Fishing: Difference between revisions

From Ylvapedia
(Fix number of fish table and example.)
(Add fishing land feat calculations.)
Line 93: Line 93:


The <code>rnd(2)</code> 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.
The <code>rnd(2)</code> 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 extra fish starts at '''5%'''.
If the land feats include '''Beach (3604)''' and '''Fishing Spot (3706)''', these feats will contribute additional chances to the base chance.
For example:
* '''Beach (3604)''' adds '''20%''' to the base chance.
* '''Fishing Spot (3706)''' adds '''25%''' to the base chance.
Starting with a '''5% chance''', the total chance is calculated using the following code:
<pre>
additionalFishChance = 5
additionalFishChance += isBeach * 20 + isFishingSpot * 25
</pre>
Where:
* '''isBeach''' is a flag (either 0 or 1) indicating whether the land feat is a '''Beach (3604)'''.
* '''isFishingSpot''' is a flag (either 0 or 1) indicating whether the land feat is a '''Fishing Spot (3706)'''.
If both features are present (i.e., both flags are set to 1), then:
<pre>
additionalFishChance = 5 + 1 * 20 + 1 * 25 = 50
</pre>
==== Checking the Chance to Increase the Number of Fish ====
The '''additionalFishChance''' value is then compared to a random number generated by the <code>rnd(100)</code> function. The value of <code>rnd(100)</code> generates a random number between '''0''' and '''99''' (inclusive).
If the value of '''additionalFishChance''' is greater than or equal to the random number, the number of fish will increase by '''1'''.
This check is done with:
<pre>
if (additionalFishChance >= rnd(100))
</pre>
* If the random number generated by <code>rnd(100)</code> is '''50 or less''', the number of fish will increase by '''1'''.
* If the random number is '''greater than 50''', the number of fish will remain the same.
Thus, the probability of increasing the number of fish is '''50%''' (because '''additionalFishChance = 50''' ).
==== Example with Land Feats ====
Let's say your fishing level is '''22''', and the fish LV is '''1'''. You calculate the base number of fish as:
<pre>numberOfFish = rnd(22 / (1 + 10)) + 1 = rnd(2) + 1</pre>
Thus, you could catch '''1 or 2 fish''', based on the random result.
Now, you evaluate the land feats:
* Starting with '''additionalFishChance = 5''' (the base chance).
* If the land feats are present:
    * '''Beach (3604)''' adds '''20''' to '''additionalFishChance'''.
    * '''Fishing Spot (3706)''' adds '''25''' to '''additionalFishChance'''.
So, the new '''additionalFishChance''' becomes:
<pre>
additionalFishChance = 5 + 20 + 25 = 50
</pre>
Next, the random chance is checked:
<pre>if (additionalFishChance >= rnd(100))</pre>
If the random number generated by <code>rnd(100)</code> is '''50 or less''', '''num2''' (the final number of fish) will increase by 1. This means that if the random number is between '''0 and 50''' (inclusive), you will catch an additional fish, making '''num2''' increase by 1.
So, '''numberOfFish''' is increased by '''1''' based on land feats, making it:
* '''numberOfFish = numberOfFish + 1''' (if the random check passes).
* If the random number exceeds '''50''', '''numberOfFish''' remains the same.


====Number of Fish Table====
====Number of Fish Table====

Revision as of 07:42, 24 November 2024

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.

Example

If your fishing level is 3, the potential fish LV is calculated as:

rnd(3 * 2) + 1

This gives a range of 1 to 6, meaning you can catch fish with LV between 1 and 6.

Fish LV Range Table

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

Code (EA 23.37)

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

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 extra fish starts at 5%.

If the land feats include Beach (3604) and Fishing Spot (3706), these feats will contribute additional chances to the base chance.

For example:

  • Beach (3604) adds 20% to the base chance.
  • Fishing Spot (3706) adds 25% to the base chance.

Starting with a 5% chance, the total chance is calculated using the following code:

additionalFishChance = 5
additionalFishChance += isBeach * 20 + isFishingSpot * 25

Where:

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

If both features are present (i.e., both flags are set to 1), then:

additionalFishChance = 5 + 1 * 20 + 1 * 25 = 50

Checking the Chance to Increase the Number of Fish

The additionalFishChance value is then compared to a random number generated by the rnd(100) function. The value of rnd(100) generates a random number between 0 and 99 (inclusive).

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

This check is done with:

if (additionalFishChance >= rnd(100))
  • If the random number generated by rnd(100) is 50 or less, the number of fish will increase by 1.
  • If the random number is greater than 50, the number of fish will remain the same.

Thus, the probability of increasing the number of fish is 50% (because additionalFishChance = 50 ).

Example with Land Feats

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

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

Thus, you could catch 1 or 2 fish, based on the random result.

Now, you evaluate the land feats:

  • Starting with additionalFishChance = 5 (the base chance).
  • If the land feats are present:
   * Beach (3604) adds 20 to additionalFishChance.
   * Fishing Spot (3706) adds 25 to additionalFishChance.

So, the new additionalFishChance becomes:

additionalFishChance = 5 + 20 + 25 = 50

Next, the random chance is checked:

if (additionalFishChance >= rnd(100))

If the random number generated by rnd(100) is 50 or less, num2 (the final number of fish) will increase by 1. This means that if the random number is between 0 and 50 (inclusive), you will catch an additional fish, making num2 increase by 1.

So, numberOfFish is increased by 1 based on land feats, making it:

  • numberOfFish = numberOfFish + 1 (if the random check passes).
  • If the random number exceeds 50, numberOfFish remains the same.

Number of Fish Table

Fish LV Minimum Fishing Level for 2 Fish Minimum Fishing Level for 3 Fish
1 22 33
5 30 45
10 40 60
15 50 75
20 60 90
25 70 105
30 80 120
35 90 135
40 100 150

Code (EA 23.37)

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