mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-10 07:14:27 +00:00
more progress
This commit is contained in:
parent
0c897ad3bd
commit
292d4ce5f5
@ -1,34 +1,36 @@
|
||||
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
|
||||
{
|
||||
public class MeteorImpactEvent : QSBEvent<WorldObjectMessage>
|
||||
public class MeteorImpactEvent : QSBEvent<MeteorImpactMessage>
|
||||
{
|
||||
public override EventType Type => EventType.MeteorImpact;
|
||||
|
||||
public override void SetupListener()
|
||||
=> GlobalMessenger<QSBMeteor>.AddListener(EventNames.QSBMeteorImpact, Handler);
|
||||
=> GlobalMessenger<int, Vector3, Vector3, float>.AddListener(EventNames.QSBMeteorImpact, Handler);
|
||||
|
||||
public override void CloseListener()
|
||||
=> GlobalMessenger<QSBMeteor>.RemoveListener(EventNames.QSBMeteorImpact, Handler);
|
||||
=> GlobalMessenger<int, Vector3, Vector3, float>.RemoveListener(EventNames.QSBMeteorImpact, Handler);
|
||||
|
||||
private void Handler(QSBMeteor qsbMeteor) => SendEvent(CreateMessage(qsbMeteor));
|
||||
private void Handler(int id, Vector3 pos, Vector3 vel, float damage) => SendEvent(CreateMessage(id, pos, vel, damage));
|
||||
|
||||
private WorldObjectMessage CreateMessage(QSBMeteor qsbMeteor) => new WorldObjectMessage
|
||||
private MeteorImpactMessage CreateMessage(int id, Vector3 pos, Vector3 vel, float damage) => new MeteorImpactMessage
|
||||
{
|
||||
ObjectId = qsbMeteor.ObjectId
|
||||
// todo where
|
||||
// todo velocity
|
||||
ObjectId = id,
|
||||
Position = pos,
|
||||
RelativeVelocity = vel,
|
||||
Damage = damage
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(bool isHost, WorldObjectMessage message)
|
||||
public override void OnReceiveRemote(bool isHost, MeteorImpactMessage message)
|
||||
{
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromId<QSBMeteor>(message.ObjectId);
|
||||
// todo
|
||||
qsbMeteor.Impact(message.Position, message.RelativeVelocity, message.Damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
29
QSB/MeteorSync/Events/MeteorImpactMessage.cs
Normal file
29
QSB/MeteorSync/Events/MeteorImpactMessage.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using QSB.WorldSync.Events;
|
||||
using QuantumUNET.Transport;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.MeteorSync.Events
|
||||
{
|
||||
public class MeteorImpactMessage : WorldObjectMessage
|
||||
{
|
||||
public Vector3 Position;
|
||||
public Vector3 RelativeVelocity;
|
||||
public float Damage;
|
||||
|
||||
public override void Deserialize(QNetworkReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
Position = reader.ReadVector3();
|
||||
RelativeVelocity = reader.ReadVector3();
|
||||
Damage = reader.ReadSingle();
|
||||
}
|
||||
|
||||
public override void Serialize(QNetworkWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
writer.Write(Position);
|
||||
writer.Write(RelativeVelocity);
|
||||
writer.Write(Damage);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,12 @@
|
||||
using HarmonyLib;
|
||||
using OWML.Common;
|
||||
using QSB.Events;
|
||||
using QSB.MeteorSync.WorldObjects;
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.MeteorSync.Patches
|
||||
{
|
||||
@ -42,6 +49,8 @@ namespace QSB.MeteorSync.Patches
|
||||
}
|
||||
}
|
||||
|
||||
// skip meteor launching
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -50,11 +59,60 @@ namespace QSB.MeteorSync.Patches
|
||||
[HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Launch))]
|
||||
public static void Launch(MeteorController __instance)
|
||||
{
|
||||
// display collisions again because we are client and have no say
|
||||
foreach (var owCollider in __instance._owColliders)
|
||||
{
|
||||
owCollider.SetActivation(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Impact))]
|
||||
public static bool Impact(MeteorController __instance,
|
||||
GameObject hitObject, Vector3 impactPoint, Vector3 impactVel)
|
||||
{
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromUnity<QSBMeteor>(__instance);
|
||||
DebugLog.DebugWrite($"{QSBPlayerManager.LocalPlayerId} {qsbMeteor.ObjectId} - oh no! hit obj is null (for now)", MessageType.Error);
|
||||
|
||||
var componentInParent = hitObject.GetComponentInParent<FragmentIntegrity>();
|
||||
if (componentInParent != null)
|
||||
{
|
||||
// get damage from server
|
||||
var damage = qsbMeteor.Damage;
|
||||
if (!componentInParent.GetIgnoreMeteorDamage())
|
||||
{
|
||||
componentInParent.AddDamage(damage);
|
||||
}
|
||||
else if (componentInParent.GetParentFragment() != null && !componentInParent.GetParentFragment().GetIgnoreMeteorDamage())
|
||||
{
|
||||
componentInParent.GetParentFragment().AddDamage(damage);
|
||||
}
|
||||
}
|
||||
MeteorImpactMapper.RecordImpact(impactPoint, componentInParent);
|
||||
__instance._intactRenderer.enabled = false;
|
||||
__instance._impactLight.enabled = true;
|
||||
__instance._impactLight.intensity = __instance._impactLightCurve.Evaluate(0f);
|
||||
var rotation = Quaternion.LookRotation(impactVel);
|
||||
foreach (var particleSystem in __instance._impactParticles)
|
||||
{
|
||||
particleSystem.transform.rotation = rotation;
|
||||
particleSystem.Play();
|
||||
}
|
||||
__instance._impactSource.PlayOneShot(AudioType.BH_MeteorImpact);
|
||||
foreach (var owCollider in __instance._owColliders)
|
||||
{
|
||||
owCollider.SetActivation(false);
|
||||
}
|
||||
__instance._owRigidbody.MakeKinematic();
|
||||
__instance.transform.SetParent(hitObject.GetAttachedOWRigidbody().transform);
|
||||
FragmentSurfaceProxy.UntrackMeteor(__instance);
|
||||
FragmentCollisionProxy.UntrackMeteor(__instance);
|
||||
__instance._ignoringCollisions = false;
|
||||
__instance._hasImpacted = true;
|
||||
__instance._impactTime = Time.time;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,12 +78,53 @@ namespace QSB.MeteorSync.Patches
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Impact))]
|
||||
public static void Impact(MeteorController __instance)
|
||||
public static bool Impact(MeteorController __instance,
|
||||
GameObject hitObject, Vector3 impactPoint, Vector3 impactVel)
|
||||
{
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromUnity<QSBMeteor>(__instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBMeteorImpact, qsbMeteor);
|
||||
|
||||
var componentInParent = hitObject.GetComponentInParent<FragmentIntegrity>();
|
||||
var damage = float.NaN;
|
||||
if (componentInParent != null)
|
||||
{
|
||||
damage = Random.Range(__instance._minDamage, __instance._maxDamage);
|
||||
if (!componentInParent.GetIgnoreMeteorDamage())
|
||||
{
|
||||
componentInParent.AddDamage(damage);
|
||||
}
|
||||
else if (componentInParent.GetParentFragment() != null && !componentInParent.GetParentFragment().GetIgnoreMeteorDamage())
|
||||
{
|
||||
componentInParent.GetParentFragment().AddDamage(damage);
|
||||
}
|
||||
}
|
||||
MeteorImpactMapper.RecordImpact(impactPoint, componentInParent);
|
||||
__instance._intactRenderer.enabled = false;
|
||||
__instance._impactLight.enabled = true;
|
||||
__instance._impactLight.intensity = __instance._impactLightCurve.Evaluate(0f);
|
||||
var rotation = Quaternion.LookRotation(impactVel);
|
||||
foreach (var particleSystem in __instance._impactParticles)
|
||||
{
|
||||
particleSystem.transform.rotation = rotation;
|
||||
particleSystem.Play();
|
||||
}
|
||||
__instance._impactSource.PlayOneShot(AudioType.BH_MeteorImpact);
|
||||
foreach (var owCollider in __instance._owColliders)
|
||||
{
|
||||
owCollider.SetActivation(false);
|
||||
}
|
||||
__instance._owRigidbody.MakeKinematic();
|
||||
__instance.transform.SetParent(hitObject.GetAttachedOWRigidbody().transform);
|
||||
FragmentSurfaceProxy.UntrackMeteor(__instance);
|
||||
FragmentCollisionProxy.UntrackMeteor(__instance);
|
||||
__instance._ignoringCollisions = false;
|
||||
__instance._hasImpacted = true;
|
||||
__instance._impactTime = Time.time;
|
||||
|
||||
QSBEventManager.FireEvent(EventNames.QSBMeteorImpact, qsbMeteor.ObjectId, impactPoint, impactVel, damage);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
using QSB.MeteorSync.TransformSync;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace QSB.MeteorSync.WorldObjects
|
||||
@ -47,10 +49,16 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
}
|
||||
|
||||
|
||||
public float Damage;
|
||||
|
||||
public void Impact()
|
||||
public void Impact(Vector3 position, Vector3 relativeVelocity, float damage)
|
||||
{
|
||||
// todo
|
||||
DebugLog.DebugWrite($"{QSBPlayerManager.LocalPlayerId} {ObjectId} - impact! "
|
||||
+ $"{position} {relativeVelocity} {damage}");
|
||||
|
||||
Damage = damage;
|
||||
// todo get object
|
||||
AttachedObject.Impact(null, position, relativeVelocity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using QSB.WorldSync;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
|
||||
namespace QSB.MeteorSync.WorldObjects
|
||||
{
|
||||
@ -15,6 +17,8 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
{
|
||||
if (preLaunch)
|
||||
{
|
||||
DebugLog.DebugWrite($"{QSBPlayerManager.LocalPlayerId} {ObjectId} - pre launch");
|
||||
|
||||
foreach (var particleSystem in AttachedObject._launchParticles)
|
||||
{
|
||||
particleSystem.Play();
|
||||
@ -22,6 +26,8 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLog.DebugWrite($"{QSBPlayerManager.LocalPlayerId} {ObjectId} - launch");
|
||||
|
||||
AttachedObject.LaunchMeteor();
|
||||
foreach (var particleSystem in AttachedObject._launchParticles)
|
||||
{
|
||||
|
@ -125,6 +125,7 @@
|
||||
<Compile Include="Menus\MenuManager.cs" />
|
||||
<Compile Include="Messaging\BoolMessage.cs" />
|
||||
<Compile Include="MeteorSync\Events\MeteorImpactEvent.cs" />
|
||||
<Compile Include="MeteorSync\Events\MeteorImpactMessage.cs" />
|
||||
<Compile Include="MeteorSync\Events\MeteorLaunchEvent.cs" />
|
||||
<Compile Include="MeteorSync\Events\MeteorResyncEvent.cs" />
|
||||
<Compile Include="MeteorSync\MeteorManager.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user