using System; using UFS2.Gameplay; using UFS2.ScriptableObjects; using UnityEngine; public class FishAttackState : IState { private FishEntity entity; private Vector3 targetDir; private float minDistance = float.PositiveInfinity; private bool isBait; private bool isLure; private bool isEatingBait; private float animSpeed; public static event Action OnStart; public FishAttackState(FishEntity entity) { this.entity = entity; } public void Enter() { if (!(entity.LureTarget == null)) { isBait = false; isLure = false; minDistance = float.PositiveInfinity; entity.Target = entity.LureTarget; entity.SetCurrentFishInAttack(); FLure component2; if (entity.LureTarget.TryGetComponent(out var _)) { bool flag = entity.Data.BehaviourType == FishBehaviourType.ActivePredator || entity.Data.BehaviourType == FishBehaviourType.PassivePredator; entity.MoveSpeed = (flag ? entity.Data.MoveMaxSpeed : entity.Data.MoveSpeed); isBait = true; } else if (entity.LureTarget.TryGetComponent(out component2)) { entity.MoveSpeed = entity.Data.MoveMaxSpeed; isLure = true; } } } public void Execute() { if (!(entity.LureTarget == null)) { float num = Mathf.Max(0.2f, entity.Physics.Rbody.velocity.magnitude * Time.deltaTime * 1.6f); float a = Vector3.Distance(entity.JointAnchor.position, entity.LureTarget.position); float b = Vector3.Distance(entity.transform.position, entity.LureTarget.position); float num2 = Mathf.Min(a, b); entity.AI.SurfacePushAway = num2 > 2f; entity.AI.KeepDirectionDuration = 0.2f; if (num2 <= num) { entity.IsInDistanceToLure = true; Debug.Log("FISH " + entity.name + " DISTANCE REACHED"); } entity.SetAnimatorFloat("speed", entity.GetMoveSpeedAnimation()); } } public void Exit() { entity.LastCatchTime = Time.time; entity.IsInDistanceToLure = false; entity.ResetCurrentFishInAttack(); entity.AI.SurfacePushAway = true; entity.AI.BottomPushAway = true; entity.AI.KeepDirectionDuration = 2f; } }