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

492 lines
14 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/AxisPunch.cs")]
public class AxisPunch : Node2D
{
public new class MethodName : Node2D.MethodName
{
public new static readonly StringName _EnterTree = "_EnterTree";
public new static readonly StringName _Process = "_Process";
public static readonly StringName SpawnSmoke = "SpawnSmoke";
}
public new class PropertyName : Node2D.PropertyName
{
public static readonly StringName hand = "hand";
public static readonly StringName impactFX = "impactFX";
public static readonly StringName smoke = "smoke";
public static readonly StringName handSpr = "handSpr";
public static readonly StringName anim = "anim";
public static readonly StringName collider = "collider";
public static readonly StringName time = "time";
public static readonly StringName state = "state";
public static readonly StringName cd = "cd";
public static readonly StringName scd = "scd";
public static readonly StringName multi = "multi";
public static readonly StringName temp = "temp";
public static readonly StringName canSmoke = "canSmoke";
}
public new class SignalName : Node2D.SignalName
{
}
[Export(PropertyHint.None, "")]
private Node2D hand;
[Export(PropertyHint.None, "")]
private Node2D impactFX;
[Export(PropertyHint.None, "")]
private Node2D smoke;
[Export(PropertyHint.None, "")]
private Sprite2D handSpr;
[Export(PropertyHint.None, "")]
private Texture2D[] anim;
[Export(PropertyHint.None, "")]
private CollisionShape2D collider;
[Export(PropertyHint.None, "")]
private float time = 60f;
private int state;
private float cd;
private float scd;
private float multi = 1f;
private Vector2 temp;
private const float y = -60f;
private const float ty = 25f;
private bool canSmoke;
public override void _EnterTree()
{
if (BattleDR.current.enemies[0].HPPercent() <= 0.5f || BattleDR.current.enemies[0].spare >= 50)
{
time /= 1.5f;
canSmoke = true;
}
}
public override void _Process(double delta)
{
switch (state)
{
case 0:
if (cd < time / 2f)
{
cd += Main.deltaTime;
hand.Position = hand.Position.Lerp(new Vector2(ToLocal(BattleDR.current.soul.GlobalPosition).X, -60f), Main.deltaTime * 0.15f);
break;
}
((Blank)hand).grazed = false;
temp = hand.GlobalPosition;
state = 1;
cd = 0f;
handSpr.Texture = anim[1];
Audio.PlaySound("snd_boost.wav");
break;
case 1:
cd += Main.deltaTime;
if (cd < time / 2f)
{
hand.GlobalPosition = temp.Lerp(temp + Vector2.Up * 60f, cd / time / 2f);
break;
}
if (cd < time)
{
hand.Modulate = ((Common.SinOverTime(2.5f) > 0f) ? Main.colorDark : Main.colorWhite);
break;
}
state = 2;
hand.Modulate = Main.colorWhite;
temp = hand.GlobalPosition;
cd = 0f;
collider.SetDeferred("disabled", false);
break;
case 2:
{
cd += Main.deltaTime;
if (cd < time / 2.2f)
{
hand.GlobalPosition = temp.Lerp(new Vector2(hand.GlobalPosition.X, base.GlobalPosition.Y + BattleDR.current.activeBoard.boardSize.Y / 2f - 15f), cd / (time / 2.2f));
if (canSmoke)
{
if (scd <= 0f)
{
scd = 5f;
SpawnSmoke(multi);
multi += 0.1f;
}
else
{
scd -= Main.deltaTime;
}
}
break;
}
scd = 0f;
state = 3;
cd = 0f;
CameraController.Shake(15f);
Audio.PlaySound("snd_impact_ch1.wav");
Node2D node2D;
AddChild(node2D = (Node2D)impactFX.Duplicate(), forceReadableName: false, InternalMode.Disabled);
node2D.Position = new Vector2(hand.Position.X, BattleDR.current.activeBoard.boardSize.Y / 2f + -4f);
node2D.ProcessMode = ProcessModeEnum.Inherit;
if (canSmoke)
{
SpawnSmoke(multi);
}
multi = 1f;
break;
}
case 3:
cd += Main.deltaTime;
if (cd >= time / 2f)
{
cd = 0f;
state = 0;
handSpr.Texture = anim[0];
collider.SetDeferred("disabled", true);
}
break;
}
}
private void SpawnSmoke(float m = 1f)
{
MoveAhead moveAhead = (MoveAhead)BattleDR.NewBullet(in smoke, hand.GlobalPosition, this);
moveAhead.speed = new Vector2(((moveAhead.GlobalPosition.X < BattleDR.current.soul.GlobalPosition.X) ? 0.25f : (-0.25f)) * m, -0.15f);
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static List<MethodInfo> GetGodotMethodList()
{
return new List<MethodInfo>(3)
{
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),
new MethodInfo(MethodName.SpawnSmoke, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
{
new PropertyInfo(Variant.Type.Float, "m", 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;
}
if (method == MethodName.SpawnSmoke && args.Count == 1)
{
SpawnSmoke(VariantUtils.ConvertTo<float>(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;
}
if (method == MethodName.SpawnSmoke)
{
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.hand)
{
hand = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.impactFX)
{
impactFX = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.smoke)
{
smoke = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.handSpr)
{
handSpr = VariantUtils.ConvertTo<Sprite2D>(in value);
return true;
}
if (name == PropertyName.anim)
{
anim = VariantUtils.ConvertToSystemArrayOfGodotObject<Texture2D>(in value);
return true;
}
if (name == PropertyName.collider)
{
collider = VariantUtils.ConvertTo<CollisionShape2D>(in value);
return true;
}
if (name == PropertyName.time)
{
time = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.state)
{
state = VariantUtils.ConvertTo<int>(in value);
return true;
}
if (name == PropertyName.cd)
{
cd = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.scd)
{
scd = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.multi)
{
multi = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.temp)
{
temp = VariantUtils.ConvertTo<Vector2>(in value);
return true;
}
if (name == PropertyName.canSmoke)
{
canSmoke = 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.hand)
{
value = VariantUtils.CreateFrom(in hand);
return true;
}
if (name == PropertyName.impactFX)
{
value = VariantUtils.CreateFrom(in impactFX);
return true;
}
if (name == PropertyName.smoke)
{
value = VariantUtils.CreateFrom(in smoke);
return true;
}
if (name == PropertyName.handSpr)
{
value = VariantUtils.CreateFrom(in handSpr);
return true;
}
if (name == PropertyName.anim)
{
GodotObject[] array = anim;
value = VariantUtils.CreateFromSystemArrayOfGodotObject(array);
return true;
}
if (name == PropertyName.collider)
{
value = VariantUtils.CreateFrom(in collider);
return true;
}
if (name == PropertyName.time)
{
value = VariantUtils.CreateFrom(in time);
return true;
}
if (name == PropertyName.state)
{
value = VariantUtils.CreateFrom(in state);
return true;
}
if (name == PropertyName.cd)
{
value = VariantUtils.CreateFrom(in cd);
return true;
}
if (name == PropertyName.scd)
{
value = VariantUtils.CreateFrom(in scd);
return true;
}
if (name == PropertyName.multi)
{
value = VariantUtils.CreateFrom(in multi);
return true;
}
if (name == PropertyName.temp)
{
value = VariantUtils.CreateFrom(in temp);
return true;
}
if (name == PropertyName.canSmoke)
{
value = VariantUtils.CreateFrom(in canSmoke);
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.hand, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.impactFX, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.smoke, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.handSpr, PropertyHint.NodeType, "Sprite2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Array, PropertyName.anim, PropertyHint.TypeString, "24/17:Texture2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.collider, PropertyHint.NodeType, "CollisionShape2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Float, PropertyName.time, PropertyHint.None, "", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Int, PropertyName.state, 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.scd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Float, PropertyName.multi, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Vector2, PropertyName.temp, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Bool, PropertyName.canSmoke, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void SaveGodotObjectData(GodotSerializationInfo info)
{
base.SaveGodotObjectData(info);
info.AddProperty(PropertyName.hand, Variant.From(in hand));
info.AddProperty(PropertyName.impactFX, Variant.From(in impactFX));
info.AddProperty(PropertyName.smoke, Variant.From(in smoke));
info.AddProperty(PropertyName.handSpr, Variant.From(in handSpr));
StringName name = PropertyName.anim;
GodotObject[] array = anim;
info.AddProperty(name, Variant.CreateFrom(array));
info.AddProperty(PropertyName.collider, Variant.From(in collider));
info.AddProperty(PropertyName.time, Variant.From(in time));
info.AddProperty(PropertyName.state, Variant.From(in state));
info.AddProperty(PropertyName.cd, Variant.From(in cd));
info.AddProperty(PropertyName.scd, Variant.From(in scd));
info.AddProperty(PropertyName.multi, Variant.From(in multi));
info.AddProperty(PropertyName.temp, Variant.From(in temp));
info.AddProperty(PropertyName.canSmoke, Variant.From(in canSmoke));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
{
base.RestoreGodotObjectData(info);
if (info.TryGetProperty(PropertyName.hand, out var value))
{
hand = value.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.impactFX, out var value2))
{
impactFX = value2.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.smoke, out var value3))
{
smoke = value3.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.handSpr, out var value4))
{
handSpr = value4.As<Sprite2D>();
}
if (info.TryGetProperty(PropertyName.anim, out var value5))
{
anim = value5.AsGodotObjectArray<Texture2D>();
}
if (info.TryGetProperty(PropertyName.collider, out var value6))
{
collider = value6.As<CollisionShape2D>();
}
if (info.TryGetProperty(PropertyName.time, out var value7))
{
time = value7.As<float>();
}
if (info.TryGetProperty(PropertyName.state, out var value8))
{
state = value8.As<int>();
}
if (info.TryGetProperty(PropertyName.cd, out var value9))
{
cd = value9.As<float>();
}
if (info.TryGetProperty(PropertyName.scd, out var value10))
{
scd = value10.As<float>();
}
if (info.TryGetProperty(PropertyName.multi, out var value11))
{
multi = value11.As<float>();
}
if (info.TryGetProperty(PropertyName.temp, out var value12))
{
temp = value12.As<Vector2>();
}
if (info.TryGetProperty(PropertyName.canSmoke, out var value13))
{
canSmoke = value13.As<bool>();
}
}
}