59 lines
1.5 KiB
C#
Raw Normal View History

using Mirror;
using QSB.Messaging;
2021-12-30 11:41:59 +00:00
using QSB.WorldSync;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace QSB.EyeOfTheUniverse.ForestOfGalaxies.Messages
{
internal class KillGalaxiesMessage : QSBMessage
{
2021-12-30 15:40:06 -08:00
private List<float> _deathDelays;
2021-12-30 11:41:59 +00:00
public KillGalaxiesMessage(List<float> deathDelays) => _deathDelays = deathDelays;
public override void Serialize(NetworkWriter writer)
2021-12-30 11:41:59 +00:00
{
base.Serialize(writer);
writer.Write(_deathDelays.Count);
foreach (var item in _deathDelays)
{
writer.Write(item);
}
}
public override void Deserialize(NetworkReader reader)
2021-12-30 11:41:59 +00:00
{
base.Deserialize(reader);
var length = reader.Read<int>();
2021-12-30 15:40:06 -08:00
_deathDelays = new List<float>(length);
2021-12-30 11:41:59 +00:00
for (var i = 0; i < length; i++)
{
_deathDelays.Add(reader.Read<float>());
2021-12-30 11:41:59 +00:00
}
}
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
2021-12-30 18:28:24 -08:00
2021-12-30 11:41:59 +00:00
public override void OnReceiveRemote()
{
var galaxyController = QSBWorldSync.GetUnityObjects<MiniGalaxyController>().First();
galaxyController._killTrigger.OnEntry -= galaxyController.OnEnterKillTrigger;
2021-12-30 18:28:24 -08:00
galaxyController._galaxies = galaxyController.GetComponentsInChildren<MiniGalaxy>(true);
2021-12-30 11:41:59 +00:00
for (var i = 0; i < galaxyController._galaxies.Length; i++)
{
galaxyController._galaxies[i].DieAfterSeconds(_deathDelays[i], true, AudioType.EyeGalaxyBlowAway);
}
2022-01-01 22:19:10 +00:00
2021-12-30 11:41:59 +00:00
galaxyController._forestIsDarkTime = Time.time + 65f;
galaxyController.enabled = true;
galaxyController._musicSource.SetLocalVolume(0f);
2021-12-30 18:28:24 -08:00
galaxyController._musicSource.FadeIn(5f);
2021-12-30 11:41:59 +00:00
}
}
}