352 lines
11 KiB
C#
352 lines
11 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/FoxBombs.cs")]
|
|
public class FoxBombs : 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 cooldown = "cooldown";
|
|
|
|
public static readonly StringName variance = "variance";
|
|
|
|
public static readonly StringName height = "height";
|
|
|
|
public static readonly StringName fallSpeed = "fallSpeed";
|
|
|
|
public static readonly StringName bellNoise = "bellNoise";
|
|
|
|
public static readonly StringName explosion = "explosion";
|
|
|
|
public static readonly StringName cd = "cd";
|
|
|
|
public static readonly StringName floor = "floor";
|
|
}
|
|
|
|
public new class SignalName : Node2D.SignalName
|
|
{
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D[] bullets;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float cooldown = 45f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float variance;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float height = 20f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private float fallSpeed = 0.025f;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStream bellNoise;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private AudioStream explosion;
|
|
|
|
private List<Node2D> bells = new List<Node2D>();
|
|
|
|
private List<float> speed = new List<float>();
|
|
|
|
private float cd;
|
|
|
|
private float floor;
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
if (BattleDR.current.enemies[0].HPPercent() < 0.6f || BattleDR.current.enemies[0].spare > 50)
|
|
{
|
|
cooldown *= 0.5f;
|
|
}
|
|
floor = BattleDR.current.activeBoard.boardSize.Y / 2f - 5f;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (cd <= 0f)
|
|
{
|
|
bells.Add((Node2D)bullets[0].Duplicate());
|
|
speed.Add(0f);
|
|
cd = cooldown + Main.RandomRange(0f - variance, variance);
|
|
Audio.PlaySound(bellNoise);
|
|
List<Node2D> list = bells;
|
|
AddChild(list[list.Count - 1], forceReadableName: false, InternalMode.Disabled);
|
|
List<Node2D> list2 = bells;
|
|
list2[list2.Count - 1].Modulate = Main.colorClear;
|
|
List<Node2D> list3 = bells;
|
|
list3[list3.Count - 1].ProcessMode = ProcessModeEnum.Inherit;
|
|
List<Node2D> list4 = bells;
|
|
list4[list4.Count - 1].Position = new Vector2(Main.RandomRange((0f - BattleDR.current.activeBoard.boardSize.X) / 2f, BattleDR.current.activeBoard.boardSize.X / 2f) * 0.9f, (0f - BattleDR.current.activeBoard.boardSize.Y) / 2f - height);
|
|
}
|
|
else
|
|
{
|
|
cd -= Main.deltaTime;
|
|
}
|
|
if (bells.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
for (int num = bells.Count - 1; num >= 0; num--)
|
|
{
|
|
speed[num] += fallSpeed * Main.deltaTime;
|
|
bells[num].Position += Vector2.Down * speed[num];
|
|
bells[num].Modulate = bells[num].Modulate.Lerp(Main.colorWhite, Main.deltaTime * 0.15f);
|
|
if (bells[num].Position.Y > floor)
|
|
{
|
|
CameraController.Shake(10f, 2f);
|
|
Audio.PlaySound(explosion);
|
|
Node2D node2D;
|
|
AddChild(node2D = (Node2D)bullets[1].Duplicate(), forceReadableName: false, InternalMode.Disabled);
|
|
node2D.Position = bells[num].Position;
|
|
node2D.ProcessMode = ProcessModeEnum.Inherit;
|
|
AddChild(node2D = (Node2D)bullets[2].Duplicate(), forceReadableName: false, InternalMode.Disabled);
|
|
node2D.Position = bells[num].Position;
|
|
node2D.ProcessMode = ProcessModeEnum.Inherit;
|
|
bells[num].QueueFree();
|
|
bells.RemoveAt(num);
|
|
speed.RemoveAt(num);
|
|
}
|
|
}
|
|
}
|
|
|
|
[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.cooldown)
|
|
{
|
|
cooldown = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.variance)
|
|
{
|
|
variance = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.height)
|
|
{
|
|
height = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.fallSpeed)
|
|
{
|
|
fallSpeed = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bellNoise)
|
|
{
|
|
bellNoise = VariantUtils.ConvertTo<AudioStream>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.explosion)
|
|
{
|
|
explosion = VariantUtils.ConvertTo<AudioStream>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
cd = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.floor)
|
|
{
|
|
floor = 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.cooldown)
|
|
{
|
|
value = VariantUtils.CreateFrom(in cooldown);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.variance)
|
|
{
|
|
value = VariantUtils.CreateFrom(in variance);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.height)
|
|
{
|
|
value = VariantUtils.CreateFrom(in height);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.fallSpeed)
|
|
{
|
|
value = VariantUtils.CreateFrom(in fallSpeed);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bellNoise)
|
|
{
|
|
value = VariantUtils.CreateFrom(in bellNoise);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.explosion)
|
|
{
|
|
value = VariantUtils.CreateFrom(in explosion);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
value = VariantUtils.CreateFrom(in cd);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.floor)
|
|
{
|
|
value = VariantUtils.CreateFrom(in floor);
|
|
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.Float, PropertyName.cooldown, 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.height, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.fallSpeed, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.bellNoise, PropertyHint.ResourceType, "AudioStream", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.explosion, PropertyHint.ResourceType, "AudioStream", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.cd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.floor, 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.cooldown, Variant.From(in cooldown));
|
|
info.AddProperty(PropertyName.variance, Variant.From(in variance));
|
|
info.AddProperty(PropertyName.height, Variant.From(in height));
|
|
info.AddProperty(PropertyName.fallSpeed, Variant.From(in fallSpeed));
|
|
info.AddProperty(PropertyName.bellNoise, Variant.From(in bellNoise));
|
|
info.AddProperty(PropertyName.explosion, Variant.From(in explosion));
|
|
info.AddProperty(PropertyName.cd, Variant.From(in cd));
|
|
info.AddProperty(PropertyName.floor, Variant.From(in floor));
|
|
}
|
|
|
|
[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.cooldown, out var value2))
|
|
{
|
|
cooldown = value2.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.variance, out var value3))
|
|
{
|
|
variance = value3.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.height, out var value4))
|
|
{
|
|
height = value4.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.fallSpeed, out var value5))
|
|
{
|
|
fallSpeed = value5.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.bellNoise, out var value6))
|
|
{
|
|
bellNoise = value6.As<AudioStream>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.explosion, out var value7))
|
|
{
|
|
explosion = value7.As<AudioStream>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.cd, out var value8))
|
|
{
|
|
cd = value8.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.floor, out var value9))
|
|
{
|
|
floor = value9.As<float>();
|
|
}
|
|
}
|
|
}
|