mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-04-15 20:42:33 +00:00
cleanup + fixes
This commit is contained in:
parent
d3334e3a77
commit
7b65d7a54a
@ -16,6 +16,7 @@
|
||||
public static string UnequipTranslator = "UnequipTranslator";
|
||||
public static string ExitShip = "ExitShip";
|
||||
public static string RestartTimeLoop = "RestartTimeLoop";
|
||||
public static string WakeUp = "WakeUp";
|
||||
|
||||
public static string QSBPlayerDeath = "QSBPlayerDeath";
|
||||
public static string QSBPlayerJoin = "QSBPlayerJoin";
|
||||
|
@ -1,6 +1,6 @@
|
||||
using QSB.Events;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
@ -13,5 +13,42 @@ namespace QSB.OrbSync
|
||||
GlobalMessenger<int>.FireEvent(EventNames.QSBOrbUser, WorldRegistry.OldOrbList.FindIndex(x => x == __instance));
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CheckOrbCollision(ref bool __result, NomaiInterfaceSlot __instance, NomaiInterfaceOrb orb, bool ____ignoreDraggedOrbs, float ____radius, float ____exitRadius, ref NomaiInterfaceOrb ____occupyingOrb)
|
||||
{
|
||||
if (____ignoreDraggedOrbs && orb.IsBeingDragged())
|
||||
{
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
var orbDistance = Vector3.Distance(orb.transform.position, __instance.transform.position);
|
||||
var triggerRadius = (!orb.IsBeingDragged()) ? ____radius : ____exitRadius;
|
||||
if (____occupyingOrb == null && orbDistance < ____radius)
|
||||
{
|
||||
____occupyingOrb = orb;
|
||||
if (Time.timeSinceLevelLoad > 1f)
|
||||
{
|
||||
WorldRegistry.HandleSlotStateChange(__instance, orb, true);
|
||||
WorldRegistry.RaiseEvent(__instance, "OnSlotActivated");
|
||||
}
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
if (!(____occupyingOrb != null) || !(____occupyingOrb == orb))
|
||||
{
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
if (orbDistance > triggerRadius)
|
||||
{
|
||||
WorldRegistry.HandleSlotStateChange(__instance, orb, false);
|
||||
____occupyingOrb = null;
|
||||
WorldRegistry.RaiseEvent(__instance, "OnSlotDeactivated");
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,11 @@ namespace QSB.OrbSync
|
||||
}
|
||||
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
{
|
||||
QSB.Helper.Events.Unity.RunWhen(() => QSB.HasWokenUp, InitSlots);
|
||||
}
|
||||
|
||||
private void InitSlots()
|
||||
{
|
||||
var orbSlots = Resources.FindObjectsOfTypeAll<NomaiInterfaceSlot>();
|
||||
for (var id = 0; id < orbSlots.Length; id++)
|
||||
|
@ -1,7 +1,6 @@
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
using QSB.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System.Linq;
|
||||
using UnityEngine.Networking;
|
||||
@ -28,12 +27,22 @@ namespace QSB.OrbSync
|
||||
{
|
||||
var fromPlayer = NetworkServer.connections
|
||||
.First(x => x.playerControllers[0].gameObject.GetComponent<PlayerTransformSync>().netId.Value == message.FromId);
|
||||
DebugLog.DebugWrite($"[S] Setting orb {message.ObjectId} to auth id {message.FromId}");
|
||||
var orb = WorldRegistry.OrbList
|
||||
var orb = WorldRegistry.OrbSyncList
|
||||
.First(x => x.AttachedOrb == WorldRegistry.OldOrbList[message.ObjectId]);
|
||||
var orbIdentity = orb.GetComponent<NetworkIdentity>();
|
||||
orbIdentity.RemoveClientAuthority(orbIdentity.clientAuthorityOwner);
|
||||
if (orbIdentity.clientAuthorityOwner != null)
|
||||
{
|
||||
orbIdentity.RemoveClientAuthority(orbIdentity.clientAuthorityOwner);
|
||||
}
|
||||
orbIdentity.AssignClientAuthority(fromPlayer);
|
||||
orb.enabled = true;
|
||||
}
|
||||
|
||||
public override void OnReceiveRemote(WorldObjectMessage message)
|
||||
{
|
||||
var orb = WorldRegistry.OrbSyncList
|
||||
.First(x => x.AttachedOrb == WorldRegistry.OldOrbList[message.ObjectId]);
|
||||
orb.enabled = true;
|
||||
}
|
||||
|
||||
public override void OnReceiveLocal(WorldObjectMessage message)
|
||||
|
@ -1,43 +1,40 @@
|
||||
using QSB.Events;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace QSB.OrbSync
|
||||
{
|
||||
public class QSBOrbSlot : WorldObject
|
||||
{
|
||||
private NomaiInterfaceSlot _interfaceSlot;
|
||||
public NomaiInterfaceSlot InterfaceSlot { get; private set; }
|
||||
private bool _initialized;
|
||||
|
||||
public void Init(NomaiInterfaceSlot slot, int id)
|
||||
{
|
||||
ObjectId = id;
|
||||
_interfaceSlot = slot;
|
||||
_interfaceSlot.OnSlotActivated += (slotInstance) => HandleEvent(true);
|
||||
_interfaceSlot.OnSlotDeactivated += (slotInstance) => HandleEvent(false);
|
||||
InterfaceSlot = slot;
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
private void HandleEvent(bool state) => GlobalMessenger<int, bool>.FireEvent(EventNames.QSBOrbSlot, ObjectId, state);
|
||||
public void HandleEvent(bool state)
|
||||
{
|
||||
if (QSB.HasWokenUp)
|
||||
{
|
||||
GlobalMessenger<int, bool>.FireEvent(EventNames.QSBOrbSlot, ObjectId, state);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(bool state)
|
||||
{
|
||||
if (state)
|
||||
if (!_initialized)
|
||||
{
|
||||
RaiseEvent(_interfaceSlot, "OnSlotActivated");
|
||||
return;
|
||||
}
|
||||
RaiseEvent(_interfaceSlot, "OnSlotDeactivated");
|
||||
}
|
||||
|
||||
private static void RaiseEvent(object instance, string eventName)
|
||||
{
|
||||
var type = instance.GetType();
|
||||
var staticFlags = BindingFlags.Instance | BindingFlags.NonPublic;
|
||||
var fieldInfo = type.GetField(eventName, staticFlags);
|
||||
var multDelegate = fieldInfo.GetValue(instance) as MulticastDelegate;
|
||||
var delegateList = multDelegate.GetInvocationList().ToList();
|
||||
delegateList.ForEach(x => x.DynamicInvoke(instance));
|
||||
if (state)
|
||||
{
|
||||
WorldRegistry.RaiseEvent(InterfaceSlot, "OnSlotActivated");
|
||||
return;
|
||||
}
|
||||
WorldRegistry.RaiseEvent(InterfaceSlot, "OnSlotDeactivated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ namespace QSB
|
||||
public static int Port { get; private set; }
|
||||
public static bool DebugMode { get; private set; }
|
||||
public static AssetBundle NetworkAssetBundle { get; private set; }
|
||||
public static bool HasWokenUp { get; set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
using OWML.Common;
|
||||
using OWML.ModHelper.Events;
|
||||
using QSB.Animation;
|
||||
using QSB.DeathSync;
|
||||
using QSB.Events;
|
||||
@ -18,6 +19,7 @@ namespace QSB
|
||||
public class QSBNetworkManager : NetworkManager
|
||||
{
|
||||
private const int MaxConnections = 128;
|
||||
private const int MaxBufferedPackets = 64;
|
||||
|
||||
public static QSBNetworkManager Instance { get; private set; }
|
||||
|
||||
@ -85,6 +87,7 @@ namespace QSB
|
||||
customConfig = true;
|
||||
connectionConfig.AddChannel(QosType.Reliable);
|
||||
connectionConfig.AddChannel(QosType.Unreliable);
|
||||
((NetworkManager)this).SetValue("m_MaxBufferedPackets", MaxBufferedPackets);
|
||||
channels.Add(QosType.Reliable);
|
||||
channels.Add(QosType.Unreliable);
|
||||
}
|
||||
@ -118,6 +121,7 @@ namespace QSB
|
||||
}
|
||||
|
||||
QSB.Helper.HarmonyHelper.AddPostfix<NomaiInterfaceOrb>("StartDragFromPosition", typeof(OrbPatches), nameof(OrbPatches.StartDragCallEvent));
|
||||
QSB.Helper.HarmonyHelper.AddPrefix<NomaiInterfaceSlot>("CheckOrbCollision", typeof(OrbPatches), nameof(OrbPatches.CheckOrbCollision));
|
||||
|
||||
_lobby.CanEditName = false;
|
||||
|
||||
|
@ -49,6 +49,15 @@ namespace QSB.TimeSync
|
||||
}
|
||||
|
||||
GlobalMessenger.AddListener(EventNames.RestartTimeLoop, OnLoopStart);
|
||||
GlobalMessenger.AddListener(EventNames.WakeUp, OnWakeUp);
|
||||
}
|
||||
|
||||
private void OnWakeUp()
|
||||
{
|
||||
if (NetworkServer.active)
|
||||
{
|
||||
QSB.HasWokenUp = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@ -59,6 +68,7 @@ namespace QSB.TimeSync
|
||||
|
||||
private void OnSceneLoaded(OWScene scene, bool isInUniverse)
|
||||
{
|
||||
QSB.HasWokenUp = false;
|
||||
if (isInUniverse)
|
||||
{
|
||||
Init();
|
||||
@ -165,6 +175,7 @@ namespace QSB.TimeSync
|
||||
EnableInput();
|
||||
}
|
||||
_isFirstFastForward = false;
|
||||
QSB.HasWokenUp = true;
|
||||
Physics.SyncTransforms();
|
||||
SpinnerUI.Hide();
|
||||
DebugLog.DebugWrite("ResetTimeScale - Request state!");
|
||||
|
@ -7,16 +7,17 @@ namespace QSB.TransformSync
|
||||
public class NomaiOrbTransformSync : NetworkBehaviour
|
||||
{
|
||||
public NomaiInterfaceOrb AttachedOrb { get; private set; }
|
||||
private int Index => WorldRegistry.OrbList.FindIndex(x => x == this);
|
||||
private int Index => WorldRegistry.OrbSyncList.FindIndex(x => x == this);
|
||||
|
||||
public Transform OrbTransform { get; private set; }
|
||||
private bool _isInitialized;
|
||||
private bool _isReady;
|
||||
private Transform OrbParent;
|
||||
private int _updateCount;
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
WorldRegistry.OrbList.Add(this);
|
||||
WorldRegistry.OrbSyncList.Add(this);
|
||||
|
||||
QSB.Helper.Events.Unity.RunWhen(() => WorldRegistry.OldOrbList.Count != 0, OnReady);
|
||||
}
|
||||
@ -71,6 +72,15 @@ namespace QSB.TransformSync
|
||||
}
|
||||
OrbTransform.position = OrbParent.TransformPoint(transform.position);
|
||||
OrbTransform.rotation = OrbParent.InverseTransformRotation(OrbTransform.rotation);
|
||||
if (transform.localPosition == Vector3.zero)
|
||||
{
|
||||
_updateCount++;
|
||||
}
|
||||
if (_updateCount >= 5)
|
||||
{
|
||||
enabled = false;
|
||||
_updateCount = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,4 @@
|
||||
using OWML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace QSB.Utility
|
||||
{
|
||||
|
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace QSB.Utility
|
||||
namespace QSB.Utility
|
||||
{
|
||||
// Stolen from here : https://stackoverflow.com/questions/3261451/using-a-bitmask-in-c-sharp
|
||||
|
||||
|
@ -1,13 +1,16 @@
|
||||
using QSB.TransformSync;
|
||||
using QSB.OrbSync;
|
||||
using QSB.TransformSync;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace QSB.WorldSync
|
||||
{
|
||||
public static class WorldRegistry
|
||||
{
|
||||
private static readonly List<WorldObject> _worldObjects = new List<WorldObject>();
|
||||
public static List<NomaiOrbTransformSync> OrbList = new List<NomaiOrbTransformSync>();
|
||||
public static List<NomaiOrbTransformSync> OrbSyncList = new List<NomaiOrbTransformSync>();
|
||||
public static List<NomaiInterfaceOrb> OldOrbList = new List<NomaiInterfaceOrb>();
|
||||
|
||||
public static void AddObject(WorldObject worldObject)
|
||||
@ -28,5 +31,29 @@ namespace QSB.WorldSync
|
||||
{
|
||||
return GetObjects<T>().FirstOrDefault(x => x.ObjectId == id);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
var type = instance.GetType();
|
||||
var staticFlags = BindingFlags.Instance | BindingFlags.NonPublic;
|
||||
var fieldInfo = type.GetField(eventName, staticFlags);
|
||||
var multDelegate = fieldInfo.GetValue(instance) as MulticastDelegate;
|
||||
if (multDelegate == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var delegateList = multDelegate.GetInvocationList().ToList();
|
||||
delegateList.ForEach(x => x.DynamicInvoke(instance));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user