mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2024-12-28 18:25:18 +00:00
Synced model ship thruster VFX
This commit is contained in:
parent
3c9c6333ec
commit
2c970f44fb
@ -2,12 +2,6 @@
|
||||
using QSB.Audio.Messages;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QSB.Audio.Patches;
|
||||
|
||||
@ -38,7 +32,9 @@ internal class ThrusterAudioPatches : QSBPatch
|
||||
if (tracker.LastPlayed != AudioType.None)
|
||||
{
|
||||
if (__instance is ShipThrusterAudio)
|
||||
{
|
||||
new ShipThrusterAudioOneShotMessage(tracker.LastPlayed, tracker.Pitch, tracker.Volume).Send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using Mirror;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using QSB.Utility.VariableSync;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,7 +8,7 @@ using UnityEngine;
|
||||
|
||||
namespace QSB.ModelShip;
|
||||
|
||||
public class ModelShipThrusterVariableSyncer : NetworkBehaviour
|
||||
public class ModelShipThrusterVariableSyncer : MonoBehaviour
|
||||
{
|
||||
public Vector3VariableSyncer AccelerationSyncer;
|
||||
|
||||
@ -15,21 +16,17 @@ public class ModelShipThrusterVariableSyncer : NetworkBehaviour
|
||||
private ThrusterAudio _thrusterAudio;
|
||||
public List<ThrusterFlameController> ThrusterFlameControllers = new();
|
||||
|
||||
public static ModelShipThrusterVariableSyncer LocalInstance;
|
||||
|
||||
public void Start()
|
||||
public void Init(GameObject modelShip)
|
||||
{
|
||||
LocalInstance = this;
|
||||
}
|
||||
DebugLog.ToConsole("init model ship");
|
||||
|
||||
public void Init()
|
||||
{
|
||||
_thrusterModel = gameObject.GetComponent<ThrusterModel>();
|
||||
_thrusterAudio = gameObject.GetComponentInChildren<ThrusterAudio>();
|
||||
_thrusterModel = modelShip.GetComponent<ThrusterModel>();
|
||||
_thrusterAudio = modelShip.GetComponentInChildren<ThrusterAudio>();
|
||||
|
||||
ThrusterFlameControllers.Clear();
|
||||
foreach (var item in gameObject.GetComponentsInChildren<ThrusterFlameController>())
|
||||
foreach (var item in modelShip.GetComponentsInChildren<ThrusterFlameController>())
|
||||
{
|
||||
DebugLog.ToConsole("adding thruster");
|
||||
ThrusterFlameControllers.Add(item);
|
||||
}
|
||||
}
|
||||
@ -38,14 +35,18 @@ public class ModelShipThrusterVariableSyncer : NetworkBehaviour
|
||||
{
|
||||
if (QSBPlayerManager.LocalPlayer.FlyingModelShip)
|
||||
{
|
||||
DebugLog.ToConsole($"{QSBPlayerManager.LocalPlayerId} is flying the model ship");
|
||||
GetFromShip();
|
||||
return;
|
||||
}
|
||||
|
||||
if (AccelerationSyncer.public_HasChanged())
|
||||
{
|
||||
DebugLog.ToConsole("value changed");
|
||||
|
||||
if (AccelerationSyncer.Value == Vector3.zero)
|
||||
{
|
||||
DebugLog.ToConsole("not flying");
|
||||
foreach (var item in ThrusterFlameControllers)
|
||||
{
|
||||
item.OnStopTranslationalThrust();
|
||||
@ -57,6 +58,7 @@ public class ModelShipThrusterVariableSyncer : NetworkBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugLog.ToConsole("flying");
|
||||
foreach (var item in ThrusterFlameControllers)
|
||||
{
|
||||
item.OnStartTranslationalThrust();
|
||||
@ -71,8 +73,10 @@ public class ModelShipThrusterVariableSyncer : NetworkBehaviour
|
||||
|
||||
private void GetFromShip()
|
||||
{
|
||||
DebugLog.ToConsole("Getting from ship");
|
||||
if (_thrusterModel)
|
||||
{
|
||||
DebugLog.ToConsole("Update local acc");
|
||||
AccelerationSyncer.Value = _thrusterModel.GetLocalAcceleration();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using HarmonyLib;
|
||||
using QSB.ModelShip.TransformSync;
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using System.Linq;
|
||||
@ -14,26 +15,18 @@ internal class ModelShipThrusterPatches : QSBPatch
|
||||
[HarmonyPatch(typeof(ThrusterFlameController), nameof(ThrusterFlameController.GetThrustFraction))]
|
||||
public static bool GetThrustFraction(ThrusterFlameController __instance, ref float __result)
|
||||
{
|
||||
if (!ModelShipThrusterVariableSyncer.LocalInstance.ThrusterFlameControllers.Contains(__instance))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
var modelShipThrusters = ModelShipTransformSync.LocalInstance?.ThrusterVariableSyncer;
|
||||
|
||||
if (!__instance._thrusterModel.IsThrusterBankEnabled(OWUtilities.GetShipThrusterBank(__instance._thruster)))
|
||||
{
|
||||
__result = 0f;
|
||||
return false;
|
||||
}
|
||||
if (modelShipThrusters == null) return true;
|
||||
|
||||
if (QSBPlayerManager.LocalPlayer.FlyingModelShip)
|
||||
if (modelShipThrusters.ThrusterFlameControllers.Contains(__instance) && !QSBPlayerManager.LocalPlayer.FlyingModelShip)
|
||||
{
|
||||
__result = Vector3.Dot(__instance._thrusterModel.GetLocalAcceleration(), __instance._thrusterFilter);
|
||||
if(__instance._thrusterModel.IsThrusterBankEnabled(OWUtilities.GetShipThrusterBank(__instance._thruster)))
|
||||
{
|
||||
__result = Vector3.Dot(modelShipThrusters.AccelerationSyncer.Value, __instance._thrusterFilter);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
__result = Vector3.Dot(ModelShipThrusterVariableSyncer.LocalInstance.AccelerationSyncer.Value, __instance._thrusterFilter);
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using QSB.Syncs.Sectored.Rigidbodies;
|
||||
using QSB.ShipSync;
|
||||
using QSB.Syncs.Sectored.Rigidbodies;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
|
||||
@ -8,6 +9,8 @@ internal class ModelShipTransformSync : SectoredRigidbodySync
|
||||
{
|
||||
public static ModelShipTransformSync LocalInstance { get; private set; }
|
||||
|
||||
public ModelShipThrusterVariableSyncer ThrusterVariableSyncer { get; private set; }
|
||||
|
||||
public override void OnStartClient()
|
||||
{
|
||||
base.OnStartClient();
|
||||
@ -31,6 +34,14 @@ internal class ModelShipTransformSync : SectoredRigidbodySync
|
||||
return modelShip;
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
ThrusterVariableSyncer = this.GetRequiredComponent<ModelShipThrusterVariableSyncer>();
|
||||
ThrusterVariableSyncer.Init(AttachedRigidbody.gameObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// replacement for base method
|
||||
/// using SetPos/Rot instead of Move
|
||||
|
Loading…
Reference in New Issue
Block a user