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