quantum-space-buddies/QSB/Player/Events/PlayerStatesRequestEvent.cs

86 lines
2.9 KiB
C#
Raw Normal View History

using OWML.Utils;
using QSB.Events;
2020-12-14 16:28:03 +00:00
using QSB.Messaging;
2021-02-08 20:04:14 +00:00
using QSB.QuantumSync;
using QSB.TranslationSync;
using QSB.TranslationSync.WorldObjects;
2020-08-22 19:21:13 +00:00
using QSB.Utility;
2020-12-11 22:42:21 +00:00
using QSB.WorldSync;
2020-08-15 13:22:56 +00:00
using System.Linq;
2020-08-10 13:40:06 +00:00
2020-11-03 21:33:48 +00:00
namespace QSB.Player.Events
2020-08-10 13:40:06 +00:00
{
2020-12-02 21:23:01 +00:00
public class PlayerStatesRequestEvent : QSBEvent<PlayerMessage>
{
public override EventType Type => EventType.PlayerStatesRequest;
2020-08-10 13:40:06 +00:00
2020-12-02 21:23:01 +00:00
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
2020-08-15 19:32:58 +00:00
2020-12-02 21:23:01 +00:00
private void Handler() => SendEvent(CreateMessage());
2020-08-15 19:52:43 +00:00
2020-12-02 21:23:01 +00:00
private PlayerMessage CreateMessage() => new PlayerMessage
{
2020-12-14 16:12:44 +00:00
AboutId = LocalPlayerId,
OnlySendToServer = true
2020-12-02 21:23:01 +00:00
};
2020-08-10 16:17:54 +00:00
2020-12-11 22:42:21 +00:00
public override void OnReceiveRemote(bool server, PlayerMessage message)
2020-12-02 21:23:01 +00:00
{
2020-12-19 10:56:25 +00:00
DebugLog.DebugWrite($"Get state request from {message.FromId} - isServer?{server}");
2021-02-10 19:59:28 +00:00
QSBEventManager.FireEvent(EventNames.QSBServerSendPlayerStates);
2020-12-02 21:23:01 +00:00
foreach (var item in QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
.Where(x => x != null && x.IsReady && x.ReferenceSector != null))
{
2021-02-10 19:34:41 +00:00
QSBEventManager.FireEvent(EventNames.QSBSectorChange, item.NetId.Value, item.ReferenceSector);
2020-12-02 21:23:01 +00:00
}
2020-12-11 22:42:21 +00:00
2020-12-19 10:56:25 +00:00
if (!server)
{
return;
}
2021-02-08 20:04:14 +00:00
// TODO : CLEAN. THIS. SHIT.
2020-12-11 22:42:21 +00:00
foreach (var condition in QSBWorldSync.DialogueConditions)
{
2021-02-10 19:34:41 +00:00
QSBEventManager.FireEvent(EventNames.DialogueCondition, condition.Key, condition.Value);
2020-12-11 22:42:21 +00:00
}
2020-12-19 10:56:25 +00:00
foreach (var fact in QSBWorldSync.ShipLogFacts)
{
2021-02-10 19:34:41 +00:00
QSBEventManager.FireEvent(EventNames.QSBRevealFact, fact.Id, fact.SaveGame, false);
2020-12-19 10:56:25 +00:00
}
foreach (var wallText in QSBWorldSync.GetWorldObjects<QSBWallText>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
{
foreach (var id in wallText.GetTranslatedIds())
{
2021-02-10 19:34:41 +00:00
QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.WallText, wallText.ObjectId, id);
}
}
foreach (var computer in QSBWorldSync.GetWorldObjects<QSBComputer>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
{
foreach (var id in computer.GetTranslatedIds())
{
2021-02-10 19:34:41 +00:00
QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.Computer, computer.ObjectId, id);
}
}
foreach (var vesselComputer in QSBWorldSync.GetWorldObjects<QSBVesselComputer>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
{
foreach (var id in vesselComputer.GetTranslatedIds())
{
2021-02-10 19:34:41 +00:00
QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id);
}
}
2021-02-08 20:04:14 +00:00
var list = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ToList();
for (var i = 0; i < list.Count; i++)
{
2021-02-10 19:34:41 +00:00
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, i, list[i].ControllingPlayer);
2021-02-08 20:04:14 +00:00
}
2020-12-02 21:23:01 +00:00
}
}
2020-12-03 08:28:05 +00:00
}