2020-09-06 08:07:31 +00:00
|
|
|
|
using QSB.OrbSync;
|
|
|
|
|
using QSB.TransformSync;
|
|
|
|
|
using System;
|
2020-09-04 19:57:35 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-08-13 17:25:12 +00:00
|
|
|
|
using System.Linq;
|
2020-09-06 08:07:31 +00:00
|
|
|
|
using System.Reflection;
|
2020-08-13 17:25:12 +00:00
|
|
|
|
|
|
|
|
|
namespace QSB.WorldSync
|
|
|
|
|
{
|
|
|
|
|
public static class WorldRegistry
|
|
|
|
|
{
|
2020-09-07 18:27:56 +00:00
|
|
|
|
private static readonly List<WorldObject> WorldObjects = new List<WorldObject>();
|
2020-09-06 08:07:31 +00:00
|
|
|
|
public static List<NomaiOrbTransformSync> OrbSyncList = new List<NomaiOrbTransformSync>();
|
2020-09-04 19:54:34 +00:00
|
|
|
|
public static List<NomaiInterfaceOrb> OldOrbList = new List<NomaiInterfaceOrb>();
|
2020-08-16 15:15:36 +00:00
|
|
|
|
|
|
|
|
|
public static void AddObject(WorldObject worldObject)
|
|
|
|
|
{
|
2020-09-07 18:27:56 +00:00
|
|
|
|
if (WorldObjects.Contains(worldObject))
|
2020-08-23 19:52:22 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-07 18:27:56 +00:00
|
|
|
|
WorldObjects.Add(worldObject);
|
2020-08-16 15:15:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-16 20:39:21 +00:00
|
|
|
|
public static IEnumerable<T> GetObjects<T>()
|
2020-08-16 15:15:36 +00:00
|
|
|
|
{
|
2020-09-07 18:27:56 +00:00
|
|
|
|
return WorldObjects.OfType<T>();
|
2020-08-16 15:15:36 +00:00
|
|
|
|
}
|
2020-08-13 17:25:12 +00:00
|
|
|
|
|
2020-08-13 18:43:47 +00:00
|
|
|
|
public static T GetObject<T>(int id) where T : WorldObject
|
2020-08-13 17:25:12 +00:00
|
|
|
|
{
|
2020-08-16 15:15:36 +00:00
|
|
|
|
return GetObjects<T>().FirstOrDefault(x => x.ObjectId == id);
|
2020-08-13 17:25:12 +00:00
|
|
|
|
}
|
2020-09-06 08:07:31 +00:00
|
|
|
|
|
2020-09-17 19:14:55 +00:00
|
|
|
|
public static void RemoveObjects<T>() where T : WorldObject
|
|
|
|
|
{
|
|
|
|
|
WorldObjects.RemoveAll(x => x.GetType() == typeof(T));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-06 08:07:31 +00:00
|
|
|
|
public static void HandleSlotStateChange(NomaiInterfaceSlot slot, NomaiInterfaceOrb affectingOrb, bool state)
|
|
|
|
|
{
|
|
|
|
|
var qsbSlot = GetObjects<QSBOrbSlot>().First(x => x.InterfaceSlot == slot);
|
|
|
|
|
var orbSync = OrbSyncList.First(x => x.AttachedOrb == affectingOrb);
|
|
|
|
|
if (orbSync.hasAuthority)
|
|
|
|
|
{
|
|
|
|
|
qsbSlot.HandleEvent(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void RaiseEvent(object instance, string eventName)
|
|
|
|
|
{
|
2020-09-07 18:27:56 +00:00
|
|
|
|
if (!(instance.GetType()
|
|
|
|
|
.GetField(eventName, BindingFlags.Instance | BindingFlags.NonPublic)?
|
|
|
|
|
.GetValue(instance) is MulticastDelegate multiDelegate))
|
2020-09-06 08:07:31 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-07 18:27:56 +00:00
|
|
|
|
var delegateList = multiDelegate.GetInvocationList().ToList();
|
2020-09-06 08:07:31 +00:00
|
|
|
|
delegateList.ForEach(x => x.DynamicInvoke(instance));
|
|
|
|
|
}
|
2020-08-13 17:25:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|