mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
96 lines
No EOL
3 KiB
C#
96 lines
No EOL
3 KiB
C#
using Cirno.Scripts.Enums;
|
|
using Cirno.Scripts.Utils;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Components.FSM.Enemy._3D;
|
|
|
|
public partial class Alert : EnemyStateBase3D
|
|
{
|
|
public override EnemyState StateId => EnemyState.Alert;
|
|
|
|
[Export] public EnemyStorage3D Storage { get; private set; }
|
|
[Export] public PlayerDetection3D PlayerDetection { get; private set; }
|
|
[Export] public NavigationProvider3D NavigationModule { get; private set; }
|
|
[Export] public bool DebugEnabled { get; set; } = false;
|
|
|
|
private bool _isPlayerInRange = false;
|
|
|
|
public override void EnterState()
|
|
{
|
|
base.EnterState();
|
|
// player detection
|
|
// damage receiver will be a module
|
|
|
|
NavigationModule.Init(MainObject);
|
|
|
|
PlayerDetection.SetRange(Storage.Root.EnemyResource.PlayerDetectionRange);
|
|
|
|
PlayerDetection.PlayerInRange += PlayerDetectionOnPlayerInRange;
|
|
|
|
PlayerDetection.PlayerOutOfRange += PlayerDetectionOnPlayerOutOfRange;
|
|
|
|
GD.Print("Entered alert");
|
|
}
|
|
|
|
private void PlayerDetectionOnPlayerOutOfRange()
|
|
{
|
|
_isPlayerInRange = false;
|
|
}
|
|
|
|
public override void ExitState()
|
|
{
|
|
base.ExitState();
|
|
PlayerDetection.PlayerInRange -= PlayerDetectionOnPlayerInRange;
|
|
|
|
PlayerDetection.PlayerOutOfRange -= PlayerDetectionOnPlayerOutOfRange;
|
|
NavigationModule.SetTarget(null);
|
|
// DamageReceiver.HealthProvider.ResourceDepleted -= HealthProviderOnResourceDepleted;
|
|
// DamageReceiver.ChangeState(false);
|
|
// NavigationModule.SetTarget(null);
|
|
}
|
|
|
|
private void PlayerDetectionOnPlayerInRange()
|
|
{
|
|
//_isPlayerInRange = true;
|
|
}
|
|
|
|
public override void PhysicsProcessState(double delta)
|
|
{
|
|
base.PhysicsProcessState(delta);
|
|
if (PlayerDetection.IsPlayerInRange(Storage.Root.EnemyResource.ViewRange) && PlayerDetection.IsPlayerInSight())
|
|
{
|
|
StateMachine.SetState(EnemyState.Shooting);
|
|
return;
|
|
}
|
|
|
|
// if player is outside disengage range, change to idle (later on, search)
|
|
if (MainObject.GlobalPosition.DistanceTo(GameController.Instance.PlayerPosition.Value) >=
|
|
Storage.Root.EnemyResource.PlayerDisengageRange)
|
|
{
|
|
StateMachine.SetState(EnemyState.Idle);
|
|
return;
|
|
}
|
|
|
|
// Move towards last known position
|
|
if (PlayerDetection.LastKnownPlayerPosition.HasValue)
|
|
{
|
|
MoveTowardsPosition(PlayerDetection.LastKnownPlayerPosition.Value);
|
|
}
|
|
|
|
NavigationModule.Move(Storage.EnemyData.MovementSpeed);
|
|
|
|
//Storage.FacingDirection = MainObject.Velocity.SnapToCardinal().Normalized();
|
|
Storage.FacingDirection = MainObject.Velocity.ToVector2().Normalized();
|
|
Storage.AimingDirection = Storage.FacingDirection;
|
|
}
|
|
|
|
private void MoveTowardsPosition(Vector3 position)
|
|
{
|
|
NavigationModule.SetTarget(position);
|
|
}
|
|
|
|
public override void ProcessState(double delta)
|
|
{
|
|
base.ProcessState(delta);
|
|
}
|
|
} |