From 94e540531484e8ffbaf002cd2bd210bf84e59e0c Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Fri, 12 Nov 2021 02:24:27 -0800 Subject: [PATCH] include flag and pool index when launching meteor --- QSB/MeteorSync/Events/MeteorLaunchEvent.cs | 14 +++++++++----- QSB/MeteorSync/Events/MeteorLaunchMessage.cs | 6 ++++++ QSB/MeteorSync/Patches/MeteorClientPatches.cs | 15 ++++++++------- QSB/MeteorSync/Patches/MeteorServerPatches.cs | 13 ++++++++----- QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs | 8 ++++++-- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/QSB/MeteorSync/Events/MeteorLaunchEvent.cs b/QSB/MeteorSync/Events/MeteorLaunchEvent.cs index fde55b7b..45379757 100644 --- a/QSB/MeteorSync/Events/MeteorLaunchEvent.cs +++ b/QSB/MeteorSync/Events/MeteorLaunchEvent.cs @@ -1,5 +1,6 @@ using QSB.Events; using QSB.MeteorSync.WorldObjects; +using QSB.Utility; using QSB.WorldSync; using EventType = QSB.Events.EventType; @@ -10,16 +11,19 @@ namespace QSB.MeteorSync.Events public override EventType Type => EventType.MeteorLaunch; public override void SetupListener() - => GlobalMessenger.AddListener(EventNames.QSBMeteorLaunch, Handler); + => GlobalMessenger.AddListener(EventNames.QSBMeteorLaunch, Handler); public override void CloseListener() - => GlobalMessenger.RemoveListener(EventNames.QSBMeteorLaunch, Handler); + => GlobalMessenger.RemoveListener(EventNames.QSBMeteorLaunch, Handler); - private void Handler(int id, float launchSpeed) => SendEvent(CreateMessage(id, launchSpeed)); + private void Handler(int id, bool flag, int poolIndex, float launchSpeed) => + SendEvent(CreateMessage(id, flag, poolIndex, launchSpeed)); - private MeteorLaunchMessage CreateMessage(int id, float launchSpeed) => new MeteorLaunchMessage + private MeteorLaunchMessage CreateMessage(int id, bool flag, int poolIndex, float launchSpeed) => new MeteorLaunchMessage { ObjectId = id, + Flag = flag, + PoolIndex = poolIndex, LaunchSpeed = launchSpeed }; @@ -31,7 +35,7 @@ namespace QSB.MeteorSync.Events } var qsbMeteorLauncher = QSBWorldSync.GetWorldFromId(message.ObjectId); - qsbMeteorLauncher.LaunchMeteor(message.LaunchSpeed); + qsbMeteorLauncher.LaunchMeteor(message.Flag, message.PoolIndex, message.LaunchSpeed); } } } diff --git a/QSB/MeteorSync/Events/MeteorLaunchMessage.cs b/QSB/MeteorSync/Events/MeteorLaunchMessage.cs index c50a3ad4..fb4971f3 100644 --- a/QSB/MeteorSync/Events/MeteorLaunchMessage.cs +++ b/QSB/MeteorSync/Events/MeteorLaunchMessage.cs @@ -5,17 +5,23 @@ namespace QSB.MeteorSync.Events { public class MeteorLaunchMessage : WorldObjectMessage { + public bool Flag; + public int PoolIndex; public float LaunchSpeed; public override void Deserialize(QNetworkReader reader) { base.Deserialize(reader); + Flag = reader.ReadBoolean(); + PoolIndex = reader.ReadInt32(); LaunchSpeed = reader.ReadSingle(); } public override void Serialize(QNetworkWriter writer) { base.Serialize(writer); + writer.Write(Flag); + writer.Write(PoolIndex); writer.Write(LaunchSpeed); } } diff --git a/QSB/MeteorSync/Patches/MeteorClientPatches.cs b/QSB/MeteorSync/Patches/MeteorClientPatches.cs index 72c8eea6..aa7b7cc8 100644 --- a/QSB/MeteorSync/Patches/MeteorClientPatches.cs +++ b/QSB/MeteorSync/Patches/MeteorClientPatches.cs @@ -59,8 +59,11 @@ namespace QSB.MeteorSync.Patches [HarmonyPatch(typeof(MeteorLauncher), nameof(MeteorLauncher.LaunchMeteor))] public static bool LaunchMeteor(MeteorLauncher __instance) { - var flag = __instance._dynamicMeteorPool != null && (__instance._meteorPool == null || Random.value < __instance._dynamicProbability); + var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity(__instance); + + var flag = qsbMeteorLauncher.Flag; MeteorController meteorController = null; + var poolIndex = qsbMeteorLauncher.PoolIndex; if (!flag) { if (__instance._meteorPool.Count == 0) @@ -69,9 +72,9 @@ namespace QSB.MeteorSync.Patches } else { - meteorController = __instance._meteorPool[__instance._meteorPool.Count - 1]; + meteorController = __instance._meteorPool[poolIndex]; meteorController.Initialize(__instance.transform, __instance._detectableField, __instance._detectableFluid); - __instance._meteorPool.QuickRemoveAt(__instance._meteorPool.Count - 1); + __instance._meteorPool.QuickRemoveAt(poolIndex); __instance._launchedMeteors.Add(meteorController); } } @@ -81,15 +84,13 @@ namespace QSB.MeteorSync.Patches } else { - meteorController = __instance._dynamicMeteorPool[__instance._dynamicMeteorPool.Count - 1]; + meteorController = __instance._dynamicMeteorPool[poolIndex]; meteorController.Initialize(__instance.transform, null, null); - __instance._dynamicMeteorPool.QuickRemoveAt(__instance._dynamicMeteorPool.Count - 1); + __instance._dynamicMeteorPool.QuickRemoveAt(poolIndex); __instance._launchedDynamicMeteors.Add(meteorController); } if (meteorController != null) { - var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity(__instance); - var launchSpeed = qsbMeteorLauncher.LaunchSpeed; var linearVelocity = __instance._parentBody.GetPointVelocity(__instance.transform.position) + __instance.transform.TransformDirection(__instance._launchDirection) * launchSpeed; var angularVelocity = __instance.transform.forward * 2f; diff --git a/QSB/MeteorSync/Patches/MeteorServerPatches.cs b/QSB/MeteorSync/Patches/MeteorServerPatches.cs index eb3f97bc..a4e4b253 100644 --- a/QSB/MeteorSync/Patches/MeteorServerPatches.cs +++ b/QSB/MeteorSync/Patches/MeteorServerPatches.cs @@ -82,6 +82,7 @@ namespace QSB.MeteorSync.Patches { var flag = __instance._dynamicMeteorPool != null && (__instance._meteorPool == null || Random.value < __instance._dynamicProbability); MeteorController meteorController = null; + var poolIndex = 0; if (!flag) { if (__instance._meteorPool.Count == 0) @@ -90,9 +91,10 @@ namespace QSB.MeteorSync.Patches } else { - meteorController = __instance._meteorPool[__instance._meteorPool.Count - 1]; + poolIndex = __instance._meteorPool.Count - 1; + meteorController = __instance._meteorPool[poolIndex]; meteorController.Initialize(__instance.transform, __instance._detectableField, __instance._detectableFluid); - __instance._meteorPool.QuickRemoveAt(__instance._meteorPool.Count - 1); + __instance._meteorPool.QuickRemoveAt(poolIndex); __instance._launchedMeteors.Add(meteorController); } } @@ -102,9 +104,10 @@ namespace QSB.MeteorSync.Patches } else { - meteorController = __instance._dynamicMeteorPool[__instance._dynamicMeteorPool.Count - 1]; + poolIndex = __instance._dynamicMeteorPool.Count - 1; + meteorController = __instance._dynamicMeteorPool[poolIndex]; meteorController.Initialize(__instance.transform, null, null); - __instance._dynamicMeteorPool.QuickRemoveAt(__instance._dynamicMeteorPool.Count - 1); + __instance._dynamicMeteorPool.QuickRemoveAt(poolIndex); __instance._launchedDynamicMeteors.Add(meteorController); } if (meteorController != null) @@ -120,7 +123,7 @@ namespace QSB.MeteorSync.Patches } var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity(__instance); - QSBEventManager.FireEvent(EventNames.QSBMeteorLaunch, qsbMeteorLauncher.ObjectId, launchSpeed); + QSBEventManager.FireEvent(EventNames.QSBMeteorLaunch, qsbMeteorLauncher.ObjectId, flag, poolIndex, launchSpeed); } return false; diff --git a/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs b/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs index 4cd8f768..99f7fa09 100644 --- a/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs +++ b/QSB/MeteorSync/WorldObjects/QSBMeteorLauncher.cs @@ -12,6 +12,8 @@ namespace QSB.MeteorSync.WorldObjects } + public bool Flag; + public int PoolIndex; public float LaunchSpeed; public void PreLaunchMeteor() @@ -24,8 +26,10 @@ namespace QSB.MeteorSync.WorldObjects DebugLog.DebugWrite($"{LogName} - pre launch"); } - public void LaunchMeteor(float launchSpeed) + public void LaunchMeteor(bool flag, int poolIndex, float launchSpeed) { + Flag = flag; + PoolIndex = poolIndex; LaunchSpeed = launchSpeed; AttachedObject.LaunchMeteor(); @@ -34,7 +38,7 @@ namespace QSB.MeteorSync.WorldObjects particleSystem.Stop(); } - DebugLog.DebugWrite($"{LogName} - launch {launchSpeed}"); + DebugLog.DebugWrite($"{LogName} - launch {flag} {poolIndex} {launchSpeed}"); } } }