using System.Collections; using Obi; using UnityEngine; public class FishingLine : MonoBehaviour { [HideInInspector] public Rigidbody toRodConnector; private Transform ObiLinesSolverContainer; public Transform[] rodLinePoints; public Reel reel; public Float fishingFloat; public Feeder feeder; public Hook hook; public Lure lure; public FishMovement fishObject; public WaterDisplacementObject lastPointDisplacement; [HideInInspector] public LineHandler currentLineHandler; [HideInInspector] public Transform handFishHandPoint; private LineRenderer lineRenderer; [HideInInspector] public LineHookHandHelper lineHookHandHelper; public float ropeOut; [Tooltip("odleglosc w metrach pomiedzy przelotką a koncem żyłki do haczyka")] public float ropeToHookDistance; [Tooltip("Napiecie żyłki według jej wytrzymałości, 1 = zrywa")] [Range(0f, 1f)] public float ropeTension; [Tooltip("Napiecie żyłki roznicy zyłki Out a dystansu")] public float ropeRoznicaTension; [Tooltip("wytrzymalóśc zylki w kg")] public float lineMaxStrength = 2f; [HideInInspector] public int currentLineTypeIndex; [HideInInspector] private Rod currRod; private float lastDstLineOut; private void Start() { currRod = GetComponent(); lineRenderer = GetComponent(); toRodConnector = rodLinePoints[0].GetComponent(); ObiLinesSolverContainer = Object.FindObjectOfType().transform; switch (GameManager.Instance.gameRods[0].type) { case GameManager.GameRods.Type.Spinning: currentLineTypeIndex = 0; BuildLure(); break; case GameManager.GameRods.Type.Float: currentLineTypeIndex = 1; BuildFloat(); BuildHook(); BuildBait(); break; case GameManager.GameRods.Type.Feeder: currentLineTypeIndex = 2; BuildFeeder(); BuildHook(); BuildBait(); break; } CreateObiFishingLine(); BuildReel(); } private void FixedUpdate() { if ((bool)currentLineHandler) { ropeToHookDistance = Vector3.Distance(lastPointDisplacement.transform.position, toRodConnector.transform.position); currentLineHandler.PhisicsLineOut = ropeOut; CalculateTension(); } } private void Update() { ropeRoznicaTension = getLineDiferent(); } private float GetVeloByLineOut() { float value = ropeToHookDistance - lastDstLineOut; lastDstLineOut = ropeToHookDistance; return Mathf.Clamp01(value) * 100f; } public float getLineDiferent() { if (!currentLineHandler) { return 0f; } return Vector3.Distance(currentLineHandler.LineConnector_1.transform.position, toRodConnector.transform.position) - currentLineHandler.PhisicsLineOut; } private void CreateObiFishingLine() { GameObject gameObject = Object.Instantiate(ScriptsHandler.Instance.fishingObiLinesPrefab[currentLineTypeIndex], toRodConnector.position, Quaternion.identity, ObiLinesSolverContainer); currentLineHandler = gameObject.GetComponent(); currentLineHandler.currentRodFishingLineComponent = this; currentLineHandler.transform.position = toRodConnector.position; currentLineHandler.LineConnector_0.transform.position = toRodConnector.position; currentLineHandler.LineConnector_0.gameObject.AddComponent().connectedBody = toRodConnector; currentLineHandler.LineConnector_1.connectedBody = toRodConnector; } private void BuildReel() { int itemIdByUniqueId = GameManager.Instance._playerData.GetItemIdByUniqueId(GameManager.ItemType.Reel, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currRod.indexOfslot].reel.uniqueId); GameObject gameObject = Object.Instantiate(GameManager.Instance.gameReels[itemIdByUniqueId].GetModelPrefab(), currRod.reelContainer); gameObject.transform.localPosition = Vector3.zero; reel = gameObject.GetComponent(); reel.currentRod = currRod; reel.maxReelStrength = GameManager.Instance.gameReels[itemIdByUniqueId].strength; SetLineMaterial(); } private void BuildLure() { int iD = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currRod.indexOfslot].bait.ID; GameObject modelPrefab = GameManager.Instance.gameBaits[iD].GetModelPrefab(); lure = Object.Instantiate(modelPrefab, null).GetComponent(); lastPointDisplacement = lure.GetComponent(); lure.GetComponent().baitID = iD; StartCoroutine(ConnectLure()); } private void BuildFloat() { int itemIdByUniqueId = GameManager.Instance._playerData.GetItemIdByUniqueId(GameManager.ItemType.Float, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currRod.indexOfslot].ffloat.uniqueId); GameObject modelPrefab = GameManager.Instance.gameFloats[itemIdByUniqueId].GetModelPrefab(); fishingFloat = Object.Instantiate(modelPrefab, null).GetComponent(); StartCoroutine(ConnectFloat()); } private void BuildHook() { int itemIdByUniqueId = GameManager.Instance._playerData.GetItemIdByUniqueId(GameManager.ItemType.Hook, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currRod.indexOfslot].hook.uniqueId); GameObject modelPrefab = GameManager.Instance.gameHooks[itemIdByUniqueId].GetModelPrefab(); hook = Object.Instantiate(modelPrefab, null).GetComponent(); lastPointDisplacement = hook.GetComponent(); hook.hookID = itemIdByUniqueId; StartCoroutine(ConnectHook()); } private void BuildFeeder() { int itemIdByUniqueId = GameManager.Instance._playerData.GetItemIdByUniqueId(GameManager.ItemType.Feeder, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currRod.indexOfslot].feeder.uniqueId); GameObject modelPrefab = GameManager.Instance.gameFeeders[itemIdByUniqueId].GetModelPrefab(); feeder = Object.Instantiate(modelPrefab, null).GetComponent(); StartCoroutine(ConnectFeeder()); } private void BuildBait() { if ((bool)hook) { int iD = Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currRod.indexOfslot].bait.ID; GameObject modelPrefab = GameManager.Instance.gameBaits[iD].GetModelPrefab(); hook.currentBait = Object.Instantiate(modelPrefab, hook.baitContainer); hook.currentBait.transform.localPosition = Vector3.zero; hook.currentBait.transform.localEulerAngles = Vector3.zero; hook.GetComponent().baitID = iD; } } public IEnumerator ConnectLure() { yield return new WaitForEndOfFrame(); if ((bool)lure) { lure.linkConnectorUp = currentLineHandler.EndLineRigidbody_1; lure.currentFishingLine = this; handFishHandPoint = currentLineHandler.LineConnector_1.transform; lure.Link(currentLineHandler.EndLineRigidbody_1); } } private IEnumerator ConnectFloat() { yield return new WaitForEndOfFrame(); if ((bool)fishingFloat) { fishingFloat.linkConnectorUp = currentLineHandler.EndLineRigidbody_1; fishingFloat.currentFishingLine = this; fishingFloat.Link(currentLineHandler.EndLineRigidbody_1); } } private IEnumerator ConnectHook() { yield return new WaitForEndOfFrame(); if ((bool)hook) { hook.linkConnectorUp = currentLineHandler.EndLineRigidbody_2; handFishHandPoint = currentLineHandler.LineConnector_2.transform; hook.currentFishingLine = this; hook.Link(currentLineHandler.EndLineRigidbody_2); } } private IEnumerator ConnectFeeder() { yield return new WaitForEndOfFrame(); if ((bool)feeder) { feeder.linkConnectorUp = currentLineHandler.EndLineRigidbody_3; feeder.currentFishingLine = this; feeder.Link(currentLineHandler.EndLineRigidbody_3); } } public void AddLineHelperHand() { if (!lineHookHandHelper) { lineHookHandHelper = Object.Instantiate(ScriptsHandler.Instance.LineHandHelper).GetComponent(); if ((bool)lure) { lineHookHandHelper.Setup(handFishHandPoint, lure.transform, lineRenderer); } else if ((bool)hook) { lineHookHandHelper.Setup(handFishHandPoint, hook.transform, lineRenderer); } } } public void RenderLine() { int num = 0; int num2 = 2; lineRenderer.positionCount = rodLinePoints.Length + num2; lineRenderer.SetPosition(num, reel.szpulaObject.transform.position); num++; if (!reel.isKablagOpen) { lineRenderer.SetPosition(num, reel.SzpulaLinepoint_1.transform.position); num++; } else { lineRenderer.SetPosition(num, reel.SzpulaLinepoint_0.transform.position); num++; } for (int num3 = rodLinePoints.Length; num3 > 0; num3--) { lineRenderer.SetPosition(num, rodLinePoints[num3 - 1].position); num++; } } public void RollLine(float speed) { ropeOut = Mathf.MoveTowards(ropeOut, 0f, Time.deltaTime * speed); ScriptsHandler.Instance.m_PlayerMain.SetAnimationToIdleByLineOut(ropeOut); } public void SetLineMaterial() { int itemIdByUniqueId = GameManager.Instance._playerData.GetItemIdByUniqueId(GameManager.ItemType.Line, Singleton.Instance.GetCurrentPlayerData().PlayerSlotsEquip[GetComponent().indexOfslot].line.uniqueId); Material material = GameManager.Instance.gameLines[itemIdByUniqueId].GetMaterial(); if ((bool)currentLineHandler.obiRopeSegment_1) { currentLineHandler.obiRopeSegment_1.GetComponent().material = material; } if ((bool)currentLineHandler.obiRopeSegment_2) { currentLineHandler.obiRopeSegment_2.GetComponent().material = material; } if ((bool)currentLineHandler.obiRopeSegment_3) { currentLineHandler.obiRopeSegment_3.GetComponent().material = material; } lineRenderer.material = material; Material materialSzpula = GameManager.Instance.gameLines[itemIdByUniqueId].GetMaterialSzpula(); reel.szpulaObject.GetComponent().material = materialSzpula; lineMaxStrength = GameManager.Instance.gameLines[itemIdByUniqueId].strength; } private void CalculateTension() { ropeRoznicaTension = getLineDiferent(); ropeRoznicaTension = Mathf.Clamp(ropeRoznicaTension, -1f, 1f); ropeTension = ropeRoznicaTension * lineMaxStrength / lineMaxStrength; ropeTension = Mathf.Clamp(ropeTension, 0f, 1.5f); } private void OnDestroy() { if ((bool)fishingFloat) { Object.Destroy(fishingFloat.gameObject); } if ((bool)feeder) { Object.Destroy(feeder.gameObject); } if ((bool)hook) { Object.Destroy(hook.gameObject); } if ((bool)lure) { Object.Destroy(lure.gameObject); } } }