mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-11 06:40:39 +00:00
Sync HazardVolume damage sounds
This commit is contained in:
parent
2de5e835ec
commit
45f88cad3b
@ -0,0 +1,12 @@
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
|
||||
namespace QSB.Audio.Messages;
|
||||
|
||||
internal class PlayerAudioControllerUpdateHazardDamageMessage : QSBMessage<(uint userID, HazardVolume.HazardType latestHazardType)>
|
||||
{
|
||||
public PlayerAudioControllerUpdateHazardDamageMessage((uint userID, HazardVolume.HazardType latestHazardType) data) : base(data) { }
|
||||
|
||||
public override void OnReceiveRemote() =>
|
||||
QSBPlayerManager.GetPlayer(Data.userID)?.AudioController.SetHazardDamage(Data.latestHazardType);
|
||||
}
|
@ -3,6 +3,7 @@ using QSB.Audio.Messages;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
using QSB.Player;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Audio.Patches;
|
||||
|
||||
@ -49,4 +50,15 @@ internal class PlayerAudioControllerPatches : QSBPatch
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlayerAudioController), nameof(PlayerAudioController.OnArtifactUnconceal))]
|
||||
public static void PlayerAudioController_OnArtifactUnconceal() => PlayOneShot(AudioType.Artifact_Unconceal);
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(PlayerAudioController), nameof(PlayerAudioController.UpdateHazardDamage))]
|
||||
public static void PlayerAudioController_UpdateHazardDamage(PlayerAudioController __instance, float damage, HazardDetector hazardDetector)
|
||||
{
|
||||
var hazardType = damage > 0f ? hazardDetector.GetLatestHazardType() : HazardVolume.HazardType.NONE;
|
||||
if (hazardType != __instance._hazardTypePlaying)
|
||||
{
|
||||
new PlayerAudioControllerUpdateHazardDamageMessage((QSBPlayerManager.LocalPlayerId, hazardDetector.GetLatestHazardType())).Send();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using QSB.Utility;
|
||||
using QSB.PlayerBodySetup.Remote;
|
||||
using QSB.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.Audio;
|
||||
@ -8,6 +9,26 @@ public class QSBPlayerAudioController : MonoBehaviour
|
||||
{
|
||||
public OWAudioSource _oneShotExternalSource;
|
||||
public OWAudioSource _repairToolSource;
|
||||
public OWAudioSource _damageAudioSource;
|
||||
|
||||
private AudioManager _audioManager;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_audioManager = Locator.GetAudioManager();
|
||||
|
||||
// This should be done in the Unity project
|
||||
var damageAudio = new GameObject("DamageAudioSource");
|
||||
damageAudio.SetActive(false);
|
||||
damageAudio.transform.SetParent(transform, false);
|
||||
damageAudio.transform.localPosition = Vector3.zero;
|
||||
_damageAudioSource = damageAudio.AddComponent<OWAudioSource>();
|
||||
_damageAudioSource._audioSource = damageAudio.GetAddComponent<AudioSource>();
|
||||
_damageAudioSource.SetTrack(_repairToolSource.GetTrack());
|
||||
_damageAudioSource.spatialBlend = 1f;
|
||||
_damageAudioSource.gameObject.GetAddComponent<QSBDopplerFixer>();
|
||||
damageAudio.SetActive(true);
|
||||
}
|
||||
|
||||
public void PlayEquipTool()
|
||||
=> _oneShotExternalSource?.PlayOneShot(AudioType.ToolTranslatorEquip);
|
||||
@ -41,4 +62,41 @@ public class QSBPlayerAudioController : MonoBehaviour
|
||||
|
||||
public void OnJump(float pitch) =>
|
||||
PlayOneShot(AudioType.MovementJump, pitch, 0.7f);
|
||||
|
||||
private void StartHazardDamage(HazardVolume.HazardType latestHazardType)
|
||||
{
|
||||
var type = AudioType.EnterVolumeDamageHeat_LP;
|
||||
if (latestHazardType == HazardVolume.HazardType.DARKMATTER)
|
||||
{
|
||||
type = AudioType.EnterVolumeDamageGhostfire_LP;
|
||||
}
|
||||
else if (latestHazardType == HazardVolume.HazardType.FIRE)
|
||||
{
|
||||
type = AudioType.EnterVolumeDamageFire_LP;
|
||||
}
|
||||
|
||||
_damageAudioSource.clip = _audioManager.GetSingleAudioClip(type, true);
|
||||
_damageAudioSource.Stop();
|
||||
_damageAudioSource.FadeIn(0.2f, true, true, 1f);
|
||||
}
|
||||
|
||||
private void EndHazardDamage()
|
||||
{
|
||||
if (_damageAudioSource.isPlaying)
|
||||
{
|
||||
_damageAudioSource.FadeOut(0.5f, OWAudioSource.FadeOutCompleteAction.STOP, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetHazardDamage(HazardVolume.HazardType latestHazardType)
|
||||
{
|
||||
if (latestHazardType == HazardVolume.HazardType.NONE)
|
||||
{
|
||||
EndHazardDamage();
|
||||
}
|
||||
else
|
||||
{
|
||||
StartHazardDamage(latestHazardType);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user