Sync marshmallow roasting related sounds

This commit is contained in:
Nick 2022-08-27 17:04:15 -04:00
parent 4008225e5e
commit d2387de39a
3 changed files with 56 additions and 7 deletions

View File

@ -0,0 +1,16 @@
using QSB.Messaging;
using QSB.Player;
using QSB.WorldSync;
namespace QSB.Audio.Messages;
public class PlayerAudioControllerOneShotMessage : QSBMessage<(AudioType audioType, uint userID)>
{
public PlayerAudioControllerOneShotMessage(AudioType audioType, uint userID) : base((audioType, userID)) { }
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
public override void OnReceiveRemote() =>
QSBPlayerManager.GetPlayer(Data.userID)?.AudioController?.PlayOneShot(Data.audioType);
}

View File

@ -0,0 +1,36 @@
using HarmonyLib;
using QSB.Audio.Messages;
using QSB.Messaging;
using QSB.Patches;
using QSB.Player;
namespace QSB.Audio.Patches;
[HarmonyPatch]
internal class PlayerAudioControllerPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
private static void PlayOneShot(AudioType audioType) =>
new PlayerAudioControllerOneShotMessage(audioType, QSBPlayerManager.LocalPlayerId).Send();
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerAudioController), nameof(PlayerAudioController.PlayMarshmallowCatchFire))]
public static void PlayerAudioController_PlayMarshmallowCatchFire() => PlayOneShot(AudioType.ToolMarshmallowIgnite);
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerAudioController), nameof(PlayerAudioController.PlayMarshmallowBlowOut))]
public static void PlayerAudioController_PlayMarshmallowBlowOut() => PlayOneShot(AudioType.ToolMarshmallowBlowOut);
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerAudioController), nameof(PlayerAudioController.PlayMarshmallowEat))]
public static void PlayerAudioController_PlayMarshmallowEat() => PlayOneShot(AudioType.ToolMarshmallowEat);
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerAudioController), nameof(PlayerAudioController.PlayMarshmallowEatBurnt))]
public static void PlayerAudioController_PlayMarshmallowEatBurnt() => PlayOneShot(AudioType.ToolMarshmallowEatBurnt);
[HarmonyPostfix]
[HarmonyPatch(typeof(PlayerAudioController), nameof(PlayerAudioController.PlayMarshmallowReplace))]
public static void PlayerAudioController_PlayMarshmallowReplace() => PlayOneShot(AudioType.ToolMarshmallowReplace);
}

View File

@ -22,14 +22,11 @@ public class QSBPlayerAudioController : MonoBehaviour
=> _oneShotExternalSource?.PlayOneShot(AudioType.ToolFlashlightOff);
public void PlayWearSuit()
=> _oneShotExternalSource?.PlayOneShot(AudioType.PlayerSuitWearSuit);
=> PlayOneShot(AudioType.PlayerSuitWearSuit);
public void PlayRemoveSuit()
=> _oneShotExternalSource?.PlayOneShot(AudioType.PlayerSuitRemoveSuit);
=> PlayOneShot(AudioType.PlayerSuitRemoveSuit);
public void PlayWearHelmet()
=> _oneShotExternalSource?.PlayOneShot(AudioType.PlayerSuitWearHelmet);
public void PlayRemoveHelmet()
=> _oneShotExternalSource?.PlayOneShot(AudioType.PlayerSuitRemoveHelmet);
public void PlayOneShot(AudioType audioType)
=> _oneShotExternalSource?.PlayOneShot(audioType, 1f);
}