484 lines
14 KiB
C#
484 lines
14 KiB
C#
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using Godot;
|
|
using Godot.Bridge;
|
|
using Godot.NativeInterop;
|
|
|
|
[ScriptPath("res://Scripts/Bullets/WrenchSpin.cs")]
|
|
public class WrenchSpin : Node2D
|
|
{
|
|
public new class MethodName : Node2D.MethodName
|
|
{
|
|
public new static readonly StringName _EnterTree = "_EnterTree";
|
|
|
|
public new static readonly StringName _ExitTree = "_ExitTree";
|
|
|
|
public new static readonly StringName _Process = "_Process";
|
|
|
|
public static readonly StringName GetTarget = "GetTarget";
|
|
}
|
|
|
|
public new class PropertyName : Node2D.PropertyName
|
|
{
|
|
public static readonly StringName nut = "nut";
|
|
|
|
public static readonly StringName wrench = "wrench";
|
|
|
|
public static readonly StringName bullet = "bullet";
|
|
|
|
public static readonly StringName cd = "cd";
|
|
|
|
public static readonly StringName nextTarget = "nextTarget";
|
|
|
|
public static readonly StringName wait = "wait";
|
|
|
|
public static readonly StringName state = "state";
|
|
|
|
public static readonly StringName entity = "entity";
|
|
|
|
public static readonly StringName mid = "mid";
|
|
|
|
public static readonly StringName target = "target";
|
|
|
|
public static readonly StringName flip = "flip";
|
|
|
|
public static readonly StringName stop = "stop";
|
|
}
|
|
|
|
public new class SignalName : Node2D.SignalName
|
|
{
|
|
}
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Sprite2D nut;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Sprite2D wrench;
|
|
|
|
[Export(PropertyHint.None, "")]
|
|
private Node2D bullet;
|
|
|
|
private float cd;
|
|
|
|
private float nextTarget;
|
|
|
|
private float wait;
|
|
|
|
private int state;
|
|
|
|
private Entity entity;
|
|
|
|
private Vector2 mid;
|
|
|
|
private Vector2 target = new Vector2(0f, -50f);
|
|
|
|
private bool flip;
|
|
|
|
private bool stop;
|
|
|
|
private const float startTime = 45f;
|
|
|
|
private const float speed = 2f;
|
|
|
|
private const float angle = 60f;
|
|
|
|
private List<Node> screws = new List<Node>();
|
|
|
|
public override void _EnterTree()
|
|
{
|
|
entity = BattleDR.current.activeBoard.caller.entity;
|
|
entity.Visible = false;
|
|
wrench.GlobalPosition = entity.GlobalPosition;
|
|
target += nut.GlobalPosition;
|
|
mid = wrench.GlobalPosition.Lerp(nut.GlobalPosition, 0.5f) + Vector2.Up * 100f;
|
|
Audio.PlaySound("snd_jump_ch1.wav");
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
entity.Visible = true;
|
|
for (int i = 0; i < screws.Count; i++)
|
|
{
|
|
screws[i].QueueFree();
|
|
}
|
|
BattleDR.current.soul.TopLevel = true;
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (state == 0)
|
|
{
|
|
if (cd <= 45f)
|
|
{
|
|
float num = Mathf.Min(cd / 45f, 1f);
|
|
cd += Main.deltaTime;
|
|
wrench.RotationDegrees = Mathf.Lerp(0f, -180f, num);
|
|
wrench.GlobalPosition = Common.Beizier(entity.GlobalPosition, mid, target, num);
|
|
}
|
|
else
|
|
{
|
|
state = 1;
|
|
cd = 30f;
|
|
CameraController.Shake(10f);
|
|
Audio.PlaySound("snd_screenshake.wav");
|
|
wrench.Reparent(nut);
|
|
}
|
|
return;
|
|
}
|
|
if (state == 1)
|
|
{
|
|
if (cd > 0f)
|
|
{
|
|
cd -= Main.deltaTime;
|
|
return;
|
|
}
|
|
state = 2;
|
|
cd = 0f;
|
|
if (Mathf.Abs(BattleDR.current.soul.GlobalPosition.X - nut.GlobalPosition.X) <= 1f)
|
|
{
|
|
flip = Main.RandomRange(0, 100) > 50;
|
|
}
|
|
else
|
|
{
|
|
flip = BattleDR.current.soul.GlobalPosition.X < nut.GlobalPosition.X;
|
|
}
|
|
GetTarget();
|
|
return;
|
|
}
|
|
if (wait > 0f)
|
|
{
|
|
wait -= Main.deltaTime;
|
|
return;
|
|
}
|
|
if (cd < 60f)
|
|
{
|
|
cd += Main.deltaTime;
|
|
}
|
|
nut.RotationDegrees += Main.deltaTime * Mathf.Min(1f, cd / 60f) * (float)((!flip) ? 1 : (-1)) * 2f;
|
|
DWMenu.instance.bulletBoardPivot.RotationDegrees = (0f - nut.RotationDegrees) / 2f;
|
|
if ((!flip || !(nut.RotationDegrees <= nextTarget)) && (flip || !(nut.RotationDegrees >= nextTarget)) && !stop)
|
|
{
|
|
return;
|
|
}
|
|
if (!stop && Main.RandomRange(0, 100) >= 50)
|
|
{
|
|
stop = true;
|
|
GetTarget();
|
|
return;
|
|
}
|
|
Audio.PlaySound("snd_screenshake.wav");
|
|
stop = false;
|
|
CameraController.Shake(15f);
|
|
wait = 30f;
|
|
cd = 0f;
|
|
GetTarget();
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
MoveAhead moveAhead = (MoveAhead)BattleDR.NewBullet(in bullet, Vector2.Zero, BattleDR.current);
|
|
moveAhead.ZIndex = 4096;
|
|
moveAhead.Scale *= 0.8f;
|
|
moveAhead.RotationDegrees = Main.RandomRange(0, 360);
|
|
float x = ((i != 0) ? ((!(wrench.GlobalPosition < nut.GlobalPosition)) ? Main.RandomRange((0f - BattleDR.current.activeBoard.boardSize.X) / 2.1f, 0f) : Main.RandomRange(0f, BattleDR.current.activeBoard.boardSize.X / 2.1f)) : Main.RandomRange((0f - BattleDR.current.activeBoard.boardSize.X) / 2.1f, BattleDR.current.activeBoard.boardSize.X / 2.1f));
|
|
moveAhead.GlobalPosition = base.GlobalPosition + new Vector2(x, -100 - 15 * i);
|
|
moveAhead.speed *= Main.RandomRange(0.9f, 1.1f);
|
|
screws.Add(moveAhead);
|
|
}
|
|
}
|
|
|
|
private void GetTarget()
|
|
{
|
|
nextTarget += (float)((!flip) ? 1 : (-1)) * 60f;
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
internal static List<MethodInfo> GetGodotMethodList()
|
|
{
|
|
return new List<MethodInfo>(4)
|
|
{
|
|
new MethodInfo(MethodName._EnterTree, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
|
|
new MethodInfo(MethodName._ExitTree, 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.GetTarget, 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._EnterTree && args.Count == 0)
|
|
{
|
|
_EnterTree();
|
|
ret = default(godot_variant);
|
|
return true;
|
|
}
|
|
if (method == MethodName._ExitTree && args.Count == 0)
|
|
{
|
|
_ExitTree();
|
|
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.GetTarget && args.Count == 0)
|
|
{
|
|
GetTarget();
|
|
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._ExitTree)
|
|
{
|
|
return true;
|
|
}
|
|
if (method == MethodName._Process)
|
|
{
|
|
return true;
|
|
}
|
|
if (method == MethodName.GetTarget)
|
|
{
|
|
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.nut)
|
|
{
|
|
nut = VariantUtils.ConvertTo<Sprite2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.wrench)
|
|
{
|
|
wrench = VariantUtils.ConvertTo<Sprite2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bullet)
|
|
{
|
|
bullet = VariantUtils.ConvertTo<Node2D>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
cd = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.nextTarget)
|
|
{
|
|
nextTarget = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.wait)
|
|
{
|
|
wait = VariantUtils.ConvertTo<float>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.state)
|
|
{
|
|
state = VariantUtils.ConvertTo<int>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.entity)
|
|
{
|
|
entity = VariantUtils.ConvertTo<Entity>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.mid)
|
|
{
|
|
mid = VariantUtils.ConvertTo<Vector2>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.target)
|
|
{
|
|
target = VariantUtils.ConvertTo<Vector2>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.flip)
|
|
{
|
|
flip = VariantUtils.ConvertTo<bool>(in value);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.stop)
|
|
{
|
|
stop = 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.nut)
|
|
{
|
|
value = VariantUtils.CreateFrom(in nut);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.wrench)
|
|
{
|
|
value = VariantUtils.CreateFrom(in wrench);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.bullet)
|
|
{
|
|
value = VariantUtils.CreateFrom(in bullet);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.cd)
|
|
{
|
|
value = VariantUtils.CreateFrom(in cd);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.nextTarget)
|
|
{
|
|
value = VariantUtils.CreateFrom(in nextTarget);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.wait)
|
|
{
|
|
value = VariantUtils.CreateFrom(in wait);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.state)
|
|
{
|
|
value = VariantUtils.CreateFrom(in state);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.entity)
|
|
{
|
|
value = VariantUtils.CreateFrom(in entity);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.mid)
|
|
{
|
|
value = VariantUtils.CreateFrom(in mid);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.target)
|
|
{
|
|
value = VariantUtils.CreateFrom(in target);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.flip)
|
|
{
|
|
value = VariantUtils.CreateFrom(in flip);
|
|
return true;
|
|
}
|
|
if (name == PropertyName.stop)
|
|
{
|
|
value = VariantUtils.CreateFrom(in stop);
|
|
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.nut, PropertyHint.NodeType, "Sprite2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.wrench, PropertyHint.NodeType, "Sprite2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.bullet, PropertyHint.NodeType, "Node2D", 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.nextTarget, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Float, PropertyName.wait, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Int, PropertyName.state, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Object, PropertyName.entity, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Vector2, PropertyName.mid, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Vector2, PropertyName.target, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.flip, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
|
|
new PropertyInfo(Variant.Type.Bool, PropertyName.stop, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
|
|
};
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void SaveGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.SaveGodotObjectData(info);
|
|
info.AddProperty(PropertyName.nut, Variant.From(in nut));
|
|
info.AddProperty(PropertyName.wrench, Variant.From(in wrench));
|
|
info.AddProperty(PropertyName.bullet, Variant.From(in bullet));
|
|
info.AddProperty(PropertyName.cd, Variant.From(in cd));
|
|
info.AddProperty(PropertyName.nextTarget, Variant.From(in nextTarget));
|
|
info.AddProperty(PropertyName.wait, Variant.From(in wait));
|
|
info.AddProperty(PropertyName.state, Variant.From(in state));
|
|
info.AddProperty(PropertyName.entity, Variant.From(in entity));
|
|
info.AddProperty(PropertyName.mid, Variant.From(in mid));
|
|
info.AddProperty(PropertyName.target, Variant.From(in target));
|
|
info.AddProperty(PropertyName.flip, Variant.From(in flip));
|
|
info.AddProperty(PropertyName.stop, Variant.From(in stop));
|
|
}
|
|
|
|
[EditorBrowsable(EditorBrowsableState.Never)]
|
|
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
|
|
{
|
|
base.RestoreGodotObjectData(info);
|
|
if (info.TryGetProperty(PropertyName.nut, out var value))
|
|
{
|
|
nut = value.As<Sprite2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.wrench, out var value2))
|
|
{
|
|
wrench = value2.As<Sprite2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.bullet, out var value3))
|
|
{
|
|
bullet = value3.As<Node2D>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.cd, out var value4))
|
|
{
|
|
cd = value4.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.nextTarget, out var value5))
|
|
{
|
|
nextTarget = value5.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.wait, out var value6))
|
|
{
|
|
wait = value6.As<float>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.state, out var value7))
|
|
{
|
|
state = value7.As<int>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.entity, out var value8))
|
|
{
|
|
entity = value8.As<Entity>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.mid, out var value9))
|
|
{
|
|
mid = value9.As<Vector2>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.target, out var value10))
|
|
{
|
|
target = value10.As<Vector2>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.flip, out var value11))
|
|
{
|
|
flip = value11.As<bool>();
|
|
}
|
|
if (info.TryGetProperty(PropertyName.stop, out var value12))
|
|
{
|
|
stop = value12.As<bool>();
|
|
}
|
|
}
|
|
}
|