2025-03-15 11:44:30 +01:00
|
|
|
|
using System.Linq;
|
2025-03-15 17:17:30 +01:00
|
|
|
|
using Cirno.Scripts.AttackPatterns;
|
2025-03-15 11:44:30 +01:00
|
|
|
|
using Godot;
|
|
|
|
|
|
using Godot.Collections;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Cirno.Scripts.Resources;
|
|
|
|
|
|
|
|
|
|
|
|
[GlobalClass]
|
2025-06-03 10:11:09 +02:00
|
|
|
|
[Tool]
|
2025-03-15 11:44:30 +01:00
|
|
|
|
public partial class BulletScript : Resource
|
|
|
|
|
|
{
|
|
|
|
|
|
[Export]
|
|
|
|
|
|
public Array<AttackPattern> Patterns { get; private set; }
|
|
|
|
|
|
|
2025-03-15 17:17:30 +01:00
|
|
|
|
public BulletScriptMachine Make(Node2D parent)
|
2025-03-15 11:44:30 +01:00
|
|
|
|
{
|
2025-03-15 17:17:30 +01:00
|
|
|
|
return new BulletScriptMachine(parent, Patterns);
|
2025-03-15 11:44:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-15 17:17:30 +01:00
|
|
|
|
public class BulletScriptMachine(Node2D parent, Array<AttackPattern> patterns)
|
2025-03-15 11:44:30 +01:00
|
|
|
|
{
|
2025-03-15 17:17:30 +01:00
|
|
|
|
private int _currentPatternIndex = 0;
|
|
|
|
|
|
//private double _patternTimer;
|
|
|
|
|
|
|
|
|
|
|
|
private AttackPattern CurrentPattern => patterns[_currentPatternIndex];
|
2025-03-15 11:44:30 +01:00
|
|
|
|
|
2025-03-15 17:17:30 +01:00
|
|
|
|
private IPatternMachine _currentPatternMachine;
|
|
|
|
|
|
|
|
|
|
|
|
public void Start()
|
2025-03-15 11:44:30 +01:00
|
|
|
|
{
|
2025-03-15 17:17:30 +01:00
|
|
|
|
if (patterns.Count == 0) return;
|
|
|
|
|
|
_currentPatternIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
_currentPatternMachine = CurrentPattern.MakeMachine(parent);
|
|
|
|
|
|
_currentPatternMachine.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdatePhase(double delta)
|
|
|
|
|
|
{
|
|
|
|
|
|
//_patternTimer += delta;
|
|
|
|
|
|
|
|
|
|
|
|
_currentPatternMachine.UpdatePattern(delta);
|
|
|
|
|
|
//CurrentPattern.UpdatePattern(delta);
|
|
|
|
|
|
|
|
|
|
|
|
if (!CurrentPattern.WaitForCompletion || _currentPatternMachine.IsComplete())
|
|
|
|
|
|
{
|
|
|
|
|
|
_currentPatternIndex = (_currentPatternIndex + 1) % patterns.Count;
|
|
|
|
|
|
_currentPatternMachine = CurrentPattern.MakeMachine(parent);
|
|
|
|
|
|
_currentPatternMachine.Start();
|
|
|
|
|
|
}
|
2025-03-15 11:44:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|