cirnogodot/Scripts/AttackPatterns/MovementPattern.cs

58 lines
1.6 KiB
C#
Raw Normal View History

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