115 lines
2.9 KiB
C#
115 lines
2.9 KiB
C#
using System.Collections;
|
|
using Moonlit.Utils;
|
|
using UnityEngine;
|
|
|
|
namespace Moonlit.IceFishing
|
|
{
|
|
[RequireComponent(typeof(vp_FPController))]
|
|
public class DrillingController : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public FishingPlayer fishingPlayer;
|
|
|
|
[HideInInspector]
|
|
public Hole currentHole;
|
|
|
|
[HideInInspector]
|
|
public bool placeChosen;
|
|
|
|
private vp_FPController _Controller;
|
|
|
|
public Auger Auger;
|
|
|
|
public Transform DrillPoint;
|
|
|
|
public bool Drilling { get; private set; }
|
|
|
|
private void Awake()
|
|
{
|
|
_Controller = GetComponent<vp_FPController>();
|
|
}
|
|
|
|
public bool StartDrilling()
|
|
{
|
|
if (Auger == null)
|
|
{
|
|
return false;
|
|
}
|
|
HolesController.HitInfo hitInfo = Singleton<HolesController>.Instance.HitCheck(DrillPoint.position, Auger.Radius);
|
|
if (hitInfo.Result != HolesController.HitResult.Unoccupied)
|
|
{
|
|
return false;
|
|
}
|
|
Drilling = true;
|
|
StartCoroutine(Drill(DrillPoint.position));
|
|
return true;
|
|
}
|
|
|
|
public bool CanIDrill()
|
|
{
|
|
return Singleton<HolesController>.Instance.HitCheck(DrillPoint.position, Auger.Radius).Result == HolesController.HitResult.Unoccupied;
|
|
}
|
|
|
|
public bool HoleFound()
|
|
{
|
|
if ((bool)Singleton<HolesController>.Instance && (bool)Auger)
|
|
{
|
|
return Singleton<HolesController>.Instance.HitCheck(DrillPoint.position, Auger.Radius).Result == HolesController.HitResult.Occupied;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void ShowDriller(bool show)
|
|
{
|
|
if (show)
|
|
{
|
|
Auger.Position(DrillPoint.position);
|
|
StartCoroutine(Auger.Lower());
|
|
Auger.FadeDriller(false);
|
|
}
|
|
else
|
|
{
|
|
Auger.FadeDriller(false);
|
|
Auger.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private IEnumerator Drill(Vector3 point)
|
|
{
|
|
Hole holeController = null;
|
|
float thickness = Singleton<HolesController>.Instance.GetIceThickness(point);
|
|
_Controller.SetState("Stop");
|
|
Auger.Position(point);
|
|
HoleData data = new HoleData
|
|
{
|
|
Position = Singleton<HolesController>.Instance.FindIcePosition(point),
|
|
Radius = Auger.Radius,
|
|
Depth = 0f,
|
|
Rotation = Random.Range(0f, 360f)
|
|
};
|
|
IEnumerator drilling = Auger.Drill(thickness);
|
|
while (drilling.MoveNext())
|
|
{
|
|
if (Auger.Depth > 0f)
|
|
{
|
|
if (holeController == null)
|
|
{
|
|
holeController = Singleton<HolesController>.Instance.Create(data);
|
|
Auger.SetParticles(holeController.View.Particles);
|
|
holeController.StartDrilling();
|
|
}
|
|
holeController.SetProgress(Auger.Depth, thickness);
|
|
}
|
|
yield return drilling.Current;
|
|
}
|
|
Auger.SetParticles(null);
|
|
holeController.FinishDrilling();
|
|
currentHole = holeController;
|
|
currentHole.centerDown = new Vector3(currentHole.holeCenter.position.x, currentHole.holeCenter.position.y - currentHole.Data.Depth, currentHole.holeCenter.position.z);
|
|
yield return StartCoroutine(Auger.Raise());
|
|
Drilling = false;
|
|
fishingPlayer.ChangeState(FishingPlayer.PlayerState.ICE_FISHING);
|
|
}
|
|
}
|
|
}
|