Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions NASB Voice Mod/Controllers/VoiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ namespace VoiceMod.Controllers
class VoiceController : MonoBehaviour
{
private string agentId;
private GameAgent agent;
private GameAgentStateMachine stateMachine;
private Voicepack voicepack;
private readonly Dictionary<int, string> lookup = new Dictionary<int, string>();
private Dictionary<string, int> stateIdDict;

void Start()
{
agentId = GetComponent<GameAgent>()?.GameUniqueIdentifier;
agent = GetComponent<GameAgent>();
agentId = agent?.GameUniqueIdentifier;
stateMachine = GetComponent<GameAgentStateMachine>();
var stateIdDict = stateMachine.GetPrivateField<Dictionary<string, int>>("stateIdDict");
stateIdDict = stateMachine.GetPrivateField<Dictionary<string, int>>("stateIdDict");

if (agentId == null ||
stateMachine == null ||
Expand Down Expand Up @@ -64,10 +67,20 @@ void Update()
{
if (lookup.TryGetValue(stateMachine.CurrentStateId, out var id))
{
voicepack.Play(id);
int entryId = stateIdDict["entrance"];
if (stateMachine.CurrentStateId == entryId)
Invoke("PlayEntranceAudio", agent.playerIndex * 1.25f);
else voicepack.Play(id);
}
}
stateLastFrame = stateMachine.CurrentStateId;
}

private void PlayEntranceAudio()
{
//All the checking and tryGets were done already. We _know_ this exists or the code wouldn't have gotten this far
string id = lookup[stateIdDict["entrance"]];
voicepack.Play(id);
}
}
}