using OWML.Common; using QSB.OrbSync; using QSB.TransformSync; using QSB.Utility; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; namespace QSB.WorldSync { public static class QSBWorldSync { private static readonly List WorldObjects = new List(); public static List OrbSyncList = new List(); public static List OldOrbList = new List(); public static List OldDialogueTrees = new List(); public static Dictionary DialogueConditions { get; } = new Dictionary(); public static void AddWorldObject(WorldObject worldObject) { if (WorldObjects.Contains(worldObject)) { return; } WorldObjects.Add(worldObject); } public static IEnumerable GetWorldObjects() { return WorldObjects.OfType(); } public static T GetWorldObject(int id) where T : WorldObject { return GetWorldObjects().FirstOrDefault(x => x.ObjectId == id); } public static void RemoveWorldObjects() where T : WorldObject { WorldObjects.RemoveAll(x => x.GetType() == typeof(T)); } public static void HandleSlotStateChange(NomaiInterfaceSlot slot, NomaiInterfaceOrb affectingOrb, bool state) { var slotList = GetWorldObjects(); if (slotList.Count() == 0) { return; } var qsbSlot = slotList.First(x => x.InterfaceSlot == slot); var orbSync = OrbSyncList.First(x => x.AttachedOrb == affectingOrb); if (orbSync.HasAuthority) { qsbSlot.HandleEvent(state, OldOrbList.IndexOf(affectingOrb)); } } 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(); foreach (var del in delegateList) { del.DynamicInvoke(instance); } } public static void SetDialogueCondition(string name, bool state) { if (!QSB.IsServer) { DebugLog.DebugWrite("Warning - Cannot write to condition dict when not server!", MessageType.Warning); return; } DialogueConditions[name] = state; } } }