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

229 lines
6.8 KiB
C#

using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/MopperBehavior.cs")]
public class MopperBehavior : Node
{
public new class MethodName : Node.MethodName
{
public new static readonly StringName _Ready = "_Ready";
public new static readonly StringName _Process = "_Process";
}
public new class PropertyName : Node.PropertyName
{
public static readonly StringName parent = "parent";
public static readonly StringName bullet = "bullet";
public static readonly StringName angry = "angry";
public static readonly StringName cd = "cd";
}
public new class SignalName : Node.SignalName
{
}
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;
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static List<MethodInfo> GetGodotMethodList()
{
return new List<MethodInfo>(2)
{
new MethodInfo(MethodName._Ready, 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._Ready && args.Count == 0)
{
_Ready();
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._Ready)
{
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.parent)
{
parent = VariantUtils.ConvertTo<Entity>(in value);
return true;
}
if (name == PropertyName.bullet)
{
bullet = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.angry)
{
angry = VariantUtils.ConvertTo<bool>(in value);
return true;
}
if (name == PropertyName.cd)
{
cd = VariantUtils.ConvertTo<float>(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.parent)
{
value = VariantUtils.CreateFrom(in parent);
return true;
}
if (name == PropertyName.bullet)
{
value = VariantUtils.CreateFrom(in bullet);
return true;
}
if (name == PropertyName.angry)
{
value = VariantUtils.CreateFrom(in angry);
return true;
}
if (name == PropertyName.cd)
{
value = VariantUtils.CreateFrom(in cd);
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.parent, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Object, PropertyName.bullet, PropertyHint.NodeType, "Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Bool, PropertyName.angry, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Float, PropertyName.cd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void SaveGodotObjectData(GodotSerializationInfo info)
{
base.SaveGodotObjectData(info);
info.AddProperty(PropertyName.parent, Variant.From(in parent));
info.AddProperty(PropertyName.bullet, Variant.From(in bullet));
info.AddProperty(PropertyName.angry, Variant.From(in angry));
info.AddProperty(PropertyName.cd, Variant.From(in cd));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
{
base.RestoreGodotObjectData(info);
if (info.TryGetProperty(PropertyName.parent, out var value))
{
parent = value.As<Entity>();
}
if (info.TryGetProperty(PropertyName.bullet, out var value2))
{
bullet = value2.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.angry, out var value3))
{
angry = value3.As<bool>();
}
if (info.TryGetProperty(PropertyName.cd, out var value4))
{
cd = value4.As<float>();
}
}
}