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

86 lines
1.9 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/StaplerBehavior.cs")]
public partial class StaplerBehavior : Node
{
[Export(PropertyHint.None, "")]
private PackedScene staple;
[Export(PropertyHint.None, "")]
private Entity entity;
[Export(PropertyHint.None, "")]
private int[] exceptions;
private bool doing;
private float cd;
private const float defaultTime = 80f;
public override void _EnterTree()
{
if (BattleDR.current == null)
{
QueueFree();
}
else
{
entity = GetParent<Entity>();
}
}
public override void _Process(double delta)
{
if (entity.battleData.skipAttack)
{
base.ProcessMode = ProcessModeEnum.Disabled;
return;
}
if (BattleDR.current?.activeBoard?.caller?.entity != entity)
{
BattleDR current = BattleDR.current;
if (current != null && current.activeBoard?.timer > 20f)
{
BattleDR current2 = BattleDR.current;
if (current2 != null && current2.activeBoard.IsInsideTree())
{
if (exceptions != null && exceptions.Contains(BattleDR.current.activeBoard.id))
{
return;
}
if (cd > 0f)
{
entity.Modulate = Main.colorWhite;
cd -= Main.deltaTime;
if (cd <= 50f && !doing)
{
doing = true;
MoveAhead obj = (MoveAhead)BattleDR.NewBullet(in staple, entity.GlobalPosition + new Vector2(-20f, -10f), BattleDR.current.activeBoard);
obj.LookAt(BattleDR.current.soul.GlobalPosition);
obj.speed = obj.GlobalPosition.DirectionTo(BattleDR.current.soul.GlobalPosition) * 0.75f;
obj.RotationDegrees -= 90f;
Audio.PlaySound("snd_switchpull_n.wav", 1f, 1.1f);
}
}
else
{
cd = 80f;
doing = false;
Audio.PlaySound("snd_noise.wav", 1f, 0.9f);
entity.anim.Play("Shoot");
}
return;
}
}
}
cd = 0f;
}
}