private void playSoundInternal(userEntry commandUser, soundCommandDef curSound, bool isRandom = false) { int pathCount = curSound.paths.Count; if (pathCount > 0 && !onCooldown(curSound, commandUser)) { string baseSoundPath; if (pathCount > 1) { int soundIndex = m_BotBrain.randomizer.Next(0, pathCount); baseSoundPath = curSound.paths[soundIndex]; } else { baseSoundPath = curSound.paths[0]; } string soundPath = System.IO.Path.Combine(jerpBot.storagePath, "sounds\\" + baseSoundPath); if (File.Exists(soundPath)) { AudioFileReader audioFile = new AudioFileReader(soundPath); m_OutputEvent.DeviceNumber = m_DeviceNumber; m_OutputEvent.Init(audioFile); float soundVolume = m_GlobalVolume; if (curSound.volume > 0) { soundVolume *= curSound.volume; } m_OutputEvent.Volume = Math.Min(soundVolume, 1.0f); m_OutputEvent.Play(); curSound.lastUsed = m_BotBrain.actionTimer.ElapsedMilliseconds; m_lastSound = curSound; if (isRandom) { m_BotBrain.sendDefaultChannelMessage(string.Format(m_BotBrain.localizer.getString("soundPlayRandom"), curSound.name)); } } } }
private bool onCooldown(soundCommandDef aSound, userEntry commandUser) { if (m_OutputEvent.PlaybackState == PlaybackState.Playing) { return(true); } if (commandUser.isBroadcaster) { return(false); } if ( (m_BotBrain.actionTimer.ElapsedMilliseconds + COOLDOWN_GLOBAL_ALL > aSound.lastUsed) && (aSound != m_lastSound || m_BotBrain.actionTimer.ElapsedMilliseconds + COOLDOWN_GLOBAL_PERSOUND > aSound.lastUsed) ) { return(false); } return(true); }