using Chickensoft.AutoInject; using Chickensoft.Introspection; using Godot; namespace Zennysoft.Game.Ma; [Meta(typeof(IAutoNode))] public partial class EnemyModelView3D : Node3D, IEnemyModelView { private const string PRIMARY_ATTACK = "primary_attack"; private const string SECONDARY_ATTACK = "secondary_attack"; private const string PRIMARY_SKILL = "primary_skill"; private const string WALK = "walk"; private const string IDLE = "idle"; private const string TAKE_DAMAGE = "take_damage"; private const string DEFEATED = "defeated"; private const string PARAMETERS_PLAYBACK = "parameters/playback"; public override void _Notification(int what) => this.Notify(what); [Export] public EnemyLoreInfo EnemyLoreInfo { get; set; } = default!; [Node] private AnimationPlayer _animationPlayer { get; set; } = default!; [Node] public AnimationTree AnimationTree { get; set; } = default!; [Node] public MeshInstance3D MeshInstance { get; set; } = default!; public void PlayPrimaryAttackAnimation() { AnimationTree.Get(PARAMETERS_PLAYBACK).As().Travel(PRIMARY_ATTACK); } public void PlaySecondaryAttackAnimation() { AnimationTree.Get(PARAMETERS_PLAYBACK).As().Travel(SECONDARY_ATTACK); } public void PlayPrimarySkillAnimation() { AnimationTree.Get(PARAMETERS_PLAYBACK).As().Travel(PRIMARY_SKILL); } public void PlayHitAnimation() { var tweener = CreateTween(); ChangeMaterial(); tweener.TweenMethod(Callable.From((float x) => SetTransparency(x)), 0.0f, 0.5f, 0.3f); tweener.TweenCallback(Callable.From(ClearDamageEffect)); } public void PlayDeathAnimation() { LoadShader("res://src/enemy/EnemyDie.tres"); var tweener = CreateTween(); tweener.TweenMethod(Callable.From((float x) => SetTransparency(x)), 0.0f, 1.0f, 0.8f); tweener.TweenCallback(Callable.From(QueueFree)); } public void PlayWalkAnimation() { AnimationTree.Get(PARAMETERS_PLAYBACK).As().Travel(WALK); } public void PlayIdleAnimation() { AnimationTree.Get(PARAMETERS_PLAYBACK).As().Travel(IDLE); } private void ChangeMaterial() { var material = new StandardMaterial3D { AlbedoColor = Color.FromHsv(0, 1, 1, 1) }; MeshInstance.MaterialOverride = (Material)material.Duplicate(); } private void LoadShader(string shaderPath) { var shader = GD.Load(shaderPath); MeshInstance.MaterialOverride = shader; } private void ClearDamageEffect() { MeshInstance.MaterialOverride = null; MeshInstance.Transparency = 0; } private void SetTransparency(float transparencyAmount) { MeshInstance.Transparency = transparencyAmount; } public override void _ExitTree() { AnimationTree.Get(PARAMETERS_PLAYBACK).As().Stop(); } public void SetCurrentDirection(Basis enemyBasis, Vector3 cameraDirection) { } }