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

672 lines
20 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using Godot;
using Godot.Bridge;
using Godot.NativeInterop;
[ScriptPath("res://Scripts/Events/SchoolTreasureRoom.cs")]
public class SchoolTreasureRoom : Node
{
public new class MethodName : Node.MethodName
{
public new static readonly StringName _EnterTree = "_EnterTree";
public static readonly StringName StartPuzzle = "StartPuzzle";
public static readonly StringName Shake = "Shake";
public static readonly StringName GateCross = "GateCross";
public static readonly StringName PuzzleComplete = "PuzzleComplete";
public static readonly StringName Crunch = "Crunch";
public static readonly StringName FreeRoom = "FreeRoom";
public new static readonly StringName _Ready = "_Ready";
public new static readonly StringName _Process = "_Process";
}
public new class PropertyName : Node.PropertyName
{
public static readonly StringName bell = "bell";
public static readonly StringName crusher = "crusher";
public static readonly StringName hiddenWall = "hiddenWall";
public static readonly StringName points = "points";
public static readonly StringName sound = "sound";
public static readonly StringName bite = "bite";
public static readonly StringName spikes = "spikes";
public static readonly StringName crusherVisible = "crusherVisible";
public static readonly StringName started = "started";
public static readonly StringName time = "time";
}
public new class SignalName : Node.SignalName
{
}
[Export(PropertyHint.None, "")]
private Sprite2D bell;
[Export(PropertyHint.None, "")]
private AnimationPlayer crusher;
[Export(PropertyHint.None, "")]
private Node2D[] hiddenWall;
[Export(PropertyHint.None, "")]
private Node2D[] points;
[Export(PropertyHint.None, "")]
private AudioStreamPlayer sound;
[Export(PropertyHint.None, "")]
private AudioStreamPlayer bite;
[Export(PropertyHint.None, "")]
private PuzzleGate[] spikes;
[Export(PropertyHint.None, "")]
private VisibleOnScreenNotifier2D crusherVisible;
public bool started;
private float time = 5000f;
private const float startTime = 5000f;
public static SchoolTreasureRoom instance;
public override void _EnterTree()
{
instance = this;
}
public void StartPuzzle()
{
Main.inEvent = Coroutine.Start(FirstEvent());
}
private IEnumerator FirstEvent()
{
SaveFile.AddFlag(SaveFile.Flags.BearFortTreasureTalk);
TextSystem.GetText("TreasureRoomEvent1");
while (TextSystem.instance.Visible)
{
yield return null;
}
Audio.ChangeMusic((Audio.AudioBlock)null, 2f);
Player.instance.DoAutoAlign(points[2].GlobalPosition);
Player.instance.followers[0].DoAutoAlign(points[3].GlobalPosition);
while (!Party.IsStopped())
{
yield return null;
}
Party.LookAt(Vector2.Up);
float a;
for (a = 0f; a < 30f; a += Main.deltaTime)
{
yield return null;
}
AudioStreamOggVorbis g = GD.Load<AudioStreamOggVorbis>("res://Audio/Sounds/snd_dtrans_square.ogg");
g.Loop = true;
sound.Stream = g;
sound.VolumeDb = Mathf.LinearToDb(0.7f);
sound.Play();
Player.instance.Emoticon(Entity.Emoticons.Exclaim);
Player.instance.followers[0].Emoticon(Entity.Emoticons.Exclaim);
for (a = 0f; a < 30f; a += Main.deltaTime)
{
yield return null;
}
TextSystem.GetText("TreasureRoomEvent2");
while (TextSystem.instance.Visible)
{
yield return null;
}
Player.instance.followers[0].anim.Play("Surprise");
Shake(30f);
a = 0f;
for (float b = 30f; a < b; a += Main.deltaTime)
{
hiddenWall[5].Modulate = Main.colorWhite.Lerp(Main.colorClear, a / b);
yield return null;
}
hiddenWall[5].Visible = false;
Player.instance.LookAt(Vector2.Right);
Vector2 cam = CameraController.instance.GlobalPosition;
Coroutine c = Coroutine.Start(CameraController.Pan(new Vector2(40f, -30f), 0.75f));
while (!c.done)
{
yield return null;
}
for (float b = 0f; b < 5f; b += Main.deltaTime)
{
yield return null;
}
Main.SetActive(hiddenWall[0], state: true);
Shake();
for (float b = 0f; b < 60f; b += Main.deltaTime)
{
yield return null;
}
c = Coroutine.Start(CameraController.Pan(new Vector2(40f, -100f), 0.75f));
while (!c.done)
{
yield return null;
}
for (float b = 0f; b < 5f; b += Main.deltaTime)
{
yield return null;
}
Shake();
Main.SetActive(hiddenWall[2], state: false);
hiddenWall[3].ProcessMode = ProcessModeEnum.Inherit;
for (float b = 0f; b < 60f; b += Main.deltaTime)
{
yield return null;
}
c = Coroutine.Start(CameraController.Pan(cam, 0.75f));
while (!c.done)
{
yield return null;
}
TextSystem.GetText("TreasureRoomEvent3");
while (TextSystem.instance.Visible)
{
yield return null;
}
CameraController.instance.follow = Player.instance;
Room.current.DoMusic(1);
hiddenWall[4].ZIndex = 0;
g.Loop = false;
crusher.Play("Active");
started = true;
}
private void Shake(float time = 10f, float intensity = 1f)
{
CameraController.Shake(time, intensity);
Audio.PlaySound("snd_screenshake.wav");
}
public void GateCross()
{
Shake();
Main.SetActive(hiddenWall[1], state: true);
}
public void PuzzleComplete()
{
Main.inEvent = Coroutine.Start(Won());
started = false;
}
private IEnumerator Won()
{
Party.StopMoving();
Audio.ChangeMusic(null);
bool lost = SaveFile.HasFlag(SaveFile.Flags.BearTreasureLost);
if (!lost)
{
Audio.PlaySound("snd_won.wav");
Room.current.eventPointers[0].QueueFree();
}
crusher.Play("Sleep");
Player.instance.lockMenu = false;
for (float a = 0f; a < 60f; a += Main.deltaTime)
{
yield return null;
}
TextSystem.GetText(lost ? "TreasureGotAfterLost" : "TreasureRoomWon");
while (TextSystem.instance.Visible)
{
yield return null;
}
if (Items.CheckFull(Items.Type.Equip))
{
TextSystem.GetText("TreasureRoomInvFull");
while (TextSystem.instance.Visible)
{
yield return null;
}
SaveFile.AddFlag(SaveFile.Flags.BearFortTreasureInvFull);
}
else
{
bell.Visible = false;
Audio.PlaySound("snd_item_ch1.wav");
TextSystem.GetText("GoldenBellGet");
while (TextSystem.instance.Visible)
{
yield return null;
}
SaveFile.current.dwArmor.Add(Items.IDs.GoldenBell);
}
SaveFile.AddFlag(SaveFile.Flags.BearFortGotTreasure);
Room.current.DoMusic();
FreeRoom();
}
public void Crunch()
{
if (crusherVisible.IsOnScreen())
{
bite.Play();
}
}
private IEnumerator Lost()
{
Party.StopMoving();
Vector2 p = CameraController.instance.GlobalPosition;
Vector2 pp = crusher.GetParent<Node2D>().GlobalPosition;
Coroutine c = Coroutine.Start(CameraController.Pan(pp, 1.25f, fixedRate: true, 800f));
while (!c.done)
{
yield return null;
}
float a = 0f;
for (float b = 30f; a < b; a += Main.deltaTime)
{
bell.GlobalPosition = points[1].GlobalPosition.Lerp(pp, a / b);
yield return null;
}
bell.Visible = false;
crusher.SpeedScale = 8f;
for (float b = 0f; b < 120f; b += Main.deltaTime)
{
yield return null;
}
Audio.ChangeMusic((Audio.AudioBlock)null, 3f);
crusher.SpeedScale = 1f;
crusher.Play("Sleep");
for (float b = 0f; b < 120f; b += Main.deltaTime)
{
yield return null;
}
c = Coroutine.Start(CameraController.Pan(p, 1.25f, fixedRate: true, 800f));
while (!c.done)
{
yield return null;
}
TextSystem.GetText("TreasureRoomLose");
while (TextSystem.instance.Visible)
{
yield return null;
}
Player.instance.lockMenu = false;
Room.current.DoMusic();
SaveFile.AddFlag(SaveFile.Flags.BearTreasureLost);
CameraController.instance.follow = Player.instance.controlling;
FreeRoom();
}
private void FreeRoom()
{
Main.SetActive(hiddenWall[0], state: false);
Main.SetActive(hiddenWall[1], state: false);
for (int i = 0; i < spikes.Length; i++)
{
spikes[i].overrideState = true;
}
}
public override void _Ready()
{
hiddenWall[5].Visible = true;
}
public override void _Process(double delta)
{
if (started && Main.inEvent == null && !TextSystem.instance.Visible)
{
time -= Main.deltaTime;
bell.GlobalPosition = points[0].GlobalPosition.Lerp(points[1].GlobalPosition, 1f - time / 5000f);
if (time <= 0f)
{
Main.inEvent = Coroutine.Start(Lost());
started = false;
}
}
}
[EditorBrowsable(EditorBrowsableState.Never)]
internal static List<MethodInfo> GetGodotMethodList()
{
return new List<MethodInfo>(9)
{
new MethodInfo(MethodName._EnterTree, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName.StartPuzzle, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName.Shake, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, new List<PropertyInfo>
{
new PropertyInfo(Variant.Type.Float, "time", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false),
new PropertyInfo(Variant.Type.Float, "intensity", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false)
}, null),
new MethodInfo(MethodName.GateCross, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName.PuzzleComplete, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName.Crunch, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
new MethodInfo(MethodName.FreeRoom, new PropertyInfo(Variant.Type.Nil, "", PropertyHint.None, "", PropertyUsageFlags.Default, exported: false), MethodFlags.Normal, null, null),
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._EnterTree && args.Count == 0)
{
_EnterTree();
ret = default(godot_variant);
return true;
}
if (method == MethodName.StartPuzzle && args.Count == 0)
{
StartPuzzle();
ret = default(godot_variant);
return true;
}
if (method == MethodName.Shake && args.Count == 2)
{
Shake(VariantUtils.ConvertTo<float>(in args[0]), VariantUtils.ConvertTo<float>(in args[1]));
ret = default(godot_variant);
return true;
}
if (method == MethodName.GateCross && args.Count == 0)
{
GateCross();
ret = default(godot_variant);
return true;
}
if (method == MethodName.PuzzleComplete && args.Count == 0)
{
PuzzleComplete();
ret = default(godot_variant);
return true;
}
if (method == MethodName.Crunch && args.Count == 0)
{
Crunch();
ret = default(godot_variant);
return true;
}
if (method == MethodName.FreeRoom && args.Count == 0)
{
FreeRoom();
ret = default(godot_variant);
return true;
}
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._EnterTree)
{
return true;
}
if (method == MethodName.StartPuzzle)
{
return true;
}
if (method == MethodName.Shake)
{
return true;
}
if (method == MethodName.GateCross)
{
return true;
}
if (method == MethodName.PuzzleComplete)
{
return true;
}
if (method == MethodName.Crunch)
{
return true;
}
if (method == MethodName.FreeRoom)
{
return true;
}
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.bell)
{
bell = VariantUtils.ConvertTo<Sprite2D>(in value);
return true;
}
if (name == PropertyName.crusher)
{
crusher = VariantUtils.ConvertTo<AnimationPlayer>(in value);
return true;
}
if (name == PropertyName.hiddenWall)
{
hiddenWall = VariantUtils.ConvertToSystemArrayOfGodotObject<Node2D>(in value);
return true;
}
if (name == PropertyName.points)
{
points = VariantUtils.ConvertToSystemArrayOfGodotObject<Node2D>(in value);
return true;
}
if (name == PropertyName.sound)
{
sound = VariantUtils.ConvertTo<AudioStreamPlayer>(in value);
return true;
}
if (name == PropertyName.bite)
{
bite = VariantUtils.ConvertTo<AudioStreamPlayer>(in value);
return true;
}
if (name == PropertyName.spikes)
{
spikes = VariantUtils.ConvertToSystemArrayOfGodotObject<PuzzleGate>(in value);
return true;
}
if (name == PropertyName.crusherVisible)
{
crusherVisible = VariantUtils.ConvertTo<VisibleOnScreenNotifier2D>(in value);
return true;
}
if (name == PropertyName.started)
{
started = VariantUtils.ConvertTo<bool>(in value);
return true;
}
if (name == PropertyName.time)
{
time = 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.bell)
{
value = VariantUtils.CreateFrom(in bell);
return true;
}
if (name == PropertyName.crusher)
{
value = VariantUtils.CreateFrom(in crusher);
return true;
}
if (name == PropertyName.hiddenWall)
{
GodotObject[] array = hiddenWall;
value = VariantUtils.CreateFromSystemArrayOfGodotObject(array);
return true;
}
if (name == PropertyName.points)
{
GodotObject[] array = points;
value = VariantUtils.CreateFromSystemArrayOfGodotObject(array);
return true;
}
if (name == PropertyName.sound)
{
value = VariantUtils.CreateFrom(in sound);
return true;
}
if (name == PropertyName.bite)
{
value = VariantUtils.CreateFrom(in bite);
return true;
}
if (name == PropertyName.spikes)
{
GodotObject[] array = spikes;
value = VariantUtils.CreateFromSystemArrayOfGodotObject(array);
return true;
}
if (name == PropertyName.crusherVisible)
{
value = VariantUtils.CreateFrom(in crusherVisible);
return true;
}
if (name == PropertyName.started)
{
value = VariantUtils.CreateFrom(in started);
return true;
}
if (name == PropertyName.time)
{
value = VariantUtils.CreateFrom(in time);
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.bell, PropertyHint.NodeType, "Sprite2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.crusher, PropertyHint.NodeType, "AnimationPlayer", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Array, PropertyName.hiddenWall, PropertyHint.TypeString, "24/34:Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Array, PropertyName.points, PropertyHint.TypeString, "24/34:Node2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.sound, PropertyHint.NodeType, "AudioStreamPlayer", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.bite, PropertyHint.NodeType, "AudioStreamPlayer", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Array, PropertyName.spikes, PropertyHint.TypeString, "24/34:StaticBody2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Object, PropertyName.crusherVisible, PropertyHint.NodeType, "VisibleOnScreenNotifier2D", PropertyUsageFlags.Default | PropertyUsageFlags.ScriptVariable, exported: true),
new PropertyInfo(Variant.Type.Bool, PropertyName.started, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false),
new PropertyInfo(Variant.Type.Float, PropertyName.time, PropertyHint.None, "", PropertyUsageFlags.ScriptVariable, exported: false)
};
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void SaveGodotObjectData(GodotSerializationInfo info)
{
base.SaveGodotObjectData(info);
info.AddProperty(PropertyName.bell, Variant.From(in bell));
info.AddProperty(PropertyName.crusher, Variant.From(in crusher));
StringName name = PropertyName.hiddenWall;
GodotObject[] array = hiddenWall;
info.AddProperty(name, Variant.CreateFrom(array));
StringName name2 = PropertyName.points;
array = points;
info.AddProperty(name2, Variant.CreateFrom(array));
info.AddProperty(PropertyName.sound, Variant.From(in sound));
info.AddProperty(PropertyName.bite, Variant.From(in bite));
StringName name3 = PropertyName.spikes;
array = spikes;
info.AddProperty(name3, Variant.CreateFrom(array));
info.AddProperty(PropertyName.crusherVisible, Variant.From(in crusherVisible));
info.AddProperty(PropertyName.started, Variant.From(in started));
info.AddProperty(PropertyName.time, Variant.From(in time));
}
[EditorBrowsable(EditorBrowsableState.Never)]
protected override void RestoreGodotObjectData(GodotSerializationInfo info)
{
base.RestoreGodotObjectData(info);
if (info.TryGetProperty(PropertyName.bell, out var value))
{
bell = value.As<Sprite2D>();
}
if (info.TryGetProperty(PropertyName.crusher, out var value2))
{
crusher = value2.As<AnimationPlayer>();
}
if (info.TryGetProperty(PropertyName.hiddenWall, out var value3))
{
hiddenWall = value3.AsGodotObjectArray<Node2D>();
}
if (info.TryGetProperty(PropertyName.points, out var value4))
{
points = value4.AsGodotObjectArray<Node2D>();
}
if (info.TryGetProperty(PropertyName.sound, out var value5))
{
sound = value5.As<AudioStreamPlayer>();
}
if (info.TryGetProperty(PropertyName.bite, out var value6))
{
bite = value6.As<AudioStreamPlayer>();
}
if (info.TryGetProperty(PropertyName.spikes, out var value7))
{
spikes = value7.AsGodotObjectArray<PuzzleGate>();
}
if (info.TryGetProperty(PropertyName.crusherVisible, out var value8))
{
crusherVisible = value8.As<VisibleOnScreenNotifier2D>();
}
if (info.TryGetProperty(PropertyName.started, out var value9))
{
started = value9.As<bool>();
}
if (info.TryGetProperty(PropertyName.time, out var value10))
{
time = value10.As<float>();
}
}
}