546 lines
17 KiB
C#
546 lines
17 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/WaveBullets.cs")]
|
|
public class WaveBullets : Node2D
|
|
{
|
|
public new class MethodName : Node2D.MethodName
|
|
{
|
|
public new static readonly StringName _EnterTree = "_EnterTree";
|
|
|
|
public new static readonly StringName _Process = "_Process";
|
|
}
|
|
|
|
public new class PropertyName : Node2D.PropertyName
|
|
{
|
|
public static readonly StringName bullets = "bullets";
|
|
|
|
public static readonly StringName holder = "holder";
|
|
|
|
public static readonly StringName delay = "delay";
|
|
|
|
public static readonly StringName variance = "variance";
|
|
|
|
public static readonly StringName maxAngle = "maxAngle";
|
|
|
|
public static readonly StringName angleVariance = "angleVariance";
|
|
|
|
public static readonly StringName speed = "speed";
|
|
|
|
public static readonly StringName skip = "skip";
|
|
|
|
public static readonly StringName skipVariance = "skipVariance";
|
|
|
|
public static readonly StringName bulletsPerWave = "bulletsPerWave";
|
|
|
|
public static readonly StringName direction = "direction";
|
|
|
|
public static readonly StringName usePlayerDirection = "usePlayerDirection";
|
|
|
|
public static readonly StringName initialDelay = "initialDelay";
|
|
|
|
public static readonly StringName sound = "sound";
|
|
|
|
public static readonly StringName soundVolume = "soundVolume";
|
|
|
|
public static readonly StringName actualHolder = "actualHolder";
|
|
|
|
public static readonly StringName cd = "cd";
|
|
|
|
public static readonly StringName angle = "angle";
|
|
}
|
|
|
|
public new class SignalName : Node2D.SignalName
|
|
{
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D[] bullets;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private NodePath holder;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public float delay = 30f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public float variance = 5f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public float maxAngle = 35f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public float angleVariance;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public float speed = 1f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public int skip = 2;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
public int skipVariance = 1;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private int bulletsPerWave = 10;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Vector2 direction;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private bool usePlayerDirection = true;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private bool initialDelay;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStream sound;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float soundVolume = 1f;
|
|
|
|
private List<Node2D> bulletObjs = new List<Node2D>();
|
|
|
|
private Node2D actualHolder;
|
|
|
|
private float cd;
|
|
|
|
private float angle;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
if (initialDelay)
|
|
{
|
|
cd = delay;
|
|
}
|
|
angle = (float)Math.PI * 2f / maxAngle;
|
|
if (holder == null || holder.IsEmpty || holder.ToString().Length < 1)
|
|
{
|
|
actualHolder = this;
|
|
}
|
|
else
|
|
{
|
|
actualHolder = GetNode<Node2D>(holder);
|
|
}
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (cd > 0f)
|
|
{
|
|
cd -= Main.deltaTime;
|
|
return;
|
|
}
|
|
cd = delay + Main.RandomRange(0f - variance, variance);
|
|
if (usePlayerDirection)
|
|
{
|
|
direction = base.GlobalPosition.DirectionTo(DWMenu.instance.soulBody.GlobalPosition);
|
|
}
|
|
int num = Main.RandomRange(0, skipVariance);
|
|
int num2 = Main.RandomRange(0, bulletsPerWave);
|
|
float num3 = Main.RandomRange(0f - angleVariance, angleVariance);
|
|
if (sound != null)
|
|
{
|
|
Audio.PlaySound(sound, soundVolume);
|
|
}
|
|
int i = 0;
|
|
int num4 = skip + num;
|
|
for (; i < bulletsPerWave + skip; i++)
|
|
{
|
|
if (num4 > 0 && i >= num2)
|
|
{
|
|
num4--;
|
|
continue;
|
|
}
|
|
int num5 = Main.RandomRange(0, bullets.Length - 1);
|
|
float weight = (float)i / (float)bulletsPerWave;
|
|
Vector2 vector = direction.Rotated(Mathf.DegToRad(Mathf.Lerp(0f, maxAngle, weight) - maxAngle / 2f + num3));
|
|
bulletObjs.Add((Node2D)bullets[num5].Duplicate());
|
|
Node2D node2D = actualHolder;
|
|
List<Node2D> list = bulletObjs;
|
|
node2D.AddChild(list[list.Count - 1], forceReadableName: false, InternalMode.Disabled);
|
|
List<Node2D> list2 = bulletObjs;
|
|
list2[list2.Count - 1].GlobalPosition = base.GlobalPosition;
|
|
List<Node2D> list3 = bulletObjs;
|
|
Main.SetActive(list3[list3.Count - 1], state: true);
|
|
List<Node2D> list4 = bulletObjs;
|
|
if (list4[list4.Count - 1] is MoveAhead moveAhead)
|
|
{
|
|
moveAhead.speed = vector * speed;
|
|
}
|
|
}
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal static List<MethodInfo> GetGodotMethodList()
|
|
{
|
|
return new List<MethodInfo>(2)
|
|
{
|
|
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)
|
|
};
|
|
}
|
|
|
|
[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;
|
|
}
|
|
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;
|
|
}
|
|
return base.HasGodotClassMethod(in method);
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override bool SetGodotClassPropertyValue(in godot_string_name name, in godot_variant value)
|
|
{
|
|
if (name == PropertyName.bullets)
|
|
{
|
|
bullets = VariantUtils.ConvertToSystemArrayOfGodotObject<Node2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.holder)
|
|
{
|
|
holder = VariantUtils.ConvertTo<NodePath>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.delay)
|
|
{
|
|
delay = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.variance)
|
|
{
|
|
variance = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.maxAngle)
|
|
{
|
|
maxAngle = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.angleVariance)
|
|
{
|
|
angleVariance = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.speed)
|
|
{
|
|
speed = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.skip)
|
|
{
|
|
skip = VariantUtils.ConvertTo<int>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.skipVariance)
|
|
{
|
|
skipVariance = VariantUtils.ConvertTo<int>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bulletsPerWave)
|
|
{
|
|
bulletsPerWave = VariantUtils.ConvertTo<int>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.direction)
|
|
{
|
|
direction = VariantUtils.ConvertTo<Vector2>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.usePlayerDirection)
|
|
{
|
|
usePlayerDirection = VariantUtils.ConvertTo<bool>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.initialDelay)
|
|
{
|
|
initialDelay = VariantUtils.ConvertTo<bool>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.sound)
|
|
{
|
|
sound = VariantUtils.ConvertTo<AudioStream>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.soundVolume)
|
|
{
|
|
soundVolume = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.actualHolder)
|
|
{
|
|
actualHolder = VariantUtils.ConvertTo<Node2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
cd = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.angle)
|
|
{
|
|
angle = VariantUtils.ConvertTo<float>(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.bullets)
|
|
{
|
|
GodotObject[] array = bullets;
|
|
value = VariantUtils.CreateFromSystemArrayOfGodotObject(array);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.holder)
|
|
{
|
|
value = VariantUtils.CreateFrom(in holder);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.delay)
|
|
{
|
|
value = VariantUtils.CreateFrom(in delay);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.variance)
|
|
{
|
|
value = VariantUtils.CreateFrom(in variance);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.maxAngle)
|
|
{
|
|
value = VariantUtils.CreateFrom(in maxAngle);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.angleVariance)
|
|
{
|
|
value = VariantUtils.CreateFrom(in angleVariance);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.speed)
|
|
{
|
|
value = VariantUtils.CreateFrom(in speed);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.skip)
|
|
{
|
|
value = VariantUtils.CreateFrom(in skip);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.skipVariance)
|
|
{
|
|
value = VariantUtils.CreateFrom(in skipVariance);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bulletsPerWave)
|
|
{
|
|
value = VariantUtils.CreateFrom(in bulletsPerWave);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.direction)
|
|
{
|
|
value = VariantUtils.CreateFrom(in direction);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.usePlayerDirection)
|
|
{
|
|
value = VariantUtils.CreateFrom(in usePlayerDirection);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.initialDelay)
|
|
{
|
|
value = VariantUtils.CreateFrom(in initialDelay);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.sound)
|
|
{
|
|
value = VariantUtils.CreateFrom(in sound);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.soundVolume)
|
|
{
|
|
value = VariantUtils.CreateFrom(in soundVolume);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.actualHolder)
|
|
{
|
|
value = VariantUtils.CreateFrom(in actualHolder);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
value = VariantUtils.CreateFrom(in cd);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.angle)
|
|
{
|
|
value = VariantUtils.CreateFrom(in angle);
|
|
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.Array, PropertyName.bullets, PropertyHint.TypeString, "24/34:Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.NodePath, PropertyName.holder, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.delay, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.variance, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.maxAngle, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.angleVariance, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.speed, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Int, PropertyName.skip, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Int, PropertyName.skipVariance, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Int, PropertyName.bulletsPerWave, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Vector2, PropertyName.direction, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.usePlayerDirection, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.initialDelay, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.sound, PropertyHint.ResourceType, "AudioStream", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.soundVolume, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.actualHolder, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.cd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.angle, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void SaveGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.SaveGodotObjectData(info);
|
|
StringName name = PropertyName.bullets;
|
|
GodotObject[] array = bullets;
|
|
info.AddProperty(name, Variant.CreateFrom(array));
|
|
info.AddProperty(PropertyName.holder, Variant.From(in holder));
|
|
info.AddProperty(PropertyName.delay, Variant.From(in delay));
|
|
info.AddProperty(PropertyName.variance, Variant.From(in variance));
|
|
info.AddProperty(PropertyName.maxAngle, Variant.From(in maxAngle));
|
|
info.AddProperty(PropertyName.angleVariance, Variant.From(in angleVariance));
|
|
info.AddProperty(PropertyName.speed, Variant.From(in speed));
|
|
info.AddProperty(PropertyName.skip, Variant.From(in skip));
|
|
info.AddProperty(PropertyName.skipVariance, Variant.From(in skipVariance));
|
|
info.AddProperty(PropertyName.bulletsPerWave, Variant.From(in bulletsPerWave));
|
|
info.AddProperty(PropertyName.direction, Variant.From(in direction));
|
|
info.AddProperty(PropertyName.usePlayerDirection, Variant.From(in usePlayerDirection));
|
|
info.AddProperty(PropertyName.initialDelay, Variant.From(in initialDelay));
|
|
info.AddProperty(PropertyName.sound, Variant.From(in sound));
|
|
info.AddProperty(PropertyName.soundVolume, Variant.From(in soundVolume));
|
|
info.AddProperty(PropertyName.actualHolder, Variant.From(in actualHolder));
|
|
info.AddProperty(PropertyName.cd, Variant.From(in cd));
|
|
info.AddProperty(PropertyName.angle, Variant.From(in angle));
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.RestoreGodotObjectData(info);
|
|
if (info.TryGetProperty(PropertyName.bullets, out var value))
|
|
{
|
|
bullets = value.AsGodotObjectArray<Node2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.holder, out var value2))
|
|
{
|
|
holder = value2.As<NodePath>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.delay, out var value3))
|
|
{
|
|
delay = value3.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.variance, out var value4))
|
|
{
|
|
variance = value4.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.maxAngle, out var value5))
|
|
{
|
|
maxAngle = value5.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.angleVariance, out var value6))
|
|
{
|
|
angleVariance = value6.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.speed, out var value7))
|
|
{
|
|
speed = value7.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.skip, out var value8))
|
|
{
|
|
skip = value8.As<int>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.skipVariance, out var value9))
|
|
{
|
|
skipVariance = value9.As<int>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.bulletsPerWave, out var value10))
|
|
{
|
|
bulletsPerWave = value10.As<int>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.direction, out var value11))
|
|
{
|
|
direction = value11.As<Vector2>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.usePlayerDirection, out var value12))
|
|
{
|
|
usePlayerDirection = value12.As<bool>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.initialDelay, out var value13))
|
|
{
|
|
initialDelay = value13.As<bool>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.sound, out var value14))
|
|
{
|
|
sound = value14.As<AudioStream>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.soundVolume, out var value15))
|
|
{
|
|
soundVolume = value15.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.actualHolder, out var value16))
|
|
{
|
|
actualHolder = value16.As<Node2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.cd, out var value17))
|
|
{
|
|
cd = value17.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.angle, out var value18))
|
|
{
|
|
angle = value18.As<float>();
|
|
}
|
|
}
|
|
}
|