1286 lines
32 KiB
C#
1286 lines
32 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BehaviorDesigner.Runtime;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class Bait : MonoBehaviour
|
|
{
|
|
public enum BaitType
|
|
{
|
|
HOOK = 0,
|
|
SPINNER = 1,
|
|
SPOON = 2,
|
|
WOBBLER = 3,
|
|
SOFT_BAIT = 4,
|
|
FLY = 5,
|
|
SAKURA_DLC_01 = 6
|
|
}
|
|
|
|
public enum FlyType
|
|
{
|
|
DRY = 0,
|
|
WET = 1,
|
|
NYMPH = 2,
|
|
STREAMER = 3
|
|
}
|
|
|
|
public enum HookColor
|
|
{
|
|
SILVER = 0,
|
|
GOLD = 1,
|
|
BLACK = 2,
|
|
RED = 3,
|
|
DARK_SILVER = 4
|
|
}
|
|
|
|
public enum VerticalMove
|
|
{
|
|
NONE = 0,
|
|
UP = 1,
|
|
DOWN = 2,
|
|
STRAIGHT = 3,
|
|
TARGET_HEIGHT = 4
|
|
}
|
|
|
|
public class FishDistancComparer : IComparer
|
|
{
|
|
private Vector2 baitPos;
|
|
|
|
public FishDistancComparer(Vector3 baitPos)
|
|
{
|
|
this.baitPos = new Vector2(baitPos.x, baitPos.z);
|
|
}
|
|
|
|
public int Compare(object x, object y)
|
|
{
|
|
Collider collider = (Collider)x;
|
|
Collider collider2 = (Collider)y;
|
|
Vector2 vector = new Vector2(collider.transform.position.x, collider.transform.position.z);
|
|
Vector2 vector2 = new Vector2(collider2.transform.position.x, collider2.transform.position.z);
|
|
vector -= baitPos;
|
|
vector2 -= baitPos;
|
|
return (int)(vector.sqrMagnitude - vector2.sqrMagnitude);
|
|
}
|
|
}
|
|
|
|
public BaitType baitType;
|
|
|
|
[ReadOnly]
|
|
public int hookSize = 8;
|
|
|
|
public float sizeScaleFactor = 1f;
|
|
|
|
public const float hookSizeCmTest = 0.032f;
|
|
|
|
[ReadOnly]
|
|
public Vector2 fishLengthRange = Vector2.one;
|
|
|
|
[ReadOnly]
|
|
public Vector2 fishWeightRang = Vector2.one;
|
|
|
|
public FlyType flyType;
|
|
|
|
public HookColor hookColor;
|
|
|
|
public GameObject ropeRigidbody;
|
|
|
|
public Transform catchPosition;
|
|
|
|
public Vector3 catchRotation = new Vector3(180f, 0f, 0f);
|
|
|
|
public Transform hookCatch;
|
|
|
|
public Vector3 hookCatchRotation = Vector3.zero;
|
|
|
|
[ReadOnly]
|
|
public Transform fishMouthTransform;
|
|
|
|
public Fish fish;
|
|
|
|
[ReadOnly]
|
|
public Junk junk;
|
|
|
|
public float length = 6f;
|
|
|
|
public float realMass = 10f;
|
|
|
|
public float valueMultiplier = 1f;
|
|
|
|
[Space(10f)]
|
|
public float buoyancy = 30f;
|
|
|
|
public float mass = 20f;
|
|
|
|
public float targetHeight = 666f;
|
|
|
|
public float targetSwimHeight = 666f;
|
|
|
|
[HideInInspector]
|
|
public Vector3 verticalForce = Vector3.up;
|
|
|
|
public VerticalMove verticalMove;
|
|
|
|
[HideInInspector]
|
|
public BoxCollider collider;
|
|
|
|
[HideInInspector]
|
|
public Vector3 colliderStartCenter = Vector3.zero;
|
|
|
|
public bool changeColliderCenter;
|
|
|
|
public Vector3 colliderIdleCenter = Vector3.zero;
|
|
|
|
[HideInInspector]
|
|
public FishingFloat fishingFloat;
|
|
|
|
[HideInInspector]
|
|
public FishingHands fishingHands;
|
|
|
|
[ReadOnly]
|
|
public bool isOnWater;
|
|
|
|
[ReadOnly]
|
|
public bool isNearPlayer;
|
|
|
|
[HideInInspector]
|
|
public Rigidbody rigidbody;
|
|
|
|
public Transform centerOfMass;
|
|
|
|
[HideInInspector]
|
|
public EquipmentObject equipmentObject;
|
|
|
|
[HideInInspector]
|
|
public ParticleSystem particleHit;
|
|
|
|
[Space(10f)]
|
|
public int baitPartsMax = 3;
|
|
|
|
[ReadOnly]
|
|
public List<BaitPart> baitParts = new List<BaitPart>();
|
|
|
|
public List<Transform> baitPartsPositions = new List<Transform>();
|
|
|
|
[HideInInspector]
|
|
public BaitAnimation baitAnimation;
|
|
|
|
private static int velocityFrames = 10;
|
|
|
|
private Queue velocities;
|
|
|
|
[ReadOnly]
|
|
public float avgVelocity;
|
|
|
|
[ReadOnly]
|
|
public bool canHitWater;
|
|
|
|
[ReadOnly]
|
|
public float isVisibleToFishTimer;
|
|
|
|
[HideInInspector]
|
|
public Vector3 prevPosition = Vector3.zero;
|
|
|
|
public FishLikesParams fishLikesParams;
|
|
|
|
private static int baitLayerNr = -1;
|
|
|
|
private Coroutine checkHookCoroutine;
|
|
|
|
private bool jkmPauseOnFound;
|
|
|
|
private float nextFindFishTime;
|
|
|
|
private Fish curFish;
|
|
|
|
private WaitForSeconds waitOneSecond = new WaitForSeconds(1f);
|
|
|
|
private void Awake()
|
|
{
|
|
if (baitLayerNr == -1)
|
|
{
|
|
baitLayerNr = LayerMask.NameToLayer("Bait");
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (base.transform.parent == null)
|
|
{
|
|
}
|
|
fish = null;
|
|
velocities = new Queue(velocityFrames);
|
|
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);
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
equipmentObject = GlobalSettings.Instance.equipmentManager.GetCurrentEquipment(EquipmentObject.EquipmentType.HOOK);
|
|
hookSize = (int)GlobalSettings.Instance.equipmentManager.currentSetSpecificParameters.currentHookSize;
|
|
fishLengthRange = GlobalSettings.Instance.fishManager.baitToFishSize[hookSize];
|
|
if (baitType == BaitType.HOOK)
|
|
{
|
|
fishWeightRang = GlobalSettings.Instance.fishManager.hookToFishWeight[hookSize];
|
|
}
|
|
else if (baitType == BaitType.FLY)
|
|
{
|
|
fishWeightRang = GlobalSettings.Instance.fishManager.flyToFishWeight[hookSize];
|
|
}
|
|
else
|
|
{
|
|
fishWeightRang = GlobalSettings.Instance.fishManager.lureToFishWeight[hookSize];
|
|
}
|
|
if ((bool)jkmStatistic.Instance)
|
|
{
|
|
if ((bool)jkmStatistic.Instance.baitRange)
|
|
{
|
|
jkmStatistic.Instance.baitRange.text = "BaitRang " + fishWeightRang.ToString();
|
|
}
|
|
jkmStatistic.NewBaitSize(this);
|
|
}
|
|
Debug.LogWarning(string.Concat("JKM bait change type = ", baitType, ", size = ,", hookSize, "(", UtilitiesUnits.GetHookSizeString(hookSize), ") rang =", fishWeightRang));
|
|
if (sizeScaleFactor < 0f)
|
|
{
|
|
base.transform.localScale = Vector3.one * (0f - sizeScaleFactor);
|
|
}
|
|
else
|
|
{
|
|
base.transform.localScale = Vector3.one * GlobalSettings.Instance.equipmentManager.hookSizesCm[hookSize] / sizeScaleFactor;
|
|
}
|
|
}
|
|
else if (sizeScaleFactor < 0f)
|
|
{
|
|
base.transform.localScale = Vector3.one * (0f - sizeScaleFactor);
|
|
}
|
|
else
|
|
{
|
|
base.transform.localScale = Vector3.one * 0.032f / sizeScaleFactor;
|
|
}
|
|
fishMouthTransform = new GameObject("FishMouthTransform").transform;
|
|
fishMouthTransform.parent = base.transform;
|
|
fishMouthTransform.localPosition = Vector3.zero;
|
|
fishMouthTransform.localEulerAngles = Vector3.zero;
|
|
verticalForce = Vector3.up * 150f;
|
|
if (GameController.Instance.iceLevel)
|
|
{
|
|
canHitWater = true;
|
|
}
|
|
if (base.transform.parent == null)
|
|
{
|
|
Initialize();
|
|
}
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
rigidbody = GetComponent<Rigidbody>();
|
|
baitAnimation = GetComponent<BaitAnimation>();
|
|
collider = GetComponent<BoxCollider>();
|
|
colliderStartCenter = collider.center;
|
|
if ((bool)centerOfMass)
|
|
{
|
|
rigidbody.centerOfMass = centerOfMass.localPosition;
|
|
}
|
|
if ((bool)fishingHands)
|
|
{
|
|
fishingFloat = fishingHands.fishingFloat;
|
|
}
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
hookSize = (int)GlobalSettings.Instance.equipmentManager.currentSetSpecificParameters.currentHookSize;
|
|
if (sizeScaleFactor < 0f)
|
|
{
|
|
base.transform.localScale = Vector3.one * (0f - sizeScaleFactor);
|
|
}
|
|
else
|
|
{
|
|
base.transform.localScale = Vector3.one * GlobalSettings.Instance.equipmentManager.hookSizesCm[hookSize] / sizeScaleFactor;
|
|
}
|
|
}
|
|
else if (sizeScaleFactor < 0f)
|
|
{
|
|
base.transform.localScale = Vector3.one * (0f - sizeScaleFactor);
|
|
}
|
|
else
|
|
{
|
|
base.transform.localScale = Vector3.one * 0.032f / sizeScaleFactor;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!fishingHands || !fishingHands.fishingPlayer || !fishingHands.baitWasThrown)
|
|
{
|
|
return;
|
|
}
|
|
if (isOnWater && fishingHands.bait.gameObject.layer != baitLayerNr)
|
|
{
|
|
Utilities.LogError("Bait wrong layer", "orange");
|
|
fishingHands.bait.UpdateLayers("Bait", true);
|
|
if ((bool)fishingHands.fishingPlayer.fish && fishingHands.fishingPlayer.fish.isWatchingFish)
|
|
{
|
|
for (int i = 0; i < fishingHands.floatWeights.Count; i++)
|
|
{
|
|
Utilities.SetLayerRecursively(fishingHands.floatWeights[i].gameObject, "TransparentFX");
|
|
}
|
|
}
|
|
}
|
|
if (base.transform.position.y < -10f && !fishingHands.updateLeftArmPos)
|
|
{
|
|
Debug.LogError("Bait transform.position.y < -10.0f");
|
|
GameController.Instance.fishingPlayer.LineBreak(Utilities.GetTranslation("HUD_MESSAGE/BAIT_HIT_OBSTACLE"), 0f);
|
|
return;
|
|
}
|
|
if (!isOnWater && base.transform.position.y <= 0f && canHitWater && (!GameController.Instance.iceLevel || fishingHands.fishingPlayer.currentState == FishingPlayer.PlayerState.ICE_FISHING))
|
|
{
|
|
HitWater();
|
|
}
|
|
if (fishingHands.fishingPlayer.gameController.iceLevel && isOnWater && base.transform.position.y > 0.05f)
|
|
{
|
|
isOnWater = false;
|
|
}
|
|
if (isOnWater && isVisibleToFishTimer > 0f)
|
|
{
|
|
isVisibleToFishTimer -= Time.deltaTime;
|
|
}
|
|
if ((bool)fish)
|
|
{
|
|
if (fish.isOnGround)
|
|
{
|
|
rigidbody.drag = 1f;
|
|
rigidbody.angularDrag = 1f;
|
|
rigidbody.mass = mass;
|
|
rigidbody.useGravity = true;
|
|
rigidbody.isKinematic = false;
|
|
}
|
|
else
|
|
{
|
|
rigidbody.drag = Mathf.Lerp(buoyancy, 0f, (base.transform.position.y + 0.1f) * 10f);
|
|
rigidbody.drag = buoyancy;
|
|
rigidbody.angularDrag = 100f;
|
|
rigidbody.mass = mass * 2f;
|
|
}
|
|
}
|
|
else if ((bool)junk)
|
|
{
|
|
rigidbody.drag = Mathf.Lerp(20f - junk.weight, 0f, (base.transform.position.y + 0.1f) * 10f);
|
|
rigidbody.drag = Mathf.Max(5f, buoyancy - junk.weight * 1.7f);
|
|
rigidbody.angularDrag = 10f;
|
|
rigidbody.mass = mass * 1.5f;
|
|
}
|
|
else if (!isOnWater)
|
|
{
|
|
rigidbody.mass = 10f;
|
|
rigidbody.drag = 1f;
|
|
rigidbody.angularDrag = 1f;
|
|
}
|
|
else
|
|
{
|
|
rigidbody.drag = Mathf.Lerp(buoyancy, 0f, (base.transform.position.y + 0.1f) * 10f);
|
|
if (fishingHands.isGroundRig)
|
|
{
|
|
rigidbody.drag = 18f;
|
|
}
|
|
else
|
|
{
|
|
rigidbody.drag = buoyancy;
|
|
}
|
|
rigidbody.angularDrag = 4f;
|
|
rigidbody.mass = mass;
|
|
rigidbody.useGravity = true;
|
|
if (base.transform.position.y < -0.05f)
|
|
{
|
|
if (fishingHands.fishingLine.looseTensionFactor > 0.45f && UtilitiesInput.isReelingIn)
|
|
{
|
|
rigidbody.drag = 45f;
|
|
}
|
|
}
|
|
else if (base.transform.position.y > 0.05f)
|
|
{
|
|
rigidbody.mass = 10f;
|
|
rigidbody.drag = 1f;
|
|
rigidbody.angularDrag = 1f;
|
|
}
|
|
}
|
|
if (isOnWater && !fish && !junk && Physics.OverlapSphere(base.transform.position, 0.1f, LayerMask.GetMask("Default", "Terrain")).Length > 0)
|
|
{
|
|
fishingHands.spinningMethodController.SpinningStateEvent(SpinningMethodController.SpinningState.GROUND);
|
|
fishingHands.fishingPlayer.gameController.hudManager.hudFishing.UpdateBaitState(1);
|
|
if ((bool)fishingHands.feeder)
|
|
{
|
|
fishingHands.feeder.TurnOn(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fishingHands.fishingPlayer.gameController.hudManager.hudFishing.UpdateBaitState(0);
|
|
if ((bool)fishingHands.feeder)
|
|
{
|
|
fishingHands.feeder.TurnOn(false);
|
|
}
|
|
}
|
|
if (!fishingHands.fishingPlayer.IsSomethingOnBait() && isOnWater)
|
|
{
|
|
baitAnimation.UpdateAnimation();
|
|
}
|
|
if (GameController.Instance.iceLevel)
|
|
{
|
|
isNearPlayer = base.transform.position.y > -1f;
|
|
}
|
|
else
|
|
{
|
|
isNearPlayer = Vector3.Distance(base.transform.position, fishingHands.fishingPlayer.transform.position) < 8f;
|
|
}
|
|
Debug.Log(string.Concat("------------- fish weight rang ------", fishWeightRang, " ------- hook size ------", hookSize));
|
|
}
|
|
|
|
private void FindIntrestedFish()
|
|
{
|
|
nextFindFishTime -= Time.deltaTime;
|
|
if (nextFindFishTime > 0f)
|
|
{
|
|
if ((bool)fish)
|
|
{
|
|
SharedVariable variable = fish.bt.GetVariable("Target");
|
|
if (variable.GetValue() == null)
|
|
{
|
|
fish = null;
|
|
nextFindFishTime = 5f;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((bool)fish)
|
|
{
|
|
return;
|
|
}
|
|
Collider[] array = Physics.OverlapSphere(base.transform.position, 35f, LayerMask.GetMask("Fish"));
|
|
if (array != null)
|
|
{
|
|
Array.Sort(array, new FishDistancComparer(base.transform.position));
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
Fish component = array[i].gameObject.GetComponent<Fish>();
|
|
float num = Vector3.Distance(base.transform.position, component.transform.position);
|
|
if (CheckFishSize(component) != 0 || !component.bt || !component.enabled)
|
|
{
|
|
continue;
|
|
}
|
|
SharedVariable variable2 = component.bt.GetVariable("Target");
|
|
if (variable2 != null && variable2.GetValue() == null && component.LikesBait(base.gameObject))
|
|
{
|
|
curFish = component;
|
|
variable2.SetValue(base.gameObject);
|
|
component.bt.SetVariable("Target", variable2);
|
|
nextFindFishTime = 90f;
|
|
if (jkmPauseOnFound)
|
|
{
|
|
Debug.Break();
|
|
}
|
|
component.UpdateStateIndicator();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
nextFindFishTime += 20f;
|
|
}
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
FixVRTeleportBug();
|
|
FixHooksPosition();
|
|
if ((bool)fishingHands && (bool)fishingHands.fishingPlayer && fishingHands.baitWasThrown)
|
|
{
|
|
if ((bool)fish && !fish.isInNetArea && !fish.isTryingBait && !fish.isOnGround)
|
|
{
|
|
base.transform.position = fishMouthTransform.position;
|
|
base.transform.rotation = fishMouthTransform.rotation;
|
|
}
|
|
else if ((!fish || (!fish.isInNetArea && !fish.isOnGround)) && !fish && fishingHands.isGroundRig && !isOnWater)
|
|
{
|
|
}
|
|
if (((bool)junk || ((bool)fish && fish.isBaitUpdate)) && base.transform.position.y > -0.1f)
|
|
{
|
|
base.transform.position = new Vector3(base.transform.position.x, -0.1f, base.transform.position.z);
|
|
}
|
|
prevPosition = base.transform.position;
|
|
}
|
|
}
|
|
|
|
public void FixedUpdate()
|
|
{
|
|
FixHooksPosition();
|
|
if (!fishingHands || !fishingHands.fishingPlayer || !fishingHands.baitWasThrown)
|
|
{
|
|
return;
|
|
}
|
|
if (!isOnWater)
|
|
{
|
|
}
|
|
if (!isOnWater)
|
|
{
|
|
}
|
|
if ((bool)junk || ((bool)fish && fish.isBaitUpdate))
|
|
{
|
|
if (base.transform.position.y > -0.1f)
|
|
{
|
|
base.transform.position = new Vector3(base.transform.position.x, -0.1f, base.transform.position.z);
|
|
}
|
|
}
|
|
else if (!fish && fishingHands.fishingPlayer.IsTrolling())
|
|
{
|
|
if (base.transform.position.y > -0.1f)
|
|
{
|
|
base.transform.position = new Vector3(base.transform.position.x, -0.1f, base.transform.position.z);
|
|
}
|
|
}
|
|
else if ((bool)fish && fish.isInNetArea && !fish.isWatchingFish)
|
|
{
|
|
rigidbody.useGravity = false;
|
|
rigidbody.isKinematic = false;
|
|
Vector3 position = base.transform.position;
|
|
position.y = 0f;
|
|
base.transform.position = position;
|
|
base.transform.eulerAngles = new Vector3((catchRotation.x != 90f) ? 90f : 180f, 0f, 180f);
|
|
}
|
|
else if ((!fish || !fish.isOnGround) && (bool)fishingHands && !GameController.Instance.iceLevel)
|
|
{
|
|
float num = 0.045f;
|
|
if (base.transform.position.y < 0.05f && fishingHands.fishingLine.looseTensionFactor > 0.45f && UtilitiesInput.isReelingIn)
|
|
{
|
|
if (rigidbody.useGravity)
|
|
{
|
|
}
|
|
if (targetSwimHeight == 0f)
|
|
{
|
|
num = 0.01f;
|
|
}
|
|
if (verticalMove == VerticalMove.DOWN)
|
|
{
|
|
rigidbody.drag = 20f;
|
|
}
|
|
else if (verticalMove == VerticalMove.UP)
|
|
{
|
|
if (base.transform.position.y < 0f)
|
|
{
|
|
rigidbody.useGravity = false;
|
|
rigidbody.AddForce(verticalForce);
|
|
}
|
|
}
|
|
else if (verticalMove == VerticalMove.TARGET_HEIGHT)
|
|
{
|
|
if (base.transform.position.y > targetSwimHeight + num)
|
|
{
|
|
rigidbody.drag = 20f;
|
|
}
|
|
else if (base.transform.position.y < targetSwimHeight - num)
|
|
{
|
|
rigidbody.useGravity = false;
|
|
rigidbody.AddForce(verticalForce);
|
|
}
|
|
else
|
|
{
|
|
rigidbody.drag = 70f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
rigidbody.useGravity = false;
|
|
}
|
|
}
|
|
else if (base.transform.position.y < 0.05f)
|
|
{
|
|
rigidbody.useGravity = true;
|
|
if (targetHeight <= 0f)
|
|
{
|
|
if (targetHeight == 0f)
|
|
{
|
|
num = 0.01f;
|
|
}
|
|
if (base.transform.position.y > targetHeight + num)
|
|
{
|
|
rigidbody.drag = 20f;
|
|
}
|
|
else if (base.transform.position.y < targetHeight - num)
|
|
{
|
|
rigidbody.useGravity = false;
|
|
rigidbody.AddForce(Vector3.up * 300f);
|
|
}
|
|
else
|
|
{
|
|
rigidbody.drag = 70f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ((bool)fish || !isOnWater || GameController.Instance.iceLevel || !(base.transform.position.y < -0.05f))
|
|
{
|
|
return;
|
|
}
|
|
Vector3 vectorAnglesNormalRange = Utilities.GetVectorAnglesNormalRange(base.transform.eulerAngles);
|
|
if (baitAnimation.useTargetXRotation || baitAnimation.useIdleXRotation)
|
|
{
|
|
if (vectorAnglesNormalRange.x < 30f)
|
|
{
|
|
vectorAnglesNormalRange.x = 30f;
|
|
}
|
|
else if (vectorAnglesNormalRange.x > 150f)
|
|
{
|
|
vectorAnglesNormalRange.x = 150f;
|
|
}
|
|
}
|
|
if (UtilitiesInput.isReelingIn)
|
|
{
|
|
if (baitAnimation.useTargetXRotation)
|
|
{
|
|
vectorAnglesNormalRange.x = Mathf.MoveTowards(vectorAnglesNormalRange.x, baitAnimation.targetXrotation, 5f);
|
|
}
|
|
else if (baitAnimation.useTargetYRotation)
|
|
{
|
|
vectorAnglesNormalRange.y = Mathf.MoveTowards(vectorAnglesNormalRange.y, baitAnimation.targetYrotation, 5f);
|
|
}
|
|
else if (baitAnimation.useTargetZRotation)
|
|
{
|
|
vectorAnglesNormalRange.z = Mathf.MoveTowards(vectorAnglesNormalRange.x, baitAnimation.targetZrotation, 5f);
|
|
}
|
|
}
|
|
else if (baitAnimation.useIdleXRotation)
|
|
{
|
|
vectorAnglesNormalRange.x = Mathf.MoveTowards(vectorAnglesNormalRange.x, baitAnimation.idleXrotation, 2f);
|
|
}
|
|
else if (baitAnimation.useIdleYRotation)
|
|
{
|
|
vectorAnglesNormalRange.y = Mathf.MoveTowards(vectorAnglesNormalRange.y, baitAnimation.idleYrotation, 2f);
|
|
}
|
|
else if (baitAnimation.useIdleZRotation)
|
|
{
|
|
vectorAnglesNormalRange.z = Mathf.MoveTowards(vectorAnglesNormalRange.x, baitAnimation.idleZrotation, 2f);
|
|
}
|
|
base.transform.eulerAngles = vectorAnglesNormalRange;
|
|
}
|
|
|
|
[Button]
|
|
public void FixHooksPosition()
|
|
{
|
|
if (!(baitAnimation == null) && baitAnimation.movingParts != null)
|
|
{
|
|
for (int i = 0; i < baitAnimation.movingParts.Count; i++)
|
|
{
|
|
baitAnimation.movingParts[i].rigidbody.transform.localPosition = baitAnimation.movingParts[i].startPosition;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateLayers(string layerName, bool changeHooks)
|
|
{
|
|
Utilities.SetLayerRecursively(fishingHands.bait.gameObject, layerName);
|
|
if (changeHooks)
|
|
{
|
|
for (int i = 0; i < baitAnimation.movingParts.Count; i++)
|
|
{
|
|
Utilities.SetLayerRecursively(baitAnimation.movingParts[i].rigidbody.gameObject, "Float");
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetFish(Fish newFish)
|
|
{
|
|
fish = newFish;
|
|
if ((bool)newFish)
|
|
{
|
|
Debug.Log("SetFish: " + ((!newFish) ? "null" : newFish.name));
|
|
EatBaitParts();
|
|
UpdateFishMouthTransform();
|
|
fishingHands.fishingPlayer.Zoom(false, 0.5f);
|
|
UtilitiesInput.SetVibration(1, true, 0.45f, 0.4f);
|
|
if ((bool)GlobalSettings.Instance && GameController.Instance.fisheryDefinition != null)
|
|
{
|
|
++GameController.Instance.fisheryDefinition.fisheryStats.bitesAmount;
|
|
GlobalSettings.Instance.levelsManager.Save();
|
|
}
|
|
}
|
|
else if ((bool)fishMouthTransform)
|
|
{
|
|
fishMouthTransform.parent = base.transform;
|
|
fishMouthTransform.localPosition = Vector3.zero;
|
|
fishMouthTransform.localEulerAngles = Vector3.zero;
|
|
}
|
|
if (fish != null)
|
|
{
|
|
StopCheckHookCoroutine();
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void UpdateFishMouthTransform()
|
|
{
|
|
if (!(fish == null))
|
|
{
|
|
if (fishMouthTransform == null)
|
|
{
|
|
fishMouthTransform = new GameObject("FishMouthTransform").transform;
|
|
}
|
|
Transform parent = base.transform.parent;
|
|
Vector3 localScale = base.transform.localScale;
|
|
catchPosition.parent = null;
|
|
base.transform.parent = catchPosition;
|
|
catchPosition.position = fish.mouth.position;
|
|
catchPosition.parent = fish.mouth;
|
|
catchPosition.localEulerAngles = catchRotation;
|
|
base.transform.parent = parent;
|
|
base.transform.localScale = localScale;
|
|
catchPosition.parent = base.transform;
|
|
fishMouthTransform.position = base.transform.position;
|
|
fishMouthTransform.rotation = base.transform.rotation;
|
|
fishMouthTransform.parent = fish.mouth;
|
|
if ((bool)hookCatch)
|
|
{
|
|
hookCatch.localEulerAngles = hookCatchRotation;
|
|
}
|
|
base.transform.position = fishMouthTransform.position;
|
|
base.transform.rotation = fishMouthTransform.rotation;
|
|
fishingHands.currentRope.regenerateRope(true);
|
|
}
|
|
}
|
|
|
|
public void SetJunk(Junk newJunk)
|
|
{
|
|
junk = newJunk;
|
|
if ((bool)newJunk)
|
|
{
|
|
ShowBaitParts(false);
|
|
}
|
|
}
|
|
|
|
public float GetDepth()
|
|
{
|
|
return base.transform.position.y;
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision col)
|
|
{
|
|
if (!isOnWater && fishingHands.baitWasThrown && !GameController.Instance.iceLevel && (bool)fishingHands)
|
|
{
|
|
fishingHands.fishingRod.fishingPlayer.LineBreak(Utilities.GetTranslation("HUD_MESSAGE/BAIT_HIT_OBSTACLE"), 0f);
|
|
fishingHands.fishingPlayer.BlockMouseLook(false);
|
|
Debug.Log("Bait collide with: " + col.gameObject.name + " at pos: " + base.transform.position.y);
|
|
}
|
|
}
|
|
|
|
public void CheckIsOnGround(GameObject collisionObject)
|
|
{
|
|
if ((isOnWater && collisionObject.layer == LayerMask.NameToLayer("Default")) || collisionObject.layer == LayerMask.NameToLayer("Terrain"))
|
|
{
|
|
fishingHands.spinningMethodController.SpinningStateEvent(SpinningMethodController.SpinningState.GROUND);
|
|
}
|
|
}
|
|
|
|
[Button]
|
|
public void ResetBait()
|
|
{
|
|
base.transform.parent = GameController.Instance.transform;
|
|
if (!GameController.Instance.iceLevel)
|
|
{
|
|
if ((bool)fishingHands.fishingFloat)
|
|
{
|
|
base.transform.position = fishingHands.fishingFloat.transform.position + new Vector3(0.01f, -1f, 0.01f).normalized * fishingHands.floatRopeDepth;
|
|
}
|
|
else if ((bool)fishingHands.fishingRod)
|
|
{
|
|
base.transform.position = fishingHands.fishingRod.GetVRBaitHoldPosition(false);
|
|
}
|
|
else if ((bool)fishingHands.fishingPlayer)
|
|
{
|
|
base.transform.position = fishingHands.fishingPlayer.transform.position + Vector3.up * 1.75f + fishingHands.fishingPlayer.transform.forward;
|
|
}
|
|
else
|
|
{
|
|
base.transform.position = fishingHands.transform.position + fishingHands.transform.forward;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
base.transform.position = fishingHands.fishingRod.rodEndPosition.position + Vector3.down * (fishingHands.baitStartPosition.x + ((!VRManager.IsVROn()) ? 0.02f : 0.06f));
|
|
}
|
|
SetFish(null);
|
|
SetJunk(null);
|
|
isOnWater = false;
|
|
if (!GameController.Instance.iceLevel)
|
|
{
|
|
canHitWater = false;
|
|
}
|
|
isVisibleToFishTimer = 0f;
|
|
baitAnimation.SetMovingPartsPhysics(true);
|
|
baitAnimation.ResetMovingParts(false);
|
|
baitAnimation.ResetAnimation();
|
|
rigidbody.isKinematic = false;
|
|
rigidbody.useGravity = true;
|
|
rigidbody.mass = 10f;
|
|
rigidbody.drag = 1f;
|
|
rigidbody.angularDrag = 1f;
|
|
rigidbody.velocity = Vector3.zero;
|
|
rigidbody.angularVelocity = Vector3.zero;
|
|
rigidbody.constraints = RigidbodyConstraints.None;
|
|
if (changeColliderCenter)
|
|
{
|
|
collider.center = colliderIdleCenter;
|
|
}
|
|
ShowBaitParts(true);
|
|
if ((bool)fishingFloat)
|
|
{
|
|
fishingHands.floatRope.regenerateRope(false);
|
|
}
|
|
StopCheckHookCoroutine();
|
|
}
|
|
|
|
public void StartThrowBait()
|
|
{
|
|
rigidbody.mass = 1f;
|
|
rigidbody.drag = 0f;
|
|
}
|
|
|
|
public void ThrowBait()
|
|
{
|
|
if ((bool)fishingHands.fishingFloat)
|
|
{
|
|
fishingHands.bait.transform.position = fishingHands.fishingFloat.transform.position + new Vector3(0f, 1f, 0f) * fishingHands.floatRopeDepth;
|
|
fishingHands.bait.rigidbody.isKinematic = false;
|
|
}
|
|
else
|
|
{
|
|
fishingHands.bait.rigidbody.isKinematic = true;
|
|
}
|
|
baitAnimation.SetMovingPartsPhysics(false);
|
|
if (changeColliderCenter)
|
|
{
|
|
collider.center = colliderStartCenter;
|
|
}
|
|
LeanTween.delayedCall((!VRManager.Instance.IsVRHoldRod()) ? 1.5f : 0.2f, (Action)delegate
|
|
{
|
|
canHitWater = true;
|
|
});
|
|
}
|
|
|
|
public void HitWater()
|
|
{
|
|
if (fishingHands == null)
|
|
{
|
|
Debug.LogError("HitWater fishingHands == null");
|
|
}
|
|
if (rigidbody == null)
|
|
{
|
|
Debug.LogError("HitWater rigidbody == null");
|
|
}
|
|
velocities.Clear();
|
|
avgVelocity = 0f;
|
|
isOnWater = true;
|
|
nextFindFishTime = 5f;
|
|
fish = null;
|
|
rigidbody.velocity = Vector3.zero;
|
|
rigidbody.angularVelocity = Vector3.zero;
|
|
rigidbody.isKinematic = false;
|
|
if ((bool)fishingHands.fishingFloat)
|
|
{
|
|
base.transform.parent = fishingFloat.transform;
|
|
fishingHands.floatRope.transform.parent = fishingFloat.transform;
|
|
fishingHands.fishingFloat.HitWater();
|
|
}
|
|
else
|
|
{
|
|
AudioController.Play("SplashBait_01", base.transform.position, base.transform, 1f);
|
|
Splash();
|
|
}
|
|
fishingHands.ThrowObjectHitWater();
|
|
HUDManager.Instance.hookSizeInfoCounter = 0;
|
|
if (!GlobalSettings.Instance && GameController.Instance.stopBaitOnWater)
|
|
{
|
|
rigidbody.isKinematic = true;
|
|
}
|
|
if (fishingHands.isFloatRig)
|
|
{
|
|
isVisibleToFishTimer = UnityEngine.Random.Range(15f, 25f);
|
|
}
|
|
else if (fishingHands.isGroundRig)
|
|
{
|
|
isVisibleToFishTimer = UnityEngine.Random.Range(20f, 35f);
|
|
}
|
|
else if (fishingHands.isFlyRig)
|
|
{
|
|
isVisibleToFishTimer = UnityEngine.Random.Range(1f, 2f);
|
|
}
|
|
else if (fishingHands.isSpinningRig)
|
|
{
|
|
isVisibleToFishTimer = UnityEngine.Random.Range(1f, 2f);
|
|
}
|
|
else
|
|
{
|
|
isVisibleToFishTimer = UnityEngine.Random.Range(10f, 25f);
|
|
}
|
|
GameObject[] array = MultiTags.FindGameObjectsWithMultiTag("BOILIE");
|
|
if (array != null)
|
|
{
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
array[i].GetComponent<Boilie>().fishCounter = 0;
|
|
}
|
|
}
|
|
if ((bool)fishingHands.feeder && (bool)fishingHands.feeder.GetComponent<Boilie>())
|
|
{
|
|
fishingHands.feeder.GetComponent<Boilie>().fishCounter = 0;
|
|
}
|
|
StartCheckHookCoroutine();
|
|
}
|
|
|
|
private void StartCheckHookCoroutine()
|
|
{
|
|
if (GlobalSettings.Instance.playerSettings.showHookPrompt && GlobalSettings.Instance.playerSettings.IsCasual())
|
|
{
|
|
checkHookCoroutine = StartCoroutine(CheckHookCoroutine());
|
|
}
|
|
}
|
|
|
|
private void StopCheckHookCoroutine()
|
|
{
|
|
HUDManager.Instance.HideEndlessMessage();
|
|
if (checkHookCoroutine != null)
|
|
{
|
|
StopCoroutine(checkHookCoroutine);
|
|
checkHookCoroutine = null;
|
|
}
|
|
}
|
|
|
|
private void RestartCheckHookCoroutine()
|
|
{
|
|
StopCheckHookCoroutine();
|
|
StartCheckHookCoroutine();
|
|
}
|
|
|
|
private IEnumerator CheckHookCoroutine()
|
|
{
|
|
if (!GlobalSettings.Instance.playerSettings.showHookPrompt)
|
|
{
|
|
StopCheckHookCoroutine();
|
|
}
|
|
float startTime = Time.time;
|
|
float currentTime = Time.time;
|
|
float timeToSwitchHook = 25f;
|
|
float timeToSwitchPlace = 20f;
|
|
float radius = 12f;
|
|
float maxDistance = 10f;
|
|
List<Fish> hitFish = new List<Fish>();
|
|
int potentialFish = 0;
|
|
int fishSizeResult = 0;
|
|
while (true)
|
|
{
|
|
currentTime = Time.time;
|
|
RaycastHit[] hits = Physics.SphereCastAll(base.transform.position, radius, base.transform.forward, maxDistance, LayerMask.GetMask("Fish"));
|
|
RaycastHit[] array = hits;
|
|
foreach (RaycastHit raycastHit in array)
|
|
{
|
|
Fish component = raycastHit.transform.gameObject.GetComponent<Fish>();
|
|
if (component != null && !hitFish.Contains(component))
|
|
{
|
|
hitFish.Add(component);
|
|
int num = CheckFishSize(component);
|
|
if (num == 0)
|
|
{
|
|
potentialFish++;
|
|
}
|
|
fishSizeResult += num;
|
|
}
|
|
}
|
|
if (currentTime - startTime > timeToSwitchPlace && potentialFish > 0)
|
|
{
|
|
if (baitType != BaitType.HOOK)
|
|
{
|
|
break;
|
|
}
|
|
if (GlobalSettings.Instance.playerSettings.difficulty != PlayerSettingsMy.Difficulty.SIMULATOR)
|
|
{
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("HUD_MESSAGE/HOOK_PROPER"), 5f);
|
|
}
|
|
StopCheckHookCoroutine();
|
|
}
|
|
if (currentTime - startTime > timeToSwitchHook && potentialFish == 0)
|
|
{
|
|
if (fishSizeResult >= 0)
|
|
{
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("HUD_MESSAGE/HOOK_SIZE") + "\n\n" + Utilities.GetTranslation("HUD_MESSAGE/HOOK_SMALLER"), -1f);
|
|
}
|
|
else
|
|
{
|
|
HUDManager.Instance.ShowMessage(Utilities.GetTranslation("HUD_MESSAGE/HOOK_SIZE") + "\n\n" + Utilities.GetTranslation("HUD_MESSAGE/HOOK_BIGGER"), -1f);
|
|
}
|
|
}
|
|
yield return waitOneSecond;
|
|
}
|
|
}
|
|
|
|
public float GetFishInterest(Fish.Species species)
|
|
{
|
|
return fishLikesParams.GetFishInterest(species);
|
|
}
|
|
|
|
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 InitBaitParts(List<BaitPart> baitPartPrefabs)
|
|
{
|
|
if (baitPartPrefabs.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
DestroyBaitParts();
|
|
int num = -1;
|
|
for (int i = 0; i < baitPartPrefabs.Count; i++)
|
|
{
|
|
if (baitPartPrefabs[i] != null && baitPartPrefabs[i].baitPartSize == 3)
|
|
{
|
|
num = i;
|
|
break;
|
|
}
|
|
}
|
|
for (int j = 0; j < baitPartPrefabs.Count && baitPartsMax > j; j++)
|
|
{
|
|
if (num != -1 && num != j)
|
|
{
|
|
continue;
|
|
}
|
|
if (baitPartPrefabs[j] != null)
|
|
{
|
|
BaitPart baitPart = UnityEngine.Object.Instantiate(baitPartPrefabs[j].GetComponent<BaitPart>());
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
baitPart.transform.localScale = Vector3.one * Mathf.Lerp(0.3f, 1.6f, GlobalSettings.Instance.equipmentManager.currentSetSpecificParameters.currentHookSize / 17f);
|
|
}
|
|
else
|
|
{
|
|
baitPart.transform.localScale = Vector3.one;
|
|
}
|
|
baitPart.transform.SetParent(base.transform);
|
|
baitPart.transform.localPosition = baitPartsPositions[j].localPosition;
|
|
baitPart.transform.localEulerAngles = baitPartsPositions[j].localEulerAngles;
|
|
baitPart.baitParent = this;
|
|
baitPart.baitPosition = j;
|
|
baitParts.Add(baitPart);
|
|
}
|
|
else
|
|
{
|
|
baitParts.Add(null);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DestroyBaitParts()
|
|
{
|
|
for (int i = 0; i < baitParts.Count; i++)
|
|
{
|
|
if (baitParts[i] != null)
|
|
{
|
|
UnityEngine.Object.Destroy(baitParts[i].gameObject);
|
|
}
|
|
}
|
|
baitParts.Clear();
|
|
}
|
|
|
|
public void DestroyBaitPart(int baitPosition)
|
|
{
|
|
if (baitPosition >= baitParts.Count)
|
|
{
|
|
Debug.LogError("DestroyBaitPart baitPosition >= baitParts.Count " + baitPosition + " " + baitParts.Count);
|
|
}
|
|
else if (baitParts[baitPosition] != null)
|
|
{
|
|
UnityEngine.Object.Destroy(baitParts[baitPosition].gameObject);
|
|
baitParts[baitPosition] = null;
|
|
}
|
|
}
|
|
|
|
public void EatBaitParts()
|
|
{
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
for (int i = 0; i < baitParts.Count; i++)
|
|
{
|
|
if ((bool)baitParts[i])
|
|
{
|
|
baitParts[i].EatBaitPart();
|
|
}
|
|
}
|
|
GlobalSettings.Instance.equipmentManager.AddFakeBaits();
|
|
GlobalSettings.Instance.equipmentManager.Save();
|
|
}
|
|
ShowBaitParts(false);
|
|
HUDManager.Instance.hudBaits.Refresh(GameController.Instance.fishingPlayer.currentHands);
|
|
}
|
|
|
|
public bool HasAnyBaitParts()
|
|
{
|
|
if (baitType != BaitType.HOOK)
|
|
{
|
|
return true;
|
|
}
|
|
bool result = !GlobalSettings.Instance;
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
for (int i = 0; i < baitParts.Count; i++)
|
|
{
|
|
if ((bool)baitParts[i] && baitParts[i].equipmentObject != null)
|
|
{
|
|
result = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public bool HasAnyLiveBait()
|
|
{
|
|
if (baitType != BaitType.HOOK)
|
|
{
|
|
return false;
|
|
}
|
|
for (int i = 0; i < baitParts.Count; i++)
|
|
{
|
|
if ((bool)baitParts[i] && baitParts[i].baitPartSize == 3)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void ShowBaitParts(bool show)
|
|
{
|
|
for (int i = 0; i < baitParts.Count; i++)
|
|
{
|
|
if ((bool)baitParts[i])
|
|
{
|
|
baitParts[i].gameObject.SetActive(show);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void LoseHook()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && equipmentObject != null)
|
|
{
|
|
equipmentObject.amount--;
|
|
if (equipmentObject.amount < 0)
|
|
{
|
|
equipmentObject.amount = 0;
|
|
GlobalSettings.Instance.equipmentManager.UnequipObject(EquipmentObject.EquipmentType.HOOK);
|
|
}
|
|
GlobalSettings.Instance.equipmentManager.Save();
|
|
fishingHands.CheckHasHook();
|
|
}
|
|
Debug.Log("Lose hook");
|
|
}
|
|
|
|
public bool CheckRequiredEquipment()
|
|
{
|
|
if ((bool)GlobalSettings.Instance && equipmentObject == null)
|
|
{
|
|
return false;
|
|
}
|
|
if ((bool)GlobalSettings.Instance && equipmentObject != null)
|
|
{
|
|
return GlobalSettings.Instance.equipmentManager.GetCurrentEquipment(EquipmentObject.EquipmentType.HOOK) != null && GlobalSettings.Instance.equipmentManager.GetCurrentEquipment(EquipmentObject.EquipmentType.HOOK).prefab != null;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void ReturnToEquipment()
|
|
{
|
|
if (!GlobalSettings.Instance)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < baitParts.Count; i++)
|
|
{
|
|
if ((bool)baitParts[i])
|
|
{
|
|
baitParts[i].ReturnToEquipment();
|
|
}
|
|
}
|
|
GlobalSettings.Instance.equipmentManager.Save();
|
|
}
|
|
|
|
public float CheckTaste(Fish interestedFish)
|
|
{
|
|
float num = 0f;
|
|
if (baitType != BaitType.HOOK)
|
|
{
|
|
num += GetFishInterest(interestedFish.species);
|
|
}
|
|
else
|
|
{
|
|
float[] array = new float[baitParts.Count];
|
|
int num2 = 0;
|
|
for (int i = 0; i < baitParts.Count; i++)
|
|
{
|
|
if ((bool)baitParts[i])
|
|
{
|
|
array[i] = baitParts[i].GetFishInterest(interestedFish.species);
|
|
if (array[i] > array[num2])
|
|
{
|
|
num2 = i;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
array[i] = 0f;
|
|
}
|
|
}
|
|
for (int j = 0; j < baitParts.Count; j++)
|
|
{
|
|
num = ((j != num2) ? (num + array[j] * 0.2f) : (num + array[j]));
|
|
}
|
|
}
|
|
return num;
|
|
}
|
|
|
|
public int CheckFishSize(Fish fishToCheck)
|
|
{
|
|
return CheckFishSizeNew(fishToCheck);
|
|
}
|
|
|
|
public int CheckFishSizeNew(Fish fishToCheck)
|
|
{
|
|
if (fishToCheck.Weight < fishWeightRang.x)
|
|
{
|
|
return 1;
|
|
}
|
|
if (fishToCheck.Weight > fishWeightRang.y)
|
|
{
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public void FixVRTeleportBug()
|
|
{
|
|
if ((bool)baitAnimation && (bool)baitAnimation.baitAnimationParent)
|
|
{
|
|
baitAnimation.baitAnimationParent.localEulerAngles = baitAnimation.baitAnimationParentStartRot;
|
|
baitAnimation.baitAnimationParent.localPosition = baitAnimation.baitAnimationParentStartPos;
|
|
}
|
|
}
|
|
}
|