2020-09-29 21:34:46 +01:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.OrbSync;
|
2020-09-06 09:07:31 +01:00
|
|
|
|
using QSB.TransformSync;
|
2020-09-29 21:34:46 +01:00
|
|
|
|
using QSB.Utility;
|
2020-09-06 09:07:31 +01:00
|
|
|
|
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
|
|
|
|
|
{
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static class WorldRegistry
|
|
|
|
|
{
|
|
|
|
|
private static readonly List<WorldObject> WorldObjects = new List<WorldObject>();
|
|
|
|
|
public static List<NomaiOrbTransformSync> OrbSyncList = new List<NomaiOrbTransformSync>();
|
|
|
|
|
public static List<NomaiInterfaceOrb> OldOrbList = new List<NomaiInterfaceOrb>();
|
|
|
|
|
public static List<CharacterDialogueTree> OldDialogueTrees = new List<CharacterDialogueTree>();
|
2020-09-22 21:11:29 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static void AddObject(WorldObject worldObject)
|
|
|
|
|
{
|
|
|
|
|
if (WorldObjects.Contains(worldObject))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
WorldObjects.Add(worldObject);
|
|
|
|
|
}
|
2020-08-16 17:15:36 +02:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static IEnumerable<T> GetObjects<T>()
|
|
|
|
|
{
|
|
|
|
|
return WorldObjects.OfType<T>();
|
|
|
|
|
}
|
2020-08-13 19:25:12 +02:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static T GetObject<T>(int id) where T : WorldObject
|
|
|
|
|
{
|
|
|
|
|
return GetObjects<T>().FirstOrDefault(x => x.ObjectId == id);
|
|
|
|
|
}
|
2020-09-06 09:07:31 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static void RemoveObjects<T>() where T : WorldObject
|
|
|
|
|
{
|
|
|
|
|
WorldObjects.RemoveAll(x => x.GetType() == typeof(T));
|
|
|
|
|
}
|
2020-09-17 20:14:55 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static void HandleSlotStateChange(NomaiInterfaceSlot slot, NomaiInterfaceOrb affectingOrb, bool state)
|
|
|
|
|
{
|
|
|
|
|
QSBOrbSlot qsbSlot = null;
|
|
|
|
|
NomaiOrbTransformSync orbSync = null;
|
|
|
|
|
var slotList = GetObjects<QSBOrbSlot>();
|
|
|
|
|
if (slotList.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
qsbSlot = slotList.First(x => x.InterfaceSlot == slot);
|
|
|
|
|
orbSync = OrbSyncList.First(x => x.AttachedOrb == affectingOrb);
|
|
|
|
|
if (orbSync.HasAuthority)
|
|
|
|
|
{
|
2020-12-07 18:49:51 +00:00
|
|
|
|
qsbSlot.HandleEvent(state, OldOrbList.IndexOf(affectingOrb));
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite("Error - Exception when handling slot state change."
|
|
|
|
|
+ Environment.NewLine + $"Slot name {slot.name} to {state}"
|
|
|
|
|
+ Environment.NewLine + $"SlotList count : {slotList?.Count()}"
|
|
|
|
|
+ Environment.NewLine + $"QSBOrbSlot null? : {qsbSlot == null}"
|
|
|
|
|
+ Environment.NewLine + $"NomaiOrbTransformSync null? : {orbSync == null}", MessageType.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-09-06 09:07:31 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
public static void RaiseEvent(object instance, string eventName)
|
|
|
|
|
{
|
|
|
|
|
if (!(instance.GetType()
|
|
|
|
|
.GetField(eventName, BindingFlags.Instance | BindingFlags.NonPublic)?
|
|
|
|
|
.GetValue(instance) is MulticastDelegate multiDelegate))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var delegateList = multiDelegate.GetInvocationList().ToList();
|
2020-12-06 17:00:23 +00:00
|
|
|
|
foreach (var del in delegateList)
|
|
|
|
|
{
|
|
|
|
|
del.DynamicInvoke(instance);
|
|
|
|
|
}
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|