276 lines
7.7 KiB
C#
276 lines
7.7 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/WardenGun.cs")]
|
|
public class WardenGun : Sprite2D
|
|
{
|
|
public class Bullet
|
|
{
|
|
public Node2D obj;
|
|
|
|
public Vector2 direction;
|
|
}
|
|
|
|
public new class MethodName : Sprite2D.MethodName
|
|
{
|
|
public new static readonly StringName _Ready = "_Ready";
|
|
|
|
public new static readonly StringName _Process = "_Process";
|
|
|
|
public new static readonly StringName _ExitTree = "_ExitTree";
|
|
}
|
|
|
|
public new class PropertyName : Sprite2D.PropertyName
|
|
{
|
|
public static readonly StringName bulletBase = "bulletBase";
|
|
|
|
public static readonly StringName point = "point";
|
|
|
|
public static readonly StringName sound = "sound";
|
|
|
|
public static readonly StringName cd = "cd";
|
|
|
|
public static readonly StringName ready = "ready";
|
|
}
|
|
|
|
public new class SignalName : Sprite2D.SignalName
|
|
{
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D bulletBase;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D point;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStreamPlayer sound;
|
|
|
|
private List<Bullet> bullets = new List<Bullet>();
|
|
|
|
private float cd = 30f;
|
|
|
|
private const float speed = 1f;
|
|
|
|
private bool ready;
|
|
|
|
public override void _Ready()
|
|
{
|
|
base.Modulate = Main.colorClear;
|
|
point = GetChild<Node2D>(0);
|
|
sound = GetChild<AudioStreamPlayer>(1);
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
LookAt(BattleDR.current.soul.GlobalPosition);
|
|
if (cd > 0f)
|
|
{
|
|
cd -= Main.deltaTime;
|
|
}
|
|
if (!ready)
|
|
{
|
|
base.Modulate = Main.colorWhite.Lerp(Main.colorClear, cd / 30f);
|
|
if (cd <= 0f)
|
|
{
|
|
ready = true;
|
|
}
|
|
}
|
|
else if (cd <= 0f)
|
|
{
|
|
cd = Main.RandomRange(30, 60);
|
|
bullets.Add(new Bullet
|
|
{
|
|
obj = (Node2D)bulletBase.Duplicate(),
|
|
direction = point.GlobalPosition.DirectionTo(BattleDR.current.soul.GlobalPosition)
|
|
});
|
|
List<Bullet> list = bullets;
|
|
AddChild(list[list.Count - 1].obj, forceReadableName: false, InternalMode.Disabled);
|
|
List<Bullet> list2 = bullets;
|
|
list2[list2.Count - 1].obj.GlobalPosition = point.GlobalPosition;
|
|
sound.Play();
|
|
}
|
|
for (int i = 0; i < bullets.Count; i++)
|
|
{
|
|
bullets[i].obj.GlobalPosition += bullets[i].direction * Main.deltaTime * 1f;
|
|
}
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
Party.Heal(playSound: false);
|
|
Party.UpdateHUD();
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal static List<MethodInfo> GetGodotMethodList()
|
|
{
|
|
return new List<MethodInfo>(3)
|
|
{
|
|
new MethodInfo(MethodName._Ready, 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._ExitTree, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, 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._Process && args.Count == 1)
|
|
{
|
|
_Process(VariantUtils.ConvertTo<double>(in args[0]));
|
|
ret = default(godot_variant);
|
|
return true;
|
|
}
|
|
if (method == MethodName._ExitTree && args.Count == 0)
|
|
{
|
|
_ExitTree();
|
|
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._Process)
|
|
{
|
|
return true;
|
|
}
|
|
if (method == MethodName._ExitTree)
|
|
{
|
|
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.bulletBase)
|
|
{
|
|
bulletBase = VariantUtils.ConvertTo<Node2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.point)
|
|
{
|
|
point = VariantUtils.ConvertTo<Node2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.sound)
|
|
{
|
|
sound = VariantUtils.ConvertTo<AudioStreamPlayer>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
cd = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.ready)
|
|
{
|
|
ready = VariantUtils.ConvertTo<bool>(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.bulletBase)
|
|
{
|
|
value = VariantUtils.CreateFrom(in bulletBase);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.point)
|
|
{
|
|
value = VariantUtils.CreateFrom(in point);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.sound)
|
|
{
|
|
value = VariantUtils.CreateFrom(in sound);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
value = VariantUtils.CreateFrom(in cd);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.ready)
|
|
{
|
|
value = VariantUtils.CreateFrom(in ready);
|
|
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.Object, PropertyName.bulletBase, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.point, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.sound, PropertyHint.NodeType, "AudioStreamPlayer", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.cd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.ready, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void SaveGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.SaveGodotObjectData(info);
|
|
info.AddProperty(PropertyName.bulletBase, Variant.From(in bulletBase));
|
|
info.AddProperty(PropertyName.point, Variant.From(in point));
|
|
info.AddProperty(PropertyName.sound, Variant.From(in sound));
|
|
info.AddProperty(PropertyName.cd, Variant.From(in cd));
|
|
info.AddProperty(PropertyName.ready, Variant.From(in ready));
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.RestoreGodotObjectData(info);
|
|
if (info.TryGetProperty(PropertyName.bulletBase, out var value))
|
|
{
|
|
bulletBase = value.As<Node2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.point, out var value2))
|
|
{
|
|
point = value2.As<Node2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.sound, out var value3))
|
|
{
|
|
sound = value3.As<AudioStreamPlayer>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.cd, out var value4))
|
|
{
|
|
cd = value4.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.ready, out var value5))
|
|
{
|
|
ready = value5.As<bool>();
|
|
}
|
|
}
|
|
}
|