522 lines
14 KiB
C#
522 lines
14 KiB
C#
using BehaviorDesigner.Runtime;
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
using UnityEngine;
|
|
|
|
public class FishMove : Action
|
|
{
|
|
public SharedFloat speed;
|
|
|
|
public SharedFloat arriveDistance;
|
|
|
|
public SharedBool lookAtTarget = true;
|
|
|
|
public SharedFloat turnRate;
|
|
|
|
public SharedGameObject target;
|
|
|
|
public SharedVector3 targetPosition;
|
|
|
|
public SharedFloat desiredSpeed;
|
|
|
|
public SharedBool completeOnTargetLost;
|
|
|
|
public bool alwaysUseDirection;
|
|
|
|
private float avoidAngle = 0.95f;
|
|
|
|
private float stopSpeedMultiplier = 2f;
|
|
|
|
private float delta;
|
|
|
|
private float rotateCounterR;
|
|
|
|
private float rotateCounterL;
|
|
|
|
public float targetSpeed = 2f;
|
|
|
|
private float tParam;
|
|
|
|
private float turnSpeed = 0.1f;
|
|
|
|
private float isTurning;
|
|
|
|
private RaycastHit hit = default(RaycastHit);
|
|
|
|
protected Fish fish;
|
|
|
|
protected Rigidbody rb;
|
|
|
|
[HideInInspector]
|
|
public new Transform transform;
|
|
|
|
private float avoidanceCheckTimer;
|
|
|
|
public override void OnStart()
|
|
{
|
|
transform = GetComponent<Transform>();
|
|
base.OnStart();
|
|
fish = transform.GetComponent<Fish>();
|
|
rb = transform.GetComponent<Rigidbody>();
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (Time.deltaTime == 0f)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
if (fish == null)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
fish.currentTarget = target.Value;
|
|
if (fish.isBaitUpdate)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
if (fish.isBoatUpdate)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
if (fish.isInNetArea)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
if (fish.isTryingBait)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
if (fish.isOnGround)
|
|
{
|
|
return TaskStatus.Running;
|
|
}
|
|
if (!Fish.useAvoidance)
|
|
{
|
|
}
|
|
if (fish.pullingUp)
|
|
{
|
|
Debug.LogError("FishMove TaskStatus.Success pullingUp");
|
|
return TaskStatus.Success;
|
|
}
|
|
if (completeOnTargetLost.Value && target.Value == null)
|
|
{
|
|
Debug.LogError("FishMove TaskStatus.Failure");
|
|
completeOnTargetLost.Value = false;
|
|
jkmFishPanel.AddFishText(fish, "ERROR : FishMove TaskStatus.Failure");
|
|
}
|
|
Vector3 vector = Target();
|
|
bool flag = (bool)target.Value && target.Value.HasTag("BAIT");
|
|
targetSpeed = fish.targetSpeed;
|
|
if (fish.isFighting)
|
|
{
|
|
}
|
|
fish.isNearBait = false;
|
|
float num = Vector3.Magnitude(fish.transform.position - vector);
|
|
if (Fish.ticket == fish && (!(num < 0.35f) || !fish.isFighting))
|
|
{
|
|
if (fish.fishingPlayer.IsTrolling())
|
|
{
|
|
targetSpeed = fish.GetSpeedValue(1f) * 1.25f;
|
|
}
|
|
else if (!fish.storedBait.HasAnyLiveBait())
|
|
{
|
|
if ((bool)fish.storedBait.fishingHands.fishingFloat || fish.storedBait.fishingHands.isGroundRig)
|
|
{
|
|
if (num < 5f)
|
|
{
|
|
targetSpeed = 1.5f;
|
|
}
|
|
if (num < 2.5f)
|
|
{
|
|
targetSpeed = ((!fish.storedBait.fishingHands.isGroundRig) ? 0.25f : 0.05f);
|
|
fish.isNearBait = true;
|
|
}
|
|
}
|
|
else if (GameController.Instance.iceLevel)
|
|
{
|
|
if (num < 2f)
|
|
{
|
|
targetSpeed *= 1f;
|
|
}
|
|
else if (num < 7f)
|
|
{
|
|
targetSpeed *= 0.5f;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (num < 7f)
|
|
{
|
|
targetSpeed *= 0.5f;
|
|
}
|
|
if (num < 2f)
|
|
{
|
|
targetSpeed *= 3.5f;
|
|
}
|
|
}
|
|
}
|
|
float num2 = 0.35f;
|
|
if (flag)
|
|
{
|
|
num2 = (fish.fishingPlayer.IsTrolling() ? 1.5f : ((fish.storedBait.baitType != Bait.BaitType.HOOK) ? Mathf.Lerp(0.05f, 0.25f, Mathf.InverseLerp(1f, 8f, fish.currentSpeed)) : Mathf.Lerp(0.03f, 0.06f, Mathf.InverseLerp(1f, 8f, fish.currentSpeed))));
|
|
}
|
|
if (num < num2 || fish.withinSightBug)
|
|
{
|
|
Debug.Log("FishMove TaskStatus.Success distance:" + num);
|
|
fish.withinSightBug = false;
|
|
return TaskStatus.Success;
|
|
}
|
|
}
|
|
if (fish.isReleasing)
|
|
{
|
|
if (transform.position.y <= 0f)
|
|
{
|
|
fish.isReleasing = false;
|
|
fish.targetDirection = (fish.Origin - transform.position).normalized;
|
|
}
|
|
if (transform.position.y <= 0.4f && transform.position.y > 0f)
|
|
{
|
|
fish.WaterSplash();
|
|
}
|
|
transform.eulerAngles = new Vector3(60f, fish.fishingPlayer.transform.eulerAngles.y, 0f);
|
|
}
|
|
bool flag2 = fish.TerrainCollision();
|
|
float deltaTime = Time.deltaTime;
|
|
float num3 = speed.Value;
|
|
if (fish.isFighting && !fish.isJerked)
|
|
{
|
|
if (fish.catchStyleCurrent == Fish.CatchStyle.STOP)
|
|
{
|
|
num3 = 0f;
|
|
}
|
|
else if (fish.catchStyleCurrent == Fish.CatchStyle.SWIM)
|
|
{
|
|
num3 *= 1.2f;
|
|
}
|
|
else if (fish.catchStyleCurrent == Fish.CatchStyle.DOWN)
|
|
{
|
|
num3 *= 0.5f;
|
|
}
|
|
}
|
|
if (fish.isFighting && fish.storedBait.fishingHands.fishingRod.isOnRodStand && (bool)fish.storedBait.fishingHands.fishingPlayer.boatSimulator)
|
|
{
|
|
num3 *= 0.1f;
|
|
}
|
|
if (fish.isFighting && !fish.storedBait.fishingHands.isFloatRig && fish.DurabilityCurrent == Fish.DurabilityMin && fish.fishingPlayer.distanceToBait > 20f)
|
|
{
|
|
num3 *= 1.2f;
|
|
}
|
|
fish.currentSpeed = num3;
|
|
transform.position += transform.TransformDirection(Vector3.forward) * Time.deltaTime * ((!fish.isReleasing) ? num3 : 4.5f);
|
|
if (flag2 && fish.isFighting)
|
|
{
|
|
if (fish.terrainLevel.y > -0.15f)
|
|
{
|
|
}
|
|
Quaternion rotation = transform.rotation;
|
|
Quaternion b = Quaternion.LookRotation(vector - transform.position);
|
|
float f = Quaternion.Angle(rotation, b);
|
|
if (Mathf.Abs(f) < 90f)
|
|
{
|
|
float num4 = fish.terrainLevel.y + 0.3f;
|
|
if (transform.position.y > fish.minDepth)
|
|
{
|
|
fish.CorrectDirection();
|
|
transform.position = new Vector3(transform.position.x, fish.minDepth, transform.position.z);
|
|
}
|
|
else if (transform.position.y < num4 && num4 < fish.minDepth)
|
|
{
|
|
transform.position = new Vector3(transform.position.x, num4, transform.position.z);
|
|
}
|
|
}
|
|
}
|
|
else if (!flag && (!flag2 || fish.storedBait == null))
|
|
{
|
|
float num5 = fish.terrainLevel.y + 0.3f;
|
|
if (transform.position.y > fish.minDepth && !fish.isJumping)
|
|
{
|
|
fish.CorrectDirection();
|
|
if (!fish.isReleasing)
|
|
{
|
|
transform.position = new Vector3(transform.position.x, fish.minDepth, transform.position.z);
|
|
}
|
|
}
|
|
else if (transform.position.y < num5 && num5 < fish.minDepth)
|
|
{
|
|
transform.position = new Vector3(transform.position.x, num5, transform.position.z);
|
|
}
|
|
}
|
|
else if (fish.pullForce == 1f)
|
|
{
|
|
transform.position = new Vector3(transform.position.x, fish.terrainLevel.y + 0.2f, transform.position.z);
|
|
}
|
|
if (lookAtTarget.Value)
|
|
{
|
|
float num6 = 6f;
|
|
if (Fish.ticket == fish)
|
|
{
|
|
num6 = 45f;
|
|
}
|
|
if (fish.isFighting)
|
|
{
|
|
num6 = 10f;
|
|
}
|
|
Quaternion rotation2 = transform.rotation;
|
|
Quaternion to = Quaternion.LookRotation(vector - transform.position);
|
|
Quaternion quaternion = Quaternion.RotateTowards(rotation2, to, turnRate.Value * num6);
|
|
Quaternion quaternion2 = Quaternion.RotateTowards(rotation2, to, turnRate.Value * num6 * ((!fish.isNearBait) ? 0.3f : 0.02f));
|
|
if (fish.isJumping || transform.position.y > 0.05f)
|
|
{
|
|
quaternion = transform.rotation;
|
|
}
|
|
transform.eulerAngles = new Vector3(quaternion2.eulerAngles.x, quaternion.eulerAngles.y, transform.eulerAngles.z);
|
|
fish.targetLookRotation = to.eulerAngles - rotation2.eulerAngles;
|
|
}
|
|
if (!(Fish.ticket == fish) || !fish.isFighting)
|
|
{
|
|
}
|
|
if (!fish.isFighting || fish.DurabilityCurrent <= Fish.DurabilityMin)
|
|
{
|
|
}
|
|
if ((flag2 || Fish.ticket != fish || fish.isFighting) && (fish.isFighting || !fish.IsUnderGround()) && (!(Fish.ticket == fish) || fish.isFighting) && !fish.isJumping && (!fish.isFighting || !(fish.DurabilityCurrent <= Fish.DurabilityMin)))
|
|
{
|
|
RotationBasedOnWaypointOrAvoidance();
|
|
}
|
|
if (!fish.isFighting || !fish.storedBait || !fish.storedBait.fishingFloat || transform.position.y < 0f - fish.storedBait.fishingHands.floatRopeDepth)
|
|
{
|
|
}
|
|
float num7 = 2.1f;
|
|
float num8 = 0.06f;
|
|
if (targetSpeed > speed.Value)
|
|
{
|
|
if ((bool)fish.storedBait && !fish.storedBait.fishingHands.fishingFloat && !fish.storedBait.fishingHands.isGroundRig && num < 2f)
|
|
{
|
|
speed.Value += deltaTime * 15f;
|
|
}
|
|
else if (fish.isJumping)
|
|
{
|
|
speed.Value += deltaTime * 5.5f;
|
|
}
|
|
else
|
|
{
|
|
speed.Value += deltaTime * 2.1f;
|
|
}
|
|
if (targetSpeed < speed.Value)
|
|
{
|
|
speed.Value = targetSpeed;
|
|
}
|
|
}
|
|
else if (targetSpeed < speed.Value)
|
|
{
|
|
speed.Value -= deltaTime * 1.1f;
|
|
if (targetSpeed > speed.Value)
|
|
{
|
|
speed.Value = targetSpeed;
|
|
}
|
|
}
|
|
if (fish.isJumping)
|
|
{
|
|
fish.JumpUpdate();
|
|
}
|
|
fish.prevPosition = transform.position;
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
public void RotationBasedOnWaypointOrAvoidance()
|
|
{
|
|
Quaternion identity = Quaternion.identity;
|
|
identity = Quaternion.LookRotation(Target() - transform.position);
|
|
fish.isAvoiding = Fish.useAvoidance && fish.useCollisionRaycasts && Avoidance();
|
|
if (!fish.isAvoiding)
|
|
{
|
|
transform.rotation = Quaternion.Slerp(transform.rotation, identity, Time.deltaTime);
|
|
}
|
|
Vector3 eulerAngles = transform.eulerAngles;
|
|
if (!fish.isJumping && !fish.isInNetArea)
|
|
{
|
|
float x = transform.localEulerAngles.x;
|
|
x = ((!(x > 180f)) ? x : (x - 360f));
|
|
eulerAngles.x = ClampAngle(x, -60f, 60f);
|
|
}
|
|
if (fish.isFighting && transform.position.y > -0.1f && eulerAngles.x < 0f)
|
|
{
|
|
if (!GlobalSettings.Instance)
|
|
{
|
|
Debug.Log("Fish fight rot.x fix");
|
|
}
|
|
eulerAngles.x = 0f;
|
|
}
|
|
transform.eulerAngles = eulerAngles;
|
|
}
|
|
|
|
private bool Avoidance()
|
|
{
|
|
avoidanceCheckTimer -= Time.deltaTime;
|
|
if (fish.isFighting || avoidanceCheckTimer <= 0f)
|
|
{
|
|
avoidanceCheckTimer = 0.2f;
|
|
float num = 0f;
|
|
Quaternion rotation = transform.rotation;
|
|
Vector3 eulerAngles = transform.rotation.eulerAngles;
|
|
Vector3 forward = transform.forward;
|
|
Vector3 right = transform.right;
|
|
float deltaTime = Time.deltaTime;
|
|
LayerMask layerMask = fish.collisionMask.value;
|
|
float num2 = 1.5f;
|
|
float num3 = 2f;
|
|
float num4 = turnRate.Value * 150f;
|
|
if (fish.isFighting)
|
|
{
|
|
num2 *= 2f;
|
|
num3 *= 2f;
|
|
num4 *= 2f;
|
|
}
|
|
if (fish.currentSpeed >= 4f)
|
|
{
|
|
num2 *= 2f;
|
|
num3 *= 2f;
|
|
num4 *= 2f;
|
|
}
|
|
if (transform.position.y < -1f && Physics.Raycast(transform.position, -Vector3.up + forward * 0.1f, out hit, 0.5f, layerMask))
|
|
{
|
|
num = (num2 - hit.distance) / num2;
|
|
float num5 = num4 * num * deltaTime * (speed.Value * 0.1f);
|
|
eulerAngles.x -= num5;
|
|
transform.eulerAngles = eulerAngles;
|
|
}
|
|
bool flag = fish.transform.position.y > -0.5f;
|
|
if (flag || Physics.Raycast(transform.position, Vector3.up + forward * 0.1f, out hit, num2, layerMask))
|
|
{
|
|
num = (num2 - hit.distance) / num2;
|
|
float num6 = num4 * num * deltaTime * (speed.Value * 0.1f);
|
|
eulerAngles.x += num6;
|
|
if (flag)
|
|
{
|
|
fish.CorrectDirection();
|
|
}
|
|
}
|
|
if (Physics.Raycast(fish.mouth.position, forward + right * (avoidAngle + rotateCounterL), out hit, num2, layerMask))
|
|
{
|
|
num = (num2 - hit.distance) / num2;
|
|
rotateCounterL += 0.1f;
|
|
float num7 = num4 * num * deltaTime * rotateCounterL * (speed.Value + 1f);
|
|
num7 *= 15f;
|
|
num7 = 30f;
|
|
fish.targetDirection = Utilities.RotateVector(transform.forward, new Vector3(0f, 0f - num7, 0f));
|
|
targetSpeed = 1f;
|
|
if (rotateCounterL > 1.5f)
|
|
{
|
|
rotateCounterL = 1.5f;
|
|
}
|
|
rotateCounterR = 0f;
|
|
isTurning = 0f;
|
|
return true;
|
|
}
|
|
if (Physics.Raycast(fish.mouth.position, forward + right * (0f - (avoidAngle + rotateCounterR)), out hit, num2, layerMask))
|
|
{
|
|
num = (num2 - hit.distance) / num2;
|
|
rotateCounterR += 0.1f;
|
|
float num8 = num4 * num * deltaTime * rotateCounterR * (speed.Value + 1f);
|
|
num8 *= 15f;
|
|
num8 = 30f;
|
|
fish.targetDirection = Utilities.RotateVector(transform.forward, new Vector3(0f, num8, 0f));
|
|
targetSpeed = 1f;
|
|
if (rotateCounterR > 1.5f)
|
|
{
|
|
rotateCounterR = 1.5f;
|
|
}
|
|
rotateCounterL = 0f;
|
|
isTurning = 0f;
|
|
return true;
|
|
}
|
|
if (Physics.Raycast(fish.mouth.position, forward, out hit, num3, layerMask))
|
|
{
|
|
num = (num3 - hit.distance) / num3;
|
|
isTurning = 1f;
|
|
float num9 = num4 * num * deltaTime * (targetSpeed * 5f + 1f) * ((!(isTurning <= 0f)) ? (-1f) : 1f);
|
|
num9 *= 15f;
|
|
num9 = 30f;
|
|
fish.targetDirection = Utilities.RotateVector(transform.forward, new Vector3(0f, num9, 0f));
|
|
targetSpeed = 0.5f;
|
|
if (speed.Value < 0.01f)
|
|
{
|
|
speed.Value = 0.01f;
|
|
}
|
|
return true;
|
|
}
|
|
rotateCounterL = 0f;
|
|
rotateCounterR = 0f;
|
|
isTurning = 0f;
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static float ClampAngle(float angle, float min, float max)
|
|
{
|
|
if (angle < -360f)
|
|
{
|
|
angle += 360f;
|
|
}
|
|
if (angle > 360f)
|
|
{
|
|
angle -= 360f;
|
|
}
|
|
return Mathf.Clamp(angle, min, max);
|
|
}
|
|
|
|
protected Vector3 Target()
|
|
{
|
|
Vector3 result = Vector3.zero;
|
|
if (fish.isJumping)
|
|
{
|
|
result = fish.jumpTarget;
|
|
}
|
|
else if (!alwaysUseDirection && target.Value != null)
|
|
{
|
|
if (target.Value.HasTag("BAIT"))
|
|
{
|
|
Bait component = target.Value.GetComponent<Bait>();
|
|
if (component.isOnWater)
|
|
{
|
|
result = (component.fishingHands.fishingFloat ? (component.baitPartsPositions[0].position - Vector3.up * fish.vectorToMouth.y * fish.transform.localScale.y) : ((!component.fishingHands.isGroundRig) ? component.catchPosition.position : (component.baitPartsPositions[0].position + Vector3.up * 0.05f * fish.transform.localScale.y)));
|
|
}
|
|
else
|
|
{
|
|
fish.SelectRandDirection();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = target.Value.transform.position;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = transform.position + fish.targetDirection.normalized * 5f;
|
|
}
|
|
if ((bool)fish.gameController && fish.gameController.iceLevel)
|
|
{
|
|
if (transform.position.y > -1.9f && result.y > -0.9f && (!fish.isFighting || !(fish.fishingPlayer.fishingController.distanceToHoleBottomCenter < 3f)))
|
|
{
|
|
result.y = -0.9f;
|
|
}
|
|
}
|
|
else if (transform.position.y > -0.3f && result.y > -0.1f && !fish.isJumping && ((fish.isFighting && !fish.isJumping) || fish.storedBait != null))
|
|
{
|
|
result.y = -0.1f;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public override void OnReset()
|
|
{
|
|
lookAtTarget = true;
|
|
}
|
|
|
|
public override void OnEnd()
|
|
{
|
|
base.OnEnd();
|
|
}
|
|
}
|