Files
UltimateFishing2020/Assets/Scripts/Assembly-CSharp/FReel.cs
2026-03-04 10:03:45 +08:00

675 lines
18 KiB
C#

using System;
using UFS2.Gameplay;
using UnityEngine;
using UnityEngine.Events;
public class FReel : MonoBehaviour
{
public enum Type
{
Normal = 0,
Casting = 1
}
[Serializable]
public class ReelingEvent : UnityEvent<float, Transform>
{
}
[Serializable]
public class ReelingUnityEvent : UnityEvent<float, float>
{
}
[Serializable]
public class SpoolUnityEvent : UnityEvent<float, Transform>
{
}
[Serializable]
public class ReelPlayTranform : UnityEvent<Transform>
{
}
public Type type;
public Transform armatureLHandUnlockPoster;
public Transform szpulaCenterPoint;
public Transform linePointSzpula;
public Transform linePointRoter;
public Transform lineFingerPoint;
public Transform handle;
public Transform BailHandle;
public Transform SpoolObject;
[HideInInspector]
public bool isBlockLineByFinger;
[HideInInspector]
public bool isBailOpen;
[HideInInspector]
public bool isHandOnHandle;
[SerializeField]
public float reelingSpeed = 1f;
private float currentReelingSpeed;
private float _reelingDrag = 1f;
private float reelSpeedFactor = 3f;
private float reelSpeedStep = 1f;
private float reelSpeedMax = 1f;
private float reelSpeedMin = 0.1f;
private float reelDragStep = 0.04f;
[HideInInspector]
public bool isDamaged;
public AudioClip[] audioClips;
public Animator animator;
[HideInInspector]
public FRod currentRod;
public float maxReelStrength = 10f;
public float currentReelStrength;
private bool lastBailState;
private float lastReelingSpeed;
private bool isLineOut;
private float lineOutAmount;
private float lastPhisicsLineOut;
private bool isFishFight;
private bool isReelDragSlow;
private bool isReelDragFast;
private float reelDragSlowAmount;
private float reelDragFastAmount;
public ReelPlayTranform OnReelDamaged;
public ReelPlayTranform OnDragValueChanged;
private float lineoutAnimSpeed;
public ReelPlayTranform OnSpeedValueChanged;
public ReelPlayTranform OnBailOpen;
public ReelPlayTranform OnBailClose;
public ReelingEvent OnReelingStart;
public ReelingEvent OnReelingStartDamaged;
public ReelingUnityEvent OnReeling;
public ReelPlayTranform OnReelingStop;
public ReelPlayTranform OnReelingStopDamaged;
public SpoolUnityEvent OnThrowSpoolUnwinding;
public SpoolUnityEvent OnThrowSpoolUnwindingWithDrag;
private bool isThrowingSoundPlayed;
private bool isReeling;
public float CurretnReelingSpeed
{
get
{
return currentReelingSpeed;
}
set
{
currentReelingSpeed = value;
}
}
[SerializeField]
public float reelingDrag
{
get
{
return _reelingDrag;
}
set
{
_reelingDrag = Mathf.Clamp01(value);
}
}
public float LinePullingForce => reelingDrag * maxReelStrength;
public float CurrentReelStrength01 => currentReelStrength / maxReelStrength;
public static event Action<Transform> OnReelDamagedGlobal;
public static event Action<Transform> OnDragValueChangedGlobal;
public static event Action<Transform> OnSpeedValueChangedGlobal;
public static event Action<Transform> OnBailOpenGlobal;
public static event Action<Transform> OnBailCloseGlobal;
public static event Action<float, Transform> OnReelingStartGlobal;
public static event Action<float, Transform> OnReelingStartDamagedGlobal;
public static event Action<float, float> OnReelingGlobal;
public static event Action<Transform> OnReelingStopGlobal;
public static event Action<Transform> OnReelingStopDamagedGlobal;
public static event Action<float, Transform> OnThrowSpoolUnwindingGlobal;
public static event Action<float, Transform> OnThrowSpoolUnwindingWithDragGlobal;
public static event Action<FReel> OnDamage;
public static event Action<float, Transform> OnLineOutStartGlobal;
public static event Action<float, float> OnLineOutGlobal;
public static event Action<Transform> OnLineOutStopGlobal;
public static event Action<float, Transform> OnLineBurstSmallStartGlobal;
public static event Action<float, float> OnLineBurstSmallGlobal;
public static event Action<Transform> OnLineBurstSmallStopGlobal;
public static event Action<float, Transform> OnLineBurstMediumStartGlobal;
public static event Action<float, float> OnLineBurstMediumGlobal;
public static event Action<Transform> OnLineBurstMediumStopGlobal;
public static event Action<float, Transform> OnReelDragSlowStartGlobal;
public static event Action<float, float> OnReelDragSlowGlobal;
public static event Action<Transform> OnReelDragSlowStopGlobal;
public static event Action<float, Transform> OnReelDragFastStartGlobal;
public static event Action<float, float> OnReelDragFastGlobal;
public static event Action<Transform> OnReelDragFastStopGlobal;
private void Start()
{
lastReelingSpeed = reelingSpeed;
}
private void Update()
{
if (!isHandOnHandle && CurretnReelingSpeed > 0f)
{
CurretnReelingSpeed = 0f;
animator.SetFloat("Reeling", CurretnReelingSpeed);
}
if (!currentRod)
{
return;
}
LineOutDragByFish();
if (!currentRod.currentPlayer || !currentRod.fishingLine.currentLineHandler)
{
return;
}
Reeling();
SoundsFX();
LineFX();
CalculateReeldStrength();
if (currentRod.currentPlayer.fishingMode == FPlayer.FishingMode.Manual)
{
isBlockLineByFinger = InputManager.isBlockLineFinger;
if (InputManager.isReelUnlockLock && CurretnReelingSpeed == 0f && !isHandOnHandle)
{
currentRod.currentPlayer.UnlockLockReel();
}
}
if (currentRod.fishingLine.currentLineHandler.PhisicsLineOut > 0f && !isHandOnHandle && !currentRod.isThrowing && !currentRod.currentPlayer.isLeftHandVisable)
{
if ((bool)handle)
{
currentRod.currentPlayer.InteractiveLeftHand(handle);
}
}
else
{
if (currentRod.fishingLine.currentLineHandler.PhisicsLineOut != 0f || !isHandOnHandle || currentRod.isThrowing)
{
return;
}
if ((bool)currentRod.currentFish)
{
if (currentRod.currentFish.isGetFish)
{
currentRod.currentPlayer.InteractiveLeftHand(null);
}
}
else
{
currentRod.currentPlayer.InteractiveLeftHand(null);
}
}
}
private void CalculateReeldStrength()
{
if ((bool)currentRod && (bool)currentRod.fishingLine && maxReelStrength != 0f)
{
currentReelStrength = currentRod.fishingLine.CurrentLineTension;
}
}
public void Damage()
{
if (!isDamaged && !TutorialManager.Instance)
{
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].SetWearRodReel(GameManager.ItemType.Reel, 0);
GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_DAMAGED"), FScriptsHandler.Instance.m_Canvas.transform);
OnReelDamaged?.Invoke(base.transform);
FReel.OnReelDamagedGlobal?.Invoke(base.transform);
isDamaged = true;
FReel.OnDamage?.Invoke(this);
FRod.OnEquipmentBreak?.Invoke(currentRod);
}
}
private void SoundsFX()
{
if (lastBailState != isBailOpen)
{
if (isBailOpen)
{
OnBailOpen?.Invoke(base.transform);
FReel.OnBailOpenGlobal?.Invoke(base.transform);
}
else
{
OnBailClose?.Invoke(base.transform);
FReel.OnBailCloseGlobal?.Invoke(base.transform);
}
lastBailState = isBailOpen;
isThrowingSoundPlayed = false;
}
if (CurretnReelingSpeed > 0f)
{
float num = 0.2f;
OnReeling?.Invoke(CurretnReelingSpeed * num, CurretnReelingSpeed * num);
FReel.OnReelingGlobal?.Invoke(CurretnReelingSpeed * num, CurretnReelingSpeed * num);
if (!isDamaged)
{
if (isReeling)
{
return;
}
OnReelingStart?.Invoke(CurretnReelingSpeed * num, base.transform);
FReel.OnReelingStartGlobal?.Invoke(CurretnReelingSpeed * num, base.transform);
isReeling = true;
}
else
{
if (isReeling)
{
return;
}
OnReelingStartDamaged?.Invoke(CurretnReelingSpeed * num, base.transform);
FReel.OnReelingStartDamagedGlobal?.Invoke(CurretnReelingSpeed * num, base.transform);
isReeling = true;
}
isThrowingSoundPlayed = false;
}
else if (!isDamaged)
{
if (!isReeling)
{
return;
}
OnReelingStop?.Invoke(base.transform);
FReel.OnReelingStopGlobal?.Invoke(base.transform);
isReeling = false;
}
else
{
if (!isReeling)
{
return;
}
OnReelingStopDamaged?.Invoke(base.transform);
FReel.OnReelingStopDamagedGlobal?.Invoke(base.transform);
isReeling = false;
}
if (animator.GetBool("LineOutunlock") && !currentRod.LureHookWaterDisplacement.IsInWater && currentRod.isThrowing && !isThrowingSoundPlayed)
{
OnThrowSpoolUnwinding?.Invoke(1f, base.transform);
FReel.OnThrowSpoolUnwindingGlobal?.Invoke(1f, base.transform);
isThrowingSoundPlayed = true;
}
else if (lineoutAnimSpeed > 0f)
{
Debug.Log("LineoutAnimSpeed transform: " + base.transform);
OnThrowSpoolUnwindingWithDrag?.Invoke(animator.GetFloat("LineOut"), base.transform);
FReel.OnThrowSpoolUnwindingWithDragGlobal?.Invoke(animator.GetFloat("LineOut"), base.transform);
}
}
private void LineFX()
{
float pitchMultiplier = 0.02f;
float num = (currentRod.fishingLine.currentLineHandler.PhisicsLineOut - lastPhisicsLineOut) * Time.deltaTime;
lastPhisicsLineOut = currentRod.fishingLine.currentLineHandler.PhisicsLineOut;
if (num > 0f && isBailOpen && currentRod.currentPlayer.throwMode != FPlayer.ThrowMode.Near && CurretnReelingSpeed <= 0f && FishEntity.CurrentFishInFight == null)
{
lineOutAmount = Mathf.MoveTowards(lineOutAmount, 1f, Time.deltaTime * 5f);
}
else
{
lineOutAmount = Mathf.MoveTowards(lineOutAmount, 0f, Time.deltaTime * 3f);
}
HandleEffect(lineOutAmount, pitchMultiplier, ref isLineOut, ref FReel.OnLineOutStartGlobal, ref FReel.OnLineOutGlobal, ref FReel.OnLineOutStopGlobal);
if (FishEntity.CurrentFishInFight == null)
{
if (isFishFight)
{
isFishFight = false;
FReel.OnLineBurstSmallStopGlobal?.Invoke(base.transform);
FReel.OnLineBurstMediumStopGlobal?.Invoke(base.transform);
}
}
else if (!isFishFight)
{
isFishFight = true;
if (reelingDrag < 0.95f)
{
pitchMultiplier = Mathf.Lerp(1f, 0.5f, reelingDrag);
if (FishEntity.CurrentFishInFight.Weight < 35f)
{
FReel.OnLineBurstSmallStartGlobal?.Invoke(pitchMultiplier, base.transform);
}
else
{
FReel.OnLineBurstMediumStartGlobal?.Invoke(pitchMultiplier, base.transform);
}
}
}
if (num <= 0f || FishEntity.CurrentFishInFight == null)
{
reelDragSlowAmount = Mathf.MoveTowards(reelDragSlowAmount, 0f, Time.deltaTime * 3f);
reelDragFastAmount = Mathf.MoveTowards(reelDragFastAmount, 0f, Time.deltaTime * 3f);
}
else if (num < 0.0007f)
{
reelDragSlowAmount = Mathf.MoveTowards(reelDragSlowAmount, 1f, Time.deltaTime * 15f);
reelDragFastAmount = Mathf.MoveTowards(reelDragFastAmount, 0f, Time.deltaTime * 3f);
}
else
{
reelDragSlowAmount = Mathf.MoveTowards(reelDragSlowAmount, 0f, Time.deltaTime * 3f);
reelDragFastAmount = Mathf.MoveTowards(reelDragFastAmount, 1f, Time.deltaTime * 15f);
}
pitchMultiplier = 1f;
HandleEffect(reelDragSlowAmount, pitchMultiplier, ref isReelDragSlow, ref FReel.OnReelDragSlowStartGlobal, ref FReel.OnReelDragSlowGlobal, ref FReel.OnReelDragSlowStopGlobal);
HandleEffect(reelDragFastAmount, pitchMultiplier, ref isReelDragFast, ref FReel.OnReelDragFastStartGlobal, ref FReel.OnReelDragFastGlobal, ref FReel.OnReelDragFastStopGlobal);
void HandleEffect(float effectAmount, float num2, ref bool isEffectPlaying, ref Action<float, Transform> onEffectStart, ref Action<float, float> onEffectPitch, ref Action<Transform> onEffectStop)
{
if (effectAmount > 0f)
{
if (!isEffectPlaying)
{
isEffectPlaying = true;
onEffectStart?.Invoke(effectAmount * num2, base.transform);
}
onEffectPitch?.Invoke(effectAmount * num2, effectAmount * num2);
}
else if (isEffectPlaying)
{
isEffectPlaying = false;
onEffectStop?.Invoke(base.transform);
}
}
}
private void PlayChangeDragSound()
{
}
private bool CanReel()
{
if (Singleton<AnglerViewFish>.Instance != null)
{
return false;
}
if (SRDebug.Instance.IsDebugPanelVisible)
{
return false;
}
return true;
}
private void Reeling()
{
if (!CanReel())
{
return;
}
if (InputManager.isReelSpeedUp)
{
reelingSpeed += Time.deltaTime * reelSpeedStep * 0.2f;
lastReelingSpeed = reelingSpeed;
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].SetReelSettings(0, reelingSpeed);
OnSpeedValueChanged?.Invoke(base.transform);
FReel.OnSpeedValueChangedGlobal?.Invoke(base.transform);
}
if (InputManager.isReelSpeedDown)
{
reelingSpeed -= Time.deltaTime * reelSpeedStep * 0.2f;
lastReelingSpeed = reelingSpeed;
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].SetReelSettings(0, reelingSpeed);
OnSpeedValueChanged?.Invoke(base.transform);
FReel.OnSpeedValueChangedGlobal?.Invoke(base.transform);
}
if (InputManager.isReelDragUp)
{
reelingDrag += reelDragStep;
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].SetReelSettings(1, reelingDrag);
FReel.OnDragValueChangedGlobal?.Invoke(base.transform);
}
if (InputManager.isReelDragDown)
{
reelingDrag -= reelDragStep;
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].SetReelSettings(1, reelingDrag);
FReel.OnDragValueChangedGlobal?.Invoke(base.transform);
}
if (FScriptsHandler.Instance.m_HudManager.selectorRodSetting == HudManager.SelectorRodSetting.Speed && Input.mouseScrollDelta.y != 0f && Time.timeScale != 0f)
{
reelingSpeed += Input.mouseScrollDelta.y * 0.04f;
lastReelingSpeed = reelingSpeed;
FReel.OnSpeedValueChangedGlobal?.Invoke(base.transform);
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].SetReelSettings(0, reelingSpeed);
}
if (FScriptsHandler.Instance.m_HudManager.selectorRodSetting == HudManager.SelectorRodSetting.Drag && Input.mouseScrollDelta.y != 0f && Time.timeScale != 0f)
{
reelingDrag += Input.mouseScrollDelta.y * 0.04f;
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].SetReelSettings(1, reelingDrag);
FReel.OnSpeedValueChangedGlobal?.Invoke(base.transform);
}
if (InputManager.isReelSpeedMax)
{
reelingSpeed = 1f;
}
else
{
reelingSpeed = lastReelingSpeed;
}
reelingSpeed = Mathf.Clamp(reelingSpeed, reelSpeedMin, reelSpeedMax);
reelingDrag = Mathf.Clamp(reelingDrag, 0f, 1f);
if (isDamaged)
{
reelingDrag = 0.5f;
}
if (!isHandOnHandle)
{
CurretnReelingSpeed = 0f;
animator.SetFloat("Reeling", CurretnReelingSpeed);
return;
}
if (InputManager.isReelReeling)
{
if (Mathf.Clamp01(currentRod.fishingLine.linelenghtDiferent) > 0.8f)
{
currentReelingSpeed = reelingSpeed * reelSpeedFactor * (1.5f - Mathf.Clamp01(currentRod.fishingLine.linelenghtDiferent));
}
else
{
currentReelingSpeed = reelingSpeed * reelSpeedFactor;
}
CurretnReelingSpeed = reelingSpeed * reelSpeedFactor * currentRod.currentPlayer.GetPlayerHandPower();
if (GameManager.Instance.controllerType == GameManager.ControllerType.GamePad && currentRod.currentFish != null && currentRod.fishingLine.linelenghtDiferent > 0.8f)
{
GameManager.Instance.ControllerVibrate(0.4f, 1);
}
if (FScriptsHandler.Instance.m_HudManager.lineCutTimer == 0f)
{
if (currentRod.fishingLine.linelenghtDiferent < 0f)
{
currentRod.fishingLine.currentLineHandler.PhisicsLineOut = Mathf.MoveTowards(currentRod.fishingLine.currentLineHandler.PhisicsLineOut, 0f, Time.deltaTime * CurretnReelingSpeed * 2f);
}
else
{
currentRod.fishingLine.currentLineHandler.PhisicsLineOut = Mathf.MoveTowards(currentRod.fishingLine.currentLineHandler.PhisicsLineOut, 0f, Time.deltaTime * CurretnReelingSpeed);
}
}
if (currentRod.fishingLine.currentLineHandler.PhisicsLineOut == 0f && isHandOnHandle)
{
currentRod.currentPlayer.InteractiveLeftHand(null);
InputManager.ResetMouseButtonsTriggers();
}
}
else
{
CurretnReelingSpeed = 0f;
}
animator.SetFloat("Reeling", CurretnReelingSpeed);
if (isBailOpen && CurretnReelingSpeed > 0f)
{
isBailOpen = false;
animator.SetBool("Lock", value: true);
}
}
private void LineOutDragByFish()
{
if (!isBailOpen)
{
if ((bool)currentRod.currentFish || (bool)currentRod.takeFish)
{
if ((bool)currentRod.currentFish && currentRod.currentFish.isGetFish)
{
lineoutAnimSpeed = 0f;
animator.SetFloat("LineOut", lineoutAnimSpeed);
return;
}
float num = maxReelStrength * reelingDrag;
float num2 = 0f;
if ((bool)currentRod.currentFish)
{
num2 = currentRod.currentFish.fishWeight * Mathf.Clamp01(currentRod.fishingLine.linelenghtDiferent);
}
if ((bool)currentRod.takeFish)
{
num2 = currentRod.takeFish.fishWeight * Mathf.Clamp01(currentRod.fishingLine.linelenghtDiferent);
}
if (num2 > num && reelingDrag < 1f)
{
currentRod.fishingLine.currentLineHandler.PhisicsLineOut += Time.deltaTime * (5f + currentRod.fishingLine.currentLineStrenght) * (1f - reelingDrag);
lineoutAnimSpeed = (1f + Mathf.Clamp01(currentRod.fishingLine.linelenghtDiferent)) * (1f - reelingDrag);
}
else
{
lineoutAnimSpeed = Mathf.MoveTowards(lineoutAnimSpeed, 0f, Time.deltaTime * 0.2f);
}
}
else
{
lineoutAnimSpeed = 0f;
}
animator.SetFloat("LineOut", lineoutAnimSpeed);
}
if (isBailOpen && !isBlockLineByFinger)
{
if (currentRod.fishingLine.linelenghtDiferent > 0f)
{
currentRod.fishingLine.currentLineHandler.PhisicsLineOut += currentRod.fishingLine.linelenghtDiferent * 1f;
animator.SetBool("LineOutunlock", value: true);
}
else
{
animator.SetBool("LineOutunlock", value: false);
}
}
else
{
animator.SetBool("LineOutunlock", value: false);
}
}
public void LockUnlockKablag()
{
if (type == Type.Casting)
{
isBailOpen = !isBailOpen;
return;
}
animator.SetBool("Unlock", value: false);
animator.SetBool("Lock", value: false);
if (!isBailOpen)
{
animator.SetBool("Unlock", value: true);
}
else
{
animator.SetBool("Lock", value: true);
}
}
private void CheckIsBaitIsInWaterAndLockReel()
{
Debug.Log("Double");
if (isBailOpen)
{
currentRod.currentPlayer.InteractiveLeftHand(handle);
}
}
}