2025-05-13 19:22:01 +08:00

86 lines
1.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using EventParts;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Events/EventParts/MoveTo.cs")]
public partial class MoveTo : Node, EventPart
{
[Export(PropertyHint.None, "")]
private int entityIndex = -1;
[Export(PropertyHint.None, "")]
private Entity entity;
[Export(PropertyHint.None, "")]
private Node2D[] position;
[Export(PropertyHint.None, "")]
private float speed = 1f;
[Export(PropertyHint.None, "")]
private bool getPartyEntity;
[Export(PropertyHint.None, "")]
private bool doFacing = true;
[Export(PropertyHint.None, "")]
private Entity.Animations walkAnim = Entity.Animations.Walk;
[Export(PropertyHint.None, "")]
private Entity.Animations endAnim;
[Export(PropertyHint.None, "")]
public bool parallel { get; set; }
public EventController parent { get; set; }
public Coroutine routine { get; set; }
public IEnumerator Routine()
{
if (position == null || position.Length == 0)
{
position = new Node2D[GetChildCount()];
for (int i = 0; i < position.Length; i++)
{
position[i] = GetChild<Node2D>(i);
}
}
if (getPartyEntity)
{
entity = Party.GetOWEntityByIndex(entityIndex);
}
else if (entity == null)
{
entity = parent.entities[entityIndex];
}
Vector2[] array = new Vector2[position.Length];
for (int j = 0; j < array.Length; j++)
{
if (position[j].HasMeta("ignoreX"))
{
array[j] = new Vector2(entity.GlobalPosition.X, position[j].GlobalPosition.Y);
}
else if (position[j].HasMeta("ignoreY"))
{
array[j] = new Vector2(position[j].GlobalPosition.X, entity.GlobalPosition.Y);
}
else
{
array[j] = position[j].GlobalPosition;
}
}
entity.DoAutoMove(array, speed, walkAnim, endAnim);
entity.moving.doFacing = doFacing;
while (entity.moving != null)
{
yield return null;
}
}
}