mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-06 00:39:55 +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
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
using HarmonyLib;
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using QSB.Tools.FlashlightTool;
|
||||
using QSB.WorldSync;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
@ -16,6 +18,14 @@ internal class LightSensorPatches : QSBPatch
|
||||
[HarmonyPatch(typeof(SingleLightSensor), nameof(SingleLightSensor.UpdateIllumination))]
|
||||
public static bool UpdateIlluminationReplacement(SingleLightSensor __instance)
|
||||
{
|
||||
if (!QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var qsbSingleLightSensor = __instance.GetWorldObject<QSBSingleLightSensor>();
|
||||
qsbSingleLightSensor.IlluminatedByLocalPlayer = false;
|
||||
|
||||
__instance._illuminated = false;
|
||||
if (__instance._illuminatingDreamLanternList != null)
|
||||
{
|
||||
@ -68,11 +78,13 @@ internal class LightSensorPatches : QSBPatch
|
||||
&& !__instance.CheckOcclusion(position, vector, sensorWorldDir))
|
||||
{
|
||||
__instance._illuminated = true;
|
||||
|
||||
qsbSingleLightSensor.IlluminatedByLocalPlayer = true;
|
||||
}
|
||||
}
|
||||
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 to = __instance.transform.position - position;
|
||||
@ -95,6 +107,7 @@ internal class LightSensorPatches : QSBPatch
|
||||
&& !__instance.CheckOcclusion(probe.GetLightSourcePosition(), vector, sensorWorldDir))
|
||||
{
|
||||
__instance._illuminated = true;
|
||||
qsbSingleLightSensor.IlluminatedByLocalPlayer = true;
|
||||
}
|
||||
|
||||
break;
|
||||
@ -114,6 +127,8 @@ internal class LightSensorPatches : QSBPatch
|
||||
{
|
||||
__instance._illuminatingDreamLanternList.Add(dreamLanternController);
|
||||
__instance._illuminated = true;
|
||||
|
||||
qsbSingleLightSensor.IlluminatedByLocalPlayer = true;
|
||||
}
|
||||
|
||||
break;
|
||||
@ -127,6 +142,8 @@ internal class LightSensorPatches : QSBPatch
|
||||
if (light.CheckIlluminationAtPoint(vector, __instance._sensorRadius, maxDistance) && !__instance.CheckOcclusion(light.transform.position, vector, sensorWorldDir, occludableLight))
|
||||
{
|
||||
__instance._illuminated = true;
|
||||
|
||||
qsbSingleLightSensor.IlluminatedByLocalPlayer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -6,4 +6,6 @@ namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
internal class QSBSingleLightSensor : WorldObject<SingleLightSensor>
|
||||
{
|
||||
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.Syncs.Unsectored.Rigidbodies;
|
||||
using QSB.Utility;
|
||||
@ -63,14 +62,8 @@ public class RaftTransformSync : UnsectoredRigidbodySync
|
||||
private void OnUnsuspend(OWRigidbody suspendedBody) => netIdentity.UpdateAuthQueue(AuthQueueAction.Add);
|
||||
private void OnSuspend(OWRigidbody suspendedBody) => netIdentity.UpdateAuthQueue(AuthQueueAction.Remove);
|
||||
|
||||
public override void OnStartAuthority() => DebugLog.DebugWrite($"{this} - start authority");
|
||||
public override void OnStopAuthority() => DebugLog.DebugWrite($"{this} - stop authority");
|
||||
|
||||
protected override void Deserialize(NetworkReader reader)
|
||||
{
|
||||
DebugLog.DebugWrite($"{this} - deserialize");
|
||||
base.Deserialize(reader);
|
||||
}
|
||||
public override void OnStartAuthority() => DebugLog.DebugWrite($"{this} - authority = true");
|
||||
public override void OnStopAuthority() => DebugLog.DebugWrite($"{this} - authority = false");
|
||||
|
||||
/// <summary>
|
||||
/// replacement for base method
|
||||
@ -78,8 +71,8 @@ public class RaftTransformSync : UnsectoredRigidbodySync
|
||||
/// </summary>
|
||||
protected override void ApplyToAttached()
|
||||
{
|
||||
var targetPos = ReferenceTransform.FromRelPos(UseInterpolation ? SmoothPosition : transform.position);
|
||||
var targetRot = ReferenceTransform.FromRelRot(UseInterpolation ? SmoothRotation : transform.rotation);
|
||||
var targetPos = ReferenceTransform.FromRelPos(transform.position);
|
||||
var targetRot = ReferenceTransform.FromRelRot(transform.rotation);
|
||||
|
||||
AttachedRigidbody.SetPosition(targetPos);
|
||||
AttachedRigidbody.SetRotation(targetRot);
|
||||
|
@ -1,7 +1,10 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Mirror;
|
||||
using QSB.AuthoritySync;
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
|
||||
using QSB.WorldSync;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
@ -21,6 +24,11 @@ public class QSBRaft : WorldObject<RaftController>
|
||||
}
|
||||
|
||||
await UniTask.WaitUntil(() => TransformSync, cancellationToken: ct);
|
||||
|
||||
foreach (var lightSensor in AttachedObject._lightSensors)
|
||||
{
|
||||
lightSensor.OnDetectLight += OnDetectLight;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnRemoval()
|
||||
@ -29,10 +37,30 @@ public class QSBRaft : WorldObject<RaftController>
|
||||
{
|
||||
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)
|
||||
{
|
||||
// todo?? SendInitialState
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user