mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 09:35:26 +00:00
fix check for "enabled"
This commit is contained in:
parent
8a5afcfb5b
commit
aee4a88391
@ -1,7 +1,5 @@
|
|||||||
using QSB.Events;
|
using QSB.Events;
|
||||||
using QSB.Player;
|
using QSB.Player;
|
||||||
using QSB.WorldSync;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace QSB.QuantumSync.Events
|
namespace QSB.QuantumSync.Events
|
||||||
{
|
{
|
||||||
@ -28,8 +26,7 @@ namespace QSB.QuantumSync.Events
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var objects = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>();
|
var obj = QuantumManager.Instance.GetObject(message.ObjectId);
|
||||||
var obj = objects.ToList()[message.ObjectId];
|
|
||||||
|
|
||||||
// Deciding if to change the object's owner
|
// Deciding if to change the object's owner
|
||||||
// Message
|
// Message
|
||||||
@ -45,15 +42,13 @@ namespace QSB.QuantumSync.Events
|
|||||||
|
|
||||||
public override void OnReceiveLocal(bool server, QuantumAuthorityMessage message)
|
public override void OnReceiveLocal(bool server, QuantumAuthorityMessage message)
|
||||||
{
|
{
|
||||||
var objects = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>();
|
var obj = QuantumManager.Instance.GetObject(message.ObjectId);
|
||||||
var obj = objects.ToList()[message.ObjectId];
|
|
||||||
obj.ControllingPlayer = message.AuthorityOwner;
|
obj.ControllingPlayer = message.AuthorityOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnReceiveRemote(bool server, QuantumAuthorityMessage message)
|
public override void OnReceiveRemote(bool server, QuantumAuthorityMessage message)
|
||||||
{
|
{
|
||||||
var objects = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>();
|
var obj = QuantumManager.Instance.GetObject(message.ObjectId);
|
||||||
var obj = objects.ToList()[message.ObjectId];
|
|
||||||
obj.ControllingPlayer = message.AuthorityOwner;
|
obj.ControllingPlayer = message.AuthorityOwner;
|
||||||
if (obj.ControllingPlayer == 0 && obj.IsEnabled)
|
if (obj.ControllingPlayer == 0 && obj.IsEnabled)
|
||||||
{
|
{
|
||||||
|
@ -45,30 +45,27 @@ namespace QSB.QuantumSync.Patches
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool Socketed_ChangeQuantumState(SocketedQuantumObject __instance)
|
public static bool Socketed_ChangeQuantumState(SocketedQuantumObject __instance)
|
||||||
=> QSBWorldSync.GetWorldObject<QSBSocketedQuantumObject>(QuantumManager.Instance.GetId(__instance)).ControllingPlayer == QSBPlayerManager.LocalPlayerId;
|
=> QSBWorldSync.GetWorldObject<QSBSocketedQuantumObject, SocketedQuantumObject>(__instance).ControllingPlayer == QSBPlayerManager.LocalPlayerId;
|
||||||
|
|
||||||
public static void Socketed_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket)
|
public static void Socketed_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket)
|
||||||
{
|
{
|
||||||
var id = QuantumManager.Instance.GetId(__instance);
|
var objectWorldObject = QSBWorldSync.GetWorldObject<QSBSocketedQuantumObject, SocketedQuantumObject>(__instance);
|
||||||
var worldObject = QSBWorldSync.GetWorldObject<QSBSocketedQuantumObject>(id);
|
var socketWorldObject = QSBWorldSync.GetWorldObject<QSBQuantumSocket, QuantumSocket>(socket);
|
||||||
if (worldObject == null)
|
if (objectWorldObject == null)
|
||||||
{
|
{
|
||||||
DebugLog.ToConsole($"Worldobject is null for id {id}!");
|
DebugLog.ToConsole($"Worldobject is null for {__instance.name}!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId)
|
if (objectWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var objId = QuantumManager.Instance.GetId(__instance);
|
|
||||||
var socketId = QuantumManager.Instance.GetId(socket);
|
|
||||||
//DebugLog.DebugWrite($"{__instance.name} to socket {socketId}");
|
|
||||||
QSBEventManager.FireEvent(
|
QSBEventManager.FireEvent(
|
||||||
EventNames.QSBSocketStateChange,
|
EventNames.QSBSocketStateChange,
|
||||||
objId,
|
objectWorldObject.ObjectId,
|
||||||
socketId,
|
socketWorldObject.ObjectId,
|
||||||
__instance.transform.localRotation);
|
__instance.transform.localRotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +76,8 @@ namespace QSB.QuantumSync.Patches
|
|||||||
ref Transform[] ____shuffledObjects,
|
ref Transform[] ____shuffledObjects,
|
||||||
ref bool __result)
|
ref bool __result)
|
||||||
{
|
{
|
||||||
if (QSBWorldSync.GetWorldObject<QSBQuantumShuffleObject>(QuantumManager.Instance.GetId(__instance)).ControllingPlayer != QSBPlayerManager.LocalPlayerId)
|
var shuffleWorldObject = QSBWorldSync.GetWorldObject<QSBQuantumShuffleObject, QuantumShuffleObject>(__instance);
|
||||||
|
if (shuffleWorldObject.ControllingPlayer != QSBPlayerManager.LocalPlayerId)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -100,7 +98,7 @@ namespace QSB.QuantumSync.Patches
|
|||||||
//DebugLog.DebugWrite($"{__instance.name} shuffled.");
|
//DebugLog.DebugWrite($"{__instance.name} shuffled.");
|
||||||
QSBEventManager.FireEvent(
|
QSBEventManager.FireEvent(
|
||||||
EventNames.QSBQuantumShuffle,
|
EventNames.QSBQuantumShuffle,
|
||||||
QuantumManager.Instance.GetId(__instance),
|
shuffleWorldObject.ObjectId,
|
||||||
____indexList.ToArray());
|
____indexList.ToArray());
|
||||||
__result = true;
|
__result = true;
|
||||||
return false;
|
return false;
|
||||||
@ -108,7 +106,7 @@ namespace QSB.QuantumSync.Patches
|
|||||||
|
|
||||||
public static bool MultiState_ChangeQuantumState(MultiStateQuantumObject __instance)
|
public static bool MultiState_ChangeQuantumState(MultiStateQuantumObject __instance)
|
||||||
{
|
{
|
||||||
var qsbObj = QSBWorldSync.GetWorldObject<QSBMultiStateQuantumObject>(QuantumManager.Instance.GetId(__instance));
|
var qsbObj = QSBWorldSync.GetWorldObject<QSBMultiStateQuantumObject, MultiStateQuantumObject>(__instance);
|
||||||
var isInControl = qsbObj.ControllingPlayer == QSBPlayerManager.LocalPlayerId;
|
var isInControl = qsbObj.ControllingPlayer == QSBPlayerManager.LocalPlayerId;
|
||||||
return isInControl;
|
return isInControl;
|
||||||
}
|
}
|
||||||
@ -129,7 +127,7 @@ namespace QSB.QuantumSync.Patches
|
|||||||
//DebugLog.DebugWrite($"{owner.AttachedObject.name} to quantum state {Array.IndexOf(owner.QuantumStates, __instance)}");
|
//DebugLog.DebugWrite($"{owner.AttachedObject.name} to quantum state {Array.IndexOf(owner.QuantumStates, __instance)}");
|
||||||
QSBEventManager.FireEvent(
|
QSBEventManager.FireEvent(
|
||||||
EventNames.QSBMultiStateChange,
|
EventNames.QSBMultiStateChange,
|
||||||
QuantumManager.Instance.GetId(owner.AttachedObject),
|
owner.ObjectId,
|
||||||
Array.IndexOf(owner.QuantumStates, __instance));
|
Array.IndexOf(owner.QuantumStates, __instance));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +160,8 @@ namespace QSB.QuantumSync.Patches
|
|||||||
|
|
||||||
public static bool Shrine_ChangeQuantumState(QuantumShrine __instance)
|
public static bool Shrine_ChangeQuantumState(QuantumShrine __instance)
|
||||||
{
|
{
|
||||||
var isInControl = QSBWorldSync.GetWorldObject<QSBSocketedQuantumObject>(QuantumManager.Instance.GetId(__instance)).ControllingPlayer == QSBPlayerManager.LocalPlayerId;
|
var shrineWorldObject = QSBWorldSync.GetWorldObject<QSBSocketedQuantumObject, SocketedQuantumObject>(__instance);
|
||||||
|
var isInControl = shrineWorldObject.ControllingPlayer == QSBPlayerManager.LocalPlayerId;
|
||||||
return isInControl;
|
return isInControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,10 +12,10 @@ namespace QSB.QuantumSync.Patches
|
|||||||
{
|
{
|
||||||
public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect;
|
public override QSBPatchTypes Type => QSBPatchTypes.OnServerClientConnect;
|
||||||
|
|
||||||
public override void DoPatches()
|
public override void DoPatches()
|
||||||
=> QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumMoon>("ChangeQuantumState", typeof(ServerQuantumPatches), nameof(Moon_ChangeQuantumState));
|
=> QSBCore.Helper.HarmonyHelper.AddPrefix<QuantumMoon>("ChangeQuantumState", typeof(ServerQuantumPatches), nameof(Moon_ChangeQuantumState));
|
||||||
|
|
||||||
public override void DoUnpatches()
|
public override void DoUnpatches()
|
||||||
=> QSBCore.Helper.HarmonyHelper.Unpatch<QuantumMoon>("ChangeQuantumState");
|
=> QSBCore.Helper.HarmonyHelper.Unpatch<QuantumMoon>("ChangeQuantumState");
|
||||||
|
|
||||||
public static bool Moon_ChangeQuantumState(
|
public static bool Moon_ChangeQuantumState(
|
||||||
|
@ -160,9 +160,15 @@ namespace QSB.QuantumSync
|
|||||||
.Any(x => VisibilityOccluder.CanYouSee(tracker, x.mainCamera.transform.position));
|
.Any(x => VisibilityOccluder.CanYouSee(tracker, x.mainCamera.transform.position));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetId(SocketedQuantumObject obj) => _socketedQuantumObjects.IndexOf(obj);
|
public int GetId(IQSBQuantumObject obj)
|
||||||
public int GetId(MultiStateQuantumObject obj) => _multiStateQuantumObjects.IndexOf(obj);
|
=> QSBWorldSync
|
||||||
public int GetId(QuantumSocket obj) => _quantumSockets.IndexOf(obj);
|
.GetWorldObjects<IQSBQuantumObject>()
|
||||||
public int GetId(QuantumShuffleObject obj) => _quantumShuffleObjects.IndexOf(obj);
|
.ToList()
|
||||||
|
.IndexOf(obj);
|
||||||
|
|
||||||
|
public IQSBQuantumObject GetObject(int id)
|
||||||
|
=> QSBWorldSync
|
||||||
|
.GetWorldObjects<IQSBQuantumObject>()
|
||||||
|
.ToList()[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using QSB.Events;
|
using OWML.Utils;
|
||||||
|
using QSB.Events;
|
||||||
using QSB.Player;
|
using QSB.Player;
|
||||||
using QSB.Utility;
|
using QSB.Utility;
|
||||||
using QSB.WorldSync;
|
using QSB.WorldSync;
|
||||||
@ -31,6 +32,7 @@ namespace QSB.QuantumSync.WorldObjects
|
|||||||
ControllingPlayer = 0u;
|
ControllingPlayer = 0u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
IsEnabled = true;
|
IsEnabled = true;
|
||||||
@ -43,7 +45,7 @@ namespace QSB.QuantumSync.WorldObjects
|
|||||||
// controlled by another player, dont care that we activate it
|
// controlled by another player, dont care that we activate it
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var id = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ToList().IndexOf(this);
|
var id = QuantumManager.Instance.GetId(this);
|
||||||
// no one is controlling this object right now, request authority
|
// no one is controlling this object right now, request authority
|
||||||
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, QSBPlayerManager.LocalPlayerId);
|
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, QSBPlayerManager.LocalPlayerId);
|
||||||
}
|
}
|
||||||
@ -60,7 +62,7 @@ namespace QSB.QuantumSync.WorldObjects
|
|||||||
// not being controlled by us, don't care if we leave area
|
// not being controlled by us, don't care if we leave area
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var id = QSBWorldSync.GetWorldObjects<IQSBQuantumObject>().ToList().IndexOf(this);
|
var id = QuantumManager.Instance.GetId(this);
|
||||||
// send event to other players that we're releasing authority
|
// send event to other players that we're releasing authority
|
||||||
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, 0u);
|
QSBEventManager.FireEvent(EventNames.QSBQuantumAuthority, id, 0u);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using OWML.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace QSB.Utility
|
namespace QSB.Utility
|
||||||
@ -18,6 +20,12 @@ namespace QSB.Utility
|
|||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
=> QSBSceneManager.OnSceneLoaded -= (OWScene scene, bool inUniverse) => Destroy(this);
|
=> QSBSceneManager.OnSceneLoaded -= (OWScene scene, bool inUniverse) => Destroy(this);
|
||||||
|
|
||||||
|
private bool GetAnyVisibilityTrackersActive()
|
||||||
|
{
|
||||||
|
var visibilityTrackers = AttachedComponent.GetValue<VisibilityTracker[]>("_visibilityTrackers");
|
||||||
|
return visibilityTrackers.All(x => x.GetValue<Shape[]>("_shapes").All(y => y.enabled));
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (AttachedComponent == null)
|
if (AttachedComponent == null)
|
||||||
@ -25,7 +33,7 @@ namespace QSB.Utility
|
|||||||
DebugLog.ToConsole($"Attached component is null!", OWML.Common.MessageType.Error);
|
DebugLog.ToConsole($"Attached component is null!", OWML.Common.MessageType.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var state = AttachedComponent.isActiveAndEnabled ? ComponentState.Enabled : ComponentState.Disabled;
|
var state = AttachedComponent.isActiveAndEnabled && GetAnyVisibilityTrackersActive() ? ComponentState.Enabled : ComponentState.Disabled;
|
||||||
if (_wasEnabled != state)
|
if (_wasEnabled != state)
|
||||||
{
|
{
|
||||||
_wasEnabled = state;
|
_wasEnabled = state;
|
||||||
|
@ -27,6 +27,15 @@ namespace QSB.WorldSync
|
|||||||
where TWorldObject : IWorldObject
|
where TWorldObject : IWorldObject
|
||||||
=> GetWorldObjects<TWorldObject>().FirstOrDefault(x => x.ObjectId == id);
|
=> GetWorldObjects<TWorldObject>().FirstOrDefault(x => x.ObjectId == id);
|
||||||
|
|
||||||
|
public static TWorldObject GetWorldObject<TWorldObject, TUnityObject>(TUnityObject unityObject)
|
||||||
|
where TWorldObject : WorldObject<TUnityObject>
|
||||||
|
where TUnityObject : MonoBehaviour
|
||||||
|
{
|
||||||
|
var allWorldObjects = GetWorldObjects<TWorldObject>();
|
||||||
|
var correctWorldObject = allWorldObjects.First(x => x.AttachedObject == unityObject);
|
||||||
|
return correctWorldObject;
|
||||||
|
}
|
||||||
|
|
||||||
public static void RemoveWorldObjects<TWorldObject>()
|
public static void RemoveWorldObjects<TWorldObject>()
|
||||||
{
|
{
|
||||||
var itemsToRemove = WorldObjects.Where(x => x is TWorldObject);
|
var itemsToRemove = WorldObjects.Where(x => x is TWorldObject);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user