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

67 lines
1.9 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/MopperBehavior.cs")]
public partial class MopperBehavior : Node
{
private Entity parent;
[Export(PropertyHint.None, "")]
private Node2D bullet;
private static readonly List<int> allowedIDs = new List<int> { 0 };
private bool angry;
private float cd;
private Vector2? startP;
public override void _Ready()
{
parent = GetParent<Entity>();
}
public override void _Process(double delta)
{
if (BattleDR.current == null || !parent.Visible)
{
return;
}
if (BattleDR.current.state == BattleDR.State.DoEnemy && GodotObject.IsInstanceValid(BattleDR.current.activeBoard) && BattleDR.current.activeBoard.IsInsideTree() && allowedIDs.Contains(BattleDR.current.activeBoard.id))
{
if (!startP.HasValue)
{
startP = parent.GlobalPosition;
parent.currentAnim = Entity.Animations.Walk;
angry = parent.battleData.internalFlags.Contains("Mess");
}
parent.GlobalPosition = startP.Value + Vector2.Right * Common.SinOverTime(0.25f) * 20f;
parent.Modulate = Main.colorWhite;
if (cd <= 0f)
{
BasicGravity basicGravity;
BattleDR.current.activeBoard.AddChild(basicGravity = (BasicGravity)bullet.Duplicate(), forceReadableName: false, InternalMode.Disabled);
basicGravity.GlobalPosition = parent.GlobalPosition;
basicGravity.direction = new Vector2(0f - Main.RandomRange(0.5f, 2.15f), 0f - Main.RandomRange(0.5f, 2.5f) - Mathf.InverseLerp(-30f, 30f, parent.Position.Y) * 1f);
basicGravity.ProcessMode = ProcessModeEnum.Inherit;
cd = ((BattleDR.current.enemies.Count == 1 || angry) ? Main.RandomRange(15, 35) : Main.RandomRange(40, 60));
}
else
{
cd -= Main.deltaTime;
}
}
else if (startP.HasValue)
{
parent.GlobalPosition = startP.Value;
startP = null;
parent.currentAnim = Entity.Animations.Idle;
}
}
}