Files
2026-02-21 16:45:37 +08:00

122 lines
3.1 KiB
C#

using System.Collections.Generic;
using UnityEngine;
public class JunkManager : MonoBehaviour
{
public float drawJunkChance = 1f;
public float drawHookMaterialChance = 0.4f;
public Junk.JunkType forceJunkType = Junk.JunkType.COUNT;
public bool drawJunk;
public Junk testJunk;
public Vector2 timerRange = new Vector2(10f, 20f);
public float timer;
public float drunkLuckFactor = 0.4f;
public List<Junk> junkNeutral = new List<Junk>();
public List<Junk> junkGood = new List<Junk>();
public List<Junk> junkBad = new List<Junk>();
public List<Junk> junkHookMaterial = new List<Junk>();
[HideInInspector]
public FishingPlayer fishingPlayer;
public void Awake()
{
ResetJunk();
}
public void MakeUpdate()
{
if (drawJunk && (fishingPlayer.gameController.iceLevel || (!(fishingPlayer.currentHands.fishingRod.GetBaitDistance() < 5f) && !(fishingPlayer.currentHands.bait.transform.position.y > -1f))) && (!fishingPlayer.gameController.iceLevel || !(fishingPlayer.currentHands.fishingRod.GetBaitDistance() < 1f)))
{
if ((bool)fishingPlayer.fish)
{
drawJunk = false;
}
timer -= Time.deltaTime;
if (timer <= 0f && UtilitiesInput.isReelingIn && !fishingPlayer.underwaterCamera.isTurnedOn)
{
DrawJunk();
drawJunk = false;
}
}
}
public void DrawJunk()
{
float num = Random.Range(0f, 1f);
float currentLuck = GetCurrentLuck();
Debug.Log("GetCurrentLuck " + currentLuck);
if (junkGood.Count == 0 && junkBad.Count == 0)
{
num = currentLuck + 0.01f;
}
Junk junk = null;
if ((bool)testJunk)
{
junk = testJunk;
}
else if (forceJunkType == Junk.JunkType.COUNT)
{
junk = ((Random.Range(0f, 1f) < drawHookMaterialChance) ? junkHookMaterial[Random.Range(0, junkHookMaterial.Count)] : ((num < 0.33f) ? junkGood[Random.Range(0, junkGood.Count)] : ((!(num < 0.66f)) ? junkBad[Random.Range(0, junkBad.Count)] : junkNeutral[Random.Range(0, junkNeutral.Count)])));
}
else if (forceJunkType == Junk.JunkType.GOOD)
{
junk = junkGood[Random.Range(0, junkGood.Count)];
}
else if (forceJunkType == Junk.JunkType.NEUTRAL)
{
junk = junkNeutral[Random.Range(0, junkNeutral.Count)];
}
else if (forceJunkType == Junk.JunkType.BAD)
{
junk = junkBad[Random.Range(0, junkBad.Count)];
}
else if (forceJunkType == Junk.JunkType.HOOK_MATERIAL)
{
junk = junkHookMaterial[Random.Range(0, junkHookMaterial.Count)];
}
Junk junk2 = Object.Instantiate(junk);
Utilities.SetLayerRecursively(junk2.gameObject, "Float");
fishingPlayer.OnCatchJunk(junk2);
Debug.Log("DrawJunk " + num + " " + junk.junkName);
}
public void CheckJunkChance()
{
if (TutorialManager.Instance.helpDontCatchAnything)
{
drawJunk = false;
return;
}
float num = Random.Range(0f, 1f);
drawJunk = num > 1f - drawJunkChance;
if (drawJunk)
{
timer = Random.Range(timerRange.x, timerRange.y);
}
}
public void ResetJunk()
{
drawJunk = false;
}
public float GetCurrentLuck()
{
float num = ((!GlobalSettings.Instance) ? 0.33f : ((float)GlobalSettings.Instance.playerSettings.playersLuck));
num += fishingPlayer.drunkLevel * drunkLuckFactor;
return Mathf.Clamp01(num);
}
}