Raft: wait until has authority before actually pushing the raft

This commit is contained in:
JohnCorby 2022-02-25 06:02:33 -08:00
parent 09d7d63774
commit 36f73ff25c
2 changed files with 33 additions and 8 deletions

View File

@ -0,0 +1,33 @@
using HarmonyLib;
using QSB.AuthoritySync;
using QSB.EchoesOfTheEye.RaftSync.WorldObjects;
using QSB.Patches;
using QSB.Utility;
using QSB.WorldSync;
using UnityEngine;
namespace QSB.EchoesOfTheEye.RaftSync.Patches;
public class RaftPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(RaftController), nameof(RaftController.OnPressInteract))]
private static bool OnPressInteract(RaftController __instance)
{
__instance._interactReceiver.SetInteractionEnabled(false);
var qsbRaft = __instance.GetWorldObject<QSBRaft>();
qsbRaft.TransformSync.netIdentity.UpdateAuthQueue(AuthQueueAction.Force);
Delay.RunWhen(() => qsbRaft.TransformSync.hasAuthority, () =>
{
var normalized = Vector3.ProjectOnPlane(Locator.GetPlayerCamera().transform.forward, __instance.transform.up).normalized;
__instance._raftBody.AddVelocityChange(normalized * 5f);
__instance._effectsController.PlayRaftPush();
__instance._pushTime = Time.time;
});
return false;
}
}

View File

@ -1,6 +1,5 @@
using Cysharp.Threading.Tasks;
using Mirror;
using QSB.AuthoritySync;
using QSB.EchoesOfTheEye.RaftSync.TransformSync;
using QSB.Utility;
using QSB.WorldSync;
@ -23,8 +22,6 @@ public class QSBRaft : WorldObject<RaftController>
}
await UniTask.WaitUntil(() => TransformSync, cancellationToken: ct);
AttachedObject._interactReceiver.OnPressInteract += OnPressInteract;
}
public override void OnRemoval()
@ -33,15 +30,10 @@ public class QSBRaft : WorldObject<RaftController>
{
NetworkServer.Destroy(TransformSync.gameObject);
}
AttachedObject._interactReceiver.OnPressInteract -= OnPressInteract;
}
public override void SendInitialState(uint to)
{
// todo?? SendInitialState
}
private void OnPressInteract() =>
TransformSync.netIdentity.UpdateAuthQueue(AuthQueueAction.Force);
}