2025-06-12 18:03:55 +02:00
|
|
|
using Cirno.Scripts;
|
2025-02-25 17:29:24 +01:00
|
|
|
using Cirno.Scripts.Components.Actors;
|
2025-02-18 22:14:42 +01:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
public partial class EnemyPossessionMovement : ActorFreeMovement
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private ActorAi _actorAi;
|
|
|
|
|
// State accessor
|
|
|
|
|
|
2025-02-23 22:38:33 +01:00
|
|
|
private AiState _previousAiState;
|
|
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
|
public AnimatedSprite2D PossessionSprite { get; private set; }
|
|
|
|
|
|
2025-03-03 15:01:12 +01:00
|
|
|
[Export] public StringName ControlEndAction { get; private set; } = "pause";
|
2025-02-25 17:29:24 +01:00
|
|
|
|
2025-03-03 15:01:12 +01:00
|
|
|
[Export] public StringName ShootAction { get; private set; } = "shoot";
|
2025-02-25 17:29:24 +01:00
|
|
|
|
|
|
|
|
[Export] public DamageReceiverActorModule DamageReceiver { get; private set; }
|
|
|
|
|
|
|
|
|
|
[Export] public Weapon EquippedWeapon;
|
|
|
|
|
|
2025-02-18 22:14:42 +01:00
|
|
|
public override void Init(Actor parent)
|
|
|
|
|
{
|
|
|
|
|
base.Init(parent);
|
|
|
|
|
|
|
|
|
|
_actorAi = parent.GetNode<ActorAi>("ActorAi");
|
2025-02-23 22:38:33 +01:00
|
|
|
_parent.OnControlAssumed += AssumeControl;
|
|
|
|
|
|
|
|
|
|
_previousAiState = _actorAi.Ai;
|
2025-02-25 17:29:24 +01:00
|
|
|
|
|
|
|
|
parent.OnDeath += () =>
|
|
|
|
|
{
|
|
|
|
|
if (_actorAi.Ai is AiState.Controlled)
|
|
|
|
|
{
|
|
|
|
|
ResumeControl();
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-02-23 22:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update(double deltaTime)
|
|
|
|
|
{
|
2025-02-25 17:29:24 +01:00
|
|
|
if (_actorAi.Ai is not AiState.Controlled) return;
|
|
|
|
|
|
|
|
|
|
if (GetActionPressed(ShootAction))
|
|
|
|
|
{
|
|
|
|
|
Shoot();
|
|
|
|
|
}
|
2025-06-25 15:36:50 +02:00
|
|
|
|
|
|
|
|
// TODO: Restore control
|
|
|
|
|
// if (GetActionJustPressed(ControlEndAction))
|
|
|
|
|
// {
|
|
|
|
|
// if (GameManager.Instance.ToggleControlMode() is GameState.Playing)
|
|
|
|
|
// {
|
|
|
|
|
// ResumeControl();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
2025-02-18 22:14:42 +01:00
|
|
|
}
|
2025-02-25 17:29:24 +01:00
|
|
|
|
|
|
|
|
private void Shoot()
|
|
|
|
|
{
|
|
|
|
|
if (EquippedWeapon == null) return;
|
|
|
|
|
|
|
|
|
|
var direction = FacingDirection.Normalized();
|
|
|
|
|
|
|
|
|
|
EquippedWeapon.ShootDirection = direction;
|
|
|
|
|
|
|
|
|
|
EquippedWeapon.Shoot(BulletOwner.Player);
|
|
|
|
|
}
|
2025-02-18 22:14:42 +01:00
|
|
|
|
2025-02-20 18:26:53 +01:00
|
|
|
public override void PhysicsUpdate(double delta)
|
2025-02-18 22:14:42 +01:00
|
|
|
{
|
2025-02-23 18:08:57 +01:00
|
|
|
if (IsDestroyed) return;
|
2025-02-18 22:14:42 +01:00
|
|
|
if (_actorAi.Ai is AiState.Controlled)
|
2025-02-20 18:26:53 +01:00
|
|
|
base.PhysicsUpdate(delta);
|
2025-02-18 22:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-23 22:38:33 +01:00
|
|
|
public void AssumeControl()
|
|
|
|
|
{
|
|
|
|
|
GameManager.Instance.CameraTargetObject(_parent);
|
2025-03-02 11:58:30 +01:00
|
|
|
//GameManager.Instance.Player.RequestMovementDisable(true);
|
2025-03-05 10:55:14 +01:00
|
|
|
GameManager.Instance.Player.SetState(PlayerState.Controlling);
|
2025-02-23 22:38:33 +01:00
|
|
|
|
|
|
|
|
_previousAiState = _actorAi.Ai;
|
|
|
|
|
_actorAi.Ai = AiState.Controlled;
|
|
|
|
|
|
2025-02-25 17:29:24 +01:00
|
|
|
DamageReceiver.BulletGroup = BulletOwner.Player;
|
|
|
|
|
|
2025-02-23 22:38:33 +01:00
|
|
|
PossessionSprite?.Show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResumeControl()
|
|
|
|
|
{
|
|
|
|
|
_actorAi.Ai = _previousAiState;
|
|
|
|
|
|
|
|
|
|
GameManager.Instance.CameraTargetPlayer();
|
2025-03-02 11:58:30 +01:00
|
|
|
//GameManager.Instance.Player.RequestMovementDisable(false);
|
2025-03-05 10:55:14 +01:00
|
|
|
GameManager.Instance.Player.SetState(PlayerState.Active);
|
2025-02-23 22:38:33 +01:00
|
|
|
|
2025-02-25 17:29:24 +01:00
|
|
|
DamageReceiver.BulletGroup = BulletOwner.Enemy;
|
|
|
|
|
|
2025-02-23 22:38:33 +01:00
|
|
|
PossessionSprite?.Hide();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 22:14:42 +01:00
|
|
|
}
|