135 lines
3.9 KiB
C#
135 lines
3.9 KiB
C#
using Chickensoft.AutoInject;
|
|
using Chickensoft.Introspection;
|
|
using Godot;
|
|
using System;
|
|
using Zennysoft.Ma.Adapter;
|
|
|
|
namespace Zennysoft.Game.Ma;
|
|
|
|
[Meta(typeof(IAutoNode))]
|
|
public abstract partial class EnemyModelView : Node3D, IEnemyModelView
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
protected readonly string _idleName = "Idle";
|
|
protected readonly string _walkingName = "Walking";
|
|
protected readonly string _stopWalkName = "Stop Walk";
|
|
protected readonly string _primaryAttackName = "Primary Attack";
|
|
protected readonly string _secondaryAttackName = "Secondary Attack";
|
|
protected readonly string _primarySkillName = "Primary Skill";
|
|
protected readonly string _activateName = "Activate";
|
|
protected readonly string _activateFront = "activate";
|
|
protected readonly string _activateLeft = "activate_left";
|
|
protected readonly string _activateRight = "activate_right";
|
|
protected readonly string _activateBack = "activate_back";
|
|
protected readonly string _parametersPlayback = "parameters/playback";
|
|
|
|
[Node] public AnimationTree AnimationTree { get; set; } = default!;
|
|
|
|
[Node] private AudioStreamPlayer3D _walkSFX { get; set; } = default!;
|
|
|
|
protected AnimationNodeStateMachinePlayback _stateMachine;
|
|
|
|
public AttackData AttackData { get; set; }
|
|
|
|
public event EventHandler HitPlayer;
|
|
|
|
public event EventHandler ActivationFinished;
|
|
|
|
public event EventHandler TeleportAnimationFinished;
|
|
|
|
[Export]
|
|
public bool CanMove { get; set; } = false;
|
|
|
|
[Export] public EnemyLoreInfo EnemyLoreInfo { get; set; } = default!;
|
|
|
|
public void OnReady()
|
|
{
|
|
if (AnimationTree != null)
|
|
{
|
|
_stateMachine = (AnimationNodeStateMachinePlayback)AnimationTree.Get(_parametersPlayback);
|
|
AnimationTree.AnimationFinished += AnimationTree_AnimationFinished;
|
|
}
|
|
}
|
|
|
|
public virtual Vector2 GetSize()
|
|
{
|
|
return Vector2.Zero;
|
|
}
|
|
|
|
public virtual void PlayPrimaryAttackAnimation()
|
|
{
|
|
if (!AnimationTree.HasAnimation("primary_attack"))
|
|
return;
|
|
_walkSFX.Stop();
|
|
_stateMachine.Travel(_primaryAttackName, false);
|
|
}
|
|
|
|
public virtual void PlaySecondaryAttackAnimation()
|
|
{
|
|
if (!AnimationTree.HasAnimation("secondary_attack"))
|
|
return;
|
|
_walkSFX.Stop();
|
|
_stateMachine.Travel(_secondaryAttackName, false);
|
|
}
|
|
|
|
public virtual void PlayPrimarySkillAnimation()
|
|
{
|
|
if (!AnimationTree.HasAnimation("teleport"))
|
|
return;
|
|
|
|
_walkSFX.Stop();
|
|
_stateMachine.Travel(_primarySkillName, false);
|
|
}
|
|
|
|
public virtual void PlayIdleAnimation()
|
|
{
|
|
_walkSFX.Stop();
|
|
_stateMachine.Travel(_idleName, false);
|
|
}
|
|
|
|
public virtual void PlayWalkAnimation()
|
|
{
|
|
if (!_walkSFX.Playing)
|
|
_walkSFX.Play();
|
|
_stateMachine.Travel(_walkingName, false);
|
|
}
|
|
|
|
public virtual void PlayStopWalkAnimation()
|
|
{
|
|
_walkSFX.Stop();
|
|
_stateMachine.Travel(_stopWalkName, false);
|
|
}
|
|
|
|
public virtual void PlayActivateAnimation()
|
|
{
|
|
if (!AnimationTree.HasAnimation(_activateFront))
|
|
return;
|
|
|
|
_walkSFX.Stop();
|
|
_stateMachine.Travel(_activateName, false);
|
|
}
|
|
|
|
public virtual void PlayDeathAnimation() => throw new System.NotImplementedException();
|
|
|
|
public virtual void PlayHitAnimation() => throw new System.NotImplementedException();
|
|
|
|
protected virtual void OnPlayerHit(AttackEventArgs arg) => HitPlayer?.Invoke(this, arg);
|
|
|
|
protected void AnimationTree_AnimationFinished(StringName animName)
|
|
{
|
|
if (animName == _activateFront || animName == _activateLeft || animName == _activateRight || animName == _activateBack)
|
|
ActivationFinished?.Invoke(this, EventArgs.Empty);
|
|
if (animName == "teleport")
|
|
TeleportAnimationFinished?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
if (AnimationTree != null)
|
|
AnimationTree.Get(_parametersPlayback).As<AnimationNodeStateMachinePlayback>().Stop();
|
|
AnimationTree.AnimationFinished -= AnimationTree_AnimationFinished;
|
|
}
|
|
}
|