2025-05-13 19:22:01 +08:00

114 lines
2.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/BearingStuffing.cs")]
public partial class BearingStuffing : Node2D
{
[Export(PropertyHint.None, "")]
public Node2D bulletBase;
[Export(PropertyHint.None, "")]
private float cooldown = 40f;
[Export(PropertyHint.None, "")]
private float variance = 8f;
[Export(PropertyHint.None, "")]
private float tossSpd = 1f;
[Export(PropertyHint.None, "")]
private float angleVariance = 15f;
private float cd;
private Entity entity;
private Coroutine toss;
private List<MoveAhead> pool = new List<MoveAhead>();
private readonly StringName size = "Size";
public override void _EnterTree()
{
entity = BattleDR.current.enemies[0].entity;
entity.Modulate = Main.colorWhite;
cd = 5f;
}
private void SetCD()
{
cd = cooldown + Main.RandomRange(0f - variance, variance);
}
public override void _Process(double delta)
{
Coroutine coroutine = toss;
if ((coroutine == null || coroutine.done) && !(BattleDR.current.activeBoard.timer < 20f))
{
if (cd > 0f)
{
cd -= Main.deltaTime;
return;
}
SetCD();
toss = Coroutine.Start(Spawn(), this);
}
}
public void Break(Node node)
{
pool.RemoveAll((MoveAhead x) => !GodotObject.IsInstanceValid(x));
MoveAhead moveAhead = (MoveAhead)node;
if (moveAhead.HP != 1)
{
return;
}
int num = (int)moveAhead.GetMeta(size) - 1;
if (num <= 0)
{
return;
}
for (int num2 = 0; num2 < 2; num2++)
{
MoveAhead moveAhead2 = (MoveAhead)BattleDR.NewBullet(in bulletBase, moveAhead.GlobalPosition, this);
moveAhead2.homing = 0.015f;
moveAhead2.speed = ((num2 == 0) ? Vector2.Up : Vector2.Down) * 0.75f;
moveAhead2.Scale = moveAhead.Scale * 0.65f;
if (num > 1)
{
pool.Add(moveAhead2);
moveAhead2.onShot = (Action<Node>)Delegate.Combine(moveAhead2.onShot, new Action<Node>(Break));
moveAhead2.SetMeta(size, num);
}
else
{
moveAhead2.HP = 1;
}
}
moveAhead.QueueFree();
pool.Remove(moveAhead);
}
private IEnumerator Spawn()
{
entity.anim.Play("Stuffing1");
for (float a = 0f; a < 15f; a += Main.deltaTime)
{
yield return null;
}
Audio.PlaySound("snd_swing.wav");
MoveAhead moveAhead = (MoveAhead)BattleDR.NewBullet(in bulletBase, entity.GlobalPosition + new Vector2(-50f, -25f), this);
moveAhead.speed = Vector2.Left.Rotated(Mathf.DegToRad(Main.RandomRange(0f - angleVariance, angleVariance))) * tossSpd;
moveAhead.homing = 0.005f;
moveAhead.onShot = (Action<Node>)Delegate.Combine(moveAhead.onShot, new Action<Node>(Break));
pool.Add(moveAhead);
}
}