Jump to content

Elin:Code Analysis/Fishing: Difference between revisions

Add fishing speed calculations.
m (Fix variable name to specify +1 additional fish.)
(Add fishing speed calculations.)
Line 213: Line 213:
}
}
</syntaxhighlight>
</syntaxhighlight>
===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:
<pre>successThreshold = Mathf.Clamp(10 - rnd(fishingLevel + 1) / 10, 5, 10)</pre>
* '''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''' (hardest) and '''10''' (easiest).
====Example====
If your fishing level is '''10''', the calculation proceeds as follows:
# <code>rnd(10 + 1)</code> generates a random number between '''0''' and '''10'''.
# This random number is divided by '''10''' and subtracted from '''10'''.
# The resulting value is clamped to the range '''[5, 10]'''.
For example:
* If <code>rnd(11) = 5</code>, the calculation is:
<pre>successThreshold = Mathf.Clamp(10 - (5 / 10), 5, 10) = 9.5 (clamped to 9)</pre>
This means the success threshold for this attempt is '''9'''. If your current ''hit'' exceeds '''9''', the fish is caught.
====Success Threshold Table====
{| class="wikitable sortable"
|-
! 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:
<pre>resetThreshold = Mathf.Clamp(10 - rnd(fishingLevel + 1) / 5, 2, 10)</pre>
* '''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 reset) and '''10''' (hardest reset).
If <code>rnd(resetThreshold)</code> equals '''0''', and ''progress >= 10'', the ''hit'' counter resets to '''0'''.
====Example====
If your fishing level is '''20''', the calculation proceeds as follows:
# <code>rnd(20 + 1)</code> generates a random number between '''0''' and '''20'''.
# This random number is divided by '''5''' and subtracted from '''10'''.
# The resulting value is clamped to the range '''[2, 10]'''.
For example:
* If <code>rnd(21) = 10</code>, the calculation is:
<pre>resetThreshold = Mathf.Clamp(10 - (10 / 5), 2, 10) = 8</pre>
A second random roll, <code>rnd(8)</code>, is performed. If the result is '''0''', the ''hit'' counter resets.
====Reset Threshold Table====
{| class="wikitable sortable"
|-
! 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)====
<syntaxhighlight lang="c#" line="1">
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();
}
}
</syntaxhighlight>
[[Category:Elin Spoiler]]
[[Category:Elin Spoiler]]
[[Category:EN]]
[[Category:EN]]
133

edits