160 lines
3.6 KiB
C#
160 lines
3.6 KiB
C#
using BehaviorDesigner.Runtime.Tasks;
|
|
using BehaviorDesigner.Runtime.Tasks.Movement;
|
|
using UnityEngine;
|
|
|
|
internal class FishCanSeeObject : CanSeeObject
|
|
{
|
|
protected Fish fish;
|
|
|
|
private GameObject foundTarget;
|
|
|
|
public bool simpleTest;
|
|
|
|
public float checkObjectTimer;
|
|
|
|
public bool updateLogic = true;
|
|
|
|
[HideInInspector]
|
|
public new Transform transform;
|
|
|
|
public override void OnStart()
|
|
{
|
|
transform = GetComponent<Transform>();
|
|
base.OnStart();
|
|
fish = transform.GetComponent<Fish>();
|
|
fieldOfViewAngle.Value = 120f;
|
|
checkObjectTimer = Random.Range(10.5f, 20.5f);
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (Time.timeScale == 0f)
|
|
{
|
|
return TaskStatus.Failure;
|
|
}
|
|
if (!fish.allowSearch)
|
|
{
|
|
return TaskStatus.Failure;
|
|
}
|
|
if (!AllowSearch())
|
|
{
|
|
return TaskStatus.Failure;
|
|
}
|
|
if (Fish.disableLogic2)
|
|
{
|
|
return TaskStatus.Failure;
|
|
}
|
|
if (targetObject.Value == null)
|
|
{
|
|
checkObjectTimer -= Time.deltaTime;
|
|
if (!(checkObjectTimer <= 0f))
|
|
{
|
|
return TaskStatus.Failure;
|
|
}
|
|
checkObjectTimer = Random.Range(10.5f, 20.5f);
|
|
GameObject gameObject = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, objectLayerMask, targetOffset.Value, ignoreLayerMask);
|
|
if (TestObject(gameObject))
|
|
{
|
|
returnedObject.Value = gameObject;
|
|
foundTarget = gameObject;
|
|
}
|
|
else
|
|
{
|
|
returnedObject.Value = null;
|
|
foundTarget = null;
|
|
}
|
|
}
|
|
else if (targetObject.Value == foundTarget)
|
|
{
|
|
if ((bool)fish.storedBait && (bool)fish.fishingPlayer.junk)
|
|
{
|
|
returnedObject.Value = null;
|
|
foundTarget = null;
|
|
fish.storedBait = null;
|
|
return TaskStatus.Failure;
|
|
}
|
|
if (checkObjectTimer > 4f)
|
|
{
|
|
checkObjectTimer = 4f;
|
|
}
|
|
checkObjectTimer -= Time.deltaTime;
|
|
if (!(checkObjectTimer <= 0f))
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
checkObjectTimer = Random.Range(3.5f, 4f);
|
|
GameObject gameObject2 = MovementUtility.WithinSight(transform, offset.Value, fieldOfViewAngle.Value, viewDistance.Value, targetObject.Value, targetOffset.Value, ignoreLayerMask);
|
|
if (TestObject(gameObject2))
|
|
{
|
|
returnedObject.Value = gameObject2;
|
|
foundTarget = gameObject2;
|
|
}
|
|
else
|
|
{
|
|
jkmFishPanel.AddFishText(fish, "FishCanSeeObject targetObject[MovementUtility.WithinSight]", fish.logColor);
|
|
returnedObject.Value = null;
|
|
foundTarget = null;
|
|
}
|
|
if (returnedObject.Value != null || fish.storedBait != null)
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
}
|
|
if ((bool)foundTarget)
|
|
{
|
|
Debug.LogWarning("<color=red>JKM foundTarget " + fish.jkmFishId + " [" + fish.name + "]</color>");
|
|
return TaskStatus.Success;
|
|
}
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
public virtual bool AllowSearch()
|
|
{
|
|
if (fish.fishingPlayer == null)
|
|
{
|
|
return false;
|
|
}
|
|
if ((bool)fish.fishingPlayer.fish)
|
|
{
|
|
return false;
|
|
}
|
|
if ((bool)FishingHands.rodStand && FishingHands.rodStand.rodPlacesOccupied > 0)
|
|
{
|
|
return true;
|
|
}
|
|
if ((bool)fish.fishingPlayer.currentHands)
|
|
{
|
|
return fish.fishingPlayer.currentHands.bait.isOnWater;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public virtual bool TestObject(GameObject go)
|
|
{
|
|
if (go == null)
|
|
{
|
|
return false;
|
|
}
|
|
if ((bool)go)
|
|
{
|
|
if (!GameController.Instance.iceLevel && go.transform.position.y > 0.3f)
|
|
{
|
|
return false;
|
|
}
|
|
if (GameController.Instance.iceLevel && go.transform.position.y > 0f - (fish.fishingPlayer.drillingController.currentHole.Data.Depth + 0.3f))
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
if (simpleTest)
|
|
{
|
|
return true;
|
|
}
|
|
return fish.LikesBait(go);
|
|
}
|
|
|
|
private void DrawLineOfSight(Transform transform, Vector3 positionOffset, float fieldOfViewAngle, float viewDistance, bool usePhysics2D, Color color)
|
|
{
|
|
}
|
|
}
|