188 lines
5.1 KiB
C#
188 lines
5.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using UFS2.Gameplay;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class BoatRodSupport : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Boat boat;
|
|
|
|
[HideInInspector]
|
|
public FRod currentRod_1;
|
|
|
|
public Transform rodContainer;
|
|
|
|
public GameObject pointerGet;
|
|
|
|
[SerializeField]
|
|
private bool isValidDropRod;
|
|
|
|
[SerializeField]
|
|
private bool isValidGetRod;
|
|
|
|
[SerializeField]
|
|
private bool hidePanelPending;
|
|
|
|
private static float lastBoatRodSupportChangeTime;
|
|
|
|
public static bool IsBoatRodSupportChanging => Time.time - lastBoatRodSupportChangeTime < 2f;
|
|
|
|
private bool IsRodDropBlocked
|
|
{
|
|
get
|
|
{
|
|
if ((bool)boat.currentPlayerCharacter && (bool)boat.currentPlayerCharacter.currentRod && !currentRod_1 && !FishEntity.CurrentFishInFight && !boat.currentPlayerCharacter.currentRod.isThrowing && !boat.currentPlayerCharacter.underWaterCamera && !boat.currentPlayerCharacter.firstPersonController.frezzePosition && Time.timeScale != 0f && !IsBoatRodSupportChanging)
|
|
{
|
|
return InventoryManager.IsInventoryChanging;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
private bool IsRodGetBlocked
|
|
{
|
|
get
|
|
{
|
|
if ((bool)boat.currentPlayerCharacter && !boat.currentPlayerCharacter.currentRod && (bool)currentRod_1 && !boat.currentPlayerCharacter.underWaterCamera && !boat.currentPlayerCharacter.firstPersonController.frezzePosition && Time.timeScale != 0f && !IsBoatRodSupportChanging)
|
|
{
|
|
return InventoryManager.IsInventoryChanging;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public static event Action<FRod> OnRodTake;
|
|
|
|
public static event Action<FRod> OnRodPutDown;
|
|
|
|
private void Update()
|
|
{
|
|
if (!boat.currentPlayerCharacter)
|
|
{
|
|
pointerGet?.SetActive(value: false);
|
|
return;
|
|
}
|
|
DropRod();
|
|
GetRod();
|
|
if (isValidDropRod)
|
|
{
|
|
if (Gamepad.current != null)
|
|
{
|
|
FScriptsHandler.Instance.m_HudManager.ShowGetDropPanel(hide: false, LanguageManager.Instance.GetText("DROP_ROD_TO_SUPPORT_PAD"));
|
|
}
|
|
else
|
|
{
|
|
FScriptsHandler.Instance.m_HudManager.ShowGetDropPanel(hide: false, LanguageManager.Instance.GetText("DROP_ROD_TO_SUPPORT_MOUSE"));
|
|
}
|
|
hidePanelPending = true;
|
|
pointerGet?.SetActive(value: true);
|
|
}
|
|
else if (isValidGetRod)
|
|
{
|
|
if (Gamepad.current != null)
|
|
{
|
|
FScriptsHandler.Instance.m_HudManager.ShowGetDropPanel(hide: false, LanguageManager.Instance.GetText("GET_ROD_FROM_SUPPORT_PAD"));
|
|
}
|
|
else
|
|
{
|
|
FScriptsHandler.Instance.m_HudManager.ShowGetDropPanel(hide: false, LanguageManager.Instance.GetText("GET_ROD_FROM_SUPPORT_MOUSE"));
|
|
}
|
|
hidePanelPending = true;
|
|
pointerGet?.SetActive(value: true);
|
|
}
|
|
else
|
|
{
|
|
if (hidePanelPending)
|
|
{
|
|
hidePanelPending = false;
|
|
FScriptsHandler.Instance.m_HudManager.ShowGetDropPanel(hide: true);
|
|
}
|
|
pointerGet?.SetActive(value: false);
|
|
}
|
|
}
|
|
|
|
private void DropRod()
|
|
{
|
|
isValidDropRod = false;
|
|
if (!IsRodDropBlocked && CheckPlayerPositionForInteraction())
|
|
{
|
|
isValidDropRod = true;
|
|
if (InputManager.isGetUpRod)
|
|
{
|
|
StartCoroutine(ReConnectRod());
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator ReConnectRod()
|
|
{
|
|
Debug.Log("Started Drop rod");
|
|
lastBoatRodSupportChangeTime = Time.time;
|
|
BoatRodSupport.OnRodPutDown?.Invoke(boat.currentPlayerCharacter.currentRod);
|
|
boat.currentPlayerCharacter.FullBodyAvatar.HideRod(bySlot: false);
|
|
yield return new WaitForSeconds(0.9f);
|
|
if ((bool)boat.currentPlayerCharacter.currentRod)
|
|
{
|
|
boat.currentPlayerCharacter.currentRod.currentReel.isHandOnHandle = false;
|
|
}
|
|
currentRod_1 = FScriptsHandler.Instance.m_InventoryManager.DropRod(rodContainer);
|
|
Debug.Log("Finished Coroutine at timestamp : " + Time.time);
|
|
boat.currentPlayerCharacter.InteractiveLeftHand(null);
|
|
yield return new WaitForSeconds(0.7f);
|
|
}
|
|
|
|
private void GetRod()
|
|
{
|
|
isValidGetRod = false;
|
|
if (!IsRodGetBlocked && CheckPlayerPositionForInteraction())
|
|
{
|
|
isValidGetRod = true;
|
|
if (InputManager.isGetUpRod)
|
|
{
|
|
StartCoroutine(ConnectRod(1));
|
|
}
|
|
}
|
|
}
|
|
|
|
private IEnumerator ConnectRod(int indexOfSlot)
|
|
{
|
|
Debug.Log("Started Drop rod");
|
|
lastBoatRodSupportChangeTime = Time.time;
|
|
BoatRodSupport.OnRodTake?.Invoke(currentRod_1);
|
|
boat.currentPlayerCharacter.FullBodyAvatar.ShowRod(bySlot: false);
|
|
yield return new WaitForSeconds(0.7f);
|
|
FScriptsHandler.Instance.m_InventoryManager.GetRodToHand(currentRod_1);
|
|
FScriptsHandler.Instance.m_HudManager.ShowGetDropPanel(hide: true);
|
|
currentRod_1 = null;
|
|
Debug.Log("Finished Coroutine at timestamp : " + Time.time);
|
|
yield return new WaitForSeconds(0.7f);
|
|
}
|
|
|
|
private bool CheckPlayerPositionForInteraction()
|
|
{
|
|
bool result = false;
|
|
if ((bool)boat.currentPlayerCharacter)
|
|
{
|
|
Vector3 position = boat.currentPlayerCharacter.transform.position;
|
|
float num = Vector3.Distance(position, rodContainer.transform.position);
|
|
if (num < 1f && num > 0.1f)
|
|
{
|
|
Vector3 vector = rodContainer.transform.position - position;
|
|
vector.y = 0f;
|
|
vector.Normalize();
|
|
Vector3 forward = boat.currentPlayerCharacter.transform.forward;
|
|
vector.y = 0f;
|
|
vector.Normalize();
|
|
float num2 = Vector3.Angle(vector, forward);
|
|
if (num2 > -15f && num2 < 15f)
|
|
{
|
|
result = true;
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|