2025-02-05 19:41:49 +01:00
|
|
|
|
using Cirno.Scripts.Actors;
|
|
|
|
|
|
using Cirno.Scripts.Resources;
|
|
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Cirno.Scripts.AttackPatterns;
|
|
|
|
|
|
|
|
|
|
|
|
[GlobalClass]
|
2025-06-03 10:11:09 +02:00
|
|
|
|
[Tool]
|
2025-02-05 19:41:49 +01:00
|
|
|
|
public partial class MovementPattern : AttackPattern
|
|
|
|
|
|
{
|
2025-03-15 17:17:30 +01:00
|
|
|
|
[Export] public Vector2 relativeTargetPosition;
|
|
|
|
|
|
[Export] public float moveDuration = 2f;
|
|
|
|
|
|
[Export] public Tween.TransitionType transitionType = Tween.TransitionType.Linear;
|
|
|
|
|
|
[Export] public Tween.EaseType easeType = Tween.EaseType.InOut;
|
|
|
|
|
|
[Export] public AttackPattern shootingPattern;
|
2025-02-05 19:41:49 +01:00
|
|
|
|
|
2025-06-11 15:28:26 +02:00
|
|
|
|
public override IPatternMachine MakeMachine(Node parent)
|
2025-03-15 17:17:30 +01:00
|
|
|
|
{
|
|
|
|
|
|
return new MovementPatternMachine(this, parent);
|
|
|
|
|
|
}
|
2025-02-05 19:41:49 +01:00
|
|
|
|
|
2025-06-11 15:28:26 +02:00
|
|
|
|
public class MovementPatternMachine(MovementPattern pattern, Node parent) : IPatternMachine
|
2025-03-15 17:17:30 +01:00
|
|
|
|
{
|
2025-06-11 15:28:26 +02:00
|
|
|
|
public Node Parent => parent;
|
2025-03-15 17:17:30 +01:00
|
|
|
|
public MovementPattern Pattern { get; } = pattern;
|
|
|
|
|
|
|
|
|
|
|
|
private IPatternMachine _machine;
|
|
|
|
|
|
|
|
|
|
|
|
private Tween tween;
|
|
|
|
|
|
private bool isComplete = false;
|
2025-03-15 11:44:30 +01:00
|
|
|
|
|
2025-03-15 17:17:30 +01:00
|
|
|
|
protected IScriptHost Boss;
|
2025-03-15 11:44:30 +01:00
|
|
|
|
|
2025-03-15 17:17:30 +01:00
|
|
|
|
public void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parent is not IScriptHost boss)
|
|
|
|
|
|
return;
|
2025-03-15 11:44:30 +01:00
|
|
|
|
|
2025-03-15 17:17:30 +01:00
|
|
|
|
Boss = boss;
|
|
|
|
|
|
tween = parent.CreateTween();
|
|
|
|
|
|
isComplete = false;
|
2025-06-11 15:28:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 targetPosition = (Boss?.HomePosition ?? boss.ParentObject.GlobalPosition) + Pattern.relativeTargetPosition;
|
2025-02-05 19:41:49 +01:00
|
|
|
|
|
2025-06-11 15:28:26 +02:00
|
|
|
|
tween.TweenProperty(boss.ParentObject, "position", targetPosition, Pattern.moveDuration)
|
2025-03-15 17:17:30 +01:00
|
|
|
|
.SetTrans(Pattern.transitionType)
|
|
|
|
|
|
.SetEase(Pattern.easeType)
|
|
|
|
|
|
.Finished += () => isComplete = true;
|
2025-02-05 19:41:49 +01:00
|
|
|
|
|
2025-03-15 17:17:30 +01:00
|
|
|
|
if (Pattern.shootingPattern != null && !Pattern.WaitForCompletion)
|
|
|
|
|
|
{
|
|
|
|
|
|
_machine = Pattern.shootingPattern.MakeMachine(parent);
|
|
|
|
|
|
_machine.Start();
|
|
|
|
|
|
}
|
2025-02-05 19:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-15 17:17:30 +01:00
|
|
|
|
public void UpdatePattern(double delta)
|
2025-02-05 19:41:49 +01:00
|
|
|
|
{
|
2025-03-15 17:17:30 +01:00
|
|
|
|
if (_machine is not null && !Pattern.WaitForCompletion)
|
|
|
|
|
|
{
|
|
|
|
|
|
_machine.UpdatePattern(delta);
|
|
|
|
|
|
//shootingPattern.UpdatePattern(delta);
|
|
|
|
|
|
}
|
2025-02-05 19:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-15 17:17:30 +01:00
|
|
|
|
public bool IsComplete()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Pattern.WaitForCompletion && _machine is not null)
|
|
|
|
|
|
return isComplete && _machine.IsComplete();
|
|
|
|
|
|
return isComplete;
|
|
|
|
|
|
}
|
2025-02-05 19:41:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|