using System; using System.Collections; using System.Collections.Generic; using System.Linq; using GPUInstancer; using Obvious.Soap; using UFS2.Gameplay; using UnityEngine; using UnityStandardAssets.Characters.FirstPerson; public class FPlayer : MonoBehaviour { public enum FishingMode { Manual = 0, Automatic = 1 } public enum ThrowMode { None = 0, Near = 1, Far = 2 } public enum FishSize { VerySmall = 1, Small = 6, Medium = 35, Big = 100 } public FishingMode fishingMode = FishingMode.Automatic; public ThrowMode throwMode; public Camera m_Camera; public Transform CameraTransform; public Camera m_EagleCamera; public Transform FirstPersonCharacter; public GameObject flashLight; public FirstPersonController firstPersonController; public FullBodyAvatar fullBodyAvatar; public float MouseSensitivityY = 2f; public float MouseSensitivityX = 2f; public FRod assignRod; [HideInInspector] public FRod currentRod; [HideInInspector] public Chwytak currentChwytak; public bool isLeftHandVisable; [HideInInspector] public Transform currentNearThrowTarget; public float notValidTargetValue; [HideInInspector] public Camera currentCameraView; [HideInInspector] public GameObject underWaterCamera; public AnglerViewFish currentAnglerFishView; [HideInInspector] public bool isZoom; [HideInInspector] public float lastCameraFov; [SerializeField] private UnityStandardAssets.Characters.FirstPerson.MouseLook m_MouseLook; private CharacterController characterController; [HideInInspector] private float walkingSpeed = 1f; private float runningSpeed = 2f; private float throwDelay = 2f; private bool isLeftHandConnectLine; private float walkSpeedInWater = 1.7f; private float runSpeedInWater = 2.5f; private bool _PlayerFirstUpdate; private bool isPickingFish; private Vector3 lastPlayerPos; private Vector3 lastBoatPos; [SerializeField] private BoolVariable IsThrowFarPreparing; [SerializeField] private BoolVariable IsThrowFar; [SerializeField] private BoolVariable IsThrowNearPreparing; [SerializeField] private BoolVariable IsThrowNear; [SerializeField] private FloatVariable ThrowPower; [SerializeField] private BoolVariable isFishCanTaken; [SerializeField] private Vector3Variable player_CurrentPosition; [SerializeField] private Vector2Variable fishMaxWeightToHandsPower; private float fishTakeTime; private Vector3 lastSafeLandPosition; [HideInInspector] public float handPullUp; private float rotRodLeftRight; private float rotRodUpDown; private float throwTimer; private FRod currentRodInHand; private Dictionary currentRodRenderers; private List splashStepList = new List(); private float delayStepSplash = 0.5f; public Transform CameraPivot { get { if (fullBodyAvatar == null) { fullBodyAvatar = FullBodyAvatar.GetAvatar(); } return fullBodyAvatar.CameraPoint; } } public FullBodyAvatar FullBodyAvatar { get { if (fullBodyAvatar == null) { fullBodyAvatar = FullBodyAvatar.GetAvatar(); } return fullBodyAvatar; } } private float fishTakeTimeTarget => 2f; public static event Action OnChangeCameraToUnderwater; public static event Action OnChangeCameraOutUnderwater; public static event Action OnPlayerFirstUpdate; public static event Action OnFishPicking; public static event Action OnFishPicked; public static event Action OnThrowFar; public static event Action OnThrowNear; public static event Action OnRodJam; private void Start() { GameManager.Instance.SetMouseCurrsor(val: false); m_Camera = Camera.main; m_EagleCamera.enabled = false; currentCameraView = m_Camera; characterController = GetComponent(); firstPersonController = GetComponent(); FScriptsHandler.Instance.AffectDisplaySetting(); FScriptsHandler.Instance.AffectGraphicsSetting(); FScriptsHandler.Instance.AffectControlsSetting(); FScriptsHandler.Instance.AffectPostProccesingFromSettings(); walkingSpeed = firstPersonController.m_WalkSpeed; runningSpeed = firstPersonController.m_RunSpeed; lastCameraFov = m_Camera.fieldOfView; fullBodyAvatar = FullBodyAvatar.GetAvatar(); fullBodyAvatar.transform.SetParent(base.transform); fullBodyAvatar.transform.SetLocalPositionAndRotation(new Vector3(0f, -1f, 0f), Quaternion.identity); fullBodyAvatar.SetGender(Singleton.Instance.GetCurrentPlayerData().PlayerSexIndex == 0); fullBodyAvatar.ShowHead(toggle: false); firstPersonController.cameraTransform = CameraPivot; firstPersonController.m_MouseLook.Init(base.transform, CameraPivot); InputManager.isHeadFlashLight = false; flashLight.SetActive(value: false); flashLight.transform.SetParent(fullBodyAvatar.CameraPoint); flashLight.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity); RandomizeSpawnPointInMultiplayer(); } private void Update() { if (Singleton.Instance != null) { return; } if (_PlayerFirstUpdate) { FPlayer.OnPlayerFirstUpdate?.Invoke(); _PlayerFirstUpdate = true; } firstPersonController.horizontal = InputManager.movementAxis.x; firstPersonController.vertical = InputManager.movementAxis.y; firstPersonController.isJumping = InputManager.isJumping; firstPersonController.isRuning = InputManager.isRunning; firstPersonController.m_MouseLook.ControllerHandMode = GameManager.Instance._playerData.Player[GameManager.Instance._playerData.currentPlayerProfileIndex].controllerSetup; player_CurrentPosition.Value = base.transform.position; CheckAndConnectRod(); HandsAnimation(); ThrowInput(); UnderWaterCameraControler(); DetectWaterStep(); FlashlightHandler(); PickFishHandler(); ViewAnglerHandler(); PreventWalkUnderWaterHandler(); if (firstPersonController.isWater) { firstPersonController.m_WalkSpeed = walkSpeedInWater; firstPersonController.m_RunSpeed = runSpeedInWater; } else { firstPersonController.m_WalkSpeed = Mathf.Lerp(firstPersonController.m_WalkSpeed, walkingSpeed * GetReelingForce(), Time.deltaTime * 8f); firstPersonController.m_RunSpeed = Mathf.Lerp(firstPersonController.m_RunSpeed, runningSpeed * GetReelingForce(), Time.deltaTime * 8f); } firstPersonController.m_MouseLook.XSensitivity = Mathf.Lerp(firstPersonController.m_MouseLook.XSensitivity, Singleton.Instance.SettingsData.MouseSensitivityValue * GetPlayerHandPower(), Time.deltaTime * 8f); firstPersonController.m_MouseLook.YSensitivity = Mathf.Lerp(firstPersonController.m_MouseLook.YSensitivity, Singleton.Instance.SettingsData.MouseSensitivityValue * GetPlayerHandPower(), Time.deltaTime * 8f); if (!currentRod) { for (int i = 0; i < Singleton.Instance.GetCurrentPlayerData().PlayerRods.Count; i++) { if (Singleton.Instance.GetCurrentPlayerData().PlayerRods[i].status == GameManager.PlayerData.CRods.Status.InUse) { Singleton.Instance.GetCurrentPlayerData().PlayerRods[i].status = GameManager.PlayerData.CRods.Status.InEquip; } } return; } if (throwDelay > 0f && !currentRod.isThrowing) { throwDelay = Mathf.MoveTowards(throwDelay, 0f, Time.deltaTime); } if (!Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].rod.isNull) { if (currentRod.CheckIsInUse()) { Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].rod.status = GameManager.PlayerData.CRods.Status.InUse; } else { Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].rod.status = GameManager.PlayerData.CRods.Status.InHand; } } } private void FixedUpdate() { Vector3 velocity = Vector3.zero; Vector3 baselineVelocity = Vector3.zero; if (Time.fixedDeltaTime > 0f) { velocity = (base.transform.position - lastPlayerPos) / Time.fixedDeltaTime; lastPlayerPos = base.transform.position; if ((bool)Singleton.Instance) { if ((bool)Singleton.Instance.currentPlayerCharacter) { baselineVelocity = (Singleton.Instance.transform.position - lastBoatPos) / Time.fixedDeltaTime; } lastBoatPos = Singleton.Instance.transform.position; } } fullBodyAvatar.MovementAnimation(firstPersonController.transform.forward, firstPersonController.transform.right, velocity, baselineVelocity, firstPersonController.m_WalkSpeed, firstPersonController.m_RunSpeed); } private void OnEnable() { OnFishPicked += PickFishEvent; FishCatchPanel.OnFishKeepGlobal += FishCatchPanel_OnFishKeepGlobal; FishEntity.OnPreSpitOutBait += FishEntity_OnPreSpitOutBait; FishEntityManager.AddTransformCull(base.transform); FirstPersonController.OnJumpGlobal += FirstPersonController_OnJumpGlobal; FirstPersonController.OnLandingGlobal += FirstPersonController_OnLandingGlobal; } private void OnDisable() { OnFishPicked -= PickFishEvent; FishCatchPanel.OnFishKeepGlobal -= FishCatchPanel_OnFishKeepGlobal; FishEntity.OnPreSpitOutBait -= FishEntity_OnPreSpitOutBait; FishEntityManager.RemoveTransformCull(base.transform); FirstPersonController.OnJumpGlobal -= FirstPersonController_OnJumpGlobal; FirstPersonController.OnLandingGlobal -= FirstPersonController_OnLandingGlobal; } private void OnDestroy() { Singleton.Instance.ResetRodStatuses(); } private void FishEntity_OnPreSpitOutBait(FishEntity fish) { isFishCanTaken.Value = false; fish.rod.fishingLine.currentLineHandler.EndLineRigidbody.isKinematic = false; } private void FirstPersonController_OnJumpGlobal(Transform t) { FullBodyAvatar.Jump(); } private void FirstPersonController_OnLandingGlobal(Transform t) { FullBodyAvatar.Land(); } private void PickFishHandler() { if (FishEntity.CurrentFishInFight == null || !isFishCanTaken.Value || FishEntity.CurrentFishInFight.IsCatched) { ResetTimer(); return; } if (InputManager.isPullUpRod) { fishTakeTime = Mathf.MoveTowards(fishTakeTime, fishTakeTimeTarget, Time.deltaTime); } else { ResetTimer(); } FPlayer.OnFishPicking?.Invoke(fishTakeTime / fishTakeTimeTarget); if (fishTakeTime == fishTakeTimeTarget) { ResetTimer(); FPlayer.OnFishPicked?.Invoke(); } void ResetTimer() { fishTakeTime = (((bool)FishEntity.CurrentFishInFight && !FishEntity.CurrentFishInFight.IsCatched && isFishCanTaken.Value) ? 0.01f : 0f); FPlayer.OnFishPicking?.Invoke(fishTakeTime); } } private void ViewAnglerHandler() { if (FishEntity.CurrentFishInFight == null || FishEntity.CurrentFishInFight.Weight >= 35f || !GameManager.Instance.fishCatchPanel) { InputManager.isCameraChange = false; } else if (InputManager.isCameraChange) { if ((bool)currentAnglerFishView) { DestroyFishViewAngler(); } else { ViewAngler(); } } } private void PreventWalkUnderWaterHandler() { Vector3 position = base.transform.position; if (GameWaterSystem.FindWaterLevelAtLocation(position, out var waterLevel)) { float num = waterLevel - position.y; if (num <= -0.1f) { lastSafeLandPosition = position; } else if (!(num <= 0f)) { base.transform.position = lastSafeLandPosition; firstPersonController.lastValidPosition = lastSafeLandPosition; } } else { lastSafeLandPosition = position; } } private void IsFishCanTaken_OnValueChanged(bool isCanTaken) { if ((bool)FishEntity.CurrentFishInFight) { Vector3.Distance(base.transform.position, FishEntity.CurrentFishInFight.transform.position); } if (handPullUp > 0f && isCanTaken && !isPickingFish && (bool)FishEntity.CurrentFishInFight) { isPickingFish = true; StopCoroutine("Timer"); StartCoroutine(Timer(isPickingFish)); } else if (!isCanTaken && isPickingFish) { isPickingFish = false; StopCoroutine("Timer"); StartCoroutine(Timer(isPickingFish)); } static IEnumerator Timer(bool isPicking) { if (isPicking) { float startTime = Time.time; float takeTimeInterval = 3.5f; float takeTime = startTime + takeTimeInterval; while (Time.time < takeTime) { FPlayer.OnFishPicking?.Invoke((Time.time - startTime) / takeTimeInterval); Debug.Log(">>>>>>>>>>>>>>>>>>>TRY PICK"); yield return null; } if ((bool)FishEntity.CurrentFishInFight) { FPlayer.OnFishPicked?.Invoke(); } } else { FPlayer.OnFishPicking?.Invoke(0f); Debug.Log("NOT PICK <<<<<<<<<<<<<<<<<<<<<<"); } } } public float GetCurrentGearStrength() { if (!currentRod) { return 1f; } if (!currentRod.currentReel) { return 1f; } if (!currentRod.currentLine) { return 1f; } float maxRodStrength = currentRod.maxRodStrength; float maxReelStrength = currentRod.currentReel.maxReelStrength; float strength = currentRod.currentLine.strength; return Mathf.Min(maxRodStrength, maxReelStrength, strength); } private void FishCatchPanel_OnFishKeepGlobal() { isPickingFish = false; currentRod.fishingLine.currentLineHandler.EndLineRigidbody.isKinematic = false; } private void PickFishEvent() { float weight = FishEntity.CurrentFishInFight.Weight; if (weight < 1f) { FishConnectToLHand(); } else if (weight < 6f) { FishConnectToLHandWithChwytak(); } else if (weight < 35f) { FishConnectToNone(); } else { FishConnectToNone(); } } private void BuildDestroyChwytak(bool destroy = false) { if (!currentChwytak && !destroy) { currentChwytak = UnityEngine.Object.Instantiate(FScriptsHandler.Instance.ChwytakPrefab, FullBodyAvatar.ChwytakJoiner).GetComponent(); currentChwytak.transform.localPosition = Vector3.zero; currentChwytak.transform.localEulerAngles = Vector3.zero; currentChwytak.currentFish = FishEntity.CurrentFishInFight; currentChwytak.currentFish.ReJoinChwytak(currentChwytak.fishJoint); } if ((bool)currentChwytak && destroy) { FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.Idle); UnityEngine.Object.Destroy(currentChwytak.gameObject); currentChwytak = null; } } public void DestroyCurrentFish() { FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.Idle); } private void FishConnectToLHand() { if (FullBodyAvatar.CurrentArmLeftState != FullBodyAvatar.ArmLeft.Catch) { InteractiveLeftHand(null); FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.Catch); } if (currentRod.fishingLine.currentLineHandler.lineType == FLineHandler.LineType.OneSegment) { PutLineToLeftHandHelper(currentRod.fishingLine.currentLineHandler.EndLineRigidbody.transform, FullBodyAvatar.LineJoinerFish, 3f); } else { PutLineToLeftHandHelper(currentRod.fishingLine.currentLineHandler.EndLineRigidbody.transform, FullBodyAvatar.LineJoinerFish, 3f); } firstPersonController.frezzePosition = true; firstPersonController.frezzeRotation = true; isLeftHandVisable = true; } private void FishConnectToLHandWithChwytak() { if (FullBodyAvatar.CurrentArmLeftState != FullBodyAvatar.ArmLeft.CatchChwytak) { InteractiveLeftHand(null); FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.CatchChwytak); } if (currentRod.fishingLine.currentLineHandler.lineType == FLineHandler.LineType.OneSegment) { PutLineToLeftHandHelper(currentRod.fishingLine.currentLineHandler.EndLineRigidbody.transform, FullBodyAvatar.ChwytakJoiner, 4f, buildChwytak: true); } else { PutLineToLeftHandHelper(currentRod.fishingLine.currentLineHandler.EndLineRigidbody_2.transform, FullBodyAvatar.ChwytakJoiner, 4f, buildChwytak: true); } firstPersonController.frezzePosition = true; firstPersonController.frezzeRotation = true; isLeftHandVisable = true; } private void FishConnectToNone() { ViewAngler(); firstPersonController.frezzePosition = true; firstPersonController.frezzeRotation = true; if (!isLeftHandVisable) { InteractiveLeftHand(null); } isLeftHandVisable = true; } public float GetReelingForce() { float num = 1f; if ((bool)currentRod && (bool)currentRod.fishingLine && (bool)FishEntity.CurrentFishInFight) { float num2 = Mathf.Clamp01(currentRod.fishingLine.linelenghtDiferent); num -= 0.2f; float num3 = Mathf.Lerp(0f, fishMaxWeightToHandsPower.Value.y, FishEntity.CurrentFishInFight.Weight / fishMaxWeightToHandsPower.Value.x); num -= num2 * num3; } return Mathf.Clamp(num, 0.1f, 1f); } public float GetPlayerHandPower() { float num = 0.85f; if ((bool)currentRod && (bool)currentRod.fishingLine) { float num2 = 0f; if (Singleton.Instance.HasCurrentPlayerSkill(GameManager.Skills.strongman_10p)) { num2 = 0.1f; } else if (Singleton.Instance.HasCurrentPlayerSkill(GameManager.Skills.strongman_5p)) { num2 = 0.05f; } num += num2; float num3 = Mathf.Clamp01(currentRod.fishingLine.linelenghtDiferent); if (!FishEntity.CurrentFishInFight) { num -= num3 * 0.2f; } else { num -= 0.3f; float num4 = Mathf.Lerp(0f, fishMaxWeightToHandsPower.Value.y, FishEntity.CurrentFishInFight.Weight / fishMaxWeightToHandsPower.Value.x); num -= num3 * num4; } } return Mathf.Clamp(num, 0.2f, 1.2f); } private bool CheckLineLenght() { float lenght = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].line.lenght; float num = 0f; if (throwMode == ThrowMode.Near) { float value = (0f - m_Camera.transform.localRotation.x) * 10f; value = (3f + Mathf.Clamp(value, -2f, 0f)) * 4f; Vector3 b = base.transform.position + base.transform.forward * value; num = Vector3.Distance(base.transform.position, b); } else { float num2 = 0f; if ((bool)currentRod.currentLure) { int indexByItemId = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Bait, currentRod.currentLure.gameID); num2 += GameManager.Instance.gameBaits[indexByItemId].weight; } if ((bool)currentRod.currentWeight) { num2 += currentRod.currentWeight.weight; } Vector3 b2 = base.transform.position + base.transform.forward * ((currentRod.throwForceMaxPower + num2) * currentRod.throwPower); num = Vector3.Distance(base.transform.position, b2); } Debug.Log("throwDistance: " + num); if (num > lenght) { return false; } return true; } private float GetMaxThrowLength() { float lenght = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].line.lenght; float num = 0f; if (throwMode == ThrowMode.Near) { float value = (0f - m_Camera.transform.localRotation.x) * 10f; value = (3f + Mathf.Clamp(value, -2f, 0f)) * 4f; Vector3 b = base.transform.position + base.transform.forward * value; num = Vector3.Distance(base.transform.position, b); } else { float num2 = 0f; if ((bool)currentRod.currentLure) { int indexByItemId = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Bait, currentRod.currentLure.gameID); num2 += GameManager.Instance.gameBaits[indexByItemId].weight; } if ((bool)currentRod.currentWeight) { num2 += currentRod.currentWeight.weight; } Vector3 b2 = base.transform.position + base.transform.forward * ((currentRod.throwForceMaxPower + num2) * currentRod.throwPower); num = Vector3.Distance(base.transform.position, b2); } return Mathf.Clamp(num, 0f, lenght); } private void ThrowInput() { if (FishEntity.CurrentFishInFight != null) { return; } if (!currentRod) { FScriptsHandler.Instance.m_HudManager.ShowHideThrowingBar(visable: false); FullBodyAvatar.ReelLockUnlockReset(); FullBodyAvatar.ThrowReset(); } if ((bool)currentRod && (bool)currentRod.currentReel && !currentRod.currentFish && !currentRod.takeFish) { if (InputManager.isCastFar) { PrepareFarThrow(); } else { ThrowFar(); } if (InputManager.isCastNear) { PrepareNearThrow(); } else { ThrowNear(); } } } private void PrepareFarThrow() { if ((bool)currentRod && (bool)currentRod.currentReel && (bool)currentRod.fishingLine && !currentRod.currentReel.isHandOnHandle && !currentRod.currentReel.isBailOpen && !FullBodyAvatar.IsThrowInProgress && !(currentRod.fishingLine.currentLineHandler.PhisicsLineOut > 0f) && !(throwDelay > 0f) && !Time.timeScale.Equals(0f)) { if (currentRod.isDamaged) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("ROD_DAMAGE"), FScriptsHandler.Instance.m_Canvas.transform); return; } if (currentRod.currentReel.isDamaged) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("REEL_DAMAGE"), FScriptsHandler.Instance.m_Canvas.transform); return; } if (!currentRod.currentLure && !currentRod.currentHook) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("BAIT_ON_HOOK_EMPTY"), FScriptsHandler.Instance.m_Canvas.transform); return; } if (Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].status != GameManager.PlayerData.CSlots.Status.Completed) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_EMPTY"), FScriptsHandler.Instance.m_Canvas.transform); return; } throwMode = ThrowMode.Far; ThrowPower.Value = Mathf.Lerp(0f, 1f, Mathf.PingPong(throwTimer, 1f)); IsThrowFarPreparing.Value = true; throwTimer += Time.deltaTime * 0.7f; currentRod.throwPower = Mathf.Lerp(0f, 1f, Mathf.PingPong(throwTimer, 1f)); currentRod.throwPowerForSounds = currentRod.throwPower; currentRod.isThrowing = true; FScriptsHandler.Instance.m_HudManager.ShowHideThrowingBar(visable: true, currentRod.throwPower, currentRod.throwMinPower); } } private void ThrowFar() { if (throwMode == ThrowMode.Far && (bool)currentRod && (bool)currentRod.fishingLine.currentLineHandler && currentRod.throwPower != 0f && !(currentRod.fishingLine.currentLineHandler.PhisicsLineOut > 0f) && !Time.timeScale.Equals(0f)) { FScriptsHandler.Instance.m_HudManager.ShowHideThrowingBar(visable: false); IsThrowFar.Value = true; float num = 0f; if ((bool)currentRod.currentLure) { int indexByItemId = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Bait, currentRod.currentLure.gameID); num += GameManager.Instance.gameBaits[indexByItemId].weight; } if ((bool)currentRod.currentWeight) { num += currentRod.currentWeight.weight; } currentRod.throwForcePower = GetMaxThrowLength(); currentRod.throwPower = 0f; FullBodyAvatar.Throw(FullBodyAvatar.ThrowMethod.Far); FPlayer.OnThrowFar?.Invoke(this); Debug.Log("Throw far Power: " + (currentRod.throwForceMaxPower + num)); throwMode = ThrowMode.None; throwDelay = 2f; throwTimer = 0f; } } private void PrepareNearThrow() { if (!currentRod || !currentRod.currentReel || !currentRod.fishingLine || FullBodyAvatar.IsThrowInProgress || currentRod.currentReel.isHandOnHandle || (currentRod.fishingLine.currentLineHandler.PhisicsLineOut > 0f && throwMode == ThrowMode.None) || throwDelay > 0f) { return; } if (currentRod.isDamaged) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("ROD_DAMAGE"), FScriptsHandler.Instance.m_Canvas.transform); return; } if (currentRod.currentReel.isDamaged) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("REEL_DAMAGE"), FScriptsHandler.Instance.m_Canvas.transform); return; } if (!currentRod.currentLure && !currentRod.currentHook) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("BAIT_ON_HOOK_EMPTY"), FScriptsHandler.Instance.m_Canvas.transform); return; } if (Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].status != GameManager.PlayerData.CSlots.Status.Completed) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_EMPTY"), FScriptsHandler.Instance.m_Canvas.transform); return; } if (isLeftHandConnectLine) { throwTimer += Time.deltaTime * 0.7f; currentRod.throwPower = Mathf.Lerp(0f, 1f, Mathf.PingPong(throwTimer, 1f)); currentRod.throwPowerForSounds = currentRod.throwPower * 0.3f; currentRod.throwNearPower = currentRod.throwPower; FScriptsHandler.Instance.m_HudManager.ShowHideThrowingBar(visable: true, currentRod.throwPower, currentRod.throwMinNearPower); float value = (0f - m_Camera.transform.localRotation.x) * 10f; value = (3f + Mathf.Clamp(value, -2f, 0f)) * 4f; Vector3 vector = base.transform.position + base.transform.forward * value; ShowHideNearThrowTarget(vector); float value2 = Vector3.Distance(vector, base.transform.position) / 12f; notValidTargetValue = FScriptsHandler.Instance.m_HudManager.currentCanvasThrowinigBar.GetComponent().SetTargetBar(value2, 1f); } if (!currentRod.currentReel.isBailOpen && throwMode == ThrowMode.None) { FullBodyAvatar.ReelControl(reelUnlock: true); } else if (currentRod.currentReel.isBailOpen) { FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.CastNear); PutLineToLeftHandHelper(currentRod.fishingLine.currentLineHandler.LineConnector_1.transform, FullBodyAvatar.LineJoiner, 3f); currentRod.isThrowing = true; } throwMode = ThrowMode.Near; IsThrowNearPreparing.Value = true; } private void ThrowNear() { if (throwMode != ThrowMode.Near || !currentRod || !currentRod.fishingLine.currentLineHandler) { return; } FScriptsHandler.Instance.m_HudManager.ShowHideThrowingBar(visable: false); IsThrowFar.Value = true; if (currentRod.throwPower == 0f) { FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.Idle); if (currentRod.currentReel.isBailOpen) { currentRod.currentReel.LockUnlockKablag(); } OutLineFromLeftHandHelper(currentRod.fishingLine.currentLineHandler.LineConnector_1.transform); throwMode = ThrowMode.None; throwTimer = 0f; currentRod.isThrowing = false; ShowHideNearThrowTarget(Vector3.zero, isHide: true); return; } if (currentRod.throwPower < currentRod.throwMinNearPower || !isLeftHandConnectLine || !CheckLineLenght()) { if (!CheckLineLenght()) { GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("LOW_LINE_LENGHT"), FScriptsHandler.Instance.m_Canvas.transform); } currentRod.throwPower = 0f; if (currentRod.currentReel.isBailOpen) { currentRod.currentReel.LockUnlockKablag(); } FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.Idle); OutLineFromLeftHandHelper(currentRod.fishingLine.currentLineHandler.LineConnector_1.transform); throwMode = ThrowMode.None; currentRod.isThrowing = false; throwDelay = 2f; ShowHideNearThrowTarget(Vector3.zero, isHide: true); return; } float num = 0f; if ((bool)currentRod.currentLure) { int indexByItemId = GameManager.Instance.GetIndexByItemId(GameManager.ItemType.Bait, currentRod.currentLure.gameID); num += GameManager.Instance.gameBaits[indexByItemId].weight; } if ((bool)currentRod.currentWeight) { num += currentRod.currentWeight.weight; } currentRod.throwForcePower = (currentRod.throwForceMaxNearPower + num) * currentRod.throwPower; currentRod.throwPower = 0f; Debug.Log("Throw near Power: " + (currentRod.throwForceMaxNearPower + num)); FullBodyAvatar.Throw(FullBodyAvatar.ThrowMethod.Near); FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.Idle); FPlayer.OnThrowNear?.Invoke(this); throwMode = ThrowMode.None; throwDelay = 2f; throwTimer = 0f; } public void ShowHideNearThrowTarget(Vector3 targetPosition, bool isHide = false) { if (isHide && !currentNearThrowTarget) { return; } if ((bool)currentNearThrowTarget) { if (isHide) { UnityEngine.Object.Destroy(currentNearThrowTarget.gameObject); return; } GameWaterSystem.FindWaterLevelAtLocation(targetPosition, out var waterLevel); targetPosition.y = waterLevel; currentNearThrowTarget.position = targetPosition; } else { currentNearThrowTarget = UnityEngine.Object.Instantiate(FScriptsHandler.Instance.nearThrowTargetPrefab, FScriptsHandler.Instance.transform).GetComponent(); } } private void PutLineToLeftHandHelper(Transform connector, Transform lHandPoint, float speed = 1f, bool buildChwytak = false) { connector.GetComponent().isKinematic = true; isLeftHandConnectLine = false; connector.position = Vector3.MoveTowards(connector.position, lHandPoint.position, Time.deltaTime * speed); currentRod.fishingLine.currentLineHandler.PhisicsLineOut = Vector3.Distance(connector.position, currentRod.fishingLine.currentLineHandler.LineConnector_0.transform.position) * 0.5f; if ((bool)FishEntity.CurrentFishInFight) { FishEntity.CurrentFishInFight.Physics.Rbody.useGravity = false; } if ((bool)FishEntity.CurrentFishInFight && currentRod.fishingLine.currentLineHandler.lineType == FLineHandler.LineType.TwoSegment) { Rigidbody endLineRigidbody_ = currentRod.fishingLine.currentLineHandler.EndLineRigidbody_1; endLineRigidbody_.isKinematic = true; endLineRigidbody_.position = Vector3.MoveTowards(endLineRigidbody_.position, lHandPoint.position, Time.deltaTime * speed); } if (buildChwytak) { BuildDestroyChwytak(); } Transform parent = (currentChwytak ? currentChwytak.fishJoint.transform : lHandPoint); currentRod.fishingLine.currentLineHandler.transform.SetParent(currentRod.transform); currentRod.fishingLine.currentLineHandler.transform.localPosition = Vector3.zero; connector.SetParent(parent); connector.localPosition = Vector3.zero; currentRod.fishingLine.currentLineHandler.PhisicsLineOut = Vector3.Distance(connector.position, currentRod.fishingLine.currentLineHandler.LineConnector_0.transform.position); isLeftHandConnectLine = true; if ((bool)FishEntity.CurrentFishInFight) { FishEntity.CurrentFishInFight.Physics.Rbody.useGravity = true; if ((bool)FishEntity.CurrentFishInFight.Physics.Collider) { FishEntity.CurrentFishInFight.Physics.Collider.enabled = true; } if (currentRod.fishingLine.currentLineHandler.lineType == FLineHandler.LineType.TwoSegment) { Rigidbody endLineRigidbody_2 = currentRod.fishingLine.currentLineHandler.EndLineRigidbody_1; endLineRigidbody_2.transform.SetParent(parent); endLineRigidbody_2.transform.localPosition = Vector3.zero; currentRod.currentFloat.transform.position = endLineRigidbody_2.position; currentRod.currentFloat.rigidbody.velocity = Vector3.zero; currentRod.currentFloat.rigidbody.angularVelocity = Vector3.zero; currentRod.currentFloat.rigidbody.useGravity = true; endLineRigidbody_2.isKinematic = false; } FullBodyAvatar.LookAtFishInHand(); } } public void OutLineFromLeftHandHelper(Transform connector) { connector.GetComponent().isKinematic = false; currentRod.fishingLine.currentLineHandler.transform.SetParent(currentRod.fishingLine.obiFixedUpdater.transform); currentRod.fishingLine.currentLineHandler.transform.localEulerAngles = Vector3.zero; connector.transform.SetParent(currentRod.fishingLine.currentLineHandler.transform); currentRod.fishingLine.currentLineHandler.PhisicsLineOut = 0f; isLeftHandConnectLine = false; if (currentRod.fishingLine.currentLineHandler.lineType == FLineHandler.LineType.TwoSegment) { currentRod.fishingLine.currentLineHandler.EndLineRigidbody_1.transform.SetParent(currentRod.fishingLine.currentLineHandler.transform); } BuildDestroyChwytak(destroy: true); } public void UnlockLockReel() { if (!currentRod.currentReel.isBailOpen) { FullBodyAvatar.ReelControl(reelUnlock: true); } else { FullBodyAvatar.ReelControl(reelUnlock: false, reelLock: true); } } private void CheckAndConnectRod() { if ((bool)assignRod && !(assignRod == currentRod)) { if ((bool)currentRod) { currentRod.transform.SetParent(base.transform.parent); currentRod.GetComponent().enabled = true; currentRod = null; } currentRod = assignRod; assignRod = null; currentRod.GetComponent().enabled = false; currentRod.GetComponent().isKinematic = true; currentRod.transform.SetParent(fullBodyAvatar.RodJoiner); currentRod.transform.localPosition = Vector3.zero; currentRod.transform.rotation = fullBodyAvatar.RodJoiner.rotation; currentRod.currentPlayer = this; } } private void UnderWaterCameraControler() { if (currentRod == null && (bool)underWaterCamera) { DestroyUnderwaterCamera(); } else { if (currentRod == null || !currentRod.fishingLine || !currentRod.fishingLine.currentLineHandler || currentRod.isThrowing || GameManager.Instance.addectiveSceneLoading || GameManager.Instance.addectiveSceneLoaded != "none" || Singleton.Instance.IsCameraZoomIn || (Singleton.Instance.GetCurrentPlayerData().GameMode == GameManager.PlayerData.CPlayer.GameMode.Realistic && !GameManager.Instance.isDevModeAllowed) || Time.timeScale == 0f) { return; } if (currentRod.fishingLine.currentLineHandler.PhisicsLineOut < 1f) { if (underWaterCamera != null) { DestroyUnderwaterCamera(); } return; } if ((bool)currentRod.LureHookWaterDisplacement) { GameWaterSystem.FindWaterLevelAtLocation(currentRod.LureHookWaterDisplacement.transform.position, out var waterLevel); if (currentRod.LureHookWaterDisplacement.transform.position.y > waterLevel + 0.2f && !currentRod.currentFish) { if (underWaterCamera != null) { DestroyUnderwaterCamera(); } return; } } if (InputManager.isUnderwaterCamera) { if (underWaterCamera == null && currentRod.LureHookWaterDisplacement.IsInWater) { underWaterCamera = UnityEngine.Object.Instantiate(FScriptsHandler.Instance.underWaterCameraPrefab, FScriptsHandler.Instance.transform); underWaterCamera.GetComponent().currentRod = currentRod; (currentCameraView = Camera.main).rect = new Rect(0f, 0f, 1f, 1f); firstPersonController.enabled = false; FullBodyAvatar.ShowHead(); FPlayer.OnChangeCameraToUnderwater?.Invoke(); } } else if (underWaterCamera != null) { DestroyUnderwaterCamera(); } } } private void DestroyUnderwaterCamera() { firstPersonController.enabled = true; currentCameraView = m_Camera; UnityEngine.Object.Destroy(underWaterCamera.gameObject); underWaterCamera = null; InputManager.isUnderwaterCamera = false; FullBodyAvatar.ShowHead(toggle: false); SetGpuInstancerCamera(m_Camera); FPlayer.OnChangeCameraOutUnderwater?.Invoke(); } private IEnumerator SetGpuInstancerCamera(Camera newCam) { yield return null; GPUInstancerTreeManager gPUInstancerTreeManager = UnityEngine.Object.FindObjectOfType(); if ((bool)gPUInstancerTreeManager) { gPUInstancerTreeManager.SetCamera(newCam); } GPUInstancerDetailManager gPUInstancerDetailManager = UnityEngine.Object.FindObjectOfType(); if ((bool)gPUInstancerDetailManager) { gPUInstancerDetailManager.SetCamera(newCam); } } public void SetMouseCursor(bool visable) { m_MouseLook.SetCursorLock(visable); m_MouseLook.UpdateCursorLock(); } public void SpawnPlayer(Transform newPosition) { Debug.Log("Spawn to: " + newPosition.position.ToString()); base.transform.position = newPosition.position; firstPersonController.lastValidPosition = newPosition.position; base.transform.localEulerAngles = newPosition.localEulerAngles; if ((bool)currentRod) { if ((bool)currentRod.fishingLine.currentLineHandler.EndLineRigidbody_1) { currentRod.fishingLine.currentLineHandler.EndLineRigidbody_1.position = base.transform.position; } if ((bool)currentRod.fishingLine.currentLineHandler.EndLineRigidbody_2) { currentRod.fishingLine.currentLineHandler.EndLineRigidbody_2.position = base.transform.position; } if ((bool)currentRod.fishingLine.currentLineHandler.EndLineRigidbody_3) { currentRod.fishingLine.currentLineHandler.EndLineRigidbody_3.position = base.transform.position; } if ((bool)currentRod.currentFloat) { currentRod.currentFloat.transform.position = currentRod.fishingLine.currentLineHandler.EndLineRigidbody_1.position; } if ((bool)currentRod.currentHook) { currentRod.currentHook.transform.position = currentRod.fishingLine.currentLineHandler.EndLineRigidbody_2.position; } if ((bool)currentRod.currentLure) { currentRod.currentLure.transform.position = currentRod.fishingLine.currentLineHandler.EndLineRigidbody_1.position; } if ((bool)currentRod.currentFeeder) { currentRod.currentFeeder.transform.position = currentRod.fishingLine.currentLineHandler.EndLineRigidbody_3.position; } } } private void ShowAnglerFishView(GameManager.FishSpecies fishSpecies, float fishWeight) { if (!currentAnglerFishView) { GameObject original = FScriptsHandler.Instance.fishAnglerViewPrefab[3]; currentAnglerFishView = UnityEngine.Object.Instantiate(original, base.transform.position, base.transform.rotation, base.transform.parent).GetComponent(); currentAnglerFishView.transform.position = new Vector3(base.transform.position.x, base.transform.position.y - characterController.height / 2f, base.transform.position.z); currentAnglerFishView.currentFish = FishEntity.CurrentFishInFight; FullBodyAvatar.ShowHead(); if (FishEntity.CurrentFishInFight.Weight >= 6f) { ToggleRodVisibility(setEnable: false); } InputManager.isCameraChange = false; } } public void DestroyFishViewAngler(bool fromPanel = false) { if ((bool)currentAnglerFishView && (!FishEntity.CurrentFishInFight || !(FishEntity.CurrentFishInFight.Weight >= 35f) || fromPanel)) { UnityEngine.Object.Destroy(currentAnglerFishView.gameObject); currentAnglerFishView = null; FullBodyAvatar.ShowHead(toggle: false); ToggleRodVisibility(setEnable: true); currentRod.currentHook?.ShowRenderer(); currentRod.currentLure?.ShowRenderer(); InputManager.isCameraChange = false; } } private void RandomizeSpawnPointInMultiplayer() { if (MultiplayerManager.InRoomLocationStatic) { Vector2 vector = new Vector2(0.5f, 3f); Vector2 vector2 = new Vector2(1f, 1f); float y = UnityEngine.Random.Range(vector.x, vector.y); Vector2 vector3 = UnityEngine.Random.insideUnitCircle.normalized * UnityEngine.Random.Range(vector2.x, vector2.y); base.transform.position += new Vector3(vector3.x, y, vector3.y); } } private void DetectWaterStep() { delayStepSplash = Mathf.MoveTowards(delayStepSplash, 0f, Time.deltaTime); if (delayStepSplash > 0f || !firstPersonController.isWater || !(firstPersonController.m_Input != Vector2.zero)) { return; } splashStepList.RemoveAll((GameObject element) => element == null); if (splashStepList.Count < 10) { GameWaterSystem.FindWaterLevelAtLocation(base.transform.position, out var waterLevel); Vector3 position = new Vector3(base.transform.position.x, waterLevel + 0.1f, base.transform.position.z) + base.transform.forward * 0.1f; if (firstPersonController.m_Input.y > 0f) { position = new Vector3(base.transform.position.x, waterLevel + 0.1f, base.transform.position.z) + base.transform.forward * 0.6f; } GameObject gameObject = UnityEngine.Object.Instantiate(FScriptsHandler.Instance.waterFishSplash[3], position, Quaternion.identity); gameObject.transform.localScale = Vector3.one * UnityEngine.Random.Range(0.05f, 0.3f); splashStepList.Add(gameObject); delayStepSplash = 0.5f; } } public void ThrowNearAnimationEvent() { OutLineFromLeftHandHelper(currentRod.fishingLine.currentLineHandler.LineConnector_1.transform); } private void ToggleRodVisibility(bool setEnable) { if (currentRod == null) { return; } if (currentRodInHand == null || currentRodInHand != currentRod) { currentRodInHand = currentRod; currentRodRenderers = new Dictionary(); AddRenderers(currentRodInHand); AddRenderers(currentRodInHand.currentLure); AddRenderers(currentRodInHand.currentFloat); AddRenderers(currentRodInHand.currentHook); AddRenderers(currentRodInHand.currentFeeder); AddRenderers(currentRodInHand.currentBait); AddRenderers(currentRodInHand.currentLine); AddRenderers(currentRodInHand.currentWeight); } foreach (KeyValuePair currentRodRenderer in currentRodRenderers) { currentRodRenderer.Key.enabled = setEnable && currentRodRenderer.Value; } currentRodInHand.fishingLine.currentLineHandler.ToggleLineVisibility(setEnable); void AddRenderers(MonoBehaviour rodEquipment) { if (rodEquipment == null) { return; } foreach (Renderer item in rodEquipment.gameObject.GetComponentsInChildren().ToList()) { if (!currentRodRenderers.ContainsKey(item)) { currentRodRenderers.Add(item, item.enabled); } } } } private void HandsAnimation() { if (!currentRod) { FullBodyAvatar.HandsIdle(); } else { if (!currentRod.currentReel) { return; } if (!FishEntity.CurrentFishInFight && isLeftHandVisable) { isLeftHandVisable = false; OutLineFromLeftHandHelper(currentRod.fishingLine.currentLineHandler.EndLineRigidbody.transform); } bool flag = FullBodyAvatar.CurrentArmLeftState == FullBodyAvatar.ArmLeft.IK; FishEntity currentFishInFight = FishEntity.CurrentFishInFight; if ((bool)currentFishInFight) { FullBodyAvatar.SetFishOnRod(FullBodyAvatar.FishOnRod.Hook); } else { FullBodyAvatar.SetFishOnRod(FullBodyAvatar.FishOnRod.None); } if (currentRod.currentReel.isHandOnHandle) { FullBodyAvatar.SetFingersLeft(FullBodyAvatar.FingersLeft.OnReelHandle); } else { FullBodyAvatar.SetFingersLeft(FullBodyAvatar.FingersLeft.Idle); } if (InputManager.isPullUpRod) { FullBodyAvatar.SetFingersRight(FullBodyAvatar.FingersRight.OnRodTight); } else { FullBodyAvatar.SetFingersRight(FullBodyAvatar.FingersRight.OnRodLoose); } float num = GetPlayerHandPower(); if ((bool)currentFishInFight && !currentFishInFight.IsHooked) { num = 7f; if (handPullUp >= 0.3f) { currentFishInFight.IsHooked = true; FPlayer.OnRodJam?.Invoke(this); } } float num2 = (InputManager.isPullUpRod ? 1f : 0f); float a = 0f; float num3 = Vector3.Distance(currentRod.fishingLine.currentLineHandler.EndLineRigidbody.transform.position, base.transform.position); if (!currentRod.isThrowing && currentRod.fishingLine.currentLineHandler.PhisicsLineOut > 1f && num3 > 5f) { Vector3 vector = currentRod.fishingLine.currentLineHandler.EndLineRigidbody.transform.position - base.transform.position; vector.y = 0f; vector.Normalize(); Vector3 forward = base.transform.forward; forward.y = 0f; forward.Normalize(); a = Mathf.Clamp(Vector3.SignedAngle(vector, forward, Vector3.up) / 45f, -1f, 1f); } float num4 = 0f; if (flag) { if (CameraPivot.localEulerAngles.x < 180f) { num4 = Mathf.InverseLerp(0f, firstPersonController.m_MouseLook.MaximumX, CameraPivot.localEulerAngles.x); num4 *= -1f; } else { num4 = Mathf.InverseLerp(0f, 0f - firstPersonController.m_MouseLook.MinimumX, 360f - CameraPivot.localEulerAngles.x); } } float num5 = 0.7f; num5 = ((!(num4 > 0f)) ? Mathf.Lerp(0.7f, 0.3f, 0f - num4) : Mathf.Lerp(0.7f, 0.2f, num4)); num2 *= num5; a = Mathf.Lerp(a, 0f, num2 * 0.4f); num4 += 0.2f; if (isFishCanTaken.Value) { num2 = fishTakeTime / fishTakeTimeTarget * 0.5f; a = 0f; num4 = 0f; } float maxDelta = ((num2 == 0f) ? Time.deltaTime : (Time.deltaTime * num)); handPullUp = Mathf.MoveTowards(handPullUp, num2, maxDelta); rotRodLeftRight = Mathf.MoveTowards(rotRodLeftRight, a, Time.deltaTime * 2f); if (num4 > rotRodUpDown) { rotRodUpDown = Mathf.MoveTowards(rotRodUpDown, num4, Time.deltaTime * num * 3f); } else { rotRodUpDown = Mathf.MoveTowards(rotRodUpDown, num4, Time.deltaTime * 3f); } FullBodyAvatar.RodPullUp(handPullUp, flag ? 1f : 0f); FullBodyAvatar.RodAngle(rotRodLeftRight, rotRodUpDown, flag ? 1f : 0f, flag ? 1f : 0f); } } public void InteractiveLeftHand(Transform interactiveObject) { if (interactiveObject == null) { FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.Idle); if ((bool)currentRod && (bool)currentRod.currentReel) { currentRod.currentReel.isHandOnHandle = false; } return; } string text = interactiveObject.tag; if (!(text == "Reel")) { if (text == "ReelUnlock") { FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.IK, currentRod.currentReel.BailHandle); if ((bool)currentRod && (bool)currentRod.currentReel) { currentRod.currentReel.isHandOnHandle = false; } } } else { FullBodyAvatar.LeftArmControl(FullBodyAvatar.ArmLeft.IK, currentRod.currentReel.handle); if ((bool)currentRod && (bool)currentRod.currentReel) { currentRod.currentReel.isHandOnHandle = true; } } } private void ViewAngler() { if ((bool)FishEntity.CurrentFishInFight) { ShowAnglerFishView(FishEntity.CurrentFishInFight.Data.Species, FishEntity.CurrentFishInFight.Weight); } } private void FlashlightHandler() { if (InputManager.isHeadFlashLight) { if (Singleton.Instance != null && (!Singleton.Instance.IsChatOpen || Time.timeScale == 0f) && !flashLight.activeSelf) { flashLight.SetActive(value: true); } } else if (flashLight.activeSelf) { flashLight.SetActive(value: false); } } }