321 lines
9.4 KiB
C#
321 lines
9.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BitStrap;
|
|
using UnityEngine;
|
|
|
|
public class RodStand : MonoBehaviour
|
|
{
|
|
[Serializable]
|
|
public class RodPlace
|
|
{
|
|
[ReadOnly]
|
|
public FishingRod fishingRod;
|
|
|
|
public Transform rodNormalPosition;
|
|
|
|
public Transform rodElectronicPosition;
|
|
|
|
public Transform electronicIndicatorPosition;
|
|
|
|
public GameObject electronicIndicatorHolderObject;
|
|
|
|
public Collider rodTrigger;
|
|
|
|
[ReadOnly]
|
|
public RodStandTrigger rodStandTrigger;
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
[Button]
|
|
public void TakeRod()
|
|
{
|
|
rodTrigger.enabled = false;
|
|
if (VRManager.Instance.IsVRHoldRod())
|
|
{
|
|
fishingRod.fishingHands.transform.parent = fishingRod.fishingHands.startParent;
|
|
}
|
|
Debug.LogError("ROD_POD TakeRod: " + rodNormalPosition.name + " " + fishingRod.name + " set: " + fishingRod.fishingHands.equipmentSetId);
|
|
fishingRod.fishingHands.HideHandsLayer(false);
|
|
fishingRod.fishingPlayer.allowRun = false;
|
|
fishingRod.fishingPlayer.ufpsController.MotorAcceleration = (fishingRod.fishingPlayer.currentMotorAcceleration = fishingRod.fishingPlayer.motorAccelerationValues.y);
|
|
fishingRod.fishingPlayer.gameController.hudManager.ShowMessageWindow(false, string.Empty);
|
|
if ((bool)fishingRod.fishingHands.biteIndicator)
|
|
{
|
|
fishingRod.fishingHands.biteIndicator.SetBellPosition(true);
|
|
if (fishingRod.fishingHands.biteIndicator.indicatorType == BiteIndicator.IndicatorType.ELECTRONIC)
|
|
{
|
|
fishingRod.fishingHands.biteIndicator.transform.parent = fishingRod.transform;
|
|
fishingRod.fishingHands.biteIndicator.gameObject.SetActive(false);
|
|
}
|
|
fishingRod.fishingHands.biteIndicator.StopIndicating();
|
|
}
|
|
Utilities.SetLayerRecursively(fishingRod.gameObject, "Weapon");
|
|
fishingRod.fishingHands.HideHandsCamera(false);
|
|
if ((bool)electronicIndicatorHolderObject)
|
|
{
|
|
electronicIndicatorHolderObject.SetActive(true);
|
|
}
|
|
if (fishingRod.fishingPlayer.currentHands != fishingRod.fishingHands)
|
|
{
|
|
fishingRod.fishingPlayer.ChangeHandsRodStand(fishingRod.fishingHands);
|
|
}
|
|
fishingRod.fishingPlayer.currentHands.TakeRod();
|
|
fishingRod.ChangeBendWarpPosition(true);
|
|
fishingRod.isOnRodStand = false;
|
|
if (fishingRod.fishingPlayer.HasFishOnCurrentRod())
|
|
{
|
|
fishingRod.fishingPlayer.fishingController.MakeFirstJerk();
|
|
if ((bool)fishingRod.fishingPlayer.boatSimulator && fishingRod.fishingPlayer.boatSimulator.keepMovingForward)
|
|
{
|
|
fishingRod.fishingPlayer.boatSimulator.StopKeepMoving();
|
|
}
|
|
}
|
|
GameController.Instance.hudManager.ShowHudFishing(true);
|
|
GameController.Instance.hudManager.hudBaits.Refresh(fishingRod.fishingHands);
|
|
GameController.Instance.hudManager.UpdateControls();
|
|
if ((bool)GlobalSettings.Instance)
|
|
{
|
|
GlobalSettings.Instance.equipmentManager.currentEquipmentSetId = fishingRod.fishingHands.equipmentSetId;
|
|
}
|
|
FishingHands.rodStand.rodPlacesOccupied--;
|
|
fishingRod = null;
|
|
}
|
|
}
|
|
|
|
public List<RodPlace> rodPlaces = new List<RodPlace>();
|
|
|
|
public bool isHorizontal = true;
|
|
|
|
public bool isBoatStand;
|
|
|
|
public bool isAlwaysAvailableBoatStand;
|
|
|
|
public bool onlyOnTerrain = true;
|
|
|
|
public float distanceFromPlayer = 1.3f;
|
|
|
|
public int rodPlacesOccupied;
|
|
|
|
[HideInInspector]
|
|
public FishingPlayer fishingPlayer;
|
|
|
|
private void Start()
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
if (!(fishingPlayer != null))
|
|
{
|
|
if ((bool)GameController.Instance)
|
|
{
|
|
fishingPlayer = GameController.Instance.fishingPlayer;
|
|
}
|
|
if (!isBoatStand)
|
|
{
|
|
base.transform.parent = null;
|
|
base.gameObject.SetActive(false);
|
|
}
|
|
for (int i = 0; i < rodPlaces.Count; i++)
|
|
{
|
|
rodPlaces[i].rodStandTrigger = rodPlaces[i].rodTrigger.GetComponent<RodStandTrigger>();
|
|
rodPlaces[i].rodStandTrigger.InteractDistance = 1.7f;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void PutStand()
|
|
{
|
|
Vector3 position = FindPutDownPosition();
|
|
if (position.y != -666f)
|
|
{
|
|
base.transform.parent = null;
|
|
base.transform.eulerAngles = new Vector3(0f, fishingPlayer.ufpsCamera.transform.eulerAngles.y, 0f);
|
|
base.transform.position = position;
|
|
base.gameObject.SetActive(true);
|
|
fishingPlayer.CameraLookAt(base.transform, Vector3.up * 1.2f, 0.5f);
|
|
}
|
|
}
|
|
|
|
public void TakeStand()
|
|
{
|
|
if (!base.gameObject.activeSelf)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < rodPlaces.Count; i++)
|
|
{
|
|
if (rodPlaces[i].fishingRod != null)
|
|
{
|
|
rodPlaces[i].TakeRod();
|
|
}
|
|
}
|
|
rodPlacesOccupied = 0;
|
|
if (!isBoatStand)
|
|
{
|
|
base.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public bool PutRod(FishingRod fishingRod)
|
|
{
|
|
RodPlace rodPlace = FindFreeRodPlace();
|
|
if (rodPlace == null)
|
|
{
|
|
return false;
|
|
}
|
|
Debug.LogError("ROD_POD PutRod: " + rodPlace.rodNormalPosition.name + " " + fishingRod.name + " set: " + fishingRod.fishingHands.equipmentSetId);
|
|
rodPlace.fishingRod = fishingRod;
|
|
if (isHorizontal && (bool)fishingRod.fishingHands.biteIndicator && fishingRod.fishingHands.biteIndicator.indicatorType == BiteIndicator.IndicatorType.ELECTRONIC)
|
|
{
|
|
fishingRod.transform.parent = rodPlace.rodElectronicPosition.transform;
|
|
}
|
|
else
|
|
{
|
|
fishingRod.transform.parent = rodPlace.rodNormalPosition.transform;
|
|
}
|
|
fishingRod.fishingHands.normalRope.transform.parent = fishingRod.transform;
|
|
fishingRod.fishingHands.reelLineParent.transform.parent = fishingRod.transform;
|
|
Utilities.SetLayerRecursively(fishingRod.gameObject, "Default");
|
|
Vector3 to = ((fishingRod.rodType != FishingRod.RodType.FLY_FISHING) ? Vector3.zero : new Vector3(0f, -0.55f, -0.02f));
|
|
LeanTween.moveLocal(fishingRod.gameObject, to, 0.7f).setOnComplete((Action)delegate
|
|
{
|
|
if (!fishingRod.fishingHands.fishingFloat)
|
|
{
|
|
Utilities.CheckUndergroundAndFix(fishingRod.fishingHands.bait.transform);
|
|
}
|
|
});
|
|
if (fishingRod.fishingHands.reel.reelType == FishingReel.ReelType.LINE_COUNTER)
|
|
{
|
|
LeanTween.rotateLocal(fishingRod.gameObject, new Vector3(0f, 180f, 0f), 0.7f);
|
|
}
|
|
else
|
|
{
|
|
LeanTween.rotateLocal(fishingRod.gameObject, Vector3.zero, 0.7f);
|
|
}
|
|
if (!isHorizontal)
|
|
{
|
|
}
|
|
if ((bool)fishingRod.fishingHands.biteIndicator)
|
|
{
|
|
fishingRod.fishingHands.biteIndicator.SetBellPosition(false);
|
|
if (isHorizontal && fishingRod.fishingHands.biteIndicator.indicatorType == BiteIndicator.IndicatorType.ELECTRONIC)
|
|
{
|
|
if ((bool)rodPlace.electronicIndicatorHolderObject)
|
|
{
|
|
rodPlace.electronicIndicatorHolderObject.SetActive(false);
|
|
}
|
|
fishingRod.fishingHands.biteIndicator.transform.parent = base.transform;
|
|
fishingRod.fishingHands.biteIndicator.transform.position = rodPlace.electronicIndicatorPosition.position;
|
|
fishingRod.fishingHands.biteIndicator.transform.rotation = rodPlace.electronicIndicatorPosition.rotation;
|
|
fishingRod.fishingHands.biteIndicator.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
fishingRod.isOnRodStand = true;
|
|
fishingRod.fishingHands.HideHandsLayer(true);
|
|
Utilities.SetLayerRecursively(fishingRod.fishingHands.reelLineParent.gameObject, "Default");
|
|
fishingPlayer.allowRun = true;
|
|
fishingPlayer.ufpsController.MotorAcceleration = (fishingPlayer.currentMotorAcceleration = fishingPlayer.motorAccelerationValues.x);
|
|
if (VRManager.Instance.IsVRHoldRod())
|
|
{
|
|
fishingRod.fishingHands.transform.parent = fishingPlayer.transform;
|
|
}
|
|
GameController.Instance.hudManager.ShowHudFishing(false);
|
|
GameController.Instance.hudManager.hudBaits.Refresh(fishingRod.fishingHands);
|
|
rodPlace.rodTrigger.enabled = true;
|
|
rodPlacesOccupied++;
|
|
return true;
|
|
}
|
|
|
|
[Button]
|
|
public void TakeFirstRod()
|
|
{
|
|
for (int i = 0; i < rodPlaces.Count; i++)
|
|
{
|
|
if (rodPlaces[i].fishingRod != null)
|
|
{
|
|
rodPlaces[i].TakeRod();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void TakeRod(int rodPlaceId)
|
|
{
|
|
if (rodPlaces[rodPlaceId].fishingRod != null)
|
|
{
|
|
rodPlaces[rodPlaceId].TakeRod();
|
|
}
|
|
}
|
|
|
|
public Vector3 FindPutDownPosition()
|
|
{
|
|
Vector3 result = Vector3.one * -666f;
|
|
Vector3 origin = fishingPlayer.transform.position + fishingPlayer.GetForwardVector() * distanceFromPlayer;
|
|
origin += Vector3.up * 1.5f;
|
|
RaycastHit hitInfo;
|
|
if (!fishingPlayer.boatSimulator && Physics.Raycast(origin, Vector3.down, out hitInfo, 2f))
|
|
{
|
|
if (hitInfo.point.y >= -0.4f && (hitInfo.collider.gameObject.layer == LayerMask.NameToLayer("Terrain") || hitInfo.collider.gameObject.HasTag("ROD_STAND")) && (!onlyOnTerrain || (bool)hitInfo.collider.gameObject.GetComponent<Terrain>()))
|
|
{
|
|
return hitInfo.point;
|
|
}
|
|
if ((bool)hitInfo.collider)
|
|
{
|
|
Debug.Log("FindPutDownPosition false " + hitInfo.point.y + " " + hitInfo.collider.gameObject.name + " " + LayerMask.LayerToName(hitInfo.collider.gameObject.layer));
|
|
}
|
|
}
|
|
GameController.Instance.hudManager.ShowMessage(Utilities.GetTranslation("HUD_MESSAGE/ROD_POD_CANT_PLACE"));
|
|
return result;
|
|
}
|
|
|
|
public RodPlace FindFreeRodPlace()
|
|
{
|
|
RodPlace result = null;
|
|
float num = 9999f;
|
|
if (fishingPlayer == null)
|
|
{
|
|
fishingPlayer = GameController.Instance.fishingPlayer;
|
|
}
|
|
for (int i = 0; i < rodPlaces.Count; i++)
|
|
{
|
|
if (rodPlaces[i].fishingRod == null)
|
|
{
|
|
float num2 = Vector3.Distance(rodPlaces[i].rodNormalPosition.position, fishingPlayer.transform.position);
|
|
if (num2 < num)
|
|
{
|
|
result = rodPlaces[i];
|
|
num = num2;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public bool IsSeeingAnyRod()
|
|
{
|
|
for (int i = 0; i < rodPlaces.Count; i++)
|
|
{
|
|
if (rodPlaces[i].rodStandTrigger.isSeeingMe)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void FixIsSeeing(int placeId)
|
|
{
|
|
for (int i = 0; i < rodPlaces.Count; i++)
|
|
{
|
|
if (i != placeId)
|
|
{
|
|
rodPlaces[i].rodStandTrigger.isSeeingMe = false;
|
|
}
|
|
}
|
|
}
|
|
}
|