mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-30 03:32:47 +00:00
Fix syncing state, current user of probe launcher
This commit is contained in:
parent
3f636494c4
commit
399073c675
@ -3,9 +3,9 @@ using QSB.StationaryProbeLauncherSync.WorldObjects;
|
|||||||
|
|
||||||
namespace QSB.StationaryProbeLauncherSync.Messages;
|
namespace QSB.StationaryProbeLauncherSync.Messages;
|
||||||
|
|
||||||
public class StationaryProbeLauncherMessage : QSBWorldObjectMessage<QSBStationaryProbeLauncher, bool>
|
public class StationaryProbeLauncherMessage : QSBWorldObjectMessage<QSBStationaryProbeLauncher, (bool, uint)>
|
||||||
{
|
{
|
||||||
public StationaryProbeLauncherMessage(bool inUse) : base(inUse) { }
|
public StationaryProbeLauncherMessage(bool inUse, uint userID) : base((inUse, userID)) { }
|
||||||
|
|
||||||
public override void OnReceiveRemote() => WorldObject.OnRemoteUseStateChanged(Data, From);
|
public override void OnReceiveRemote() => WorldObject.OnRemoteUseStateChanged(Data.Item1, Data.Item2);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using QSB.Messaging;
|
using QSB.Messaging;
|
||||||
using QSB.Patches;
|
using QSB.Patches;
|
||||||
|
using QSB.Player;
|
||||||
using QSB.StationaryProbeLauncherSync.Messages;
|
using QSB.StationaryProbeLauncherSync.Messages;
|
||||||
using QSB.StationaryProbeLauncherSync.WorldObjects;
|
using QSB.StationaryProbeLauncherSync.WorldObjects;
|
||||||
using QSB.WorldSync;
|
using QSB.WorldSync;
|
||||||
@ -14,9 +15,6 @@ public class StationaryProbeLauncherPatches : QSBPatch
|
|||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(StationaryProbeLauncher), nameof(StationaryProbeLauncher.FinishExitSequence))]
|
[HarmonyPatch(typeof(StationaryProbeLauncher), nameof(StationaryProbeLauncher.FinishExitSequence))]
|
||||||
public static void StationaryProbeLauncher_FinishExitSequence(StationaryProbeLauncher __instance)
|
public static void StationaryProbeLauncher_FinishExitSequence(StationaryProbeLauncher __instance) =>
|
||||||
{
|
__instance.GetWorldObject<QSBStationaryProbeLauncher>().OnLocalUseStateChanged(false);
|
||||||
var qsbStationaryProbe = __instance.GetWorldObject<QSBStationaryProbeLauncher>();
|
|
||||||
qsbStationaryProbe.SendMessage(new StationaryProbeLauncherMessage(false));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ namespace QSB.StationaryProbeLauncherSync.WorldObjects;
|
|||||||
|
|
||||||
public class QSBStationaryProbeLauncher : QSBProbeLauncher, ILinkedWorldObject<StationaryProbeLauncherVariableSync>
|
public class QSBStationaryProbeLauncher : QSBProbeLauncher, ILinkedWorldObject<StationaryProbeLauncherVariableSync>
|
||||||
{
|
{
|
||||||
|
private uint _currentUser = uint.MaxValue;
|
||||||
|
|
||||||
public StationaryProbeLauncherVariableSync NetworkBehaviour { get; private set; }
|
public StationaryProbeLauncherVariableSync NetworkBehaviour { get; private set; }
|
||||||
public void SetNetworkBehaviour(NetworkBehaviour networkBehaviour) => NetworkBehaviour = (StationaryProbeLauncherVariableSync)networkBehaviour;
|
public void SetNetworkBehaviour(NetworkBehaviour networkBehaviour) => NetworkBehaviour = (StationaryProbeLauncherVariableSync)networkBehaviour;
|
||||||
|
|
||||||
@ -21,8 +23,8 @@ public class QSBStationaryProbeLauncher : QSBProbeLauncher, ILinkedWorldObject<S
|
|||||||
|
|
||||||
public override async UniTask Init(CancellationToken ct)
|
public override async UniTask Init(CancellationToken ct)
|
||||||
{
|
{
|
||||||
// This is implemented by inheriting LinkedWorldObject normally, however I want to inherit from QSBProbeLauncher
|
// This is implemented by inheriting LinkedWorldObject normally,
|
||||||
// Else we'd have to redo the sync for the effects
|
// However I want to inherit from QSBProbeLauncher or else we'd have to redo the sync for the VFX/SFX
|
||||||
if (QSBCore.IsHost)
|
if (QSBCore.IsHost)
|
||||||
{
|
{
|
||||||
this.SpawnLinked(QSBNetworkManager.singleton.StationaryProbeLauncherPrefab, false);
|
this.SpawnLinked(QSBNetworkManager.singleton.StationaryProbeLauncherPrefab, false);
|
||||||
@ -52,39 +54,43 @@ public class QSBStationaryProbeLauncher : QSBProbeLauncher, ILinkedWorldObject<S
|
|||||||
_stationaryProbeLauncher._interactVolume.OnPressInteract -= OnPressInteract;
|
_stationaryProbeLauncher._interactVolume.OnPressInteract -= OnPressInteract;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPressInteract()
|
private void OnPressInteract() => OnLocalUseStateChanged(true);
|
||||||
{
|
|
||||||
// Whoever is using it needs authority to be able to rotate it
|
|
||||||
// If this is a client they'll get authority from the host when the message is received otherwise give now
|
|
||||||
if (QSBCore.IsHost)
|
|
||||||
{
|
|
||||||
NetworkBehaviour.netIdentity.SetAuthority(QSBPlayerManager.LocalPlayerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
_isInUse = true;
|
|
||||||
this.SendMessage(new StationaryProbeLauncherMessage(_isInUse));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SendInitialState(uint to)
|
public override void SendInitialState(uint to)
|
||||||
{
|
{
|
||||||
base.SendInitialState(to);
|
base.SendInitialState(to);
|
||||||
|
|
||||||
// even tho from is always host here, it's okay because it won't set authority
|
this.SendMessage(new StationaryProbeLauncherMessage(_isInUse, _currentUser) { To = to });
|
||||||
// (since OnRemoteUseStateChanged is only called from OnReceiveRemote)
|
|
||||||
this.SendMessage(new StationaryProbeLauncherMessage(_isInUse) { To = to });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnRemoteUseStateChanged(bool isInUse, uint user)
|
public void OnRemoteUseStateChanged(bool isInUse, uint user)
|
||||||
{
|
{
|
||||||
|
_isInUse = isInUse;
|
||||||
|
|
||||||
|
_currentUser = isInUse ? user : uint.MaxValue;
|
||||||
|
|
||||||
// Whoever is using it needs authority to be able to rotate it
|
// Whoever is using it needs authority to be able to rotate it
|
||||||
if (QSBCore.IsHost)
|
if (QSBCore.IsHost)
|
||||||
{
|
{
|
||||||
NetworkBehaviour.netIdentity.SetAuthority(isInUse ? user : uint.MaxValue);
|
NetworkBehaviour.netIdentity.SetAuthority(_currentUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateUse();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnLocalUseStateChanged(bool isInUse)
|
||||||
|
{
|
||||||
_isInUse = isInUse;
|
_isInUse = isInUse;
|
||||||
|
|
||||||
UpdateUse();
|
_currentUser = isInUse ? QSBPlayerManager.LocalPlayerId : uint.MaxValue;
|
||||||
|
|
||||||
|
// Whoever is using it needs authority to be able to rotate it
|
||||||
|
if (QSBCore.IsHost)
|
||||||
|
{
|
||||||
|
NetworkBehaviour.netIdentity.SetAuthority(_currentUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.SendMessage(new StationaryProbeLauncherMessage(isInUse, _currentUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateUse()
|
private void UpdateUse()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user