609 lines
15 KiB
C#
609 lines
15 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class FishingRod : MonoBehaviour
|
|
{
|
|
public enum RodType
|
|
{
|
|
SPINNING = 0,
|
|
CASTING = 1,
|
|
FLY_FISHING = 2,
|
|
ICE_FISHING = 3,
|
|
GROUND = 4,
|
|
BAT = 5
|
|
}
|
|
|
|
public RodType rodType;
|
|
|
|
public FishingReel.ReelType reelType;
|
|
|
|
public MegaBend rodMegaPrefab;
|
|
|
|
[HideInInspector]
|
|
public bool firstUpdate = true;
|
|
|
|
[HideInInspector]
|
|
public bool lateInitialized;
|
|
|
|
public float durability = 0.5f;
|
|
|
|
public float weightDurability;
|
|
|
|
[ReadOnly]
|
|
public int length = 230;
|
|
|
|
public int lengthSimple = 280;
|
|
|
|
public Vector2 CW = Vector2.one;
|
|
|
|
[ReadOnly]
|
|
public bool isOnRodStand;
|
|
|
|
[Header("Ice Rod")]
|
|
public bool isIceRod;
|
|
|
|
public FishingReel mountedReel;
|
|
|
|
public Vector3 iceFishingLookOffset = Vector3.zero;
|
|
|
|
[Header("Reel Line")]
|
|
public Transform reelLineAttach;
|
|
|
|
public MeshRenderer lineStatic;
|
|
|
|
public MeshRenderer lineStaticTop;
|
|
|
|
[Space(10f)]
|
|
public Transform rodEndPosition;
|
|
|
|
public GameObject rodPhysics;
|
|
|
|
public bool updateRodPhysicsLength = true;
|
|
|
|
public Transform rodMegaAttachPosition;
|
|
|
|
[ReadOnly]
|
|
public MegaAttach rodMegaAttach;
|
|
|
|
public Transform ropeStartPosition;
|
|
|
|
[HideInInspector]
|
|
public ConfigurableJoint ropeStartJoint;
|
|
|
|
public Transform[] megaAttachObjects = new Transform[0];
|
|
|
|
public Transform baitThrowPosition;
|
|
|
|
public float rodLength = 2f;
|
|
|
|
public Vector3 modelStartPos = Vector3.zero;
|
|
|
|
public Vector3 modelStartRot = Vector3.zero;
|
|
|
|
public Transform reelMountPosition;
|
|
|
|
public Transform handMountPosition;
|
|
|
|
public Transform handMultiMountPosition;
|
|
|
|
[HideInInspector]
|
|
public FishingPlayer fishingPlayer;
|
|
|
|
[HideInInspector]
|
|
public FishingHands fishingHands;
|
|
|
|
[Header("Rod Bend")]
|
|
public MegaBendWarp megaBendWarp;
|
|
|
|
[HideInInspector]
|
|
public Vector3 megaBendWarpStartPos = Vector3.zero;
|
|
|
|
[HideInInspector]
|
|
public Vector3 megaBendWarpStandPos = Vector3.zero;
|
|
|
|
public List<GameObject> bendObjects = new List<GameObject>();
|
|
|
|
[HideInInspector]
|
|
public List<MegaModifyObject> bendMegaModifiers = new List<MegaModifyObject>();
|
|
|
|
public Vector2 startBend = new Vector2(-90f, 0f);
|
|
|
|
public Vector2 maxBend = new Vector2(30f, 50f);
|
|
|
|
public Vector2 bendFactor = new Vector2(1f, 0.5f);
|
|
|
|
public Vector2 bendSpeed = new Vector2(5f, 100f);
|
|
|
|
public float bendSpeedSthreshold = 10f;
|
|
|
|
public AnimationCurve bendSpeedCurve = new AnimationCurve();
|
|
|
|
[ReadOnly]
|
|
public float bendAngle;
|
|
|
|
public float bendDir;
|
|
|
|
[ReadOnly]
|
|
public Vector2 currentBend = Vector2.zero;
|
|
|
|
public Vector2 targetBend = Vector2.zero;
|
|
|
|
public float dirAddHack;
|
|
|
|
[ReadOnly]
|
|
public bool isBending;
|
|
|
|
[ReadOnly]
|
|
public bool isIn_180_360_Bend = true;
|
|
|
|
public float bendAngleMultiplier = 2.1f;
|
|
|
|
private Vector3 closestPointLine1 = Vector3.zero;
|
|
|
|
private Vector3 closestPointLine2 = Vector3.zero;
|
|
|
|
public LTDescr leanShake;
|
|
|
|
[ReadOnly]
|
|
public float bendShakeValue = 0.1f;
|
|
|
|
public Vector2 currentLeanShake = Vector2.zero;
|
|
|
|
[ReadOnly]
|
|
[Space(10f)]
|
|
public float distanceToBait = -1f;
|
|
|
|
[ReadOnly]
|
|
public float distanceToThrowObject = -1f;
|
|
|
|
[ReadOnly]
|
|
public float distanceBaitToFloat = -1f;
|
|
|
|
[ReadOnly]
|
|
public float distanceToBaitNoBend = -1f;
|
|
|
|
[ReadOnly]
|
|
public float prevDistanceToBait = -1f;
|
|
|
|
[ReadOnly]
|
|
public float distanceToBaitChange;
|
|
|
|
private void Awake()
|
|
{
|
|
if (rodMegaAttachPosition == null)
|
|
{
|
|
rodMegaAttachPosition = rodEndPosition;
|
|
}
|
|
ropeStartJoint = ropeStartPosition.GetComponent<ConfigurableJoint>();
|
|
ropeStartJoint.autoConfigureConnectedAnchor = false;
|
|
ropeStartJoint.connectedAnchor = new Vector3(0f, 1f, 0f);
|
|
modelStartPos = bendObjects[0].transform.localPosition;
|
|
modelStartRot = bendObjects[0].transform.localEulerAngles;
|
|
if ((bool)megaBendWarp)
|
|
{
|
|
megaBendWarpStartPos = megaBendWarp.transform.localPosition;
|
|
megaBendWarpStandPos = megaBendWarpStartPos + megaBendWarp.transform.forward * Vector3.Distance(megaBendWarp.transform.position, rodEndPosition.position) * 0.6f;
|
|
megaBendWarp.DisplayGizmo = false;
|
|
if ((bool)GameController.Instance && !GameController.Instance.iceLevel)
|
|
{
|
|
megaBendWarp.doRegion = true;
|
|
megaBendWarp.from = 0f - megaBendWarp.Length;
|
|
}
|
|
foreach (GameObject bendObject in bendObjects)
|
|
{
|
|
if (bendObject.activeSelf)
|
|
{
|
|
MegaModifyObject megaModifyObject = bendObject.AddComponent<MegaModifyObject>();
|
|
MegaWarpBind megaWarpBind = bendObject.AddComponent<MegaWarpBind>();
|
|
megaWarpBind.SetTarget(megaBendWarp.gameObject);
|
|
megaWarpBind.DisplayGizmo = false;
|
|
megaModifyObject.DrawGizmos = false;
|
|
megaModifyObject.recalcnorms = false;
|
|
bendMegaModifiers.Add(megaModifyObject);
|
|
}
|
|
}
|
|
}
|
|
if ((bool)rodMegaPrefab)
|
|
{
|
|
MegaBend megaBend = UnityEngine.Object.Instantiate(rodMegaPrefab);
|
|
megaBend.transform.parent = base.transform;
|
|
megaBend.transform.localPosition = Vector3.zero;
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void ChangeMegaBendParams()
|
|
{
|
|
megaBendWarp.doRegion = true;
|
|
megaBendWarp.from = 0f - megaBendWarp.Length;
|
|
foreach (GameObject bendObject in bendObjects)
|
|
{
|
|
bendObject.GetComponent<MegaModifyObject>().recalcnorms = false;
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
rodEndPosition.Find("TestCube").gameObject.SetActive(false);
|
|
if (base.transform.parent == null)
|
|
{
|
|
base.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
leanShake = LeanTween.value(base.gameObject, Vector2.zero, Vector2.one, 0.3f).setOnUpdate(delegate(Vector2 val)
|
|
{
|
|
currentLeanShake = val;
|
|
}).setEase(LeanTweenType.easeShake)
|
|
.setRepeat(-1);
|
|
CalculateWeightDurability();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!(fishingPlayer == null) && fishingHands.baitWasThrown)
|
|
{
|
|
UpdateBaitDistance();
|
|
if (VRManager.Instance.IsControllersInput() && OVRInput.GetLocalControllerVelocity(VRControllersManager.Instance.GetPrimaryController()).sqrMagnitude > 1.65f)
|
|
{
|
|
fishingHands.spinningMethodController.SpinningStateEvent(SpinningMethodController.SpinningState.JERK);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (!(fishingPlayer == null))
|
|
{
|
|
UpdateBend();
|
|
bendObjects[0].transform.localPosition = modelStartPos;
|
|
bendObjects[0].transform.localEulerAngles = modelStartRot;
|
|
if (lateInitialized)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (lateInitialized)
|
|
{
|
|
if (updateRodPhysicsLength)
|
|
{
|
|
rodPhysics.transform.localScale = new Vector3(rodPhysics.transform.localScale.x, Vector3.Distance(rodPhysics.transform.position, rodMegaAttachPosition.position), rodPhysics.transform.localScale.z);
|
|
}
|
|
ropeStartJoint.connectedAnchor = new Vector3(0f, 1f, 0f);
|
|
}
|
|
}
|
|
|
|
public void UpdateBaitDistance()
|
|
{
|
|
distanceToBait = Vector3.Distance(ropeStartPosition.position, fishingHands.bait.transform.position);
|
|
if ((bool)fishingHands.fishingFloat)
|
|
{
|
|
distanceToThrowObject = Vector3.Distance(ropeStartPosition.position, fishingHands.throwObject.transform.position);
|
|
distanceBaitToFloat = Vector3.Distance(fishingHands.bait.transform.position, fishingHands.fishingFloat.transform.position);
|
|
}
|
|
else
|
|
{
|
|
distanceToThrowObject = distanceToBait;
|
|
distanceBaitToFloat = -1f;
|
|
}
|
|
}
|
|
|
|
public void ShowReelLine(bool show)
|
|
{
|
|
if ((bool)fishingHands.reelLine)
|
|
{
|
|
fishingHands.reelLine.enabled = show;
|
|
}
|
|
if ((bool)fishingHands.reelLineIdle)
|
|
{
|
|
fishingHands.reelLineIdle.enabled = !show;
|
|
}
|
|
}
|
|
|
|
public float GetBaitDistance()
|
|
{
|
|
return distanceToBait;
|
|
}
|
|
|
|
public float GetThrowObjectDistance()
|
|
{
|
|
return distanceToThrowObject;
|
|
}
|
|
|
|
public float GetBaitFloatDistance()
|
|
{
|
|
return distanceBaitToFloat;
|
|
}
|
|
|
|
public float GetBaitDistanceNoBend()
|
|
{
|
|
return distanceToBaitNoBend;
|
|
}
|
|
|
|
public float GetBaitDistanceChange()
|
|
{
|
|
return distanceToBaitChange;
|
|
}
|
|
|
|
public void InitBend()
|
|
{
|
|
if ((bool)megaBendWarp && bendObjects.Count > 0)
|
|
{
|
|
rodMegaAttach = rodMegaAttachPosition.gameObject.AddComponent<MegaAttach>();
|
|
rodMegaAttach.target = bendObjects[0].GetComponent<MegaModifyObject>();
|
|
rodMegaAttach.worldSpace = true;
|
|
rodMegaAttach.updateRotation = false;
|
|
rodMegaAttach.radius = 0.02f;
|
|
Transform[] array = megaAttachObjects;
|
|
foreach (Transform transform in array)
|
|
{
|
|
MegaAttach megaAttach = transform.gameObject.AddComponent<MegaAttach>();
|
|
megaAttach.target = bendObjects[0].GetComponent<MegaModifyObject>();
|
|
megaAttach.worldSpace = true;
|
|
megaAttach.updateRotation = false;
|
|
megaAttach.radius = 0.02f;
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerator UpdateBendMofidiers()
|
|
{
|
|
yield return new WaitForSeconds(2f);
|
|
while (true)
|
|
{
|
|
for (int i = 0; i < bendMegaModifiers.Count; i++)
|
|
{
|
|
bendMegaModifiers[i].Enabled = false;
|
|
}
|
|
for (int k = 0; (float)k < fishingHands.rodBendDelay; k++)
|
|
{
|
|
yield return null;
|
|
}
|
|
for (int j = 0; j < bendMegaModifiers.Count; j++)
|
|
{
|
|
bendMegaModifiers[j].Enabled = true;
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
public IEnumerator InitAttach()
|
|
{
|
|
if (fishingPlayer == null || !rodMegaAttach || rodMegaAttach.attached)
|
|
{
|
|
yield break;
|
|
}
|
|
yield return null;
|
|
if (!(rodMegaAttach == null))
|
|
{
|
|
Debug.Log("InitAttach");
|
|
rodMegaAttach.AttachIt(rodMegaAttach.transform.position);
|
|
Transform[] array = megaAttachObjects;
|
|
foreach (Transform transform in array)
|
|
{
|
|
transform.GetComponent<MegaAttach>().AttachIt(transform.position);
|
|
}
|
|
if ((bool)megaBendWarp)
|
|
{
|
|
}
|
|
ShowReelLine(false);
|
|
if (GameController.Instance.iceLevel && fishingPlayer.currentState != FishingPlayer.PlayerState.ICE_FISHING)
|
|
{
|
|
fishingPlayer.currentHands.HideRod();
|
|
}
|
|
lateInitialized = true;
|
|
fishingPlayer.LateInitialize();
|
|
}
|
|
}
|
|
|
|
public void UpdateBend()
|
|
{
|
|
if (megaBendWarp == null || !isBending || !lateInitialized)
|
|
{
|
|
return;
|
|
}
|
|
if (GameController.Instance.iceLevel && (bool)fishingPlayer.fish && fishingPlayer.fish.isWatchingFish)
|
|
{
|
|
megaBendWarp.dir = startBend.x;
|
|
if (VRManager.Instance.IsVRHoldRod())
|
|
{
|
|
megaBendWarp.angle = startBend.y;
|
|
}
|
|
else
|
|
{
|
|
megaBendWarp.angle = startBend.y + 100f;
|
|
}
|
|
currentBend = (targetBend = startBend);
|
|
return;
|
|
}
|
|
if (fishingPlayer.IsTrolling() && !fishingHands.bait.fish && !fishingHands.biteIndicator.isIndicating)
|
|
{
|
|
megaBendWarp.dir = startBend.x;
|
|
megaBendWarp.angle = startBend.y;
|
|
currentBend = (targetBend = startBend);
|
|
return;
|
|
}
|
|
if (isOnRodStand && (bool)fishingPlayer.boatSimulator && fishingHands.biteIndicator.isIndicating)
|
|
{
|
|
megaBendWarp.angle = startBend.y + fishingHands.biteIndicator.bendValue;
|
|
if (fishingHands.reel.reelType == FishingReel.ReelType.LINE_COUNTER)
|
|
{
|
|
megaBendWarp.angle = 0f - megaBendWarp.angle;
|
|
}
|
|
megaBendWarp.dir = -90f;
|
|
return;
|
|
}
|
|
if (fishingHands.isGroundRig && fishingHands.biteIndicator.isIndicating && (isOnRodStand || ((bool)fishingPlayer.fish && !fishingPlayer.fish.isJerked)))
|
|
{
|
|
megaBendWarp.angle = startBend.y + fishingHands.biteIndicator.bendValue * ((rodType != RodType.GROUND) ? 0.4f : 1f);
|
|
if (fishingHands.reel.reelType == FishingReel.ReelType.LINE_COUNTER)
|
|
{
|
|
megaBendWarp.angle = 0f - megaBendWarp.angle;
|
|
}
|
|
megaBendWarp.dir = -90f;
|
|
return;
|
|
}
|
|
float num = 0f;
|
|
if (GameController.Instance.iceLevel)
|
|
{
|
|
Vector3 vector = fishingHands.fakeLineIceTarget.position - handMountPosition.position;
|
|
vector.y = 0f;
|
|
Vector3 forward = rodEndPosition.forward;
|
|
forward.y = 0f;
|
|
num = Vector3.Angle(forward, vector);
|
|
num *= (float)((!(Vector3.Cross(forward, vector).y < 0f)) ? 1 : (-1));
|
|
bendAngle = fishingHands.fishingLine.currentTension * fishingHands.FRC.maxBendAngleIce.y;
|
|
bendAngle = Mathf.Clamp(bendAngle, fishingHands.FRC.maxBendAngleIce.x, fishingHands.FRC.maxBendAngleIce.y);
|
|
}
|
|
else
|
|
{
|
|
Vector3 vector2 = fishingHands.throwObject.transform.position - handMountPosition.position;
|
|
vector2.y = 0f;
|
|
Vector3 forward2 = fishingPlayer.transform.forward;
|
|
forward2.y = 0f;
|
|
num = Vector3.Angle(forward2, vector2);
|
|
num *= (float)((!(Vector3.Cross(forward2, vector2).y < 0f)) ? 1 : (-1));
|
|
fishingHands.SetHandsRotation(0f - num);
|
|
Vector3 vector3 = rodEndPosition.position - handMountPosition.position;
|
|
Vector3 to = ropeStartPosition.position - handMountPosition.position;
|
|
float num2 = 0f;
|
|
bendAngle = Vector3.Angle(vector3, to);
|
|
bendAngle *= bendAngleMultiplier;
|
|
if ((bool)fishingPlayer.fish && fishingPlayer.fish.IsItTinyFish())
|
|
{
|
|
bendAngle *= 0.2f;
|
|
}
|
|
bendAngle = Mathf.Clamp(bendAngle, fishingHands.FRC.maxBendAngle.x, fishingHands.FRC.maxBendAngle.y);
|
|
}
|
|
if (GameController.Instance.iceLevel)
|
|
{
|
|
Vector3 position = fishingHands.fakeLineIceTarget.position;
|
|
position.y = 0f;
|
|
Vector3 position2 = rodEndPosition.position;
|
|
position2.y = 0f;
|
|
float value = Vector3.Distance(position, position2);
|
|
bendDir = 0f - num;
|
|
value = Mathf.InverseLerp(0f, 0.2f, value);
|
|
value = Mathf.Pow(value, 2f);
|
|
bendDir *= value;
|
|
bendDir = Mathf.Clamp(bendDir, -90f, 90f);
|
|
bendDir *= 0.5f;
|
|
}
|
|
else
|
|
{
|
|
Utilities.ClosestPointsOnTwoLines(out closestPointLine1, out closestPointLine2, rodEndPosition.position, rodEndPosition.up, rodPhysics.transform.position, rodPhysics.transform.up);
|
|
if (!GlobalSettings.Instance)
|
|
{
|
|
}
|
|
bendDir = Utilities.AngleWithDirection(-rodEndPosition.up, closestPointLine2 - rodEndPosition.position, rodEndPosition.forward);
|
|
if (!GlobalSettings.Instance)
|
|
{
|
|
}
|
|
float num3 = fishingHands.FRC.dirAddHack * (bendAngle * 1f);
|
|
bendDir += num3;
|
|
if (fishingHands.FRC.clampBendDir)
|
|
{
|
|
bendDir = Mathf.Clamp(bendDir, -90f, 90f);
|
|
}
|
|
if (bendDir < 0f)
|
|
{
|
|
bendDir += 360f;
|
|
}
|
|
bendDir += 90f;
|
|
if (bendDir > 360f)
|
|
{
|
|
bendDir -= 360f;
|
|
}
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
}
|
|
}
|
|
megaBendWarp.angle = startBend.y + bendAngle;
|
|
megaBendWarp.dir = startBend.x + bendDir;
|
|
}
|
|
|
|
public void ShakeBend(float newBendShake)
|
|
{
|
|
bendShakeValue = newBendShake;
|
|
bool flag = newBendShake > 0f;
|
|
if (flag && leanShake.direction == 0f)
|
|
{
|
|
leanShake.resume();
|
|
}
|
|
else if (!flag && leanShake.direction != 0f)
|
|
{
|
|
leanShake.pause();
|
|
}
|
|
}
|
|
|
|
public void ResetBend()
|
|
{
|
|
if (GameController.Instance.iceLevel)
|
|
{
|
|
return;
|
|
}
|
|
isBending = false;
|
|
if ((bool)megaBendWarp)
|
|
{
|
|
megaBendWarp.dir = startBend.x;
|
|
megaBendWarp.angle = startBend.y;
|
|
currentBend = (targetBend = startBend);
|
|
if ((bool)rodPhysics)
|
|
{
|
|
rodPhysics.transform.localEulerAngles = Vector3.zero;
|
|
}
|
|
megaBendWarp.Enabled = true;
|
|
LeanTween.delayedCall(0.1f, (Action)delegate
|
|
{
|
|
megaBendWarp.Enabled = false;
|
|
});
|
|
}
|
|
prevDistanceToBait = -1f;
|
|
}
|
|
|
|
public void StartBend()
|
|
{
|
|
isBending = true;
|
|
megaBendWarp.Enabled = true;
|
|
currentBend = (targetBend = startBend);
|
|
if ((bool)rodPhysics)
|
|
{
|
|
rodPhysics.GetComponent<Rigidbody>().isKinematic = false;
|
|
}
|
|
}
|
|
|
|
public void ChangeBendWarpPosition(bool startPosition)
|
|
{
|
|
megaBendWarp.transform.localPosition = ((!startPosition) ? megaBendWarpStandPos : megaBendWarpStartPos);
|
|
}
|
|
|
|
[Button]
|
|
public void CalculateWeightDurability()
|
|
{
|
|
if (durability <= 1f)
|
|
{
|
|
weightDurability = Mathf.Lerp(0f, 70f, Mathf.Pow(durability, 1.5f));
|
|
}
|
|
else
|
|
{
|
|
weightDurability = Mathf.Lerp(70f, 110f, Mathf.Pow(durability - 1f, 1.5f));
|
|
}
|
|
weightDurability = (float)Mathf.RoundToInt(weightDurability * 10f) * 0.1f;
|
|
}
|
|
|
|
public Vector3 GetVRBaitHoldPosition(bool withFish)
|
|
{
|
|
Vector3 position = rodEndPosition.position;
|
|
if (GameController.Instance.iceLevel)
|
|
{
|
|
return position + Vector3.down * 0.4f;
|
|
}
|
|
return position + Vector3.down * (Vector3.Distance(rodEndPosition.position, reelMountPosition.position) - ((!withFish) ? 0.2f : 0.3f));
|
|
}
|
|
}
|