Files
UltimateFishing/Assets/Scripts/Assembly-CSharp/FishFight.cs
2026-02-21 16:45:37 +08:00

462 lines
13 KiB
C#

using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using BitStrap;
using UnityEngine;
public class FishFight : Action
{
public SharedGameObject bait;
private FishingPlayer fishingPlayer;
private Fish fish;
private float fightForce = 0.1f;
public float fightForceMin = 0.1f;
public float fightForceAvg = 0.5f;
public float fightForceMax = 1f;
public float fightForceGainSpeed = 1.3f;
public float fightForceLooseSpeed = 1.3f;
public float fightForceHoldHighTime = 0.2f;
public float fightForceHoldAvgTime = 10f;
public float fightForceHoldLowTime = 0.1f;
public float fightForceChangeSpeed = 2f;
private float fightForceTimer = -1f;
private int forceState;
private float shallowWaterDepth = 1.5f;
private float dragChangeDirectionTimer = -1f;
private float changeDirectionTimer = -1f;
private Vector3 moveDirection;
private bool dragMaxDirection;
private float dragMaxDirectionTimer;
private float dragMaxDirectionXTimer;
private float dragMaxDirectionXValue;
[ReadOnly]
public float biteLineTimer = -1f;
public override void OnStart()
{
base.OnStart();
fish = transform.GetComponent<Fish>();
fishingPlayer = fish.fishingPlayer;
fightForceTimer = -1f;
forceState = 0;
fish.isJerked = false;
fish.isInNetArea = false;
fish.isOnGround = false;
fish.StopSeeingBait();
if (fish.storedBait.fishingHands.fishingRod.isOnRodStand)
{
Fish.jerkDuration = 15f;
Fish.jerkDurationThreshold = 15f;
}
else if (fish.storedBait.fishingHands.isGroundRig)
{
Fish.jerkDuration = 10f;
Fish.jerkDurationThreshold = 10f;
}
else if ((bool)fish.storedBait.fishingHands.fishingFloat)
{
Fish.jerkDuration = 9f;
Fish.jerkDurationThreshold = 7f;
}
else
{
Fish.jerkDuration = 5f;
Fish.jerkDurationThreshold = 5f;
}
fish.jerkTimer = Fish.jerkDuration;
SetupDirection(true, false);
dragMaxDirectionTimer = Time.time + Random.Range(3f, 4f);
dragMaxDirectionXTimer = Random.Range(3f, 4f);
if (fish.huntStyle == Fish.HuntStyle.PREDATOR && fish.storedBait.fishingHands.fishingLine.lineType == FishingLine.LineType.MONO)
{
biteLineTimer = Random.Range(4f, 10f);
}
Debug.Log("!!! FishFight OnStart " + fish.fishName + " " + fish.watchStyle);
Debug.Log("!!! FishFight Equipment " + fishingPlayer.currentHands.fishingRod.name + " " + fishingPlayer.currentHands.bait.name + " " + fishingPlayer.currentHands.floatRopeDepth);
Debug.Log("!!! isSpinningRig: " + fish.storedBait.fishingHands.isSpinningRig + " | isFloatRig: " + fish.storedBait.fishingHands.isFloatRig + " | isGroundRig: " + fish.storedBait.fishingHands.isGroundRig + " | isFlyRig: " + fish.storedBait.fishingHands.isFlyRig);
if (fish.catchStyleCurrent == Fish.CatchStyle.STOP)
{
fish.animController.ChangeAnimation(FishAnimationController.AnimType.TRYING_BAIT);
}
if (fish.storedBait.HasAnyLiveBait() || fish.fishingPlayer.IsTrolling())
{
fish.fishingPlayer.fishingController.MakeFirstJerk();
}
if ((bool)fish.fishingPlayer.boatSimulator && fish.storedBait.fishingHands.fishingRod.isOnRodStand)
{
fish.AttachToBoat(fish.fishingPlayer.boatSimulator);
}
fish.UpdateTargetSpeed();
fish.DurabilityBoostAmountCurrent = 0;
if ((bool)GlobalSettings.Instance && !GlobalSettings.Instance.playerSettings.IsCasual())
{
if (Random.value < 0.75f)
{
fish.DurabilityBoostAmountCurrent = 1;
}
if (Random.value < 0.3f)
{
fish.DurabilityBoostAmountCurrent = 2;
}
}
else if (Random.value < 0.4f)
{
fish.DurabilityBoostAmountCurrent = 1;
}
Debug.Log("!!! DurabilityBoostAmountCurrent " + fish.DurabilityBoostAmountCurrent + " Weight " + fish.Weight);
fish.DurabilityBoostDistance = Random.Range(10f, 35f);
if ((bool)fish.fishSpawner)
{
fish.fishSpawner.HideOtherDuringFight(fish, true);
}
}
public override TaskStatus OnUpdate()
{
if (Time.timeScale == 0f)
{
return TaskStatus.Running;
}
if (fish.isReleasing)
{
return TaskStatus.Failure;
}
if (!fish.storedBait)
{
return TaskStatus.Failure;
}
if (!fish.storedBait.fishingHands)
{
return TaskStatus.Failure;
}
if (fish.isInNetArea)
{
return TaskStatus.Running;
}
if (fish.isOnGround)
{
return TaskStatus.Running;
}
if (fish.isJumping)
{
return TaskStatus.Running;
}
if (fish.isBoatUpdate)
{
return TaskStatus.Running;
}
if (!fish.isBaitUpdate && fishingPlayer.DragFishStrengthDiff >= 0f && fish.storedBait.fishingHands.fishingLine.looseTensionFactorColliders > 0.6f)
{
SetupDirection(false, true);
}
if (dragMaxDirectionTimer < Time.time)
{
dragMaxDirection = !dragMaxDirection;
float num = Mathf.Lerp(1f, 6f, 1f - fish.AggressivenessFight);
num += Random.Range(0f, 2f);
dragMaxDirectionTimer = Time.time + num;
}
dragMaxDirectionXTimer -= Time.deltaTime;
if (!fish.isJerked && fish.isFighting && !fish.storedBait.fishingHands.fishingRod.isOnRodStand)
{
fish.jerkTimer -= Time.deltaTime * ((!(fish.pullForce > 0f)) ? 1f : 2f);
if (fish.jerkTimer <= 0f)
{
fish.jerkTimer = 0f;
if (!fish.storedBait.fishingHands.fishingFloat)
{
fish.targetDirection = (fish.Origin - transform.position).normalized;
}
fishingPlayer.LineBreak(Utilities.GetTranslation("HUD_MESSAGE/FISH_ESCAPED") + ".\n" + Utilities.GetTranslation("HUD_MESSAGE/NO_JERK"), 0f);
return TaskStatus.Failure;
}
if (fish.catchStyleCurrent == Fish.CatchStyle.STOP)
{
return TaskStatus.Running;
}
}
if (fish.isJerked && fish.isFighting && fish.jerkTimer < Fish.jerkDuration && fish.jerkTimer > Fish.jerkDurationThreshold)
{
fishingPlayer.LineBreak(Utilities.GetTranslation("HUD_MESSAGE/FISH_ESCAPED") + ".\n" + Utilities.GetTranslation("HUD_MESSAGE/JERK_TOO_FAST"), 0f);
fish.targetDirection = (fish.Origin - transform.position).normalized;
return TaskStatus.Failure;
}
fishingPlayer.floatCamera.TurnOn(false);
if (fish.notPulling && !fish.isInNetArea && !UtilitiesInput.isReelingIn && !fish.storedBait.fishingHands.fishingRod.isOnRodStand)
{
fish.notPullingTimer -= Time.deltaTime;
if (fish.notPullingTimer < 0f && !GameController.Instance.fightTest)
{
fishingPlayer.LineBreak(Utilities.GetTranslation("HUD_MESSAGE/FISH_ESCAPED") + ".\n" + Utilities.GetTranslation("HUD_MESSAGE/NOT_ENOUGH_TENSION"), 0f);
fish.targetDirection = (fish.Origin - transform.position).normalized;
return TaskStatus.Failure;
}
}
bool flag;
int num8;
if (biteLineTimer > 0f)
{
flag = fish.huntStyle == Fish.HuntStyle.PREDATOR;
}
else
num8 = 0;
if (!fish.storedBait.fishingHands.fishingRod.isOnRodStand)
{
float num2 = 0f;
fish.DurabilityCurrent -= fish.DurabilityIdleSpeed * Time.deltaTime;
num2 += fish.DurabilityIdleSpeed;
if (fishingPlayer.wasJustJerked && fish.storedBait.fishingHands.fishingLine.isLoose)
{
fish.DurabilityCurrent -= fish.DurabilityJerkFactor * fish.DurabilityStart;
num2 += fish.DurabilityJerkFactor;
}
float num3 = 0f;
float num4 = Vector3.Angle(moveDirection, fish.pullDirection);
if (fish.pullForce < Mathf.Epsilon && fish.storedBait.fishingHands.fishingLine.stretchToDistance < 0.04f)
{
num3 = 0f;
}
else
{
float num5 = num4 / 180f;
fish.fightLevel = num5;
num3 = num5;
if (fish.pullForce < Mathf.Epsilon)
{
float num6 = 0.05f + fish.storedBait.fishingHands.reel.GetDragForce() * 0.2f;
num3 *= num6;
}
num3 = fish.storedBait.fishingHands.UpdateHandsRotationFactor(num3);
num3 = fish.storedBait.fishingHands.UpdateJerkFactor(num3);
if (fish.pullForce == 1f)
{
num3 = 0.2f * fish.storedBait.fishingHands.UpdateReelSpeedFactor(num3);
}
else if (fish.pullForce > 0f)
{
num3 = 0.4f * fish.storedBait.fishingHands.UpdateReelSpeedFactor(num3);
}
}
fish.DurabilityCurrent -= num3 * Time.deltaTime;
num2 += num3;
GameController.Instance.hudManager.hudFishing.UpdateFishDurabilityDrain(num2);
if (fish.DurabilityCurrent < Fish.DurabilityMin)
{
fish.DurabilityCurrent = Fish.DurabilityMin;
}
}
if (fish.isBaitUpdate)
{
return TaskStatus.Running;
}
if (!fish.TerrainCollision())
{
CalcFightForce();
fish.fightForce = fightForce;
float num7 = fightForce;
num7 *= fish.DurabilityCurrent / 40f;
Vector3 pullDirection = fish.pullDirection;
if (fish.pullForce > 0f)
{
pullDirection *= fish.pullForce;
fish.animController.ChangeAnimation(FishAnimationController.AnimType.SWIM);
}
else
{
pullDirection *= 0f;
fish.animController.ChangeAnimation(FishAnimationController.AnimType.SWIM);
}
Vector3 vector = pullDirection;
vector += moveDirection * num7;
if (fish.pullForce > 0f)
{
}
fish.targetDirection = vector.normalized;
if (changeDirectionTimer < Time.time)
{
SetupDirection(false, false);
}
}
else
{
Vector3 vector2 = fish.pullDirection * fish.pullForce;
fish.targetDirection = vector2.normalized;
if (fish.TerrainCollision())
{
fish.targetDirection = (fish.Origin - transform.position).normalized;
}
else
{
Debug.LogError("FISH FIGHT WTF?");
}
}
fish.UpdateTargetSpeed();
return TaskStatus.Running;
}
private void CalcFightForce()
{
fightForceTimer -= Time.deltaTime;
if (!(fightForceTimer > 0f))
{
if (forceState == 0 || forceState == 4)
{
forceState = 2;
fightForceTimer = fightForceHoldAvgTime;
ChangeFightForce(fightForceAvg, fightForceChangeSpeed);
}
else if (forceState == 2)
{
forceState = ((!(Random.Range(0f, 1f) < Mathf.Lerp(0.25f, 0.7f, fish.DurabilityCurrentRatio))) ? 4 : 0);
fightForceTimer = ((forceState != 0) ? fightForceHoldLowTime : fightForceHoldHighTime);
ChangeFightForce((forceState != 0) ? fightForceMin : fightForceMax, fightForceChangeSpeed);
}
fightForceTimer *= Random.Range(0.7f, 1.3f);
}
}
public void ChangeFightForce(float target, float speed)
{
LeanTween.value(fightForce, target, speed).setOnUpdate(delegate(float val)
{
fightForce = val;
});
}
public void SetupDirection(bool firstSetup, bool dragMax)
{
if (fish.storedBait == null)
{
Debug.LogError("fish.storedBait");
}
else
{
if (fish.pullForce > 1f || fish.isJumping || (!fish.isJerked && fish.catchStyleCurrent == Fish.CatchStyle.STOP))
{
return;
}
if (firstSetup)
{
if (fish.catchStyleCurrent == Fish.CatchStyle.DOWN)
{
float x = 80f;
float y = 0f;
Vector3 position = fishingPlayer.transform.position;
position.y = 0f;
position = (transform.position - position).normalized;
position = Utilities.RotateVector(position, new Vector3(x, y, 0f));
moveDirection = position;
changeDirectionTimer = Time.time + Random.Range(2.4f, 2.5f);
}
}
else
{
if (fish.changeDirectionTimer > 0f)
{
return;
}
fish.changeDirectionTimer = fish.changeDirectionDelay;
bool flag = false;
if (dragChangeDirectionTimer > 0f)
{
dragChangeDirectionTimer -= Time.deltaTime;
if (dragChangeDirectionTimer < 0f)
{
dragChangeDirectionTimer = 0f;
}
}
if (!fish.TerrainCollision() && !flag && !dragMax)
{
Vector3 position2 = fishingPlayer.transform.position;
position2.y = transform.position.y;
position2 = (transform.position - position2).normalized;
float num = Random.Range(10f, 60f) * fish.DepthAggressivenessFight;
if (Random.Range(0f, 1f) < 0.5f)
{
num *= -1f;
}
float y2 = Random.Range(-90f, 90f) * (0.5f + fish.FromPlayerAggressiveness);
position2 = Utilities.RotateVector(position2, new Vector3(num, y2, 0f));
position2 = fish.UpdateRotationDepthStyle(position2, fish.fightDepthStyle, fish.fightDepthLevel);
moveDirection = position2;
float num2 = Mathf.Lerp(0.5f, 3f, 1f - fish.AggressivenessFight);
num2 += Random.Range(0f, 2f);
changeDirectionTimer = Time.time + num2;
}
else if (flag)
{
Vector3 normalized = (fish.storedBait.fishingHands.fishingRod.transform.position - transform.position).normalized;
normalized = Utilities.RotateVector(normalized, new Vector3(0f, Random.Range(-35f, 35f), 0f));
moveDirection = normalized;
Debug.Log("SetupDirection tooFar");
changeDirectionTimer = Time.time + Random.Range(1.5f, 2f);
}
else if (dragMax)
{
if (!(dragChangeDirectionTimer <= 0f))
{
return;
}
Vector3 position3 = fishingPlayer.transform.position;
position3.y = transform.position.y;
position3 = (transform.position - position3).normalized;
float num3 = dragMaxDirectionXValue;
float num4 = Random.Range(93f, Mathf.Lerp(93f, 130f, fish.FromPlayerAggressiveness));
if (dragMaxDirection)
{
num4 *= -1f;
}
if (dragMaxDirectionXTimer < 0f)
{
num3 = Random.Range(10f, 60f) * fish.DepthAggressivenessFight;
if (Random.Range(0f, 1f) < 0.5f)
{
num3 *= -1f;
}
dragMaxDirectionXTimer = Random.Range(1f, 8f);
dragMaxDirectionXValue = num3;
}
position3 = Utilities.RotateVector(position3, new Vector3(num3, num4, 0f));
position3 = fish.UpdateRotationDepthStyle(position3, fish.fightDepthStyle, fish.fightDepthLevel);
moveDirection = position3;
dragChangeDirectionTimer = 0.1f;
changeDirectionTimer = Time.time + Random.Range(0.3f, 0.8f);
}
else
{
Debug.Log("TerrainCollision");
moveDirection = (fish.Origin - transform.position).normalized;
changeDirectionTimer = Time.time + Random.Range(3f, 4f);
}
}
}
}
private void CheckDurabilityBoost()
{
fish.DurabilityBoost();
}
}