sync detaching

This commit is contained in:
Mister_Nebula 2022-05-14 12:18:48 +01:00
parent 6596cab2b5
commit 942535c162
12 changed files with 189 additions and 32 deletions

View File

@ -15,30 +15,6 @@ public class DeathPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
// TODO : Remove with future functionality.
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipEjectionSystem), nameof(ShipEjectionSystem.OnPressInteract))]
public static bool DisableEjection()
=> false;
// TODO : Remove with future functionality.
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipDetachableLeg), nameof(ShipDetachableLeg.Detach))]
public static bool ShipDetachableLeg_Detach(out OWRigidbody __result)
{
__result = null;
return false;
}
// TODO : Remove with future functionality.
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipDetachableModule), nameof(ShipDetachableModule.Detach))]
public static bool ShipDetachableModule_Detach(out OWRigidbody __result)
{
__result = null;
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerResources), nameof(PlayerResources.OnImpact))]
public static bool PlayerResources_OnImpact(PlayerResources __instance, ImpactData impact) =>
@ -260,13 +236,6 @@ public class DeathPatches : QSBPatch
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipDamageController), nameof(ShipDamageController.Explode))]
public static bool ShipDamageController_Explode()
// prevent ship from exploding
// todo remove this when sync ship explosions
=> false;
[HarmonyPrefix]
[HarmonyPatch(typeof(DestructionVolume), nameof(DestructionVolume.VanishShip))]
public static bool DestructionVolume_VanishShip(DestructionVolume __instance)

View File

@ -28,6 +28,8 @@ public class PlayerJoinMessage : QSBMessage
var allEnabledMods = QSBCore.Helper.Interaction.GetMods();
FirstIncompatibleMod = "";
#if RELEASE
foreach (var mod in allEnabledMods)
{
if (QSBCore.IncompatibleMods.Contains(mod.ModHelper.Manifest.UniqueName))
@ -35,6 +37,7 @@ public class PlayerJoinMessage : QSBMessage
FirstIncompatibleMod = mod.ModHelper.Manifest.UniqueName;
}
}
#endif
AddonHashes = QSBCore.Addons.Keys
.Select(x => x.GetStableHashCode())

View File

@ -49,6 +49,8 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
public GameObject DoorPrefab { get; private set; }
public GameObject ElevatorPrefab { get; private set; }
public GameObject AirlockPrefab { get; private set; }
public GameObject ShipModulePrefab { get; private set; }
public GameObject ShipLegPrefab { get; private set; }
private string PlayerName { get; set; }
private GameObject _probePrefab;
@ -130,6 +132,12 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
AirlockPrefab = MakeNewNetworkObject(11, "NetworkGhostAirlock", typeof(AirlockVariableSyncer));
spawnPrefabs.Add(AirlockPrefab);
ShipModulePrefab = MakeNewNetworkObject(12, "NetworkShipModule", typeof(ShipModuleTransformSync));
spawnPrefabs.Add(ShipModulePrefab);
ShipLegPrefab = MakeNewNetworkObject(13, "NetworkShipLeg", typeof(ShipLegTransformSync));
spawnPrefabs.Add(ShipLegPrefab);
ConfigureNetworkManager();
}

View File

@ -0,0 +1,17 @@
using QSB.Messaging;
using QSB.ShipSync.WorldObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QSB.ShipSync.Messages;
internal class ModuleDetachMessage : QSBWorldObjectMessage<QSBShipDetachableModule>
{
public override void OnReceiveRemote()
{
WorldObject.AttachedObject.Detach();
}
}

View File

@ -0,0 +1,23 @@
using HarmonyLib;
using QSB.Messaging;
using QSB.Patches;
using QSB.ShipSync.Messages;
using QSB.ShipSync.WorldObjects;
using QSB.Utility;
using QSB.WorldSync;
using UnityEngine;
namespace QSB.ShipSync.Patches;
[HarmonyPatch(typeof(ShipDetachableModule))]
internal class ShipDetachableModulePatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPostfix]
[HarmonyPatch(nameof(ShipDetachableModule.Detach))]
public static void Detach(ShipDetachableModule __instance)
{
__instance.GetWorldObject<QSBShipDetachableModule>().SendMessage(new ModuleDetachMessage());
}
}

View File

@ -128,6 +128,9 @@ internal class ShipManager : WorldObjectManager
ShipCockpitUI._probeLauncherScreenLight,
ShipCockpitUI._sigScopeScreenLight
});
QSBWorldSync.Init<QSBShipDetachableModule, ShipDetachableModule>();
QSBWorldSync.Init<QSBShipDetachableLeg, ShipDetachableLeg>();
}
public override void UnbuildWorldObjects() => Destroy(_shipCustomAttach);

View File

@ -0,0 +1,45 @@
using QSB.ShipSync.WorldObjects;
using QSB.Syncs.Sectored.Rigidbodies;
using QSB.Utility.LinkedWorldObject;
using QSB.WorldSync;
namespace QSB.ShipSync.TransformSync;
internal class ShipLegTransformSync : SectoredRigidbodySync, ILinkedNetworkBehaviour
{
/// <summary>
/// normally prints error when attached object is null.
/// this overrides it so that doesn't happen, since the module can be destroyed.
/// </summary>
protected override bool CheckValid()
=> AttachedTransform
&& base.CheckValid();
protected override bool CheckReady()
=> _qsbModule != null
&& _qsbModule.AttachedObject.isDetached
&& base.CheckReady();
protected override bool UseInterpolation => true;
protected override float DistanceChangeThreshold => 1f;
private QSBShipDetachableLeg _qsbModule;
public void SetWorldObject(IWorldObject worldObject) => _qsbModule = (QSBShipDetachableLeg)worldObject;
protected override OWRigidbody InitAttachedRigidbody()
{
var owRigidbody = _qsbModule.AttachedObject.GetComponent<OWRigidbody>();
SectorDetector.Init(owRigidbody.transform.Find("DetectorVolume").GetComponent<SectorDetector>());
return owRigidbody;
}
protected override void ApplyToAttached()
{
if (!_qsbModule.AttachedObject.isDetached)
{
return;
}
base.ApplyToAttached();
}
}

View File

@ -0,0 +1,45 @@
using QSB.ShipSync.WorldObjects;
using QSB.Syncs.Sectored.Rigidbodies;
using QSB.Utility.LinkedWorldObject;
using QSB.WorldSync;
namespace QSB.ShipSync.TransformSync;
internal class ShipModuleTransformSync : SectoredRigidbodySync, ILinkedNetworkBehaviour
{
/// <summary>
/// normally prints error when attached object is null.
/// this overrides it so that doesn't happen, since the module can be destroyed.
/// </summary>
protected override bool CheckValid()
=> AttachedTransform
&& base.CheckValid();
protected override bool CheckReady()
=> _qsbModule != null
&& _qsbModule.AttachedObject.isDetached
&& base.CheckReady();
protected override bool UseInterpolation => true;
protected override float DistanceChangeThreshold => 1f;
private QSBShipDetachableModule _qsbModule;
public void SetWorldObject(IWorldObject worldObject) => _qsbModule = (QSBShipDetachableModule)worldObject;
protected override OWRigidbody InitAttachedRigidbody()
{
var owRigidbody = _qsbModule.AttachedObject.GetComponent<OWRigidbody>();
SectorDetector.Init(owRigidbody.transform.Find("DetectorVolume").GetComponent<SectorDetector>());
return owRigidbody;
}
protected override void ApplyToAttached()
{
if (!_qsbModule.AttachedObject.isDetached)
{
return;
}
base.ApplyToAttached();
}
}

View File

@ -0,0 +1,21 @@
using QSB.ShipSync.TransformSync;
using QSB.Utility.LinkedWorldObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.ShipSync.WorldObjects;
internal class QSBShipDetachableLeg : LinkedWorldObject<ShipDetachableLeg, ShipLegTransformSync>
{
protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.ShipLegPrefab;
protected override bool SpawnWithServerAuthority => true;
public override void SendInitialState(uint to)
{
}
}

View File

@ -0,0 +1,21 @@
using QSB.ShipSync.TransformSync;
using QSB.Utility.LinkedWorldObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace QSB.ShipSync.WorldObjects;
internal class QSBShipDetachableModule : LinkedWorldObject<ShipDetachableModule, ShipModuleTransformSync>
{
protected override GameObject NetworkObjectPrefab => QSBNetworkManager.singleton.ShipModulePrefab;
protected override bool SpawnWithServerAuthority => true;
public override void SendInitialState(uint to)
{
}
}

View File

@ -22,6 +22,8 @@ public static class Extensions
/// </summary>
public static void SpawnLinked(this ILinkedWorldObject<NetworkBehaviour> worldObject, GameObject prefab, bool spawnWithServerAuthority)
{
DebugLog.DebugWrite($"SpawnLinked {prefab.name}");
var go = Object.Instantiate(prefab);
var networkBehaviour = go.GetComponent<ILinkedNetworkBehaviour>();

View File

@ -9,6 +9,6 @@
"uniqueName": "Raicuparta.QuantumSpaceBuddies",
"version": "0.19.0",
"owmlVersion": "2.3.3",
"dependencies": [ "_nebula.MenuFramework" ],
"dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ],
"pathsToPreserve": [ "debugsettings.json", "storage.json" ]
}