Hi @BeeAntOS, you have to do something like here.
Code:
using System.Linq;
namespace Turbo.Plugins.User
{
public class SpeakEntry
{
public readonly string Text;
public readonly bool BeSilentInTown;
public readonly bool BeSilentWhenDead;
public readonly bool SpeakOnlyWithEnemies;
public readonly double VolumeMultiplier;
public readonly int Priority;
public bool CanSpeak => !string.IsNullOrEmpty(Text);
public bool IsPriorityOverride(SpeakEntry other) => Priority < other.Priority;
public SpeakEntry(string text, bool beSilentInTown = true, bool beSilentWhenDead = true, bool speakOnlyWithEnemies = true, double volumeMultiplier = 1.0, int priority = 100)
{
Text = text;
BeSilentInTown = beSilentInTown;
BeSilentWhenDead = beSilentWhenDead;
SpeakOnlyWithEnemies = speakOnlyWithEnemies;
VolumeMultiplier = volumeMultiplier;
Priority = priority;
}
}
public class SoundHelper
{
private readonly IController Hud;
private SpeakEntry lastSpeak = new SpeakEntry("");
public SoundHelper(IController hud)
{
Hud = hud;
}
public void Speak(SpeakEntry entry)
{
if (string.IsNullOrEmpty(entry.Text))
return;
if (entry.BeSilentInTown && Hud.Game.IsInTown)
return;
if (entry.BeSilentWhenDead && Hud.Game.Me.IsDead)
return;
if (entry.SpeakOnlyWithEnemies && !Hud.Game.AliveMonsters.Any())
return;
// Save volume.
var restoreVolume = false;
var VolumeMultiplier = Hud.Sound.VolumeMultiplier;
var VolumeMode = Hud.Sound.VolumeMode;
if (entry.VolumeMultiplier > 0 && (VolumeMultiplier != entry.VolumeMultiplier || VolumeMode != VolumeMode.AutoMaster))
{
restoreVolume = true;
Hud.Sound.VolumeMultiplier = entry.VolumeMultiplier;
if (Hud.Sound.VolumeMode != VolumeMode.AutoMaster)
{
Hud.Sound.VolumeMode = VolumeMode.AutoMaster;
}
}
lastSpeak = entry;
if (entry.IsPriorityOverride(lastSpeak))
{
// If priority is less, override pervious speak if it is still playing.
Hud.Sound.StopSpeak();
}
Hud.Sound.Speak(entry.Text);
// Restore volume.
if (restoreVolume)
{
Hud.Sound.VolumeMultiplier = VolumeMultiplier;
Hud.Sound.VolumeMode = VolumeMode;
}
}
}
}