mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-14 06:40:41 +00:00
Raft: get authority on sensor light-up
This commit is contained in:
parent
3dce355bd5
commit
0428ee9f13
@ -82,8 +82,15 @@ public static class AuthorityManager
|
|||||||
|
|
||||||
#region any client
|
#region any client
|
||||||
|
|
||||||
public static void UpdateAuthQueue(this NetworkIdentity identity, AuthQueueAction action) =>
|
public static void UpdateAuthQueue(this NetworkIdentity identity, AuthQueueAction action)
|
||||||
|
{
|
||||||
|
if (action == AuthQueueAction.Force && identity.hasAuthority)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
new AuthQueueMessage(identity.netId, action).Send();
|
new AuthQueueMessage(identity.netId, action).Send();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
@ -1,7 +1,9 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||||
using QSB.Patches;
|
using QSB.Patches;
|
||||||
using QSB.Player;
|
using QSB.Player;
|
||||||
using QSB.Tools.FlashlightTool;
|
using QSB.Tools.FlashlightTool;
|
||||||
|
using QSB.WorldSync;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -16,6 +18,14 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
[HarmonyPatch(typeof(SingleLightSensor), nameof(SingleLightSensor.UpdateIllumination))]
|
[HarmonyPatch(typeof(SingleLightSensor), nameof(SingleLightSensor.UpdateIllumination))]
|
||||||
public static bool UpdateIlluminationReplacement(SingleLightSensor __instance)
|
public static bool UpdateIlluminationReplacement(SingleLightSensor __instance)
|
||||||
{
|
{
|
||||||
|
if (!QSBWorldSync.AllObjectsReady)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var qsbSingleLightSensor = __instance.GetWorldObject<QSBSingleLightSensor>();
|
||||||
|
qsbSingleLightSensor.IlluminatedByLocalPlayer = false;
|
||||||
|
|
||||||
__instance._illuminated = false;
|
__instance._illuminated = false;
|
||||||
if (__instance._illuminatingDreamLanternList != null)
|
if (__instance._illuminatingDreamLanternList != null)
|
||||||
{
|
{
|
||||||
@ -68,11 +78,13 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
&& !__instance.CheckOcclusion(position, vector, sensorWorldDir))
|
&& !__instance.CheckOcclusion(position, vector, sensorWorldDir))
|
||||||
{
|
{
|
||||||
__instance._illuminated = true;
|
__instance._illuminated = true;
|
||||||
|
|
||||||
|
qsbSingleLightSensor.IlluminatedByLocalPlayer = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var player = QSBPlayerManager.PlayerList.First(x => x.FlashLight == (QSBFlashlight)source /*bug ??? always invalid cast*/);
|
var player = QSBPlayerManager.PlayerList.First(x => x.FlashLight == source as QSBFlashlight);
|
||||||
|
|
||||||
var position = player.Camera.transform.position;
|
var position = player.Camera.transform.position;
|
||||||
var to = __instance.transform.position - position;
|
var to = __instance.transform.position - position;
|
||||||
@ -95,6 +107,7 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
&& !__instance.CheckOcclusion(probe.GetLightSourcePosition(), vector, sensorWorldDir))
|
&& !__instance.CheckOcclusion(probe.GetLightSourcePosition(), vector, sensorWorldDir))
|
||||||
{
|
{
|
||||||
__instance._illuminated = true;
|
__instance._illuminated = true;
|
||||||
|
qsbSingleLightSensor.IlluminatedByLocalPlayer = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -114,6 +127,8 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
{
|
{
|
||||||
__instance._illuminatingDreamLanternList.Add(dreamLanternController);
|
__instance._illuminatingDreamLanternList.Add(dreamLanternController);
|
||||||
__instance._illuminated = true;
|
__instance._illuminated = true;
|
||||||
|
|
||||||
|
qsbSingleLightSensor.IlluminatedByLocalPlayer = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -127,6 +142,8 @@ internal class LightSensorPatches : QSBPatch
|
|||||||
if (light.CheckIlluminationAtPoint(vector, __instance._sensorRadius, maxDistance) && !__instance.CheckOcclusion(light.transform.position, vector, sensorWorldDir, occludableLight))
|
if (light.CheckIlluminationAtPoint(vector, __instance._sensorRadius, maxDistance) && !__instance.CheckOcclusion(light.transform.position, vector, sensorWorldDir, occludableLight))
|
||||||
{
|
{
|
||||||
__instance._illuminated = true;
|
__instance._illuminated = true;
|
||||||
|
|
||||||
|
qsbSingleLightSensor.IlluminatedByLocalPlayer = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,4 +6,6 @@ namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
|||||||
internal class QSBSingleLightSensor : WorldObject<SingleLightSensor>
|
internal class QSBSingleLightSensor : WorldObject<SingleLightSensor>
|
||||||
{
|
{
|
||||||
public override void SendInitialState(uint to) { }
|
public override void SendInitialState(uint to) { }
|
||||||
|
|
||||||
|
public bool IlluminatedByLocalPlayer;
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
using Mirror;
|
using QSB.AuthoritySync;
|
||||||
using QSB.AuthoritySync;
|
|
||||||
using QSB.EchoesOfTheEye.RaftSync.WorldObjects;
|
using QSB.EchoesOfTheEye.RaftSync.WorldObjects;
|
||||||
using QSB.Syncs.Unsectored.Rigidbodies;
|
using QSB.Syncs.Unsectored.Rigidbodies;
|
||||||
using QSB.Utility;
|
using QSB.Utility;
|
||||||
@ -63,14 +62,8 @@ public class RaftTransformSync : UnsectoredRigidbodySync
|
|||||||
private void OnUnsuspend(OWRigidbody suspendedBody) => netIdentity.UpdateAuthQueue(AuthQueueAction.Add);
|
private void OnUnsuspend(OWRigidbody suspendedBody) => netIdentity.UpdateAuthQueue(AuthQueueAction.Add);
|
||||||
private void OnSuspend(OWRigidbody suspendedBody) => netIdentity.UpdateAuthQueue(AuthQueueAction.Remove);
|
private void OnSuspend(OWRigidbody suspendedBody) => netIdentity.UpdateAuthQueue(AuthQueueAction.Remove);
|
||||||
|
|
||||||
public override void OnStartAuthority() => DebugLog.DebugWrite($"{this} - start authority");
|
public override void OnStartAuthority() => DebugLog.DebugWrite($"{this} - authority = true");
|
||||||
public override void OnStopAuthority() => DebugLog.DebugWrite($"{this} - stop authority");
|
public override void OnStopAuthority() => DebugLog.DebugWrite($"{this} - authority = false");
|
||||||
|
|
||||||
protected override void Deserialize(NetworkReader reader)
|
|
||||||
{
|
|
||||||
DebugLog.DebugWrite($"{this} - deserialize");
|
|
||||||
base.Deserialize(reader);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// replacement for base method
|
/// replacement for base method
|
||||||
@ -78,8 +71,8 @@ public class RaftTransformSync : UnsectoredRigidbodySync
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void ApplyToAttached()
|
protected override void ApplyToAttached()
|
||||||
{
|
{
|
||||||
var targetPos = ReferenceTransform.FromRelPos(UseInterpolation ? SmoothPosition : transform.position);
|
var targetPos = ReferenceTransform.FromRelPos(transform.position);
|
||||||
var targetRot = ReferenceTransform.FromRelRot(UseInterpolation ? SmoothRotation : transform.rotation);
|
var targetRot = ReferenceTransform.FromRelRot(transform.rotation);
|
||||||
|
|
||||||
AttachedRigidbody.SetPosition(targetPos);
|
AttachedRigidbody.SetPosition(targetPos);
|
||||||
AttachedRigidbody.SetRotation(targetRot);
|
AttachedRigidbody.SetRotation(targetRot);
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
using Mirror;
|
using Mirror;
|
||||||
|
using QSB.AuthoritySync;
|
||||||
|
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||||
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
|
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
|
||||||
using QSB.WorldSync;
|
using QSB.WorldSync;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
@ -21,6 +24,11 @@ public class QSBRaft : WorldObject<RaftController>
|
|||||||
}
|
}
|
||||||
|
|
||||||
await UniTask.WaitUntil(() => TransformSync, cancellationToken: ct);
|
await UniTask.WaitUntil(() => TransformSync, cancellationToken: ct);
|
||||||
|
|
||||||
|
foreach (var lightSensor in AttachedObject._lightSensors)
|
||||||
|
{
|
||||||
|
lightSensor.OnDetectLight += OnDetectLight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnRemoval()
|
public override void OnRemoval()
|
||||||
@ -29,6 +37,26 @@ public class QSBRaft : WorldObject<RaftController>
|
|||||||
{
|
{
|
||||||
NetworkServer.Destroy(TransformSync.gameObject);
|
NetworkServer.Destroy(TransformSync.gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var lightSensor in AttachedObject._lightSensors)
|
||||||
|
{
|
||||||
|
lightSensor.OnDetectLight -= OnDetectLight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDetectLight()
|
||||||
|
{
|
||||||
|
if (!AttachedObject._fluidDetector.InFluidType(FluidVolume.Type.WATER))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!AttachedObject._lightSensors.Any(x => x.GetWorldObject<QSBSingleLightSensor>().IlluminatedByLocalPlayer))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TransformSync.netIdentity.UpdateAuthQueue(AuthQueueAction.Force);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SendInitialState(uint to)
|
public override void SendInitialState(uint to)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user