487 lines
13 KiB
C#
487 lines
13 KiB
C#
using System;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class FishingFloat : MonoBehaviour
|
|
{
|
|
public enum Shape
|
|
{
|
|
OVAL = 0
|
|
}
|
|
|
|
public Shape shape;
|
|
|
|
public bool setRopePosition;
|
|
|
|
public GameObject ropeRigidbody;
|
|
|
|
public GameObject ropeBaitRigidbody;
|
|
|
|
[ReadOnly]
|
|
public Collider collider;
|
|
|
|
[Space(10f)]
|
|
public Transform model;
|
|
|
|
public Transform resizeParent;
|
|
|
|
[ReadOnly]
|
|
public float modelResizeFactor = 1f;
|
|
|
|
public float mainRopeOffset;
|
|
|
|
public float standardOffset;
|
|
|
|
[ReadOnly]
|
|
public float currentStandardOffset;
|
|
|
|
[Header("Burden")]
|
|
public float length = 20f;
|
|
|
|
public float realMass = 2.5f;
|
|
|
|
public float mass = 30f;
|
|
|
|
public float currentBurden = 1f;
|
|
|
|
public float optimalBurden = 1f;
|
|
|
|
[ReadOnly]
|
|
public float burdenFactor;
|
|
|
|
[ReadOnly]
|
|
public float burdenOffset;
|
|
|
|
[ReadOnly]
|
|
public float burdenRotation;
|
|
|
|
public Vector2 burdenOffsetMinMax = Vector2.zero;
|
|
|
|
[Header("Floating")]
|
|
[ReadOnly]
|
|
public float floatingTimer;
|
|
|
|
[ReadOnly]
|
|
public float floatingOffset;
|
|
|
|
[ReadOnly]
|
|
public float floatingEasedOffset;
|
|
|
|
public float floatingSpeed = 0.04f;
|
|
|
|
public float floatingMax = 0.03f;
|
|
|
|
[ReadOnly]
|
|
public float floatingTarget;
|
|
|
|
[ReadOnly]
|
|
public float floatingPrevTarget;
|
|
|
|
public AnimationCurve floatingCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f);
|
|
|
|
[ReadOnly]
|
|
[Header("FishTriesBait")]
|
|
public float fishTriesTimer;
|
|
|
|
[ReadOnly]
|
|
public float fishTriesForceTimer;
|
|
|
|
[ReadOnly]
|
|
public float fishTriesPullTimer;
|
|
|
|
[ReadOnly]
|
|
public float fishTriesRippleTimer;
|
|
|
|
public Vector2 fishTriesForce = Vector2.one;
|
|
|
|
[ReadOnly]
|
|
public float fishTriesCurrentForce;
|
|
|
|
public float fishTriesForceMenuMultiplier = 2f;
|
|
|
|
[HideInInspector]
|
|
[Space(10f)]
|
|
public Bait bait;
|
|
|
|
[HideInInspector]
|
|
public FishingHands fishingHands;
|
|
|
|
[HideInInspector]
|
|
public bool isOnWater;
|
|
|
|
[HideInInspector]
|
|
public Rigidbody rigidbody;
|
|
|
|
[HideInInspector]
|
|
public ParticleSystem particleHit;
|
|
|
|
public static float moveSurfaceSpeed = 3f;
|
|
|
|
public static float rotateSurfaceSpeed = 30f;
|
|
|
|
[HideInInspector]
|
|
public bool newPhysics;
|
|
|
|
[ReadOnly]
|
|
public bool isLoose = true;
|
|
|
|
[ReadOnly]
|
|
public bool isTryAnimation;
|
|
|
|
[ReadOnly]
|
|
public bool canHitWater;
|
|
|
|
private void Awake()
|
|
{
|
|
modelResizeFactor = resizeParent.localScale.x;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (base.transform.parent == null)
|
|
{
|
|
base.gameObject.SetActive(false);
|
|
}
|
|
if (GameController.Instance.iceLevel)
|
|
{
|
|
particleHit = UnityEngine.Object.Instantiate(GameController.Instance.waterEffectsManager.GetSplashParticlePrefab(WaterEffectsManager.SplashSize.VERY_SMALL));
|
|
}
|
|
else
|
|
{
|
|
particleHit = UnityEngine.Object.Instantiate(GameController.Instance.waterEffectsManager.GetSplashParticlePrefab(WaterEffectsManager.SplashSize.SMALL));
|
|
}
|
|
particleHit.transform.parent = null;
|
|
GameController.Instance.waterEffectsManager.InitParticleDisplacement(particleHit);
|
|
setRopePosition = true;
|
|
fishTriesForce.x = 2000f;
|
|
fishTriesForce.y = 2000f;
|
|
fishTriesForceMenuMultiplier = 4f;
|
|
floatingSpeed = 0.01f;
|
|
floatingMax = 0.01f;
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
rigidbody = GetComponent<Rigidbody>();
|
|
collider = GetComponent<Collider>();
|
|
bait = fishingHands.bait;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Time.timeScale == 0f || !fishingHands.fishingPlayer)
|
|
{
|
|
return;
|
|
}
|
|
if (!fishingHands.baitWasThrown)
|
|
{
|
|
rigidbody.useGravity = true;
|
|
rigidbody.drag = 1f;
|
|
rigidbody.angularDrag = 1f;
|
|
return;
|
|
}
|
|
isLoose = !bait.fish || fishingHands.fishingLine.isLoose;
|
|
if (!isOnWater && base.transform.position.y <= 0f && canHitWater)
|
|
{
|
|
HitWater();
|
|
}
|
|
currentStandardOffset = standardOffset;
|
|
if (!fishingHands.fishingPlayer.underwaterCamera.isTurnedOn)
|
|
{
|
|
currentStandardOffset *= fishingHands.floatSizeMultiplier;
|
|
}
|
|
burdenFactor = Mathf.Lerp(-1f, 1f, (optimalBurden - currentBurden) / (optimalBurden * 2f) + 0.5f);
|
|
if (burdenFactor <= 0f)
|
|
{
|
|
burdenOffset = Mathf.Lerp(0f, burdenOffsetMinMax.x, 0f - burdenFactor);
|
|
}
|
|
else if (burdenFactor == 1f)
|
|
{
|
|
burdenOffset = (0f - currentStandardOffset) * 1.2f;
|
|
}
|
|
else if (burdenFactor > 0f)
|
|
{
|
|
burdenOffset = Mathf.Lerp(0f, 0f - currentStandardOffset, burdenFactor);
|
|
}
|
|
else
|
|
{
|
|
burdenOffset = 0f - currentStandardOffset;
|
|
}
|
|
UpdateFloatingOffset();
|
|
float num = currentStandardOffset + burdenOffset + floatingEasedOffset;
|
|
if (base.transform.position.y < num)
|
|
{
|
|
rigidbody.mass = mass;
|
|
if (isLoose)
|
|
{
|
|
if (burdenFactor > -1f)
|
|
{
|
|
base.transform.position = Vector3.MoveTowards(base.transform.position, new Vector3(base.transform.position.x, num, base.transform.position.z), moveSurfaceSpeed * Time.deltaTime);
|
|
rigidbody.velocity = Vector3.zero;
|
|
rigidbody.angularVelocity = Vector3.zero;
|
|
rigidbody.useGravity = false;
|
|
rigidbody.drag = 5f;
|
|
rigidbody.angularDrag = 5f;
|
|
}
|
|
else
|
|
{
|
|
rigidbody.useGravity = true;
|
|
rigidbody.drag = 15f;
|
|
rigidbody.angularDrag = 1f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
rigidbody.useGravity = false;
|
|
rigidbody.drag = 15f;
|
|
rigidbody.angularDrag = 20f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
rigidbody.useGravity = true;
|
|
rigidbody.drag = 1f;
|
|
rigidbody.angularDrag = 1f;
|
|
}
|
|
if ((bool)fishingHands.fishingPlayer.fish && fishingHands.fishingPlayer.fish.storedBait != bait)
|
|
{
|
|
isTryAnimation = false;
|
|
}
|
|
else
|
|
{
|
|
isTryAnimation = ((bool)fishingHands.fishingPlayer.fish && fishingHands.fishingPlayer.fish.isTryingBait) || (isOnWater && fishTriesTimer >= 0f && (!fishingHands.fishingPlayer.fish || fishingHands.fishingPlayer.fish.isTryingBait));
|
|
}
|
|
if (isTryAnimation)
|
|
{
|
|
FishTriesBaitAnimation();
|
|
}
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (Time.timeScale != 0f && (bool)fishingHands && (bool)fishingHands.fishingPlayer && setRopePosition && !fishingHands.fishingPlayer.fish)
|
|
{
|
|
fishingHands.floatRope.transform.position = base.transform.position;
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (Time.timeScale == 0f || !fishingHands || !fishingHands.fishingPlayer)
|
|
{
|
|
return;
|
|
}
|
|
if ((bool)resizeParent)
|
|
{
|
|
if (fishingHands.baitWasThrown && !fishingHands.fishingPlayer.underwaterCamera.isTurnedOn)
|
|
{
|
|
resizeParent.localScale = Vector3.one * modelResizeFactor * fishingHands.floatSizeMultiplier;
|
|
}
|
|
else
|
|
{
|
|
resizeParent.localScale = Vector3.one * modelResizeFactor;
|
|
}
|
|
}
|
|
if (!fishingHands.baitWasThrown || !isOnWater)
|
|
{
|
|
return;
|
|
}
|
|
if (setRopePosition && !fishingHands.fishingPlayer.fish)
|
|
{
|
|
fishingHands.floatRope.transform.position = base.transform.position;
|
|
}
|
|
Vector3 vectorAngles180Range = Utilities.GetVectorAngles180Range(base.transform.eulerAngles);
|
|
if (isTryAnimation)
|
|
{
|
|
vectorAngles180Range.x = Mathf.Clamp(vectorAngles180Range.x, -5f, 5f);
|
|
vectorAngles180Range.z = Mathf.Clamp(vectorAngles180Range.z, -5f, 5f);
|
|
base.transform.eulerAngles = vectorAngles180Range;
|
|
}
|
|
else if (!newPhysics && fishingHands.fishingLine.isLoose)
|
|
{
|
|
if (burdenFactor <= 0f)
|
|
{
|
|
vectorAngles180Range.x = Mathf.Clamp(vectorAngles180Range.x, -5f, 5f);
|
|
vectorAngles180Range.z = Mathf.Clamp(vectorAngles180Range.z, -5f, 5f);
|
|
}
|
|
else
|
|
{
|
|
vectorAngles180Range.x = Mathf.Clamp(vectorAngles180Range.x, -90f, 90f);
|
|
vectorAngles180Range.z = Mathf.Clamp(vectorAngles180Range.z, -90f, 90f);
|
|
}
|
|
base.transform.eulerAngles = Vector3.MoveTowards(Utilities.GetVectorAngles180Range(base.transform.eulerAngles), vectorAngles180Range, rotateSurfaceSpeed * Time.deltaTime);
|
|
bool flag = true;
|
|
if ((bool)fishingHands.fishingPlayer.fish || (bool)fishingHands.fishingPlayer.junk)
|
|
{
|
|
flag = false;
|
|
}
|
|
if (burdenFactor <= 0f)
|
|
{
|
|
flag = false;
|
|
}
|
|
if (rigidbody.velocity.sqrMagnitude > 1f)
|
|
{
|
|
flag = false;
|
|
}
|
|
if (flag)
|
|
{
|
|
vectorAngles180Range = Utilities.GetVectorAngles180Range(model.transform.localEulerAngles);
|
|
burdenRotation = Mathf.Lerp(0f, 89f, Mathf.Pow(burdenFactor, 2f));
|
|
vectorAngles180Range.x = Mathf.MoveTowards(vectorAngles180Range.x, burdenRotation, rotateSurfaceSpeed * Time.deltaTime * 3f);
|
|
vectorAngles180Range.y = 180f;
|
|
vectorAngles180Range.z = 0f;
|
|
model.transform.localEulerAngles = vectorAngles180Range;
|
|
}
|
|
}
|
|
vectorAngles180Range = Utilities.GetVectorAngles180Range(model.transform.eulerAngles);
|
|
vectorAngles180Range.x = Mathf.MoveTowards(vectorAngles180Range.x, Mathf.Clamp(vectorAngles180Range.x, -89f, 89f), rotateSurfaceSpeed * Time.deltaTime * 10f);
|
|
model.transform.eulerAngles = vectorAngles180Range;
|
|
}
|
|
|
|
public void UpdateFloatingOffset()
|
|
{
|
|
floatingOffset += Time.deltaTime * floatingSpeed * ((!(floatingTarget > 0f)) ? (-1f) : 1f);
|
|
if ((floatingTarget < 0f && floatingOffset <= floatingTarget) || (floatingTarget > 0f && floatingOffset >= floatingTarget))
|
|
{
|
|
floatingPrevTarget = floatingTarget;
|
|
floatingTarget = UnityEngine.Random.Range(0.01f, (!(floatingTarget < 0f)) ? (floatingMax * 2f) : floatingMax) * ((!(floatingTarget > 0f)) ? 1f : (-1f));
|
|
}
|
|
float num = Mathf.Abs(floatingPrevTarget - floatingTarget);
|
|
float num2 = Mathf.Abs(floatingOffset - floatingTarget);
|
|
floatingEasedOffset = Mathf.Lerp(floatingPrevTarget, floatingTarget, floatingCurve.Evaluate((num - num2) / num));
|
|
}
|
|
|
|
public float GetDepth()
|
|
{
|
|
return base.transform.position.y;
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision col)
|
|
{
|
|
if (!isOnWater)
|
|
{
|
|
fishingHands.fishingRod.fishingPlayer.LineBreak(Utilities.GetTranslation("HUD_MESSAGE/BAIT_HIT_OBSTACLE"), 0f);
|
|
fishingHands.fishingPlayer.BlockMouseLook(false);
|
|
Debug.Log("Float collide with: " + col.gameObject.name + " at pos: " + base.transform.position.y);
|
|
}
|
|
}
|
|
|
|
public void ResetFloat()
|
|
{
|
|
base.transform.parent = GameController.Instance.transform;
|
|
float num = fishingHands.baitStartPosition.y;
|
|
if (fishingHands.floatRopeDepth > 1.5f)
|
|
{
|
|
num -= fishingHands.floatRopeDepth - 1.5f;
|
|
}
|
|
base.transform.position = fishingHands.fishingRod.rodEndPosition.position + new Vector3(0f, 0f - num, 0f);
|
|
rigidbody.isKinematic = false;
|
|
isOnWater = false;
|
|
canHitWater = false;
|
|
rigidbody.mass = 10f;
|
|
rigidbody.drag = 1f;
|
|
rigidbody.angularDrag = 1f;
|
|
rigidbody.velocity = Vector3.zero;
|
|
rigidbody.angularVelocity = Vector3.zero;
|
|
rigidbody.constraints = RigidbodyConstraints.None;
|
|
floatingOffset = 0f;
|
|
floatingTarget = 0f - floatingMax;
|
|
floatingPrevTarget = 0f;
|
|
fishTriesTimer = -1f;
|
|
fishTriesForceTimer = -1f;
|
|
fishTriesPullTimer = 0f;
|
|
fishTriesRippleTimer = -1f;
|
|
}
|
|
|
|
public void StartThrowFloat()
|
|
{
|
|
rigidbody.mass = 1f;
|
|
rigidbody.drag = 0f;
|
|
}
|
|
|
|
public void ThrowFloat()
|
|
{
|
|
fishingHands.fishingFloat.rigidbody.isKinematic = true;
|
|
fishingHands.fishingFloat.collider.isTrigger = false;
|
|
LeanTween.delayedCall((!VRManager.Instance.IsVRHoldRod()) ? 1.5f : 0.2f, (Action)delegate
|
|
{
|
|
canHitWater = true;
|
|
});
|
|
}
|
|
|
|
public void HitWater()
|
|
{
|
|
if (isOnWater)
|
|
{
|
|
return;
|
|
}
|
|
AudioController.Play("SplashBait_01", base.transform.position, base.transform, 1f);
|
|
isOnWater = true;
|
|
Splash();
|
|
rigidbody.isKinematic = false;
|
|
fishingHands.ThrowObjectHitWater();
|
|
fishingHands.fishingPlayer.floatCamera.TurnOn(true);
|
|
if ((bool)GlobalSettings.Instance && GlobalSettings.Instance.playerSettings.IsCasual())
|
|
{
|
|
if (currentBurden >= optimalBurden * 2f)
|
|
{
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("HUD_MESSAGE/FLOAT_TOO_HEAVY"), 7f);
|
|
}
|
|
else if (currentBurden == 0f)
|
|
{
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("HUD_MESSAGE/FLOAT_NO_WEIGHT"), 7f);
|
|
}
|
|
}
|
|
}
|
|
|
|
public float GetBaitFloatDistance()
|
|
{
|
|
return Vector3.Distance(ropeBaitRigidbody.transform.position, bait.transform.position);
|
|
}
|
|
|
|
public void Splash()
|
|
{
|
|
particleHit.transform.position = new Vector3(base.transform.position.x, (!GameController.Instance.iceLevel) ? 0.3f : 0f, base.transform.position.z);
|
|
particleHit.transform.eulerAngles = new Vector3(-90f, 0f, 0f);
|
|
particleHit.Play(true);
|
|
GameController.Instance.waterEffectsManager.SplashWakeEffect(particleHit.transform.position, 3f);
|
|
}
|
|
|
|
public void FishTriesBaitAnimation()
|
|
{
|
|
fishTriesTimer += Time.deltaTime;
|
|
fishTriesRippleTimer -= Time.deltaTime;
|
|
fishTriesForceTimer -= Time.deltaTime;
|
|
float num = Mathf.InverseLerp(0f, 4f, fishTriesTimer);
|
|
if (fishTriesPullTimer > 0f)
|
|
{
|
|
fishTriesPullTimer -= Time.deltaTime;
|
|
Vector3 force = Vector3.down * fishTriesCurrentForce * num * moveSurfaceSpeed;
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
force *= fishTriesForceMenuMultiplier;
|
|
}
|
|
force *= 1f - Mathf.Abs(burdenFactor);
|
|
rigidbody.AddForce(force);
|
|
if (fishTriesRippleTimer <= 0f)
|
|
{
|
|
GameController.Instance.PlayWaterRipple(base.transform.position, Mathf.Lerp(10f, 50f, num), Mathf.Lerp(0.6f, 1f, num));
|
|
fishTriesRippleTimer = UnityEngine.Random.Range(2f, 2.5f) - num;
|
|
}
|
|
}
|
|
else if (fishTriesForceTimer < 0f)
|
|
{
|
|
fishTriesForceTimer = UnityEngine.Random.Range(0.8f, 1.2f);
|
|
fishTriesPullTimer = UnityEngine.Random.Range(0.1f, 0.2f);
|
|
fishTriesCurrentForce = UnityEngine.Random.Range(fishTriesForce.x, fishTriesForce.y);
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void StartTriesAnim()
|
|
{
|
|
fishTriesTimer = 0f;
|
|
fishTriesRippleTimer = 3f;
|
|
}
|
|
}
|