cirnogodot/Scripts/Resources/BossPhase.cs

80 lines
2.3 KiB
C#
Raw Normal View History

2025-02-05 19:41:49 +01:00
using Cirno.Scripts.Actors;
2025-03-15 17:17:30 +01:00
using Cirno.Scripts.AttackPatterns;
2026-03-01 23:14:33 +01:00
using Cirno.Scripts.Resources.BulletScripts;
2025-02-05 19:41:49 +01:00
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Resources;
[GlobalClass]
2025-06-03 10:11:09 +02:00
[Tool]
2025-02-05 19:41:49 +01:00
public partial class BossPhase : Resource
{
2025-02-13 11:15:06 +01:00
[Export] public string PhaseName = string.Empty;
2025-02-05 19:41:49 +01:00
[Export] public int Threshold;
2025-02-12 18:16:16 +01:00
[Export] public bool PlayAnimation;
2026-03-01 23:14:33 +01:00
[Export] public BulletScript3D BulletScript3D;
// Legacy path kept for backwards compatibility with existing phase compositions.
// TODO: Migrate compositions to BulletScript3D-first workflows where possible.
2025-02-05 19:41:49 +01:00
[Export] public Array<AttackPattern> Patterns;
private int currentPatternIndex = 0;
private double patternTimer;
2026-03-01 23:14:33 +01:00
private bool _useBulletScript3D;
2025-02-05 19:41:49 +01:00
2025-03-15 17:17:30 +01:00
private IPatternMachine _patternMachine;
2026-03-01 23:14:33 +01:00
private BulletScript3D.BulletScriptMachine _bulletScriptMachine;
2025-06-10 16:33:43 +02:00
public void Start(Node boss)
2025-02-05 19:41:49 +01:00
{
2026-03-01 23:14:33 +01:00
_useBulletScript3D = BulletScript3D is not null;
patternTimer = 0;
if (_useBulletScript3D)
{
_bulletScriptMachine = BulletScript3D.Make(boss);
_bulletScriptMachine.Start();
_patternMachine = null;
return;
}
if (Patterns is null || Patterns.Count == 0)
{
GD.PushWarning($"BossPhase '{PhaseName}' has no legacy Patterns and no BulletScript3D assigned.");
_patternMachine = null;
return;
}
2025-02-05 19:41:49 +01:00
currentPatternIndex = 0;
2025-03-15 17:17:30 +01:00
_patternMachine = Patterns[currentPatternIndex].MakeMachine(boss);
_patternMachine.Start();
2025-02-05 19:41:49 +01:00
}
public void UpdatePhase(double delta)
{
2026-03-01 23:14:33 +01:00
if (_useBulletScript3D)
{
_bulletScriptMachine?.UpdatePhase(delta);
return;
}
if (_patternMachine is null || Patterns is null || Patterns.Count == 0)
{
return;
}
2025-02-05 19:41:49 +01:00
patternTimer += delta;
var currentPattern = Patterns[currentPatternIndex];
2025-03-15 17:17:30 +01:00
_patternMachine.UpdatePattern(delta);
2025-02-05 19:41:49 +01:00
2025-03-15 17:17:30 +01:00
if (!currentPattern.WaitForCompletion || _patternMachine.IsComplete())
2025-02-05 19:41:49 +01:00
{
currentPatternIndex = (currentPatternIndex + 1) % Patterns.Count;
2025-03-15 17:17:30 +01:00
var oldParent = _patternMachine.Parent;
_patternMachine = Patterns[currentPatternIndex].MakeMachine(oldParent);
_patternMachine.Start();
2025-02-05 19:41:49 +01:00
}
}
}