2021-12-01 21:34:02 -08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.AuthoritySync;
|
2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2021-04-28 10:02:16 +01:00
|
|
|
|
using QSB.OrbSync.TransformSync;
|
2020-09-29 21:34:46 +01:00
|
|
|
|
using QSB.Utility;
|
2020-09-04 20:54:34 +01:00
|
|
|
|
using QSB.WorldSync;
|
2020-11-03 22:18:22 +00:00
|
|
|
|
using QSB.WorldSync.Events;
|
2020-09-04 20:54:34 +01:00
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.OrbSync.Events
|
2020-09-04 20:54:34 +01:00
|
|
|
|
{
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public class OrbUserEvent : QSBEvent<WorldObjectMessage>
|
|
|
|
|
{
|
|
|
|
|
public override void SetupListener() => GlobalMessenger<int>.AddListener(EventNames.QSBOrbUser, Handler);
|
|
|
|
|
public override void CloseListener() => GlobalMessenger<int>.RemoveListener(EventNames.QSBOrbUser, Handler);
|
2020-09-04 20:54:34 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
private void Handler(int id) => SendEvent(CreateMessage(id));
|
2020-09-04 20:54:34 +01:00
|
|
|
|
|
2021-11-20 19:49:50 +00:00
|
|
|
|
private WorldObjectMessage CreateMessage(int id) => new()
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
ObjectId = id
|
|
|
|
|
};
|
2020-09-04 20:54:34 +01:00
|
|
|
|
|
2020-12-19 13:31:05 +00:00
|
|
|
|
public override void OnReceiveLocal(bool server, WorldObjectMessage message)
|
|
|
|
|
{
|
|
|
|
|
if (server)
|
|
|
|
|
{
|
|
|
|
|
HandleServer(message);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HandleClient(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
public override void OnReceiveRemote(bool server, WorldObjectMessage message)
|
2020-12-14 21:20:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (server)
|
|
|
|
|
{
|
|
|
|
|
HandleServer(message);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HandleClient(message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 21:41:56 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
private static void HandleServer(WorldObjectMessage message)
|
|
|
|
|
{
|
2021-04-28 16:32:01 +01:00
|
|
|
|
if (NomaiOrbTransformSync.OrbTransformSyncs == null || NomaiOrbTransformSync.OrbTransformSyncs.Count == 0)
|
2020-12-14 21:20:53 +00:00
|
|
|
|
{
|
2021-04-28 13:37:51 +01:00
|
|
|
|
DebugLog.ToConsole($"Error - OrbTransformSyncs is empty or null. (ID {message.ObjectId})", MessageType.Error);
|
2021-03-23 13:18:29 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-03-23 13:18:29 +00:00
|
|
|
|
if (QSBWorldSync.OldOrbList == null || QSBWorldSync.OldOrbList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Error - OldOrbList is empty or null. (ID {message.ObjectId})", MessageType.Error);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-10-26 14:08:23 +01:00
|
|
|
|
var orbSync = NomaiOrbTransformSync.OrbTransformSyncs.Where(x => x != null)
|
2021-07-08 14:14:56 +01:00
|
|
|
|
.FirstOrDefault(x => x.AttachedObject == QSBWorldSync.OldOrbList[message.ObjectId].transform);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
if (orbSync == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Error - No orb found for user event. (ID {message.ObjectId})", MessageType.Error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-12-01 21:34:02 -08:00
|
|
|
|
orbSync.NetIdentity.SetAuthority(message.FromId);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
orbSync.enabled = true;
|
|
|
|
|
}
|
2020-12-11 22:42:21 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
private static void HandleClient(WorldObjectMessage message)
|
|
|
|
|
{
|
2021-04-28 16:32:01 +01:00
|
|
|
|
if (NomaiOrbTransformSync.OrbTransformSyncs == null || NomaiOrbTransformSync.OrbTransformSyncs.Count == 0)
|
2021-03-23 13:18:29 +00:00
|
|
|
|
{
|
2021-04-28 13:37:51 +01:00
|
|
|
|
DebugLog.ToConsole($"Error - OrbTransformSyncs is empty or null. (ID {message.ObjectId})", MessageType.Error);
|
2021-03-23 13:18:29 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-03-23 13:18:29 +00:00
|
|
|
|
if (QSBWorldSync.OldOrbList == null || QSBWorldSync.OldOrbList.Count == 0)
|
2020-12-14 21:20:53 +00:00
|
|
|
|
{
|
2021-03-23 13:18:29 +00:00
|
|
|
|
DebugLog.ToConsole($"Error - OldOrbList is empty or null. (ID {message.ObjectId})", MessageType.Error);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-10-26 14:08:23 +01:00
|
|
|
|
if (!NomaiOrbTransformSync.OrbTransformSyncs.Where(x => x != null).Any(x => x.AttachedObject == QSBWorldSync.OldOrbList[message.ObjectId].transform))
|
2020-12-19 18:49:46 +00:00
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Error - No NomaiOrbTransformSync has AttachedOrb with objectId {message.ObjectId}!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2021-10-26 14:08:23 +01:00
|
|
|
|
var orb = NomaiOrbTransformSync.OrbTransformSyncs.Where(x => x != null)
|
2021-07-09 12:08:43 +01:00
|
|
|
|
.First(x => x.AttachedObject == QSBWorldSync.OldOrbList[message.ObjectId].transform);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
orb.enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-01 21:34:02 -08:00
|
|
|
|
}
|