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

382 lines
11 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/BearingCart.cs")]
public class BearingCart : 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 cartBase = "cartBase";
public static readonly StringName entityPos = "entityPos";
public static readonly StringName cartPos = "cartPos";
public static readonly StringName entity = "entity";
public static readonly StringName amt = "amt";
public static readonly StringName state = "state";
public static readonly StringName delay = "delay";
public static readonly StringName cartSpeed = "cartSpeed";
public static readonly StringName allDone = "allDone";
}
public new class SignalName : Node2D.SignalName
{
}
[Export(PropertyHint.None, "")]
private Node2D cartBase;
[Export(PropertyHint.None, "")]
private Node2D entityPos;
[Export(PropertyHint.None, "")]
private Node2D cartPos;
private Entity entity;
private int amt;
private int state;
private float delay;
private float cartSpeed;
private bool allDone;
private const float fallTime = 35f;
private Coroutine routine;
private List<Node2D> carts = new List<Node2D>();
public override void _EnterTree()
{
entity = BattleDR.current.enemies[0].entity;
entity.Modulate = Main.colorWhite;
entity.GlobalPosition = entityPos.GlobalPosition;
float progress = entity.battleData.GetProgress();
amt = ((progress > 0.5f) ? 5 : 3);
delay = ((progress > 0.5f) ? 20 : 40);
cartSpeed = ((progress > 0.5f) ? 2.75f : 2f);
}
public override void _Process(double delta)
{
BattleDR.current.activeBoard.timer = 999999f;
for (int num = carts.Count - 1; num >= 0; num--)
{
carts[num].GlobalPosition += Vector2.Left * Main.deltaTime * cartSpeed;
if (carts[num].Position.X < -200f)
{
carts[num].QueueFree();
carts.RemoveAt(num);
}
}
if (!GodotObject.IsInstanceValid(BattleDR.current.activeBoard))
{
QueueFree();
}
else
{
if (routine != null && !routine.done)
{
return;
}
if (allDone)
{
if (carts.Count == 0)
{
BattleDR.current.activeBoard.timer = 0f;
}
}
else
{
routine = Coroutine.Start(CartPunch());
}
}
}
private IEnumerator CartPunch()
{
Vector2 cs = cartPos.GlobalPosition + Vector2.Up * 300f;
Node2D cart = BattleDR.NewBullet(in cartBase, cs, this);
int idx = Main.RandomRange(2, 4);
IBullet child = cart.GetChild<IBullet>(idx);
child.node.Modulate = Main.colorYellow;
child.type = IBullet.Type.Yellow;
Audio.PlaySound("snd_arrow.wav");
float a = 0f;
for (float b = 35f; a <= b; a += Main.deltaTime)
{
cart.GlobalPosition = cs.Lerp(cartPos.GlobalPosition, a / b);
yield return null;
}
cart.GlobalPosition = cartPos.GlobalPosition;
Audio.PlaySound("snd_bump_ch1.wav");
for (float b = 0f; b < 5f; b += Main.deltaTime)
{
yield return null;
}
Audio.PlaySound("snd_noise.wav").Bus = "Reverb";
entity.anim.Play("Punch0");
entity.Shake(delay);
while (entity.shake > 0f)
{
yield return null;
}
entity.anim.Play("Punch1");
Audio.PlaySound("snd_impact_ch1.wav");
CameraController.Shake();
carts.Add(cart);
for (float b = 0f; b < 20f; b += Main.deltaTime)
{
yield return null;
}
entity.anim.Play("Idle");
amt--;
if (amt <= 0)
{
allDone = true;
}
}
[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.cartBase)
{
cartBase = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.entityPos)
{
entityPos = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.cartPos)
{
cartPos = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.entity)
{
entity = VariantUtils.ConvertTo<Entity>(in value);
return true;
}
if (name == PropertyName.amt)
{
amt = VariantUtils.ConvertTo<int>(in value);
return true;
}
if (name == PropertyName.state)
{
state = VariantUtils.ConvertTo<int>(in value);
return true;
}
if (name == PropertyName.delay)
{
delay = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.cartSpeed)
{
cartSpeed = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.allDone)
{
allDone = 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.cartBase)
{
value = VariantUtils.CreateFrom(in cartBase);
return true;
}
if (name == PropertyName.entityPos)
{
value = VariantUtils.CreateFrom(in entityPos);
return true;
}
if (name == PropertyName.cartPos)
{
value = VariantUtils.CreateFrom(in cartPos);
return true;
}
if (name == PropertyName.entity)
{
value = VariantUtils.CreateFrom(in entity);
return true;
}
if (name == PropertyName.amt)
{
value = VariantUtils.CreateFrom(in amt);
return true;
}
if (name == PropertyName.state)
{
value = VariantUtils.CreateFrom(in state);
return true;
}
if (name == PropertyName.delay)
{
value = VariantUtils.CreateFrom(in delay);
return true;
}
if (name == PropertyName.cartSpeed)
{
value = VariantUtils.CreateFrom(in cartSpeed);
return true;
}
if (name == PropertyName.allDone)
{
value = VariantUtils.CreateFrom(in allDone);
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.cartBase, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.entityPos, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.cartPos, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.entity, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Int, PropertyName.amt, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Int, PropertyName.state, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Float, PropertyName.delay, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Float, PropertyName.cartSpeed, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Bool, PropertyName.allDone, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void SaveGodotObjectData(GodotSerializationInfo info)
{
base.SaveGodotObjectData(info);
info.AddProperty(PropertyName.cartBase, Variant.From(in cartBase));
info.AddProperty(PropertyName.entityPos, Variant.From(in entityPos));
info.AddProperty(PropertyName.cartPos, Variant.From(in cartPos));
info.AddProperty(PropertyName.entity, Variant.From(in entity));
info.AddProperty(PropertyName.amt, Variant.From(in amt));
info.AddProperty(PropertyName.state, Variant.From(in state));
info.AddProperty(PropertyName.delay, Variant.From(in delay));
info.AddProperty(PropertyName.cartSpeed, Variant.From(in cartSpeed));
info.AddProperty(PropertyName.allDone, Variant.From(in allDone));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
{
base.RestoreGodotObjectData(info);
if (info.TryGetProperty(PropertyName.cartBase, out var value))
{
cartBase = value.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.entityPos, out var value2))
{
entityPos = value2.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.cartPos, out var value3))
{
cartPos = value3.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.entity, out var value4))
{
entity = value4.As<Entity>();
}
if (info.TryGetProperty(PropertyName.amt, out var value5))
{
amt = value5.As<int>();
}
if (info.TryGetProperty(PropertyName.state, out var value6))
{
state = value6.As<int>();
}
if (info.TryGetProperty(PropertyName.delay, out var value7))
{
delay = value7.As<float>();
}
if (info.TryGetProperty(PropertyName.cartSpeed, out var value8))
{
cartSpeed = value8.As<float>();
}
if (info.TryGetProperty(PropertyName.allDone, out var value9))
{
allDone = value9.As<bool>();
}
}
}