2021-12-23 17:07:29 -08:00
|
|
|
|
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;
|
2021-12-23 16:26:31 -08:00
|
|
|
|
using QSB.ConversationSync.Messages;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.Events;
|
2021-12-24 21:28:41 -08:00
|
|
|
|
using QSB.LogSync.Messages;
|
2020-12-14 16:28:03 +00:00
|
|
|
|
using QSB.Messaging;
|
2021-12-23 02:17:56 -08:00
|
|
|
|
using QSB.MeteorSync.Messages;
|
2021-11-25 15:32:34 +00:00
|
|
|
|
using QSB.MeteorSync.WorldObjects;
|
2021-12-23 02:17:56 -08:00
|
|
|
|
using QSB.OrbSync.Messages;
|
2021-12-14 20:24:02 -08:00
|
|
|
|
using QSB.OrbSync.WorldObjects;
|
2021-12-23 16:26:31 -08:00
|
|
|
|
using QSB.QuantumSync.Messages;
|
2021-12-13 22:49:18 -08:00
|
|
|
|
using QSB.QuantumSync.WorldObjects;
|
2021-12-24 21:39:32 -08:00
|
|
|
|
using QSB.Tools.TranslatorTool.TranslationSync.Messages;
|
2021-11-25 15:25:17 +00:00
|
|
|
|
using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects;
|
2021-12-24 16:47:10 -08:00
|
|
|
|
using QSB.TornadoSync.Messages;
|
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;
|
2021-12-23 17:07:29 -08:00
|
|
|
|
using System.Linq;
|
2021-12-19 15:50:54 -08:00
|
|
|
|
using UnityEngine;
|
2020-08-10 14:40:06 +01:00
|
|
|
|
|
2021-12-23 13:49:47 -08:00
|
|
|
|
namespace QSB.Player.Messages
|
2020-08-10 14:40:06 +01:00
|
|
|
|
{
|
2021-12-24 21:42:14 -08:00
|
|
|
|
// Can be sent by any client (including host) to signal they want latest worldobject, player, and server information
|
2021-12-22 18:20:53 -08:00
|
|
|
|
public class RequestStateResyncMessage : QSBMessage
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-12-22 18:20:53 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// set to true when we send this, and false when we receive a player info message back. <br/>
|
|
|
|
|
/// this prevents message spam a bit.
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal static bool _waitingForEvent;
|
2020-08-15 20:32:58 +01:00
|
|
|
|
|
2021-12-22 18:20:53 -08:00
|
|
|
|
public void Send()
|
2021-12-11 11:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
if (_waitingForEvent)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_waitingForEvent = true;
|
2021-12-22 18:20:53 -08:00
|
|
|
|
QSBMessageManager.Send(this);
|
2021-12-11 11:47:21 +00:00
|
|
|
|
}
|
2020-08-15 21:52:43 +02:00
|
|
|
|
|
2021-12-22 18:20:53 -08:00
|
|
|
|
public override void OnReceiveLocal()
|
2021-12-11 11:47:21 +00:00
|
|
|
|
{
|
|
|
|
|
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-12-22 18:20:53 -08:00
|
|
|
|
public override void OnReceiveRemote()
|
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-22 18:20:53 -08:00
|
|
|
|
QSBEventManager.ForIdOverride = From;
|
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
|
2021-12-22 18:20:53 -08:00
|
|
|
|
if (QSBCore.IsHost)
|
2021-12-06 01:43:06 -08:00
|
|
|
|
{
|
2021-12-22 18:37:24 -08:00
|
|
|
|
ServerStateManager.Instance.SendChangeServerStateMessage(ServerStateManager.Instance.GetServerState());
|
2021-12-22 17:38:08 -08:00
|
|
|
|
new PlayerInformationMessage().Send();
|
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-22 17:38:08 -08:00
|
|
|
|
new PlayerInformationMessage().Send();
|
2021-12-06 00:49:56 -08:00
|
|
|
|
}
|
2021-12-13 22:16:32 -08:00
|
|
|
|
|
2021-12-15 01:20:51 -08:00
|
|
|
|
if (WorldObjectManager.AllObjectsReady)
|
2021-12-13 22:16:32 -08:00
|
|
|
|
{
|
2021-12-15 01:20:51 -08:00
|
|
|
|
SendAuthorityObjectInfo();
|
2021-12-13 22:16:32 -08:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 18:20:53 -08:00
|
|
|
|
private static void SendWorldObjectInfo()
|
2021-08-08 20:04:15 +01:00
|
|
|
|
{
|
2021-07-07 23:04:00 +01:00
|
|
|
|
QSBWorldSync.DialogueConditions.ForEach(condition
|
2021-12-23 16:20:17 -08:00
|
|
|
|
=> new DialogueConditionMessage(condition.Key, condition.Value).Send());
|
2020-12-31 12:10:55 +00:00
|
|
|
|
|
2021-07-07 23:04:00 +01:00
|
|
|
|
QSBWorldSync.ShipLogFacts.ForEach(fact
|
2021-12-24 21:28:41 -08:00
|
|
|
|
=> new RevealFactMessage(fact.Id, fact.SaveGame, false).Send());
|
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-12-24 21:39:32 -08:00
|
|
|
|
=> wallText.SendMessage(new WallTextTranslatedMessage(id)));
|
2021-07-07 09:05:39 +01:00
|
|
|
|
}
|
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-12-24 21:39:32 -08:00
|
|
|
|
=> computer.SendMessage(new ComputerTranslatedMessage(id)));
|
2021-07-07 09:05:39 +01:00
|
|
|
|
}
|
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-12-24 21:39:32 -08:00
|
|
|
|
=> vesselComputer.SendMessage(new VesselComputerTranslatedMessage(id)));
|
2021-07-07 09:05:39 +01:00
|
|
|
|
}
|
2021-02-08 20:04:14 +00:00
|
|
|
|
|
2021-12-19 15:50:54 -08:00
|
|
|
|
QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ForEach(x =>
|
|
|
|
|
{
|
2021-12-22 18:31:58 -08:00
|
|
|
|
x.SendMessage(new QuantumAuthorityMessage(x.ControllingPlayer));
|
2021-12-19 15:50:54 -08:00
|
|
|
|
|
|
|
|
|
if (x is QSBQuantumMoon qsbQuantumMoon)
|
|
|
|
|
{
|
|
|
|
|
int stateIndex;
|
|
|
|
|
Vector3 onUnitSphere;
|
|
|
|
|
int orbitAngle;
|
|
|
|
|
|
|
|
|
|
var moon = qsbQuantumMoon.AttachedObject;
|
|
|
|
|
var moonBody = moon._moonBody;
|
|
|
|
|
stateIndex = moon.GetStateIndex();
|
|
|
|
|
var orbit = moon._orbits.First(y => y.GetStateIndex() == stateIndex);
|
|
|
|
|
var orbitBody = orbit.GetAttachedOWRigidbody();
|
|
|
|
|
var relPos = moonBody.GetWorldCenterOfMass() - orbitBody.GetWorldCenterOfMass();
|
|
|
|
|
var relVel = moonBody.GetVelocity() - orbitBody.GetVelocity();
|
|
|
|
|
onUnitSphere = relPos.normalized;
|
|
|
|
|
var perpendicular = Vector3.Cross(relPos, Vector3.up).normalized;
|
|
|
|
|
orbitAngle = (int)OWMath.WrapAngle(OWMath.Angle(perpendicular, relVel, relPos));
|
|
|
|
|
|
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBMoonStateChange, stateIndex, onUnitSphere, orbitAngle);
|
|
|
|
|
}
|
|
|
|
|
});
|
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
|
2021-12-23 01:24:57 -08:00
|
|
|
|
=> fragment.SendMessage(new FragmentResyncMessage(fragment)));
|
2021-12-05 20:09:54 -08:00
|
|
|
|
|
2021-12-06 03:09:23 -08:00
|
|
|
|
QSBWorldSync.GetWorldObjects<QSBTornado>().ForEach(tornado
|
2021-12-24 16:47:10 -08:00
|
|
|
|
=> tornado.SendMessage(new TornadoFormStateMessage(tornado.FormState)));
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2021-12-15 01:20:51 -08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// send info for objects we have authority over
|
|
|
|
|
/// </summary>
|
2021-12-22 18:20:53 -08:00
|
|
|
|
private static void SendAuthorityObjectInfo()
|
2021-12-15 01:20:51 -08:00
|
|
|
|
{
|
|
|
|
|
foreach (var qsbOrb in QSBWorldSync.GetWorldObjects<QSBOrb>())
|
|
|
|
|
{
|
2021-12-15 02:25:13 -08:00
|
|
|
|
if (!qsbOrb.TransformSync.enabled ||
|
2021-12-17 16:53:23 -08:00
|
|
|
|
!qsbOrb.TransformSync.HasAuthority)
|
2021-12-15 01:20:51 -08:00
|
|
|
|
{
|
2021-12-15 02:25:13 -08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-23 01:50:09 -08:00
|
|
|
|
qsbOrb.SendMessage(new OrbDragMessage(qsbOrb.AttachedObject._isBeingDragged));
|
|
|
|
|
qsbOrb.SendMessage(new OrbSlotMessage(qsbOrb.AttachedObject._slots.IndexOf(qsbOrb.AttachedObject._occupiedSlot)));
|
2021-12-15 01:20:51 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2021-12-22 22:59:08 -08:00
|
|
|
|
}
|