From 36f73ff25ca4284ee0f5982126b086af984c6bd2 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 25 Feb 2022 06:02:33 -0800 Subject: [PATCH] Raft: wait until has authority before actually pushing the raft --- .../RaftSync/Patches/RaftPatches.cs | 33 +++++++++++++++++++ .../RaftSync/WorldObjects/QSBRaft.cs | 8 ----- 2 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 QSB/EchoesOfTheEye/RaftSync/Patches/RaftPatches.cs diff --git a/QSB/EchoesOfTheEye/RaftSync/Patches/RaftPatches.cs b/QSB/EchoesOfTheEye/RaftSync/Patches/RaftPatches.cs new file mode 100644 index 00000000..377cf19c --- /dev/null +++ b/QSB/EchoesOfTheEye/RaftSync/Patches/RaftPatches.cs @@ -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.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; + } +} diff --git a/QSB/EchoesOfTheEye/RaftSync/WorldObjects/QSBRaft.cs b/QSB/EchoesOfTheEye/RaftSync/WorldObjects/QSBRaft.cs index 2a6451f5..8e6d998c 100644 --- a/QSB/EchoesOfTheEye/RaftSync/WorldObjects/QSBRaft.cs +++ b/QSB/EchoesOfTheEye/RaftSync/WorldObjects/QSBRaft.cs @@ -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 } await UniTask.WaitUntil(() => TransformSync, cancellationToken: ct); - - AttachedObject._interactReceiver.OnPressInteract += OnPressInteract; } public override void OnRemoval() @@ -33,15 +30,10 @@ public class QSBRaft : WorldObject { NetworkServer.Destroy(TransformSync.gameObject); } - - AttachedObject._interactReceiver.OnPressInteract -= OnPressInteract; } public override void SendInitialState(uint to) { // todo?? SendInitialState } - - private void OnPressInteract() => - TransformSync.netIdentity.UpdateAuthQueue(AuthQueueAction.Force); }