include flag and pool index when launching meteor

This commit is contained in:
JohnCorby 2021-11-12 02:24:27 -08:00
parent 0949924f59
commit 94e5405314
5 changed files with 37 additions and 19 deletions

View File

@ -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<int, float>.AddListener(EventNames.QSBMeteorLaunch, Handler);
=> GlobalMessenger<int, bool, int, float>.AddListener(EventNames.QSBMeteorLaunch, Handler);
public override void CloseListener()
=> GlobalMessenger<int, float>.RemoveListener(EventNames.QSBMeteorLaunch, Handler);
=> GlobalMessenger<int, bool, int, float>.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<QSBMeteorLauncher>(message.ObjectId);
qsbMeteorLauncher.LaunchMeteor(message.LaunchSpeed);
qsbMeteorLauncher.LaunchMeteor(message.Flag, message.PoolIndex, message.LaunchSpeed);
}
}
}

View File

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

View File

@ -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<QSBMeteorLauncher>(__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<QSBMeteorLauncher>(__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;

View File

@ -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<QSBMeteorLauncher>(__instance);
QSBEventManager.FireEvent(EventNames.QSBMeteorLaunch, qsbMeteorLauncher.ObjectId, launchSpeed);
QSBEventManager.FireEvent(EventNames.QSBMeteorLaunch, qsbMeteorLauncher.ObjectId, flag, poolIndex, launchSpeed);
}
return false;

View File

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