-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now, if enabled in the config, sleepers can wake up from players talking. This is a host-only feature meaning the host has to be running the mod for it to work, clients are optional.
- Loading branch information
Showing
4 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Agents; | ||
using Dissonance; | ||
using Dissonance.Audio.Playback; | ||
using Player; | ||
using PlayFab.DataModels; | ||
using ProximityChat.Dissonance; | ||
using ProximityChat.PlayerHandler; | ||
using ProximityChat.SteamComms; | ||
using SNetwork; | ||
using UnityEngine; | ||
|
||
namespace ProximityChat.TalkState | ||
{ | ||
public class SleeperWake | ||
{ | ||
// Setup instance linking. | ||
private MainPlugin rootInstance; | ||
private DissonanceUtils dissonanceInstance; | ||
private SteamLink steamLink; | ||
private SlotManager slotManager; | ||
|
||
// Giver Instance Loader. | ||
private static SleeperWake _instance; | ||
public static SleeperWake Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
_instance = new SleeperWake(); | ||
return _instance; | ||
} | ||
} | ||
|
||
public bool sleepWakeEnabled = false; | ||
|
||
// Proceed. | ||
public void Init() | ||
{ | ||
if (!ProximityConfig.enableSleeperWake.Value) | ||
return; | ||
|
||
MainPlugin.SendLog.LogInfo("[SleeperWake] Config is true, checking host..."); | ||
if (!SNet.LocalPlayer.IsMaster) | ||
{ | ||
MainPlugin.SendLog.LogError("[SleeperWake] SleeperWake is enabled, but user is not the host. Disabling SleeperWake..."); | ||
return; | ||
} | ||
MainPlugin.SendLog.LogInfo("[SleeperWake] User is indeed the host, enabling SleeperWake functionality!"); | ||
|
||
sleepWakeEnabled = true; // Tells LinkPositionUpdater to pass Player Variables to us. | ||
|
||
} | ||
|
||
public async void enableSleeperWake(PlayerAgent sourceAgent, VoicePlayback? sourceObject = null, VoicePlayerState? selfObject = null) | ||
{ | ||
// Save local copies to prevent nulling mfw | ||
var pAgent = sourceAgent; | ||
VoicePlayback dissonanceObject = sourceObject; | ||
|
||
MainPlugin.SendLog.LogInfo($"[SleeperWake] Starting listener for {pAgent.PlayerName}!"); | ||
|
||
while (pAgent != null) | ||
{ | ||
if (GameStateManager.CurrentStateName.ToString() != "InLevel") | ||
{ | ||
MainPlugin.SendLog.LogInfo($"[SleeperWake] Supposedly exited level, shutting down!"); | ||
break; | ||
} | ||
|
||
await Task.Delay(12); | ||
|
||
if (sourceObject == null && selfObject != null) // If local player | ||
{ | ||
while (selfObject.IsSpeaking) | ||
{ | ||
pAgent.Noise = Agent.NoiseType.Walk; | ||
await Task.Delay(12); | ||
} | ||
continue; | ||
} | ||
|
||
while (dissonanceObject.IsSpeaking) | ||
{ | ||
pAgent.Noise = Agent.NoiseType.Walk; | ||
await Task.Delay(12); | ||
} | ||
} | ||
MainPlugin.SendLog.LogError("[SleeperWake] Connection to player unexpectedly severed!"); | ||
} | ||
} | ||
} |