Files
deltarune-yellow-translation/Scripts-new/AxisSphere.cs
2025-05-03 20:36:17 +08:00

362 lines
10 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Bullets/AxisSphere.cs")]
public class AxisSphere : Node2D
{
public class Sphere
{
public AxisSphereSphere obj;
public Area2D area;
public bool inside;
}
public new class MethodName : Node2D.MethodName
{
public new static readonly StringName _EnterTree = "_EnterTree";
public new static readonly StringName _Process = "_Process";
public static readonly StringName SphereHit = "SphereHit";
public static readonly StringName NewSphere = "NewSphere";
}
public new class PropertyName : Node2D.PropertyName
{
public static readonly StringName sphere = "sphere";
public static readonly StringName entity = "entity";
public static readonly StringName cd = "cd";
public static readonly StringName weak = "weak";
public static readonly StringName done = "done";
public static readonly StringName rect = "rect";
}
public new class SignalName : Node2D.SignalName
{
}
[Export(PropertyHint.None, "")]
private Node2D sphere;
private List<Sphere> spheres = new List<Sphere>();
private Entity entity;
private float cd;
private bool weak;
private bool done;
private Coroutine shoot;
private Rect2 rect;
private const float spd = 1.1f;
public override void _EnterTree()
{
rect = new Rect2(base.GlobalPosition, BattleDR.current.activeBoard.boardSize * 0.9f);
entity = BattleDR.current.enemies[0].entity;
weak = entity.battleData.HPPercent() <= 0.5f || entity.battleData.spare >= 50;
entity.Modulate = Main.colorWhite;
if (weak)
{
BattleDR.current.activeBoard.timer *= 1.35f;
}
}
public override void _Process(double delta)
{
if (done)
{
return;
}
Coroutine coroutine = shoot;
if (coroutine == null || coroutine.done)
{
if (cd > 0f)
{
cd -= Main.deltaTime;
}
else
{
shoot = Coroutine.Start(Shoot());
}
}
}
private IEnumerator Shoot()
{
Audio.PlaySound("snd_electric_talk.wav");
entity.anim.Play("Shoot1");
for (float a = 0f; a < 30f; a += Main.deltaTime)
{
yield return null;
}
Audio.PlaySound("snd_swing.wav");
entity.anim.Play("Shoot2");
for (float a = 0f; a < 7f; a += Main.deltaTime)
{
yield return null;
}
NewSphere(spheres.Count > 0);
for (float a = 0f; a < 20f; a += Main.deltaTime)
{
yield return null;
}
if (spheres.Count == ((!weak) ? 1 : 2))
{
done = true;
}
else
{
cd = 25f;
}
entity.anim.Play("Idle");
}
private void SphereHit(Node other)
{
Audio.PlaySound("snd_ceroba_shield_impact.wav", 1f, 0.9f);
spheres[0].obj.speed = -spheres[0].obj.GlobalPosition.DirectionTo(spheres[1].obj.GlobalPosition);
spheres[1].obj.speed = -spheres[1].obj.GlobalPosition.DirectionTo(spheres[0].obj.GlobalPosition);
}
private void NewSphere(bool blue = false)
{
AxisSphereSphere axisSphereSphere = (AxisSphereSphere)BattleDR.NewBullet(in this.sphere, entity.GlobalPosition + new Vector2(-10f, -35f), this);
Sphere sphere = new Sphere
{
obj = axisSphereSphere,
area = axisSphereSphere.GetChild<Area2D>(0)
};
sphere.area.BodyEntered += axisSphereSphere.WallHit;
axisSphereSphere.data = sphere;
if (spheres.Count == 0)
{
sphere.area.AreaEntered += SphereHit;
}
spheres.Add(sphere);
axisSphereSphere.speed = Vector2.Left.Rotated(Mathf.DegToRad(Main.RandomRange(-25, 25))) * 1.1f * ((!blue) ? 1.2f : 1f);
if (blue)
{
axisSphereSphere.Modulate = Main.colorCyan;
axisSphereSphere.type = IBullet.Type.Blue;
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static List<MethodInfo> GetGodotMethodList()
{
return new List<MethodInfo>(4)
{
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),
new MethodInfo(MethodName.SphereHit, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
{
new PropertyInfo(Variant.Type.Object, "other", PropertyHint.None, "", PropertyUsageFlags.Default, new StringName("Node"), exported: false)
}, null),
new MethodInfo(MethodName.NewSphere, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
{
new PropertyInfo(Variant.Type.Bool, "blue", 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;
}
if (method == MethodName.SphereHit && args.Count == 1)
{
SphereHit(VariantUtils.ConvertTo<Node>(in args[0]));
ret = default(godot_variant);
return true;
}
if (method == MethodName.NewSphere && args.Count == 1)
{
NewSphere(VariantUtils.ConvertTo<bool>(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;
}
if (method == MethodName.SphereHit)
{
return true;
}
if (method == MethodName.NewSphere)
{
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.sphere)
{
sphere = VariantUtils.ConvertTo<Node2D>(in value);
return true;
}
if (name == PropertyName.entity)
{
entity = VariantUtils.ConvertTo<Entity>(in value);
return true;
}
if (name == PropertyName.cd)
{
cd = VariantUtils.ConvertTo<float>(in value);
return true;
}
if (name == PropertyName.weak)
{
weak = VariantUtils.ConvertTo<bool>(in value);
return true;
}
if (name == PropertyName.done)
{
done = VariantUtils.ConvertTo<bool>(in value);
return true;
}
if (name == PropertyName.rect)
{
rect = VariantUtils.ConvertTo<Rect2>(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.sphere)
{
value = VariantUtils.CreateFrom(in sphere);
return true;
}
if (name == PropertyName.entity)
{
value = VariantUtils.CreateFrom(in entity);
return true;
}
if (name == PropertyName.cd)
{
value = VariantUtils.CreateFrom(in cd);
return true;
}
if (name == PropertyName.weak)
{
value = VariantUtils.CreateFrom(in weak);
return true;
}
if (name == PropertyName.done)
{
value = VariantUtils.CreateFrom(in done);
return true;
}
if (name == PropertyName.rect)
{
value = VariantUtils.CreateFrom(in rect);
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.sphere, 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.Float, PropertyName.cd, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Bool, PropertyName.weak, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Bool, PropertyName.done, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Rect2, PropertyName.rect, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void SaveGodotObjectData(GodotSerializationInfo info)
{
base.SaveGodotObjectData(info);
info.AddProperty(PropertyName.sphere, Variant.From(in sphere));
info.AddProperty(PropertyName.entity, Variant.From(in entity));
info.AddProperty(PropertyName.cd, Variant.From(in cd));
info.AddProperty(PropertyName.weak, Variant.From(in weak));
info.AddProperty(PropertyName.done, Variant.From(in done));
info.AddProperty(PropertyName.rect, Variant.From(in rect));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
{
base.RestoreGodotObjectData(info);
if (info.TryGetProperty(PropertyName.sphere, out var value))
{
sphere = value.As<Node2D>();
}
if (info.TryGetProperty(PropertyName.entity, out var value2))
{
entity = value2.As<Entity>();
}
if (info.TryGetProperty(PropertyName.cd, out var value3))
{
cd = value3.As<float>();
}
if (info.TryGetProperty(PropertyName.weak, out var value4))
{
weak = value4.As<bool>();
}
if (info.TryGetProperty(PropertyName.done, out var value5))
{
done = value5.As<bool>();
}
if (info.TryGetProperty(PropertyName.rect, out var value6))
{
rect = value6.As<Rect2>();
}
}
}