cirnogodot/Scripts/Components/Actors/Actor.cs

76 lines
1.7 KiB
C#
Raw Normal View History

2025-02-17 21:53:05 +01:00
using System.Collections.Generic;
using Cirno.Scripts;
2025-02-18 17:40:33 +01:00
using Cirno.Scripts.Components.Actors;
2025-02-17 21:53:05 +01:00
using Godot;
public partial class Actor : CharacterBody2D
{
[Export]
2025-02-23 21:08:52 +01:00
public float MovementSpeed { get; private set; } = 20f;
[Export]
public float Health { get; private set; } = 4f;
2025-02-18 17:40:33 +01:00
2025-02-23 19:32:36 +01:00
[ExportCategory("Defeat Script")]
[Export] public Node2D DefeatScript { get; set; }
[Export] public ActivationType ActivationType { get; private set; } = ActivationType.Toggle;
2025-02-23 22:38:33 +01:00
[Export]
public AiState StartingAiState { get; private set; }
2025-02-23 19:32:36 +01:00
2025-02-18 17:40:33 +01:00
public Vector2 MovementDirection { get; set; }
2025-02-17 21:53:05 +01:00
public Vector2 FacingDirection { get; set; }
private GameManager _gameManager;
2025-02-20 18:26:53 +01:00
private List<ActorModule> _modules = new();
2025-02-23 19:19:12 +01:00
[Signal]
public delegate void OnDeathEventHandler();
2025-02-23 22:38:33 +01:00
[Signal]
public delegate void OnControlAssumedEventHandler();
2025-02-23 18:08:57 +01:00
public bool IsDestroyed { get; set; }
2025-02-17 21:53:05 +01:00
public override void _Ready()
{
_gameManager = this.GetGameManager();
var children = GetChildren();
2025-02-20 18:26:53 +01:00
foreach (var child in children)
{
if (child is not ActorModule actorModule) continue;
_modules.Add(actorModule);
actorModule.Init(this);
2025-02-17 21:53:05 +01:00
}
}
2025-02-20 18:26:53 +01:00
public override void _Process(double delta)
2025-02-17 21:53:05 +01:00
{
2025-02-20 18:26:53 +01:00
foreach (var handler in _modules)
2025-02-17 21:53:05 +01:00
{
2025-02-20 18:26:53 +01:00
handler.Update(delta);
2025-02-17 21:53:05 +01:00
}
2025-02-20 18:26:53 +01:00
}
public override void _PhysicsProcess(double delta)
{
foreach (var handler in _modules)
2025-02-18 17:40:33 +01:00
{
2025-02-20 18:26:53 +01:00
handler.PhysicsUpdate(delta);
2025-02-18 17:40:33 +01:00
}
2025-02-17 21:53:05 +01:00
}
2025-02-23 19:19:12 +01:00
public void TriggerDeath()
{
EmitSignal(SignalName.OnDeath);
}
2025-02-23 22:38:33 +01:00
public void AssumeControl()
{
EmitSignal(SignalName.OnControlAssumed);
}
2025-02-17 21:53:05 +01:00
}