From 2f648733c25b7fe1dd295b875f126fd56848ea30 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 15 Dec 2021 00:10:35 -0800 Subject: [PATCH] pass slot before setting it to null --- QSB/OrbSync/Events/OrbSlotEvent.cs | 11 ++++++----- QSB/OrbSync/Events/OrbSlotMessage.cs | 3 +++ QSB/OrbSync/Patches/OrbPatches.cs | 4 ++-- QSB/OrbSync/WorldObjects/QSBOrb.cs | 16 ++++++++-------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/QSB/OrbSync/Events/OrbSlotEvent.cs b/QSB/OrbSync/Events/OrbSlotEvent.cs index e6904956..b28721fe 100644 --- a/QSB/OrbSync/Events/OrbSlotEvent.cs +++ b/QSB/OrbSync/Events/OrbSlotEvent.cs @@ -9,22 +9,23 @@ namespace QSB.OrbSync.Events { public override bool RequireWorldObjectsReady => true; - public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBOrbSlot, Handler); - public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBOrbSlot, Handler); + public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBOrbSlot, Handler); + public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBOrbSlot, Handler); - private void Handler(QSBOrb qsbOrb, NomaiInterfaceSlot slot, bool playAudio) => SendEvent(CreateMessage(qsbOrb, slot, playAudio)); + private void Handler(QSBOrb qsbOrb, NomaiInterfaceSlot slot, bool slotted, bool playAudio) => SendEvent(CreateMessage(qsbOrb, slot, slotted, playAudio)); - private OrbSlotMessage CreateMessage(QSBOrb qsbOrb, NomaiInterfaceSlot slot, bool playAudio) => new() + private OrbSlotMessage CreateMessage(QSBOrb qsbOrb, NomaiInterfaceSlot slot, bool slotted, bool playAudio) => new() { ObjectId = qsbOrb.ObjectId, SlotIndex = qsbOrb.AttachedObject._slots.IndexOf(slot), + Slotted = slotted, PlayAudio = playAudio }; public override void OnReceiveRemote(bool server, OrbSlotMessage message) { var qsbOrb = QSBWorldSync.GetWorldFromId(message.ObjectId); - qsbOrb.SetOccupiedSlot(message.SlotIndex == -1 ? null : qsbOrb.AttachedObject._slots[message.SlotIndex], message.PlayAudio); + qsbOrb.SetOccupiedSlot(qsbOrb.AttachedObject._slots[message.SlotIndex], message.Slotted, message.PlayAudio); } } } diff --git a/QSB/OrbSync/Events/OrbSlotMessage.cs b/QSB/OrbSync/Events/OrbSlotMessage.cs index e1cf65fb..8cdeb421 100644 --- a/QSB/OrbSync/Events/OrbSlotMessage.cs +++ b/QSB/OrbSync/Events/OrbSlotMessage.cs @@ -6,12 +6,14 @@ namespace QSB.OrbSync.Events public class OrbSlotMessage : WorldObjectMessage { public int SlotIndex; + public bool Slotted; public bool PlayAudio; public override void Deserialize(QNetworkReader reader) { base.Deserialize(reader); SlotIndex = reader.ReadInt32(); + Slotted = reader.ReadBoolean(); PlayAudio = reader.ReadBoolean(); } @@ -19,6 +21,7 @@ namespace QSB.OrbSync.Events { base.Serialize(writer); writer.Write(SlotIndex); + writer.Write(Slotted); writer.Write(PlayAudio); } } diff --git a/QSB/OrbSync/Patches/OrbPatches.cs b/QSB/OrbSync/Patches/OrbPatches.cs index f760c636..984d32e3 100644 --- a/QSB/OrbSync/Patches/OrbPatches.cs +++ b/QSB/OrbSync/Patches/OrbPatches.cs @@ -81,15 +81,15 @@ namespace QSB.OrbSync.Patches { __instance._orbAudio.PlaySlotActivatedClip(); } - QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrb, __instance._occupiedSlot, playAudio); + QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrb, __instance._occupiedSlot, true, playAudio); break; } } } else if ((!__instance._occupiedSlot.IsAttractive() || __instance._isBeingDragged) && !__instance._occupiedSlot.CheckOrbCollision(__instance)) { + QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrb, __instance._occupiedSlot, false, playAudio); __instance._occupiedSlot = null; - QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrb, __instance._occupiedSlot, playAudio); } __instance._owCollider.SetActivation(__instance._occupiedSlot == null || !__instance._occupiedSlot.IsAttractive() || __instance._isBeingDragged); diff --git a/QSB/OrbSync/WorldObjects/QSBOrb.cs b/QSB/OrbSync/WorldObjects/QSBOrb.cs index b99e0887..8b68623e 100644 --- a/QSB/OrbSync/WorldObjects/QSBOrb.cs +++ b/QSB/OrbSync/WorldObjects/QSBOrb.cs @@ -58,31 +58,31 @@ namespace QSB.OrbSync.WorldObjects public NomaiInterfaceSlot OccupiedSlot => AttachedObject._occupiedSlot; - public void SetOccupiedSlot(NomaiInterfaceSlot slot, bool playAudio) + public void SetOccupiedSlot(NomaiInterfaceSlot slot, bool slotted, bool playAudio) { - if (slot == OccupiedSlot) + if (slotted == OccupiedSlot) { return; } - if (slot) + if (slotted) { + slot._occupyingOrb = AttachedObject; + slot.RaiseEvent(nameof(slot.OnSlotActivated), slot); + AttachedObject._occupiedSlot = slot; AttachedObject._enterSlotTime = Time.time; if (playAudio && AttachedObject._orbAudio != null && slot.GetPlayActivationAudio()) { AttachedObject._orbAudio.PlaySlotActivatedClip(); } - - slot._occupyingOrb = AttachedObject; - slot.RaiseEvent(nameof(slot.OnSlotActivated), slot); } else { - AttachedObject._occupiedSlot = null; - slot._occupyingOrb = null; slot.RaiseEvent(nameof(slot.OnSlotDeactivated), slot); + + AttachedObject._occupiedSlot = null; } } }