mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-10 16:14:45 +00:00
make impacting work
This commit is contained in:
parent
15af7e1ce3
commit
fdeaf8111a
@ -22,8 +22,6 @@ namespace QSB.MeteorSync.Events
|
||||
private MeteorImpactMessage CreateMessage(int id, Vector3 pos, Vector3 vel, float damage) => new MeteorImpactMessage
|
||||
{
|
||||
ObjectId = id,
|
||||
Position = pos,
|
||||
RelativeVelocity = vel,
|
||||
Damage = damage
|
||||
};
|
||||
|
||||
@ -35,7 +33,7 @@ namespace QSB.MeteorSync.Events
|
||||
}
|
||||
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromId<QSBMeteor>(message.ObjectId);
|
||||
qsbMeteor.Impact(message.Position, message.RelativeVelocity, message.Damage);
|
||||
qsbMeteor.Impact(message.Damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,21 @@
|
||||
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,6 +1,8 @@
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using HarmonyLib;
|
||||
using QSB.MeteorSync.WorldObjects;
|
||||
using QSB.Patches;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using UnityEngine;
|
||||
|
||||
@ -71,10 +73,10 @@ namespace QSB.MeteorSync.Patches
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromUnity<QSBMeteor>(__instance);
|
||||
|
||||
var componentInParent = hitObject.GetComponentInParent<FragmentIntegrity>();
|
||||
if (componentInParent != null)
|
||||
{
|
||||
// get damage from server
|
||||
var damage = qsbMeteor.Damage;
|
||||
if (componentInParent != null)
|
||||
{
|
||||
if (!componentInParent.GetIgnoreMeteorDamage())
|
||||
{
|
||||
componentInParent.AddDamage(damage);
|
||||
@ -107,7 +109,24 @@ namespace QSB.MeteorSync.Patches
|
||||
__instance._hasImpacted = true;
|
||||
__instance._impactTime = Time.time;
|
||||
|
||||
DebugLog.DebugWrite($"{qsbMeteor.LogName} - impact! "
|
||||
+ $"{hitObject.name} {impactPoint} {impactVel} {damage}");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Suspend), new Type[0])]
|
||||
public static void Suspend(MeteorController __instance)
|
||||
{
|
||||
if (!MeteorManager.MeteorsReady)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var qsbMeteor = QSBWorldSync.GetWorldFromUnity<QSBMeteor>(__instance);
|
||||
DebugLog.DebugWrite($"{qsbMeteor.LogName} - suspended");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using QSB.MeteorSync.TransformSync;
|
||||
using System.Linq;
|
||||
using OWML.Common;
|
||||
using QSB.MeteorSync.TransformSync;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using QuantumUNET;
|
||||
@ -48,16 +50,21 @@ namespace QSB.MeteorSync.WorldObjects
|
||||
}
|
||||
|
||||
|
||||
public float Damage;
|
||||
public float Damage = float.NaN;
|
||||
|
||||
public void Impact(Vector3 position, Vector3 relativeVelocity, float damage)
|
||||
public void Impact(float damage)
|
||||
{
|
||||
DebugLog.DebugWrite($"{LogName} - impact! "
|
||||
+ $"{position} {relativeVelocity} {damage}");
|
||||
|
||||
Damage = damage;
|
||||
// todo get object
|
||||
// AttachedObject.Impact(null, position, relativeVelocity);
|
||||
|
||||
// just in case, set this up so even if no hit happens, it will reset itself eventually
|
||||
AttachedObject._hasImpacted = true;
|
||||
AttachedObject._impactTime = Time.time;
|
||||
|
||||
// let the collision happen naturally
|
||||
foreach (var owCollider in AttachedObject._owColliders)
|
||||
{
|
||||
owCollider.SetActivation(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user