-
Notifications
You must be signed in to change notification settings - Fork 0
/
HumanSoundsMissionBehavior.cs
53 lines (46 loc) · 2.15 KB
/
HumanSoundsMissionBehavior.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using RealisticBattleSounds.Settings;
using TaleWorlds.Core;
using TaleWorlds.MountAndBlade;
namespace RealisticBattleSounds;
internal class HumanSoundsMissionBehavior : MissionBehavior
{
public override MissionBehaviorType BehaviorType => MissionBehaviorType.Other;
private float CoughRate;
private float InsultRate;
private bool insultActivated;
public override void OnDeploymentFinished()
{
InsultRate = Mission.Agents.Count * 0.0001f;
CoughRate = Mission.Agents.Count * 0.00006f;
insultActivated = RBSSettings.Instance?.EnableInsults == true;
}
public override void OnAgentRemoved(Agent affectedAgent, Agent affectorAgent, AgentState agentState, KillingBlow blow)
{
if (Mission.Agents.Count > 1)
{
InsultRate = Mission.Agents.Count * 0.00014f;
CoughRate = Mission.Agents.Count * 0.00006f;
}
else
CoughRate = 0;
}
public override void OnMissionTick(float dt)
{
if (!Mission.IsFinalized && RealisticSoundsContainer.RSRandom.NextFloat() <= InsultRate && Mission.Mode == MissionMode.Battle && !Mission.IsInPhotoMode && !MBCommon.IsPaused)
{
Agent agent = this.Mission.Agents.GetRandomElementWithPredicate(x => x.Health > 0 && !x.IsFemale && !x.IsMainAgent && !x.IsCheering && !x.IsRetreating());
if (agent == null)
return;
if (insultActivated && agent.ImmediateEnemy != null && agent.Health > (agent.HealthLimit * 0.15f))
{
Mission.MakeSound(RealisticSoundsContainer.RealisticSoundsDic["event:/voice/combat/insult"],
agent.Position, false, false, agent.Index, Agent.Main != null ? Agent.Main.Index : agent.Index);
}
if (RealisticSoundsContainer.RSRandom.NextFloat() <= CoughRate)
{
if (agent.WalkMode || agent.HasMount)
Mission.MakeSound(RealisticSoundsContainer.RealisticSoundsDic["event:/voice/combat/cough"], agent.Position, false, false, agent.Index, Agent.Main != null ? Agent.Main.Index : agent.Index);
}
}
}
}