mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-21 09:39:56 +00:00
we do a little reworking
This commit is contained in:
parent
a2c2688dce
commit
4e4bad6885
@ -1,5 +1,6 @@
|
||||
using QSB.Events;
|
||||
using QSB.MeteorSync.WorldObjects;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
using EventType = QSB.Events.EventType;
|
||||
@ -11,17 +12,18 @@ namespace QSB.MeteorSync.Events
|
||||
public override EventType Type => EventType.MeteorImpact;
|
||||
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger<int, Vector3, float>.AddListener(EventNames.QSBMeteorImpact, Handler);
|
||||
=> GlobalMessenger<int, Vector3, Quaternion, float>.AddListener(EventNames.QSBMeteorImpact, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger<int, Vector3, float>.RemoveListener(EventNames.QSBMeteorImpact, Handler);
|
||||
=> GlobalMessenger<int, Vector3, Quaternion, float>.RemoveListener(EventNames.QSBMeteorImpact, Handler);
|
||||
|
||||
private void Handler(int id, Vector3 impactPoint, float damage) => SendEvent(CreateMessage(id, impactPoint, damage));
|
||||
private void Handler(int id, Vector3 pos, Quaternion rot, float damage) => SendEvent(CreateMessage(id, pos, rot, damage));
|
||||
|
||||
private MeteorImpactMessage CreateMessage(int id, Vector3 impactPoint, float damage) => new MeteorImpactMessage
|
||||
private MeteorImpactMessage CreateMessage(int id, Vector3 pos, Quaternion rot, float damage) => new MeteorImpactMessage
|
||||
{
|
||||
ObjectId = id,
|
||||
ImpactPoint = impactPoint,
|
||||
Pos = pos,
|
||||
Rot = rot,
|
||||
Damage = damage
|
||||
};
|
||||
|
||||
@ -33,7 +35,7 @@ namespace QSB.MeteorSync.Events
|
||||
}
|
||||
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromId<QSBMeteor>(message.ObjectId);
|
||||
qsbMeteor.Impact(message.ImpactPoint, message.Damage);
|
||||
qsbMeteor.Impact(message.Pos, message.Rot, message.Damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,20 +6,23 @@ namespace QSB.MeteorSync.Events
|
||||
{
|
||||
public class MeteorImpactMessage : WorldObjectMessage
|
||||
{
|
||||
public Vector3 ImpactPoint;
|
||||
public Vector3 Pos;
|
||||
public Quaternion Rot;
|
||||
public float Damage;
|
||||
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
ImpactPoint = reader.ReadVector3();
|
||||
Pos = reader.ReadVector3();
|
||||
Rot = reader.ReadQuaternion();
|
||||
Damage = reader.ReadSingle();
|
||||
}
|
||||
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(ImpactPoint);
|
||||
writer.Write(Pos);
|
||||
writer.Write(Rot);
|
||||
writer.Write(Damage);
|
||||
}
|
||||
}
|
||||
|
@ -11,19 +11,18 @@ namespace QSB.MeteorSync.Events
|
||||
public override EventType Type => EventType.MeteorLaunch;
|
||||
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger<int, bool, int, float>.AddListener(EventNames.QSBMeteorLaunch, Handler);
|
||||
=> GlobalMessenger<int, int, float>.AddListener(EventNames.QSBMeteorLaunch, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger<int, bool, int, float>.RemoveListener(EventNames.QSBMeteorLaunch, Handler);
|
||||
=> GlobalMessenger<int, int, float>.RemoveListener(EventNames.QSBMeteorLaunch, Handler);
|
||||
|
||||
private void Handler(int id, bool flag, int poolIndex, float launchSpeed) =>
|
||||
SendEvent(CreateMessage(id, flag, poolIndex, launchSpeed));
|
||||
private void Handler(int id, int meteorId, float launchSpeed) =>
|
||||
SendEvent(CreateMessage(id, meteorId, launchSpeed));
|
||||
|
||||
private MeteorLaunchMessage CreateMessage(int id, bool flag, int poolIndex, float launchSpeed) => new MeteorLaunchMessage
|
||||
private MeteorLaunchMessage CreateMessage(int id, int meteorId, float launchSpeed) => new MeteorLaunchMessage
|
||||
{
|
||||
ObjectId = id,
|
||||
Flag = flag,
|
||||
PoolIndex = poolIndex,
|
||||
MeteorId = meteorId,
|
||||
LaunchSpeed = launchSpeed
|
||||
};
|
||||
|
||||
@ -35,7 +34,7 @@ namespace QSB.MeteorSync.Events
|
||||
}
|
||||
|
||||
var qsbMeteorLauncher = QSBWorldSync.GetWorldFromId<QSBMeteorLauncher>(message.ObjectId);
|
||||
qsbMeteorLauncher.LaunchMeteor(message.Flag, message.PoolIndex, message.LaunchSpeed);
|
||||
qsbMeteorLauncher.LaunchMeteor(message.MeteorId, message.LaunchSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,23 +5,20 @@ namespace QSB.MeteorSync.Events
|
||||
{
|
||||
public class MeteorLaunchMessage : WorldObjectMessage
|
||||
{
|
||||
public bool Flag;
|
||||
public int PoolIndex;
|
||||
public int MeteorId;
|
||||
public float LaunchSpeed;
|
||||
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Flag = reader.ReadBoolean();
|
||||
PoolIndex = reader.ReadInt32();
|
||||
MeteorId = reader.ReadInt32();
|
||||
LaunchSpeed = reader.ReadSingle();
|
||||
}
|
||||
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(Flag);
|
||||
writer.Write(PoolIndex);
|
||||
writer.Write(MeteorId);
|
||||
writer.Write(LaunchSpeed);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
using QSB.Events;
|
||||
using QSB.MeteorSync.WorldObjects;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QSB.WorldSync.Events;
|
||||
using UnityEngine;
|
||||
using EventType = QSB.Events.EventType;
|
||||
|
||||
namespace QSB.MeteorSync.Events
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using OWML.Common;
|
||||
using QSB.MeteorSync.WorldObjects;
|
||||
@ -61,16 +62,19 @@ namespace QSB.MeteorSync.Patches
|
||||
{
|
||||
var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity<QSBMeteorLauncher>(__instance);
|
||||
|
||||
var flag = qsbMeteorLauncher.Flag;
|
||||
MeteorController meteorController = null;
|
||||
var poolIndex = qsbMeteorLauncher.PoolIndex;
|
||||
if (!flag)
|
||||
QSBMeteor qsbMeteor = null;
|
||||
|
||||
bool MeteorMatches(MeteorController x)
|
||||
{
|
||||
if (__instance._meteorPool.Count == 0)
|
||||
{
|
||||
Debug.LogWarning("MeteorLauncher is out of Meteors!", __instance);
|
||||
}
|
||||
else
|
||||
qsbMeteor = QSBWorldSync.GetWorldFromUnity<QSBMeteor>(x);
|
||||
return qsbMeteor.ObjectId == qsbMeteorLauncher.MeteorId;
|
||||
}
|
||||
|
||||
if (__instance._meteorPool != null)
|
||||
{
|
||||
var poolIndex = __instance._meteorPool.FindIndex(MeteorMatches);
|
||||
if (poolIndex != -1)
|
||||
{
|
||||
meteorController = __instance._meteorPool[poolIndex];
|
||||
meteorController.Initialize(__instance.transform, __instance._detectableField, __instance._detectableFluid);
|
||||
@ -78,16 +82,16 @@ namespace QSB.MeteorSync.Patches
|
||||
__instance._launchedMeteors.Add(meteorController);
|
||||
}
|
||||
}
|
||||
else if (__instance._dynamicMeteorPool.Count == 0)
|
||||
else if (__instance._dynamicMeteorPool != null)
|
||||
{
|
||||
Debug.LogWarning("MeteorLauncher is out of Dynamic Meteors!", __instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
meteorController = __instance._dynamicMeteorPool[poolIndex];
|
||||
meteorController.Initialize(__instance.transform, null, null);
|
||||
__instance._dynamicMeteorPool.QuickRemoveAt(poolIndex);
|
||||
__instance._launchedDynamicMeteors.Add(meteorController);
|
||||
var poolIndex = __instance._dynamicMeteorPool.FindIndex(MeteorMatches);
|
||||
if (poolIndex != -1)
|
||||
{
|
||||
meteorController = __instance._dynamicMeteorPool[poolIndex];
|
||||
meteorController.Initialize(__instance.transform, null, null);
|
||||
__instance._dynamicMeteorPool.QuickRemoveAt(poolIndex);
|
||||
__instance._launchedDynamicMeteors.Add(meteorController);
|
||||
}
|
||||
}
|
||||
if (meteorController != null)
|
||||
{
|
||||
@ -100,18 +104,35 @@ namespace QSB.MeteorSync.Patches
|
||||
__instance._launchSource.pitch = Random.Range(0.4f, 0.6f);
|
||||
__instance._launchSource.PlayOneShot(AudioType.BH_MeteorLaunch);
|
||||
}
|
||||
DebugLog.DebugWrite($"{qsbMeteorLauncher.LogName} - launch {flag} {poolIndex} {launchSpeed}");
|
||||
DebugLog.DebugWrite($"{qsbMeteorLauncher.LogName} - launch {qsbMeteor.LogName} {launchSpeed}");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(MeteorController), nameof(MeteorController.OnCollisionEnter))]
|
||||
public static bool OnCollisionEnter(MeteorController __instance,
|
||||
Collision collision)
|
||||
=> false;
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Launch))]
|
||||
public static void Launch(MeteorController __instance,
|
||||
Transform parent, Vector3 worldPosition, Quaternion worldRotation, Vector3 linearVelocity, Vector3 angularVelocity)
|
||||
{
|
||||
__instance.gameObject.SetActive(true);
|
||||
__instance.transform.SetParent(parent);
|
||||
__instance.transform.SetPositionAndRotation(worldPosition, worldRotation);
|
||||
__instance._owRigidbody.MakeNonKinematic();
|
||||
__instance._owRigidbody.SetVelocity(linearVelocity);
|
||||
__instance._owRigidbody.SetAngularVelocity(angularVelocity);
|
||||
__instance._intactRenderer.enabled = true;
|
||||
__instance._glowLight.intensity = __instance._lightStartIntensity;
|
||||
__instance._smokeTrail.enabled = true;
|
||||
__instance._smokeTrail.GetParticleSystem().Play();
|
||||
__instance._suspended = false;
|
||||
__instance._hasLaunched = true;
|
||||
__instance._launchTime = Time.time;
|
||||
__instance._hasImpacted = false;
|
||||
__instance._impactTime = 0f;
|
||||
__instance._heat = 1f;
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPrefix]
|
||||
@ -121,7 +142,7 @@ namespace QSB.MeteorSync.Patches
|
||||
{
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromUnity<QSBMeteor>(__instance);
|
||||
|
||||
var componentInParent = hitObject != null ? hitObject.GetComponentInParent<FragmentIntegrity>() : null;
|
||||
var componentInParent = hitObject.GetComponentInParent<FragmentIntegrity>();
|
||||
var damage = qsbMeteor.Damage;
|
||||
if (componentInParent != null)
|
||||
{
|
||||
@ -150,24 +171,21 @@ namespace QSB.MeteorSync.Patches
|
||||
owCollider.SetActivation(false);
|
||||
}
|
||||
__instance._owRigidbody.MakeKinematic();
|
||||
if (hitObject != null)
|
||||
{
|
||||
__instance.transform.SetParent(hitObject.GetAttachedOWRigidbody().transform);
|
||||
}
|
||||
__instance.transform.SetParent(hitObject.GetAttachedOWRigidbody().transform);
|
||||
FragmentSurfaceProxy.UntrackMeteor(__instance);
|
||||
FragmentCollisionProxy.UntrackMeteor(__instance);
|
||||
__instance._ignoringCollisions = false;
|
||||
__instance._hasImpacted = true;
|
||||
__instance._impactTime = Time.time;
|
||||
|
||||
if (hitObject != null)
|
||||
if (qsbMeteor.ShouldImpact)
|
||||
{
|
||||
DebugLog.DebugWrite($"{qsbMeteor.LogName} - impact! {hitObject.name} {impactPoint} {impactVel} {damage}");
|
||||
qsbMeteor.ShouldImpact = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLog.ToConsole($"{qsbMeteor.LogName} - got impact from server, but found no hit object locally "
|
||||
+ $"({impactPoint} {impactVel} {damage})", MessageType.Error);
|
||||
DebugLog.ToConsole($"{qsbMeteor.LogName} - impacted locally, but not on server. THIS SHOULD BE IMPOSSIBLE", MessageType.Error);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -184,6 +202,11 @@ namespace QSB.MeteorSync.Patches
|
||||
}
|
||||
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromUnity<QSBMeteor>(__instance);
|
||||
if (qsbMeteor.ShouldImpact)
|
||||
{
|
||||
DebugLog.ToConsole($"{qsbMeteor.LogName} - impacted on server, but not locally", MessageType.Error);
|
||||
qsbMeteor.ShouldImpact = false;
|
||||
}
|
||||
DebugLog.DebugWrite($"{qsbMeteor.LogName} - suspended");
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,6 @@ namespace QSB.MeteorSync.Patches
|
||||
|
||||
var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity<QSBMeteorLauncher>(__instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBMeteorPreLaunch, qsbMeteorLauncher.ObjectId);
|
||||
DebugLog.DebugWrite($"{qsbMeteorLauncher.LogName} - pre launch");
|
||||
}
|
||||
if (Time.time > __instance._lastLaunchTime + __instance._launchDelay + 2.3f)
|
||||
{
|
||||
@ -86,7 +85,6 @@ 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)
|
||||
@ -95,24 +93,25 @@ namespace QSB.MeteorSync.Patches
|
||||
}
|
||||
else
|
||||
{
|
||||
poolIndex = __instance._meteorPool.Count - 1;
|
||||
meteorController = __instance._meteorPool[poolIndex];
|
||||
meteorController = __instance._meteorPool[__instance._meteorPool.Count - 1];
|
||||
meteorController.Initialize(__instance.transform, __instance._detectableField, __instance._detectableFluid);
|
||||
__instance._meteorPool.QuickRemoveAt(poolIndex);
|
||||
__instance._meteorPool.QuickRemoveAt(__instance._meteorPool.Count - 1);
|
||||
__instance._launchedMeteors.Add(meteorController);
|
||||
}
|
||||
}
|
||||
else if (__instance._dynamicMeteorPool.Count == 0)
|
||||
{
|
||||
Debug.LogWarning("MeteorLauncher is out of Dynamic Meteors!", __instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
poolIndex = __instance._dynamicMeteorPool.Count - 1;
|
||||
meteorController = __instance._dynamicMeteorPool[poolIndex];
|
||||
meteorController.Initialize(__instance.transform, null, null);
|
||||
__instance._dynamicMeteorPool.QuickRemoveAt(poolIndex);
|
||||
__instance._launchedDynamicMeteors.Add(meteorController);
|
||||
if (__instance._dynamicMeteorPool.Count == 0)
|
||||
{
|
||||
Debug.LogWarning("MeteorLauncher is out of Dynamic Meteors!", __instance);
|
||||
}
|
||||
else
|
||||
{
|
||||
meteorController = __instance._dynamicMeteorPool[__instance._dynamicMeteorPool.Count - 1];
|
||||
meteorController.Initialize(__instance.transform, null, null);
|
||||
__instance._dynamicMeteorPool.QuickRemoveAt(__instance._dynamicMeteorPool.Count - 1);
|
||||
__instance._launchedDynamicMeteors.Add(meteorController);
|
||||
}
|
||||
}
|
||||
if (meteorController != null)
|
||||
{
|
||||
@ -127,8 +126,9 @@ namespace QSB.MeteorSync.Patches
|
||||
}
|
||||
|
||||
var qsbMeteorLauncher = QSBWorldSync.GetWorldFromUnity<QSBMeteorLauncher>(__instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBMeteorLaunch, qsbMeteorLauncher.ObjectId, flag, poolIndex, launchSpeed);
|
||||
DebugLog.DebugWrite($"{qsbMeteorLauncher.LogName} - launch {flag} {poolIndex} {launchSpeed}");
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromUnity<QSBMeteor>(meteorController);
|
||||
QSBEventManager.FireEvent(EventNames.QSBMeteorLaunch, qsbMeteorLauncher.ObjectId, qsbMeteor.ObjectId, launchSpeed);
|
||||
DebugLog.DebugWrite($"{qsbMeteorLauncher.LogName} - launch {qsbMeteor.LogName} {launchSpeed}");
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -177,8 +177,9 @@ namespace QSB.MeteorSync.Patches
|
||||
__instance._impactTime = Time.time;
|
||||
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromUnity<QSBMeteor>(__instance);
|
||||
impactPoint = Locator._brittleHollow.transform.InverseTransformPoint(impactPoint);
|
||||
QSBEventManager.FireEvent(EventNames.QSBMeteorImpact, qsbMeteor.ObjectId, impactPoint, damage);
|
||||
var pos = Locator._brittleHollow.transform.InverseTransformPoint(__instance.owRigidbody.GetPosition());
|
||||
var rot = Locator._brittleHollow.transform.InverseTransformRotation(__instance.owRigidbody.GetRotation());
|
||||
QSBEventManager.FireEvent(EventNames.QSBMeteorImpact, qsbMeteor.ObjectId, pos, rot, damage);
|
||||
DebugLog.DebugWrite($"{qsbMeteor.LogName} - impact! {hitObject.name} {impactPoint} {impactVel} {damage}");
|
||||
|
||||
return false;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Linq;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
@ -34,22 +34,29 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
}
|
||||
|
||||
|
||||
public bool ShouldImpact;
|
||||
public float Damage;
|
||||
|
||||
public void Impact(Vector3 impactPoint, float damage)
|
||||
public void Impact(Vector3 pos, Quaternion rot, float damage)
|
||||
{
|
||||
impactPoint = Locator._brittleHollow.transform.TransformPoint(impactPoint);
|
||||
pos = Locator._brittleHollow.transform.TransformPoint(pos);
|
||||
rot = Locator._brittleHollow.transform.TransformRotation(rot);
|
||||
Damage = damage;
|
||||
|
||||
var hits = Physics.OverlapSphere(impactPoint, 1, OWLayerMask.physicalMask, QueryTriggerInteraction.Ignore);
|
||||
var obj = hits
|
||||
.Select(x => x.gameObject)
|
||||
.OrderBy(x => Vector3.Distance(impactPoint, x.transform.position))
|
||||
.FirstOrDefault();
|
||||
AttachedObject.owRigidbody.SetPosition(pos);
|
||||
AttachedObject.owRigidbody.SetRotation(rot);
|
||||
|
||||
AttachedObject.owRigidbody.MoveToPosition(impactPoint);
|
||||
var impactVel = obj != null ? AttachedObject.owRigidbody.GetVelocity() - obj.GetAttachedOWRigidbody().GetVelocity() : default;
|
||||
AttachedObject.Impact(obj, impactPoint, impactVel);
|
||||
foreach (var owCollider in AttachedObject._owColliders)
|
||||
{
|
||||
owCollider.SetActivation(!OWLayerMask.IsLayerInMask(owCollider.gameObject.layer, OWLayerMask.physicalMask));
|
||||
}
|
||||
FragmentSurfaceProxy.TrackMeteor(AttachedObject);
|
||||
FragmentCollisionProxy.TrackMeteor(AttachedObject);
|
||||
|
||||
AttachedObject._hasImpacted = true;
|
||||
AttachedObject._impactTime = Time.time;
|
||||
|
||||
ShouldImpact = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.MeteorSync.WorldObjects
|
||||
{
|
||||
@ -12,8 +11,7 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
}
|
||||
|
||||
|
||||
public bool Flag;
|
||||
public int PoolIndex;
|
||||
public int MeteorId;
|
||||
public float LaunchSpeed;
|
||||
|
||||
public void PreLaunchMeteor()
|
||||
@ -22,14 +20,11 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
{
|
||||
particleSystem.Play();
|
||||
}
|
||||
|
||||
DebugLog.DebugWrite($"{LogName} - pre launch");
|
||||
}
|
||||
|
||||
public void LaunchMeteor(bool flag, int poolIndex, float launchSpeed)
|
||||
public void LaunchMeteor(int meteorId, float launchSpeed)
|
||||
{
|
||||
Flag = flag;
|
||||
PoolIndex = poolIndex;
|
||||
MeteorId = meteorId;
|
||||
LaunchSpeed = launchSpeed;
|
||||
|
||||
AttachedObject.LaunchMeteor();
|
||||
|
Loading…
x
Reference in New Issue
Block a user