270 lines
7.9 KiB
C#
270 lines
7.9 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Entities/Follower.cs")]
|
|
public class Follower : Entity
|
|
{
|
|
public new class MethodName : Entity.MethodName
|
|
{
|
|
public new static readonly StringName _EnterTree = "_EnterTree";
|
|
|
|
public new static readonly StringName _Process = "_Process";
|
|
|
|
public static readonly StringName DoMovement = "DoMovement";
|
|
}
|
|
|
|
public new class PropertyName : Entity.PropertyName
|
|
{
|
|
public static readonly StringName followIndex = "followIndex";
|
|
|
|
public static readonly StringName DWOverlay = "DWOverlay";
|
|
|
|
public static readonly StringName soul = "soul";
|
|
|
|
public static readonly StringName soulHitbox = "soulHitbox";
|
|
}
|
|
|
|
public new class SignalName : Entity.SignalName
|
|
{
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public int followIndex;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Sprite2D DWOverlay;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Sprite2D soul;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public Area2D soulHitbox;
|
|
|
|
private const int followDelay = 20;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
base._EnterTree();
|
|
base.CollisionLayer = 524288u;
|
|
base.CollisionMask = 524288u;
|
|
Player instance = Player.instance;
|
|
if (instance != null)
|
|
{
|
|
List<Follower> followers = instance.followers;
|
|
if (((followers != null) ? new bool?(!followers.Contains(this)) : ((bool?)null)) == true)
|
|
{
|
|
Player.instance.followers.Add(this);
|
|
}
|
|
}
|
|
Room.current?.entities.Add(this);
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
base._Process(delta);
|
|
if (sprite != null)
|
|
{
|
|
if (Player.instance.dangerZoneCD > 0f)
|
|
{
|
|
sprite.SelfModulate = sprite.SelfModulate.Lerp(Main.colorDark, Main.deltaTime * 0.2f);
|
|
}
|
|
else
|
|
{
|
|
sprite.SelfModulate = sprite.SelfModulate.Lerp(Main.colorWhite, Main.deltaTime * 0.2f);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TryUpdateComponents(force: true);
|
|
}
|
|
if (Main.inEvent == null && Player.instance.splitEntity != this)
|
|
{
|
|
DoMovement();
|
|
}
|
|
}
|
|
|
|
public void DoMovement(bool force = false)
|
|
{
|
|
if (Player.instance.slide == null || base.GlobalPosition.Y > Player.instance.GlobalPosition.Y)
|
|
{
|
|
if (!Player.instance.waitForMove || force)
|
|
{
|
|
Vector2 vector = Player.instance.pos[100 - 20 * (followIndex + 1)];
|
|
if (base.GlobalPosition.DistanceSquaredTo(vector) > 0.2f)
|
|
{
|
|
LookAt(vector);
|
|
base.GlobalPosition = base.GlobalPosition.Lerp(vector, Main.deltaTime * 0.2f);
|
|
currentAnim = Animations.Walk;
|
|
}
|
|
else
|
|
{
|
|
currentAnim = Animations.Idle;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
currentAnim = Animations.Slide;
|
|
base.GlobalPosition = base.GlobalPosition.Lerp(Player.instance.GlobalPosition + Vector2.Up * 16f * (followIndex + 1), Main.deltaTime * 0.1f);
|
|
}
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal new static List<MethodInfo> GetGodotMethodList()
|
|
{
|
|
return new List<MethodInfo>(3)
|
|
{
|
|
new MethodInfo(MethodName._EnterTree, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
|
|
new MethodInfo(MethodName._Process, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
|
|
{
|
|
new PropertyInfo(Variant.Type.Float, "delta", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false)
|
|
}, null),
|
|
new MethodInfo(MethodName.DoMovement, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
|
|
{
|
|
new PropertyInfo(Variant.Type.Bool, "force", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false)
|
|
}, null)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
|
|
{
|
|
if (method == MethodName._EnterTree && args.Count == 0)
|
|
{
|
|
_EnterTree();
|
|
ret = default(godot_variant);
|
|
return true;
|
|
}
|
|
if (method == MethodName._Process && args.Count == 1)
|
|
{
|
|
_Process(VariantUtils.ConvertTo<double>(in args[0]));
|
|
ret = default(godot_variant);
|
|
return true;
|
|
}
|
|
if (method == MethodName.DoMovement && args.Count == 1)
|
|
{
|
|
DoMovement(VariantUtils.ConvertTo<bool>(in args[0]));
|
|
ret = default(godot_variant);
|
|
return true;
|
|
}
|
|
return base.InvokeGodotClassMethod(in method, args, out ret);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool HasGodotClassMethod(in godot_string_name method)
|
|
{
|
|
if (method == MethodName._EnterTree)
|
|
{
|
|
return true;
|
|
}
|
|
if (method == MethodName._Process)
|
|
{
|
|
return true;
|
|
}
|
|
if (method == MethodName.DoMovement)
|
|
{
|
|
return true;
|
|
}
|
|
return base.HasGodotClassMethod(in method);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool SetGodotClassPropertyValue(in godot_string_name name, in godot_variant value)
|
|
{
|
|
if (name == PropertyName.followIndex)
|
|
{
|
|
followIndex = VariantUtils.ConvertTo<int>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.DWOverlay)
|
|
{
|
|
DWOverlay = VariantUtils.ConvertTo<Sprite2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.soul)
|
|
{
|
|
soul = VariantUtils.ConvertTo<Sprite2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.soulHitbox)
|
|
{
|
|
soulHitbox = VariantUtils.ConvertTo<Area2D>(in value);
|
|
return true;
|
|
}
|
|
return base.SetGodotClassPropertyValue(in name, in value);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool GetGodotClassPropertyValue(in godot_string_name name, out godot_variant value)
|
|
{
|
|
if (name == PropertyName.followIndex)
|
|
{
|
|
value = VariantUtils.CreateFrom(in followIndex);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.DWOverlay)
|
|
{
|
|
value = VariantUtils.CreateFrom(in DWOverlay);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.soul)
|
|
{
|
|
value = VariantUtils.CreateFrom(in soul);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.soulHitbox)
|
|
{
|
|
value = VariantUtils.CreateFrom(in soulHitbox);
|
|
return true;
|
|
}
|
|
return base.GetGodotClassPropertyValue(in name, out value);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal new static List<PropertyInfo> GetGodotPropertyList()
|
|
{
|
|
return new List<PropertyInfo>
|
|
{
|
|
new PropertyInfo(Variant.Type.Int, PropertyName.followIndex, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.DWOverlay, PropertyHint.NodeType, "Sprite2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.soul, PropertyHint.NodeType, "Sprite2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.soulHitbox, PropertyHint.NodeType, "Area2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void SaveGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.SaveGodotObjectData(info);
|
|
info.AddProperty(PropertyName.followIndex, Variant.From(in followIndex));
|
|
info.AddProperty(PropertyName.DWOverlay, Variant.From(in DWOverlay));
|
|
info.AddProperty(PropertyName.soul, Variant.From(in soul));
|
|
info.AddProperty(PropertyName.soulHitbox, Variant.From(in soulHitbox));
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.RestoreGodotObjectData(info);
|
|
if (info.TryGetProperty(PropertyName.followIndex, out var value))
|
|
{
|
|
followIndex = value.As<int>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.DWOverlay, out var value2))
|
|
{
|
|
DWOverlay = value2.As<Sprite2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.soul, out var value3))
|
|
{
|
|
soul = value3.As<Sprite2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.soulHitbox, out var value4))
|
|
{
|
|
soulHitbox = value4.As<Area2D>();
|
|
}
|
|
}
|
|
}
|