Files
2026-03-04 10:03:45 +08:00

331 lines
9.6 KiB
C#

using System;
using KWS;
using UFS2.Gameplay;
using UltimateWater;
using UnityEngine;
public class FFloat : MonoBehaviour
{
[HideInInspector]
public Rigidbody rigidbody;
[HideInInspector]
public FWaterDisplacement waterDisplacement;
[HideInInspector]
public FRod currentRod;
public float currentFloatDeepth = 0.2f;
public float newDeepth = 0.21f;
public float floatDisplacement;
private BoxCollider collider;
private Vector3 colliderCenterOriginal;
private ConfigurableJoint joint;
[SerializeField]
private UltimateWater.WaterInteractive waterInteractive;
private float startWaterInteractiveMultiple = 5f;
private Transform currentWaterDrop;
[SerializeField]
private Transform scallingObject;
private bool isInWater;
private bool destroyDropFx;
public static event Action OnFloatEnterWater;
public static event Action OnFloatExitWater;
private void KW_Interact()
{
base.gameObject.AddComponent<KWS_InteractWithWater>().StrengthMultiplier = 0.5f;
}
private void Start()
{
rigidbody = GetComponent<Rigidbody>();
waterDisplacement = GetComponent<FWaterDisplacement>();
waterDisplacement.objectDisplacement = floatDisplacement;
collider = GetComponent<BoxCollider>();
colliderCenterOriginal = collider.center;
joint = GetComponent<ConfigurableJoint>();
KW_Interact();
if ((bool)currentRod)
{
currentRod.fishingLine.currentLineHandler.SetSegmentTwoLenght(currentFloatDeepth);
}
if ((bool)waterInteractive)
{
waterInteractive.enabled = false;
startWaterInteractiveMultiple = waterInteractive.Multiplier;
}
Invoke("EnableWaterInteractive", 3f);
SetUpFluoFloat();
}
private void OnEnable()
{
FishCatchState.OnExit += ShowRenderer;
}
private void OnDisable()
{
FishCatchState.OnExit -= ShowRenderer;
FFloat.OnFloatExitWater?.Invoke();
}
private void Update()
{
if ((bool)currentRod)
{
waterDisplacement.useSplashes = !currentRod.isThrowing;
}
ShowWaterFX();
SetDeepth();
Scalling();
}
private void FixedUpdate()
{
DisplcementController();
if (waterDisplacement.IsInWater)
{
if (!isInWater)
{
FFloat.OnFloatEnterWater?.Invoke();
isInWater = true;
}
}
else if (isInWater)
{
FFloat.OnFloatExitWater?.Invoke();
isInWater = false;
}
}
private void OnDestroy()
{
if ((bool)currentWaterDrop)
{
UnityEngine.Object.Destroy(currentWaterDrop.gameObject);
}
}
public void HideRenderer()
{
if (TryGetComponent<Renderer>(out var component))
{
component.enabled = false;
}
}
public void ShowRenderer()
{
if (TryGetComponent<Renderer>(out var component))
{
component.enabled = true;
}
}
private void Scalling()
{
if ((bool)scallingObject && (bool)currentRod.fishingLine && (bool)currentRod.fishingLine.currentLineHandler && (bool)currentRod.fishingLine.currentLineHandler.EndLineRigidbody_0)
{
float floatSizeValue = Singleton<SaveDataManager>.Instance.SettingsData.FloatSizeValue;
float num = Vector3.Distance(currentRod.fishingLine.currentLineHandler.EndLineRigidbody_0.transform.position, scallingObject.transform.position);
if ((bool)waterInteractive)
{
waterInteractive.Multiplier = startWaterInteractiveMultiple / (scallingObject.localScale.x * 2f);
}
if (Singleton<GameCameraController>.Instance.IsInWater)
{
scallingObject.localScale = Vector3.one;
}
else if (waterDisplacement.IsInWater && !currentRod.currentFish)
{
float value = 1f + num * 0.4f / floatSizeValue * floatSizeValue;
value = Mathf.Clamp(value, 0f, floatSizeValue);
scallingObject.localScale = Vector3.MoveTowards(scallingObject.localScale, Vector3.one * value, Time.deltaTime * 5f);
}
else
{
scallingObject.localScale = Vector3.MoveTowards(scallingObject.localScale, Vector3.one, Time.deltaTime * 10f);
}
}
}
private void EnableWaterInteractive()
{
if ((bool)waterInteractive)
{
waterInteractive.enabled = true;
}
}
private void DisplcementController()
{
if (!currentRod || !currentRod.currentWeight)
{
return;
}
if (waterDisplacement.IsInWater)
{
int gameItemIndexByItemId = GameManager.Instance._playerData.GetGameItemIndexByItemId(GameManager.ItemType.Float, Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].ffloat.ID);
int gameItemIndexByItemId2 = GameManager.Instance._playerData.GetGameItemIndexByItemId(GameManager.ItemType.Bait, Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].bait.ID);
int gameItemIndexByItemId3 = GameManager.Instance._playerData.GetGameItemIndexByItemId(GameManager.ItemType.Weight, Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].weight.ID);
if (gameItemIndexByItemId < 0 || gameItemIndexByItemId2 < 0 || gameItemIndexByItemId3 < 0)
{
return;
}
GameManager.GameFloats obj = GameManager.Instance.gameFloats[gameItemIndexByItemId];
GameManager.GameBaits gameBaits = GameManager.Instance.gameBaits[gameItemIndexByItemId2];
GameManager.GameWeights gameWeights = GameManager.Instance.gameWeights[gameItemIndexByItemId3];
float num = 0.05f;
if (obj.displacement < gameBaits.weight * 0f + gameWeights.weight)
{
num = 10f;
}
float num2 = floatDisplacement;
if (num2 > 0f)
{
if (waterDisplacement.depth > num)
{
float t = Mathf.InverseLerp(num, 1f, waterDisplacement.depth);
num2 = Mathf.Lerp(num2 * 3f, num2 * 10f, t);
}
else
{
float t2 = Mathf.InverseLerp(0f, num, waterDisplacement.depth);
num2 = Mathf.Lerp(0f, num2 * 3f, t2);
}
}
num2 = Mathf.Clamp(num2, -1f, 10f);
waterDisplacement.objectDisplacement = num2;
if (rigidbody.velocity.magnitude < 1f && ProbeDeep(base.transform) < currentFloatDeepth)
{
collider.center = new Vector3(0f, colliderCenterOriginal.y, 0.07f);
}
else
{
collider.center = new Vector3(0f, colliderCenterOriginal.y, 0f);
}
}
else
{
Vector3 anchor = joint.anchor;
Vector3 vector = -anchor.normalized;
float num3 = collider.size.y / 2f;
Vector3 vector2 = anchor + vector * num3;
collider.center = new Vector3(0f, vector2.y, 0f);
}
}
private float ProbeDeep(Transform probeObject)
{
int mask = LayerMask.GetMask("Terrain");
float result = 0f;
if (Physics.Raycast(probeObject.transform.position, -Vector3.up, out var hitInfo, float.PositiveInfinity, mask))
{
result = hitInfo.distance;
}
return result;
}
private void SetDeepth()
{
if ((bool)currentRod && (bool)currentRod.currentHook && !(currentRod.fishingLine.currentLineHandler.PhisicsLineOut > 2f) && !currentRod.currentFish)
{
if (newDeepth != currentFloatDeepth)
{
currentRod.fishingLine.currentLineHandler.SetSegmentTwoLenght(newDeepth);
currentFloatDeepth = newDeepth;
}
if (InputManager.isDeepthFloatUp)
{
newDeepth += 0.1f;
newDeepth = Mathf.Clamp(newDeepth, 0.15f, 2.5f);
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].ffloat.lastSetGroundValue = newDeepth;
GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_FLOAT_DEEPTH_TO") + newDeepth.ToString("F2") + " m", FScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
}
if (InputManager.isDeepthFloatDown)
{
newDeepth -= 0.1f;
newDeepth = Mathf.Clamp(newDeepth, 0.15f, 2.5f);
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].ffloat.lastSetGroundValue = newDeepth;
GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_FLOAT_DEEPTH_TO") + newDeepth.ToString("F2") + " m", FScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
}
if (FScriptsHandler.Instance.m_HudManager.selectorRodSetting == HudManager.SelectorRodSetting.Leeder && Input.mouseScrollDelta.y != 0f && Time.timeScale != 0f)
{
newDeepth += Input.mouseScrollDelta.y * 0.02f;
newDeepth = Mathf.Clamp(newDeepth, 0.15f, 2.5f);
Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerSlotsEquip[currentRod.indexOfslot].ffloat.lastSetGroundValue = newDeepth;
GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_FLOAT_DEEPTH_TO") + newDeepth.ToString("F2") + " m", FScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
}
}
}
private void DestroyDelayFxDrop()
{
if ((bool)currentWaterDrop)
{
UnityEngine.Object.Destroy(currentWaterDrop.gameObject);
destroyDropFx = false;
}
}
private void ShowWaterFX()
{
float num = 0f - base.transform.position.y;
if (num < 0.1f && num > -0.1f)
{
if ((bool)currentWaterDrop)
{
currentWaterDrop.position = new Vector3(base.transform.position.x, 0f, base.transform.position.z);
}
}
else if ((bool)currentWaterDrop)
{
if (!destroyDropFx)
{
Invoke("DestroyDelayFxDrop", 4f);
}
destroyDropFx = true;
}
}
private void SetUpFluoFloat()
{
if (!scallingObject)
{
return;
}
Renderer componentInChildren = scallingObject.GetComponentInChildren<Renderer>();
if (!(componentInChildren == null))
{
Material material = componentInChildren.material;
if (!(material == null) && material.IsKeywordEnabled("_EMISSION") && !(material.GetColor("_EmissionColor").maxColorComponent < 0.2f))
{
GameObject obj = new GameObject("FluoLight");
obj.transform.SetParent(base.transform);
obj.transform.localPosition = Vector3.zero;
Light light = obj.AddComponent<Light>();
light.type = LightType.Point;
light.range = 1f;
light.intensity = 2f;
light.color = new Color(0.6f, 1f, 0.3f);
light.bounceIntensity = 0f;
light.shadows = LightShadows.None;
}
}
}
}