2025-05-03 20:36:17 +08:00

533 lines
16 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/MoveAhead.cs")]
public class MoveAhead : Node2D, IBullet
{
public new class MethodName : Node2D.MethodName
{
public new static readonly StringName _Ready = "_Ready";
public new static readonly StringName _EnterTree = "_EnterTree";
public static readonly StringName SetSpd = "SetSpd";
public new static readonly StringName _Process = "_Process";
}
public new class PropertyName : Node2D.PropertyName
{
public static readonly StringName grazed = "grazed";
public static readonly StringName node = "node";
public static readonly StringName anim = "anim";
public static readonly StringName generatedFrom = "generatedFrom";
public static readonly StringName HP = "HP";
public static readonly StringName type = "type";
public static readonly StringName notifier = "notifier";
public static readonly StringName spawnSound = "spawnSound";
public static readonly StringName speed = "speed";
public static readonly StringName rotation = "rotation";
public static readonly StringName rotationLookFix = "rotationLookFix";
public static readonly StringName lifeTime = "lifeTime";
public static readonly StringName homing = "homing";
public static readonly StringName local = "local";
public static readonly StringName sound = "sound";
public static readonly StringName ogSpd = "ogSpd";
}
public new class SignalName : Node2D.SignalName
{
}
private VisibleOnScreenNotifier2D notifier;
[Export(PropertyHint.None, "")]
private AudioStream spawnSound;
[Export(PropertyHint.None, "")]
public Vector2 speed;
[Export(PropertyHint.None, "")]
public float rotation;
[Export(PropertyHint.None, "")]
public float rotationLookFix;
[Export(PropertyHint.None, "")]
public float lifeTime = -100f;
[Export(PropertyHint.None, "")]
public float homing;
[Export(PropertyHint.None, "")]
private bool local;
private bool sound;
private Vector2 ogSpd;
[Export(PropertyHint.None, "")]
public bool grazed { get; set; }
public Node2D node { get; set; }
public AnimationPlayer anim { get; set; }
public BulletGenerator generatedFrom { get; set; }
[Export(PropertyHint.None, "")]
public int HP { get; set; } = 1;
[Export(PropertyHint.None, "")]
public IBullet.Type type { get; set; }
public Action<Node> onShot { get; set; }
public override void _Ready()
{
node = this;
VisibleOnScreenNotifier2D[] array = Common.FindChildOfType<VisibleOnScreenNotifier2D>(this);
if (array.Length != 0)
{
notifier = array[0];
}
}
public override void _EnterTree()
{
CallDeferred("SetSpd");
}
private void SetSpd()
{
ogSpd = speed;
}
public override void _Process(double delta)
{
if (lifeTime > -15f)
{
lifeTime -= Main.deltaTime;
if (lifeTime < 0f)
{
base.Modulate = base.Modulate.Lerp(Main.colorClear, Main.deltaTime * 0.1f);
}
}
else if (lifeTime > -30f)
{
QueueFree();
}
if (homing > 0f)
{
speed = speed.Lerp(base.GlobalPosition.DirectionTo(BattleDR.current.soul.GlobalPosition) * ogSpd.Length(), homing * Main.deltaTime);
}
if (!sound && spawnSound != null)
{
if (notifier != null)
{
if (notifier.IsOnScreen())
{
Audio.PlaySound(spawnSound);
sound = true;
}
}
else
{
Audio.PlaySound(spawnSound);
sound = true;
}
}
else
{
VisibleOnScreenNotifier2D visibleOnScreenNotifier2D = notifier;
if (visibleOnScreenNotifier2D != null && !visibleOnScreenNotifier2D.IsOnScreen())
{
sound = false;
}
}
base.RotationDegrees += rotation;
if (local)
{
base.Position += speed * Main.deltaTime;
}
else
{
base.GlobalPosition += speed * Main.deltaTime;
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static List<MethodInfo> GetGodotMethodList()
{
return new List<MethodInfo>(4)
{
new MethodInfo(MethodName._Ready, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName._EnterTree, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName.SetSpd, 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)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
{
if (method == MethodName._Ready && args.Count == 0)
{
_Ready();
ret = default(godot_variant);
return true;
}
if (method == MethodName._EnterTree && args.Count == 0)
{
_EnterTree();
ret = default(godot_variant);
return true;
}
if (method == MethodName.SetSpd && args.Count == 0)
{
SetSpd();
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;
}
return base.InvokeGodotClassMethod(in method, args, out ret);
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override bool HasGodotClassMethod(in godot_string_name method)
{
if (method == MethodName._Ready)
{
return true;
}
if (method == MethodName._EnterTree)
{
return true;
}
if (method == MethodName.SetSpd)
{
return true;
}
if (method == MethodName._Process)
{
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.grazed)
{
grazed = VariantUtils.ConvertTo<bool>(in value);
return true;
}
if (name == PropertyName.node)
{
node = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.anim)
{
anim = VariantUtils.ConvertTo<AnimationPlayer>(in value);
return true;
}
if (name == PropertyName.generatedFrom)
{
generatedFrom = VariantUtils.ConvertTo<BulletGenerator>(in value);
return true;
}
if (name == PropertyName.HP)
{
HP = VariantUtils.ConvertTo<int>(in value);
return true;
}
if (name == PropertyName.type)
{
type = VariantUtils.ConvertTo<IBullet.Type>(in value);
return true;
}
if (name == PropertyName.notifier)
{
notifier = VariantUtils.ConvertTo<VisibleOnScreenNotifier2D>(in value);
return true;
}
if (name == PropertyName.spawnSound)
{
spawnSound = VariantUtils.ConvertTo<AudioStream>(in value);
return true;
}
if (name == PropertyName.speed)
{
speed = VariantUtils.ConvertTo<Vector2>(in value);
return true;
}
if (name == PropertyName.rotation)
{
rotation = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.rotationLookFix)
{
rotationLookFix = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.lifeTime)
{
lifeTime = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.homing)
{
homing = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.local)
{
local = VariantUtils.ConvertTo<bool>(in value);
return true;
}
if (name == PropertyName.sound)
{
sound = VariantUtils.ConvertTo<bool>(in value);
return true;
}
if (name == PropertyName.ogSpd)
{
ogSpd = VariantUtils.ConvertTo<Vector2>(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.grazed)
{
value = VariantUtils.CreateFrom<bool>(grazed);
return true;
}
if (name == PropertyName.node)
{
value = VariantUtils.CreateFrom<Node2D>(node);
return true;
}
if (name == PropertyName.anim)
{
value = VariantUtils.CreateFrom<AnimationPlayer>(anim);
return true;
}
if (name == PropertyName.generatedFrom)
{
value = VariantUtils.CreateFrom<BulletGenerator>(generatedFrom);
return true;
}
if (name == PropertyName.HP)
{
value = VariantUtils.CreateFrom<int>(HP);
return true;
}
if (name == PropertyName.type)
{
value = VariantUtils.CreateFrom<IBullet.Type>(type);
return true;
}
if (name == PropertyName.notifier)
{
value = VariantUtils.CreateFrom(in notifier);
return true;
}
if (name == PropertyName.spawnSound)
{
value = VariantUtils.CreateFrom(in spawnSound);
return true;
}
if (name == PropertyName.speed)
{
value = VariantUtils.CreateFrom(in speed);
return true;
}
if (name == PropertyName.rotation)
{
value = VariantUtils.CreateFrom(in rotation);
return true;
}
if (name == PropertyName.rotationLookFix)
{
value = VariantUtils.CreateFrom(in rotationLookFix);
return true;
}
if (name == PropertyName.lifeTime)
{
value = VariantUtils.CreateFrom(in lifeTime);
return true;
}
if (name == PropertyName.homing)
{
value = VariantUtils.CreateFrom(in homing);
return true;
}
if (name == PropertyName.local)
{
value = VariantUtils.CreateFrom(in local);
return true;
}
if (name == PropertyName.sound)
{
value = VariantUtils.CreateFrom(in sound);
return true;
}
if (name == PropertyName.ogSpd)
{
value = VariantUtils.CreateFrom(in ogSpd);
return true;
}
return base.GetGodotClassPropertyValue(in name, out value);
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static List<PropertyInfo> GetGodotPropertyList()
{
return new List<PropertyInfo>
{
new PropertyInfo(Variant.Type.Bool, PropertyName.grazed, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.node, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Object, PropertyName.anim, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Object, PropertyName.generatedFrom, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Int, PropertyName.HP, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.notifier, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Object, PropertyName.spawnSound, PropertyHint.ResourceType, "AudioStream", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Vector2, PropertyName.speed, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Float, PropertyName.rotation, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Float, PropertyName.rotationLookFix, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Float, PropertyName.lifeTime, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Float, PropertyName.homing, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Bool, PropertyName.local, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Int, PropertyName.type, PropertyHint.Enum, "Normal,Blue,Orange,Green,Yellow,Block", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Bool, PropertyName.sound, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Vector2, PropertyName.ogSpd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void SaveGodotObjectData(GodotSerializationInfo info)
{
base.SaveGodotObjectData(info);
info.AddProperty(PropertyName.grazed, Variant.From<bool>(grazed));
info.AddProperty(PropertyName.node, Variant.From<Node2D>(node));
info.AddProperty(PropertyName.anim, Variant.From<AnimationPlayer>(anim));
info.AddProperty(PropertyName.generatedFrom, Variant.From<BulletGenerator>(generatedFrom));
info.AddProperty(PropertyName.HP, Variant.From<int>(HP));
info.AddProperty(PropertyName.type, Variant.From<IBullet.Type>(type));
info.AddProperty(PropertyName.notifier, Variant.From(in notifier));
info.AddProperty(PropertyName.spawnSound, Variant.From(in spawnSound));
info.AddProperty(PropertyName.speed, Variant.From(in speed));
info.AddProperty(PropertyName.rotation, Variant.From(in rotation));
info.AddProperty(PropertyName.rotationLookFix, Variant.From(in rotationLookFix));
info.AddProperty(PropertyName.lifeTime, Variant.From(in lifeTime));
info.AddProperty(PropertyName.homing, Variant.From(in homing));
info.AddProperty(PropertyName.local, Variant.From(in local));
info.AddProperty(PropertyName.sound, Variant.From(in sound));
info.AddProperty(PropertyName.ogSpd, Variant.From(in ogSpd));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
{
base.RestoreGodotObjectData(info);
if (info.TryGetProperty(PropertyName.grazed, out var value))
{
grazed = value.As<bool>();
}
if (info.TryGetProperty(PropertyName.node, out var value2))
{
node = value2.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.anim, out var value3))
{
anim = value3.As<AnimationPlayer>();
}
if (info.TryGetProperty(PropertyName.generatedFrom, out var value4))
{
generatedFrom = value4.As<BulletGenerator>();
}
if (info.TryGetProperty(PropertyName.HP, out var value5))
{
HP = value5.As<int>();
}
if (info.TryGetProperty(PropertyName.type, out var value6))
{
type = value6.As<IBullet.Type>();
}
if (info.TryGetProperty(PropertyName.notifier, out var value7))
{
notifier = value7.As<VisibleOnScreenNotifier2D>();
}
if (info.TryGetProperty(PropertyName.spawnSound, out var value8))
{
spawnSound = value8.As<AudioStream>();
}
if (info.TryGetProperty(PropertyName.speed, out var value9))
{
speed = value9.As<Vector2>();
}
if (info.TryGetProperty(PropertyName.rotation, out var value10))
{
rotation = value10.As<float>();
}
if (info.TryGetProperty(PropertyName.rotationLookFix, out var value11))
{
rotationLookFix = value11.As<float>();
}
if (info.TryGetProperty(PropertyName.lifeTime, out var value12))
{
lifeTime = value12.As<float>();
}
if (info.TryGetProperty(PropertyName.homing, out var value13))
{
homing = value13.As<float>();
}
if (info.TryGetProperty(PropertyName.local, out var value14))
{
local = value14.As<bool>();
}
if (info.TryGetProperty(PropertyName.sound, out var value15))
{
sound = value15.As<bool>();
}
if (info.TryGetProperty(PropertyName.ogSpd, out var value16))
{
ogSpd = value16.As<Vector2>();
}
}
}