2021-12-05 20:09:54 -08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using OWML.Utils;
|
2021-08-09 11:49:58 +01:00
|
|
|
|
using QSB.CampfireSync.WorldObjects;
|
2021-08-08 20:04:15 +01:00
|
|
|
|
using QSB.ClientServerStateSync;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.Events;
|
2020-12-14 16:28:03 +00:00
|
|
|
|
using QSB.Messaging;
|
2021-11-25 15:32:34 +00:00
|
|
|
|
using QSB.MeteorSync.WorldObjects;
|
2021-12-13 22:16:32 -08:00
|
|
|
|
using QSB.OrbSync;
|
|
|
|
|
using QSB.OrbSync.TransformSync;
|
2021-02-08 20:04:14 +00:00
|
|
|
|
using QSB.QuantumSync;
|
2021-11-25 15:25:17 +00:00
|
|
|
|
using QSB.Tools.TranslatorTool.TranslationSync;
|
|
|
|
|
using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects;
|
2021-12-05 21:30:04 -08:00
|
|
|
|
using QSB.TornadoSync;
|
2021-12-06 03:09:23 -08:00
|
|
|
|
using QSB.TornadoSync.WorldObjects;
|
2020-08-22 20:21:13 +01:00
|
|
|
|
using QSB.Utility;
|
2020-12-11 22:42:21 +00:00
|
|
|
|
using QSB.WorldSync;
|
2020-08-10 14:40:06 +01:00
|
|
|
|
|
2020-11-03 21:33:48 +00:00
|
|
|
|
namespace QSB.Player.Events
|
2020-08-10 14:40:06 +01:00
|
|
|
|
{
|
2021-08-08 20:04:15 +01:00
|
|
|
|
// Can be sent by any client (including host) to signal they want latest worldobject, player, and server infomation
|
|
|
|
|
public class RequestStateResyncEvent : QSBEvent<PlayerMessage>
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-12-11 11:47:21 +00:00
|
|
|
|
public static bool _waitingForEvent;
|
|
|
|
|
|
2021-12-05 11:03:09 +00:00
|
|
|
|
public override bool RequireWorldObjectsReady => false;
|
2021-12-04 16:39:37 +00:00
|
|
|
|
|
2021-08-08 20:04:15 +01:00
|
|
|
|
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBRequestStateResync, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBRequestStateResync, Handler);
|
2020-08-15 20:32:58 +01:00
|
|
|
|
|
2021-12-11 11:47:21 +00:00
|
|
|
|
private void Handler()
|
|
|
|
|
{
|
|
|
|
|
if (_waitingForEvent)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_waitingForEvent = true;
|
|
|
|
|
SendEvent(CreateMessage());
|
|
|
|
|
}
|
2020-08-15 21:52:43 +02:00
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private PlayerMessage CreateMessage() => new()
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-08-08 20:04:15 +01:00
|
|
|
|
AboutId = LocalPlayerId
|
2020-12-02 21:23:01 +00:00
|
|
|
|
};
|
2020-08-10 18:17:54 +02:00
|
|
|
|
|
2021-12-11 11:47:21 +00:00
|
|
|
|
public override void OnReceiveLocal(bool isHost, PlayerMessage message)
|
|
|
|
|
{
|
|
|
|
|
QSBCore.UnityEvents.FireInNUpdates(() =>
|
|
|
|
|
{
|
|
|
|
|
if (_waitingForEvent)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Did not receive PlayerInformationEvent in time. Setting _waitingForEvent to false.", OWML.Common.MessageType.Info);
|
|
|
|
|
_waitingForEvent = false;
|
|
|
|
|
}
|
|
|
|
|
}, 60);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-08 20:04:15 +01:00
|
|
|
|
public override void OnReceiveRemote(bool isHost, PlayerMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-12-06 01:00:56 -08:00
|
|
|
|
// send response only to the requesting client
|
2021-12-06 01:57:56 -08:00
|
|
|
|
QSBEventManager.ForIdOverride = message.FromId;
|
2021-12-06 01:43:06 -08:00
|
|
|
|
try
|
2020-12-19 10:56:25 +00:00
|
|
|
|
{
|
2021-12-06 01:43:06 -08:00
|
|
|
|
// if host, send worldobject and server states
|
|
|
|
|
if (isHost)
|
|
|
|
|
{
|
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBServerState, ServerStateManager.Instance.GetServerState());
|
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);
|
2021-08-08 20:04:15 +01:00
|
|
|
|
|
2021-12-06 01:43:06 -08:00
|
|
|
|
if (WorldObjectManager.AllObjectsReady)
|
|
|
|
|
{
|
|
|
|
|
SendWorldObjectInfo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// if client, send player and client states
|
|
|
|
|
else
|
2021-12-06 00:49:56 -08:00
|
|
|
|
{
|
2021-12-06 01:43:06 -08:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBPlayerInformation);
|
2021-12-06 00:49:56 -08:00
|
|
|
|
}
|
2021-12-13 22:16:32 -08:00
|
|
|
|
|
|
|
|
|
// SPECIAL CASE: whoever owns the orbs sends their drag state
|
|
|
|
|
foreach (var sync in NomaiOrbTransformSync.Instances)
|
|
|
|
|
{
|
|
|
|
|
if (sync && sync.HasAuthority && sync.Orb)
|
|
|
|
|
{
|
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBOrbUser, OrbManager.Orbs.IndexOf(sync.Orb), sync.Orb._isBeingDragged);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-19 10:56:25 +00:00
|
|
|
|
}
|
2021-12-06 01:43:06 -08:00
|
|
|
|
finally
|
2021-12-06 00:02:51 -08:00
|
|
|
|
{
|
2021-12-06 01:57:56 -08:00
|
|
|
|
QSBEventManager.ForIdOverride = uint.MaxValue;
|
2020-12-19 10:56:25 +00:00
|
|
|
|
}
|
2021-08-08 20:04:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SendWorldObjectInfo()
|
|
|
|
|
{
|
2021-07-07 23:04:00 +01:00
|
|
|
|
QSBWorldSync.DialogueConditions.ForEach(condition
|
2021-12-03 19:39:01 -08:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.DialogueConditionChanged, condition.Key, condition.Value));
|
2020-12-31 12:10:55 +00:00
|
|
|
|
|
2021-07-07 23:04:00 +01:00
|
|
|
|
QSBWorldSync.ShipLogFacts.ForEach(fact
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBRevealFact, fact.Id, fact.SaveGame, false));
|
2021-07-07 09:02:23 +01:00
|
|
|
|
|
2020-12-31 12:10:55 +00:00
|
|
|
|
foreach (var wallText in QSBWorldSync.GetWorldObjects<QSBWallText>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
|
2021-07-07 09:05:39 +01:00
|
|
|
|
{
|
2021-07-07 23:04:00 +01:00
|
|
|
|
wallText.GetTranslatedIds().ForEach(id
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.WallText, wallText.ObjectId, id));
|
|
|
|
|
}
|
2020-12-31 12:10:55 +00:00
|
|
|
|
|
|
|
|
|
foreach (var computer in QSBWorldSync.GetWorldObjects<QSBComputer>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
|
2021-07-07 09:05:39 +01:00
|
|
|
|
{
|
2021-07-07 23:04:00 +01:00
|
|
|
|
computer.GetTranslatedIds().ForEach(id
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.Computer, computer.ObjectId, id));
|
|
|
|
|
}
|
2020-12-31 12:10:55 +00:00
|
|
|
|
|
|
|
|
|
foreach (var vesselComputer in QSBWorldSync.GetWorldObjects<QSBVesselComputer>().Where(x => x.AttachedObject.GetValue<bool>("_initialized") && x.AttachedObject.GetNumTextBlocks() > 0))
|
2021-07-07 09:05:39 +01:00
|
|
|
|
{
|
2021-07-07 23:04:00 +01:00
|
|
|
|
vesselComputer.GetTranslatedIds().ForEach(id
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBTextTranslated, NomaiTextType.VesselComputer, vesselComputer.ObjectId, id));
|
|
|
|
|
}
|
2021-02-08 20:04:14 +00:00
|
|
|
|
|
2021-12-11 21:36:41 -08:00
|
|
|
|
QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ForEach(x
|
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, x.ObjectId, x.ControllingPlayer));
|
2021-03-29 23:41:12 +01:00
|
|
|
|
|
2021-07-07 23:04:00 +01:00
|
|
|
|
QSBWorldSync.GetWorldObjects<QSBCampfire>().ForEach(campfire
|
2021-07-07 09:05:39 +01:00
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBCampfireState, campfire.ObjectId, campfire.GetState()));
|
2021-11-10 21:13:49 -08:00
|
|
|
|
|
2021-11-13 20:41:46 -08:00
|
|
|
|
QSBWorldSync.GetWorldObjects<QSBFragment>().ForEach(fragment
|
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBFragmentResync, fragment));
|
2021-12-05 20:09:54 -08:00
|
|
|
|
|
2021-12-06 03:09:23 -08:00
|
|
|
|
QSBWorldSync.GetWorldObjects<QSBTornado>().ForEach(tornado
|
|
|
|
|
=> QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, tornado));
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-08 20:04:15 +01:00
|
|
|
|
}
|