Rework enemy behavior (still in progress but shouldn't crash)

This commit is contained in:
2025-10-20 19:24:50 -07:00
parent 20b659681a
commit 44fd8c82b0
135 changed files with 2165 additions and 2415 deletions

View File

@@ -0,0 +1,48 @@
using Chickensoft.AutoInject;
using Chickensoft.Introspection;
using Godot;
using Zennysoft.Ma.Adapter;
namespace Zennysoft.Game.Ma;
[Meta(typeof(IAutoNode))]
public abstract partial class Enemy2D : Enemy
{
public override void _Notification(int what) => this.Notify(what);
public override IEnemyModelView EnemyModelView => _enemyModelView;
[Node] private EnemyModelView2D _enemyModelView { get; set; } = default!;
public override void _PhysicsProcess(double delta)
{
_enemyModelView.SetCurrentDirection(GlobalBasis, -_player.CurrentBasis.Z);
}
protected void PlayerDetector_BodyEntered(Node3D node)
{
if (node is IPlayer)
_enemyLogic.Input(new EnemyLogic.Input.ReachedPlayer());
}
protected void PlayerDetector_BodyExited(Node3D node)
{
if (node is IPlayer)
_enemyLogic.Input(new EnemyLogic.Input.Follow());
}
protected void OnVelocityComputed(Vector3 safeVelocity)
{
Velocity = safeVelocity;
LookAtTarget(safeVelocity);
if (Velocity > Vector3.Zero)
_enemyLogic.Input(new EnemyLogic.Input.Move());
else
_enemyLogic.Input(new EnemyLogic.Input.Idle());
MoveAndSlide();
}
protected void EngagePlayerBehavior_TakeAction() => EnemyModelView.PlayPrimaryAttackAnimation();
protected void EngagePlayerBehavior_AcquireTarget() => LookAt(new Vector3(_player.CurrentPosition.X, GlobalPosition.Y, _player.CurrentPosition.Z), Vector3.Up, true);
}