form state for real

This commit is contained in:
JohnCorby 2021-12-05 20:09:54 -08:00
parent 85ef887698
commit 543e2d57d5
6 changed files with 38 additions and 24 deletions

View File

@ -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);
}
}

View File

@ -107,7 +107,7 @@ namespace QSB.Events
new FragmentDamageEvent(),
new FragmentResyncEvent(),
new JellyfishRisingEvent(),
new TornadoFormCollapseEvent(),
new TornadoFormStateEvent(),
// Conversation/dialogue/exploration
new ConversationEvent(),
new ConversationStartEndEvent(),

View File

@ -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<QSBFragment>().ForEach(fragment
=> QSBEventManager.FireEvent(EventNames.QSBFragmentResync, fragment));
QSBWorldSync.GetWorldObjects<QSBTornado>().ForEach(tornado
=> QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, tornado));
}
}
}

View File

@ -5,28 +5,28 @@ using QSB.WorldSync.Events;
namespace QSB.TornadoSync.Events
{
public class TornadoFormCollapseEvent : QSBEvent<BoolWorldObjectMessage>
public class TornadoFormStateEvent : QSBEvent<BoolWorldObjectMessage>
{
public override bool RequireWorldObjectsReady => true;
public override void SetupListener()
=> GlobalMessenger<QSBTornado, bool>.AddListener(EventNames.QSBJellyfishRising, Handler);
=> GlobalMessenger<QSBTornado>.AddListener(EventNames.QSBTornadoFormState, Handler);
public override void CloseListener()
=> GlobalMessenger<QSBTornado, bool>.RemoveListener(EventNames.QSBJellyfishRising, Handler);
=> GlobalMessenger<QSBTornado>.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<QSBTornado>(message.ObjectId);
qsbTornado.FormCollapse(message.State);
qsbTornado.FormState = message.State;
}
}
}

View File

@ -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<QSBTornado>(__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<QSBTornado>(__instance);
QSBEventManager.FireEvent(EventNames.QSBTornadoFormCollapse, qsbTornado, false);
QSBEventManager.FireEvent(EventNames.QSBTornadoFormState, qsbTornado);
}
return false;

View File

@ -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");
}
}
}
}