298 lines
6.9 KiB
C#
298 lines
6.9 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 partial class SchoolTreasureRoom : Node
|
|
{
|
|
[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;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|