2021-11-10 21:13:49 -08:00
|
|
|
|
using HarmonyLib;
|
2021-11-10 21:36:30 -08:00
|
|
|
|
using QSB.MeteorSync.WorldObjects;
|
2021-11-10 21:13:49 -08:00
|
|
|
|
using QSB.Patches;
|
2021-11-10 21:36:30 -08:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
using UnityEngine;
|
2021-11-10 21:13:49 -08:00
|
|
|
|
|
|
|
|
|
namespace QSB.MeteorSync.Patches
|
|
|
|
|
{
|
|
|
|
|
public class MeteorClientPatches : QSBPatch
|
|
|
|
|
{
|
|
|
|
|
public override QSBPatchTypes Type => QSBPatchTypes.OnNonServerClientConnect;
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(typeof(MeteorLauncher), nameof(MeteorLauncher.FixedUpdate))]
|
|
|
|
|
public static bool FixedUpdate(MeteorLauncher __instance)
|
|
|
|
|
{
|
|
|
|
|
if (__instance._launchedMeteors != null)
|
|
|
|
|
{
|
|
|
|
|
for (var i = __instance._launchedMeteors.Count - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
if (__instance._launchedMeteors[i] == null)
|
|
|
|
|
{
|
|
|
|
|
__instance._launchedMeteors.QuickRemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
else if (__instance._launchedMeteors[i].isSuspended)
|
|
|
|
|
{
|
|
|
|
|
__instance._meteorPool.Add(__instance._launchedMeteors[i]);
|
|
|
|
|
__instance._launchedMeteors.QuickRemoveAt(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (__instance._launchedDynamicMeteors != null)
|
|
|
|
|
{
|
|
|
|
|
for (var j = __instance._launchedDynamicMeteors.Count - 1; j >= 0; j--)
|
|
|
|
|
{
|
|
|
|
|
if (__instance._launchedDynamicMeteors[j] == null)
|
|
|
|
|
{
|
|
|
|
|
__instance._launchedDynamicMeteors.QuickRemoveAt(j);
|
|
|
|
|
}
|
|
|
|
|
else if (__instance._launchedDynamicMeteors[j].isSuspended)
|
|
|
|
|
{
|
|
|
|
|
__instance._dynamicMeteorPool.Add(__instance._launchedDynamicMeteors[j]);
|
|
|
|
|
__instance._launchedDynamicMeteors.QuickRemoveAt(j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 21:36:30 -08:00
|
|
|
|
// skip meteor launching
|
|
|
|
|
|
2021-11-10 21:13:49 -08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HarmonyPostfix]
|
|
|
|
|
[HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Launch))]
|
|
|
|
|
public static void Launch(MeteorController __instance)
|
|
|
|
|
{
|
2021-11-10 22:08:57 -08:00
|
|
|
|
// disable stuff again because we are client and have no say
|
2021-11-10 21:36:30 -08:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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);
|
2021-11-10 21:13:49 -08:00
|
|
|
|
foreach (var owCollider in __instance._owColliders)
|
|
|
|
|
{
|
|
|
|
|
owCollider.SetActivation(false);
|
|
|
|
|
}
|
|
|
|
|
__instance._owRigidbody.MakeKinematic();
|
2021-11-10 21:36:30 -08:00
|
|
|
|
__instance.transform.SetParent(hitObject.GetAttachedOWRigidbody().transform);
|
|
|
|
|
FragmentSurfaceProxy.UntrackMeteor(__instance);
|
|
|
|
|
FragmentCollisionProxy.UntrackMeteor(__instance);
|
|
|
|
|
__instance._ignoringCollisions = false;
|
|
|
|
|
__instance._hasImpacted = true;
|
|
|
|
|
__instance._impactTime = Time.time;
|
|
|
|
|
|
|
|
|
|
return false;
|
2021-11-10 21:13:49 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|