From 543e2d57d5859d84a4218069d44177370e6d0f25 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Sun, 5 Dec 2021 20:09:54 -0800 Subject: [PATCH] form state for real --- QSB/Events/EventNames.cs | 2 +- QSB/Events/QSBEventManager.cs | 2 +- QSB/Player/Events/RequestStateResyncEvent.cs | 8 +++-- ...lapseEvent.cs => TornadoFormStateEvent.cs} | 14 ++++----- QSB/TornadoSync/Patches/TornadoPatches.cs | 6 ++-- QSB/TornadoSync/WorldObjects/QSBTornado.cs | 30 +++++++++++++------ 6 files changed, 38 insertions(+), 24 deletions(-) rename QSB/TornadoSync/Events/{TornadoFormCollapseEvent.cs => TornadoFormStateEvent.cs} (54%) diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs index dbf91074..fca3dd4a 100644 --- a/QSB/Events/EventNames.cs +++ b/QSB/Events/EventNames.cs @@ -102,6 +102,6 @@ public const string QSBSatelliteRepaired = nameof(QSBSatelliteRepairTick); public const string QSBAuthorityQueue = nameof(QSBAuthorityQueue); public const string QSBJellyfishRising = nameof(QSBJellyfishRising); - public const string QSBTornadoFormCollapse = nameof(QSBTornadoFormCollapse); + public const string QSBTornadoFormState = nameof(QSBTornadoFormState); } } diff --git a/QSB/Events/QSBEventManager.cs b/QSB/Events/QSBEventManager.cs index 536186d3..f751f11e 100644 --- a/QSB/Events/QSBEventManager.cs +++ b/QSB/Events/QSBEventManager.cs @@ -107,7 +107,7 @@ namespace QSB.Events new FragmentDamageEvent(), new FragmentResyncEvent(), new JellyfishRisingEvent(), - new TornadoFormCollapseEvent(), + new TornadoFormStateEvent(), // Conversation/dialogue/exploration new ConversationEvent(), new ConversationStartEndEvent(), diff --git a/QSB/Player/Events/RequestStateResyncEvent.cs b/QSB/Player/Events/RequestStateResyncEvent.cs index ab1f32f1..d0948b84 100644 --- a/QSB/Player/Events/RequestStateResyncEvent.cs +++ b/QSB/Player/Events/RequestStateResyncEvent.cs @@ -1,4 +1,5 @@ -using OWML.Utils; +using System.Linq; +using OWML.Utils; using QSB.CampfireSync.WorldObjects; using QSB.ClientServerStateSync; using QSB.Events; @@ -7,9 +8,9 @@ using QSB.MeteorSync.WorldObjects; using QSB.QuantumSync; using QSB.Tools.TranslatorTool.TranslationSync; using QSB.Tools.TranslatorTool.TranslationSync.WorldObjects; +using QSB.TornadoSync.WorldObjects; using QSB.Utility; using QSB.WorldSync; -using System.Linq; namespace QSB.Player.Events { @@ -83,6 +84,9 @@ namespace QSB.Player.Events QSBWorldSync.GetWorldObjects().ForEach(fragment => QSBEventManager.FireEvent(EventNames.QSBFragmentResync, fragment)); + + QSBWorldSync.GetWorldObjects().ForEach(tornado + => QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, tornado)); } } } diff --git a/QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs b/QSB/TornadoSync/Events/TornadoFormStateEvent.cs similarity index 54% rename from QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs rename to QSB/TornadoSync/Events/TornadoFormStateEvent.cs index c5b16d81..6e5c9c21 100644 --- a/QSB/TornadoSync/Events/TornadoFormCollapseEvent.cs +++ b/QSB/TornadoSync/Events/TornadoFormStateEvent.cs @@ -5,28 +5,28 @@ using QSB.WorldSync.Events; namespace QSB.TornadoSync.Events { - public class TornadoFormCollapseEvent : QSBEvent + public class TornadoFormStateEvent : QSBEvent { public override bool RequireWorldObjectsReady => true; public override void SetupListener() - => GlobalMessenger.AddListener(EventNames.QSBJellyfishRising, Handler); + => GlobalMessenger.AddListener(EventNames.QSBTornadoFormState, Handler); public override void CloseListener() - => GlobalMessenger.RemoveListener(EventNames.QSBJellyfishRising, Handler); + => GlobalMessenger.RemoveListener(EventNames.QSBTornadoFormState, Handler); - private void Handler(QSBTornado qsbTornado, bool formCollapse) => SendEvent(CreateMessage(qsbTornado, formCollapse)); + private void Handler(QSBTornado qsbTornado) => SendEvent(CreateMessage(qsbTornado)); - private BoolWorldObjectMessage CreateMessage(QSBTornado qsbTornado, bool formCollapse) => new() + private BoolWorldObjectMessage CreateMessage(QSBTornado qsbTornado) => new() { ObjectId = qsbTornado.ObjectId, - State = formCollapse + State = qsbTornado.FormState }; public override void OnReceiveRemote(bool isHost, BoolWorldObjectMessage message) { var qsbTornado = QSBWorldSync.GetWorldFromId(message.ObjectId); - qsbTornado.FormCollapse(message.State); + qsbTornado.FormState = message.State; } } } diff --git a/QSB/TornadoSync/Patches/TornadoPatches.cs b/QSB/TornadoSync/Patches/TornadoPatches.cs index c2d2e514..ca6ad2f1 100644 --- a/QSB/TornadoSync/Patches/TornadoPatches.cs +++ b/QSB/TornadoSync/Patches/TornadoPatches.cs @@ -1,7 +1,5 @@ using HarmonyLib; -using QSB.AuthoritySync; using QSB.Events; -using QSB.JellyfishSync.WorldObjects; using QSB.Patches; using QSB.TornadoSync.WorldObjects; using QSB.WorldSync; @@ -24,7 +22,7 @@ namespace QSB.TornadoSync.Patches { __instance.StartFormation(); var qsbTornado = QSBWorldSync.GetWorldFromUnity(__instance); - QSBEventManager.FireEvent(EventNames.QSBTornadoFormCollapse, qsbTornado, true); + QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, qsbTornado); return false; } } @@ -64,7 +62,7 @@ namespace QSB.TornadoSync.Patches { __instance.StartCollapse(); var qsbTornado = QSBWorldSync.GetWorldFromUnity(__instance); - QSBEventManager.FireEvent(EventNames.QSBTornadoFormCollapse, qsbTornado, false); + QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, qsbTornado); } return false; diff --git a/QSB/TornadoSync/WorldObjects/QSBTornado.cs b/QSB/TornadoSync/WorldObjects/QSBTornado.cs index 83293199..d51edf72 100644 --- a/QSB/TornadoSync/WorldObjects/QSBTornado.cs +++ b/QSB/TornadoSync/WorldObjects/QSBTornado.cs @@ -11,17 +11,29 @@ namespace QSB.TornadoSync.WorldObjects AttachedObject = attachedObject; } - public void FormCollapse(bool formCollapse) + public bool FormState { - if (formCollapse) + get => AttachedObject._tornadoRoot.activeSelf // forming or formed or collapsing + && !AttachedObject._tornadoCollapsing; // and not collapsing + set { - AttachedObject.StartFormation(); - DebugLog.DebugWrite($"{LogName} form"); - } - else - { - AttachedObject.StartCollapse(); - DebugLog.DebugWrite($"{LogName} collapse"); + if (FormState == value) + { + return; + } + + if (value) + { + AttachedObject._tornadoCollapsing = false; + AttachedObject.StartFormation(); + DebugLog.DebugWrite($"{LogName} form"); + } + else + { + AttachedObject._secondsUntilFormation = 0; + AttachedObject.StartCollapse(); + DebugLog.DebugWrite($"{LogName} collapse"); + } } } }