mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-25 15:35:22 +00:00
pass slot before setting it to null
This commit is contained in:
parent
1284ce3012
commit
2f648733c2
@ -9,22 +9,23 @@ namespace QSB.OrbSync.Events
|
||||
{
|
||||
public override bool RequireWorldObjectsReady => true;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<QSBOrb, NomaiInterfaceSlot, bool>.AddListener(EventNames.QSBOrbSlot, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<QSBOrb, NomaiInterfaceSlot, bool>.RemoveListener(EventNames.QSBOrbSlot, Handler);
|
||||
public override void SetupListener() => GlobalMessenger<QSBOrb, NomaiInterfaceSlot, bool, bool>.AddListener(EventNames.QSBOrbSlot, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<QSBOrb, NomaiInterfaceSlot, bool, bool>.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<QSBOrb>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user