Jump to content

Elin:Code Analysis/Fishing: Difference between revisions

Add fishing land feat calculations.
(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====
135

edits