using System.Threading.Tasks; using Cirno.Scripts.Resources; using Cirno.Scripts.UI; using Godot; using Godot.Collections; namespace Cirno.Scripts.Actors; public partial class Boss : Enemy, IActivable { [Export] private Array Phases; private int currentPhaseIndex = 0; private bool _started = false; private GameManager _gameManager; public GameManager GameManager => _gameManager; private Vector2 _homePosition; public Vector2 HomePosition => _homePosition; private BossPhase CurrentPhase => Phases[currentPhaseIndex]; // [Export] // private PackedScene _bossPhaseAnimationPrefab; private TextureRect _animationTextureRect; [Export] private Texture2D _bossPortraitTexture; public override void _Ready() { base._Ready(); _gameManager = this.GetGameManager(); _homePosition = this.GlobalPosition; if (_bossPortraitTexture is not null) { var canvas = new CanvasLayer(); canvas.Name = "BossPhaseAnimationCanvas"; _gameManager.CallDeferred("add_child", canvas); _animationTextureRect = new TextureRect(); _animationTextureRect.Texture = _bossPortraitTexture; canvas.CallDeferred("add_child", _animationTextureRect); //canvas.AddChild(animationTextureRect); _animationTextureRect.Position = new Vector2(180, 10); _animationTextureRect.Visible = false; //var animation = _bossPhaseAnimationPrefab.Instantiate(); // _gameManager.AddChild(animation); } } public override void _Process(double delta) { base._Process(delta); if (!_started) return; CurrentPhase.UpdatePhase(delta); if (_currentHealth <= CurrentPhase.Threshold && currentPhaseIndex + 1 < Phases.Count) { currentPhaseIndex++; StartPhase(CurrentPhase); } } private void StartPhase(BossPhase phase) { if (phase.PlayAnimation) { _ = Switchphase(phase); } else { phase.Start(this); } } public void TakeDamage(int amount) { if (!_started) return; _currentHealth -= amount; } public void Activate(ActivationType activationType = ActivationType.Toggle) { _started = true; StartPhase(CurrentPhase); } private async Task Switchphase(BossPhase phase) { await PlayAnimation(); phase.Start(this); } private async Task PlayAnimation() { _animationTextureRect.Modulate = new Color(_animationTextureRect.Modulate.R, _animationTextureRect.Modulate.G, _animationTextureRect.Modulate.B, 0f); _animationTextureRect.Visible = true; var tween = GetTree().CreateTween(); tween.SetEase(Tween.EaseType.InOut); tween.SetTrans(Tween.TransitionType.Linear); tween.TweenProperty(_animationTextureRect, "modulate:a", 1f, 0.2f); tween.TweenProperty(_animationTextureRect, "global_position", _animationTextureRect.GlobalPosition + new Vector2(-64f, 20f), 1.5f); tween.TweenProperty(_animationTextureRect, "modulate:a", 0f, 0.2f); //await Task.Delay(800); // Wait for the tween to finish await ToSignal(tween, "finished"); _animationTextureRect.Visible = false; } }