Bunch of new sounds by Omniary, some charactersound & soundplayer refactoring
This commit is contained in:
@@ -57,7 +57,15 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
PlaySound((aiController == null) ? AIController.AiState.None : aiController.State);
|
||||
switch (aiController.State)
|
||||
{
|
||||
case AIController.AiState.Attack:
|
||||
PlaySound(CharacterSound.SoundType.Attack);
|
||||
break;
|
||||
default:
|
||||
PlaySound(CharacterSound.SoundType.Idle);
|
||||
break;
|
||||
}
|
||||
soundTimer = soundInterval;
|
||||
}
|
||||
|
||||
|
||||
@@ -121,10 +121,7 @@ namespace Barotrauma
|
||||
|
||||
private float bleeding;
|
||||
|
||||
private Sound[] sounds;
|
||||
private float[] soundRange;
|
||||
//which AIstate each sound is for
|
||||
private AIController.AiState[] soundStates;
|
||||
private List<CharacterSound> sounds;
|
||||
|
||||
private float attackCoolDown;
|
||||
|
||||
@@ -574,28 +571,13 @@ namespace Barotrauma
|
||||
soundInterval = ToolBox.GetAttributeFloat(doc.Root, "soundinterval", 10.0f);
|
||||
|
||||
var soundElements = doc.Root.Elements("sound").ToList();
|
||||
if (soundElements.Any())
|
||||
|
||||
sounds = new List<CharacterSound>();
|
||||
foreach (XElement soundElement in soundElements)
|
||||
{
|
||||
sounds = new Sound[soundElements.Count];
|
||||
soundStates = new AIController.AiState[soundElements.Count];
|
||||
soundRange = new float[soundElements.Count];
|
||||
int i = 0;
|
||||
foreach (XElement soundElement in soundElements)
|
||||
{
|
||||
sounds[i] = Sound.Load(soundElement.Attribute("file").Value);
|
||||
soundRange[i] = ToolBox.GetAttributeFloat(soundElement, "range", 1000.0f);
|
||||
if (soundElement.Attribute("state") == null)
|
||||
{
|
||||
soundStates[i] = AIController.AiState.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
soundStates[i] = (AIController.AiState)Enum.Parse(
|
||||
typeof(AIController.AiState), soundElement.Attribute("state").Value, true);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
sounds.Add(new CharacterSound(soundElement));
|
||||
}
|
||||
|
||||
|
||||
if (file == humanConfigFile)
|
||||
{
|
||||
@@ -1322,8 +1304,14 @@ namespace Barotrauma
|
||||
|
||||
private void UpdateOxygen(float deltaTime)
|
||||
{
|
||||
float prevOxygen = oxygen;
|
||||
Oxygen += deltaTime * (oxygenAvailable < 30.0f ? -5.0f : 10.0f);
|
||||
|
||||
if (prevOxygen > 0.0f && Oxygen <= 0.0f && controlled == this)
|
||||
{
|
||||
SoundPlayer.PlaySound("drown");
|
||||
}
|
||||
|
||||
PressureProtection -= deltaTime * 100.0f;
|
||||
|
||||
float hullAvailableOxygen = 0.0f;
|
||||
@@ -1449,24 +1437,15 @@ namespace Barotrauma
|
||||
return progressBar;
|
||||
}
|
||||
|
||||
public void PlaySound(AIController.AiState state)
|
||||
public void PlaySound(CharacterSound.SoundType soundType)
|
||||
{
|
||||
if (sounds == null || !sounds.Any()) return;
|
||||
var matchingSoundStates = soundStates.Where(x => x == state).ToList();
|
||||
if (sounds == null || sounds.Count == 0) return;
|
||||
|
||||
int selectedSound = Rand.Int(matchingSoundStates.Count);
|
||||
var matchingSounds = sounds.FindAll(s => s.Type == soundType);
|
||||
if (matchingSounds.Count == 0) return;
|
||||
|
||||
int n = 0;
|
||||
for (int i = 0; i < sounds.Length; i++)
|
||||
{
|
||||
if (soundStates[i] != state) continue;
|
||||
if (n == selectedSound && sounds[i]!=null)
|
||||
{
|
||||
sounds[i].Play(1.0f, soundRange[i], AnimController.Limbs[0].WorldPosition);
|
||||
return;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
var selectedSound = matchingSounds[Rand.Int(matchingSounds.Count)];
|
||||
selectedSound.Sound.Play(1.0f, selectedSound.Range, AnimController.WorldPosition);
|
||||
}
|
||||
|
||||
public virtual void AddDamage(CauseOfDeath causeOfDeath, float amount, IDamageable attacker)
|
||||
@@ -1567,7 +1546,7 @@ namespace Barotrauma
|
||||
// limb.Damage = 100.0f;
|
||||
}
|
||||
|
||||
SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.Collider);
|
||||
SoundPlayer.PlaySound("implode", 1.0f, 150.0f, WorldPosition);
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
@@ -1620,11 +1599,9 @@ namespace Barotrauma
|
||||
GameServer.Log(Name+" has died (Cause of death: "+causeOfDeath+")", Color.Red);
|
||||
|
||||
if (OnDeath != null) OnDeath(this, causeOfDeath);
|
||||
|
||||
//CoroutineManager.StartCoroutine(DeathAnim(GameMain.GameScreen.Cam));
|
||||
|
||||
//health = 0.0f;
|
||||
|
||||
|
||||
PlaySound(CharacterSound.SoundType.Die);
|
||||
|
||||
isDead = true;
|
||||
this.causeOfDeath = causeOfDeath;
|
||||
AnimController.movement = Vector2.Zero;
|
||||
@@ -1635,7 +1612,7 @@ namespace Barotrauma
|
||||
if (selectedItems[i] != null) selectedItems[i].Drop(this);
|
||||
}
|
||||
|
||||
if (aiTarget!=null)
|
||||
if (aiTarget != null)
|
||||
{
|
||||
aiTarget.Remove();
|
||||
aiTarget = null;
|
||||
|
||||
31
Subsurface/Source/Characters/CharacterSound.cs
Normal file
31
Subsurface/Source/Characters/CharacterSound.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class CharacterSound
|
||||
{
|
||||
public enum SoundType
|
||||
{
|
||||
Idle, Attack, Die
|
||||
}
|
||||
|
||||
public readonly Sound Sound;
|
||||
|
||||
public readonly SoundType Type;
|
||||
|
||||
public readonly float Range;
|
||||
|
||||
public CharacterSound(XElement element)
|
||||
{
|
||||
Sound = Sound.Load(element.Attribute("file").Value);
|
||||
Range = ToolBox.GetAttributeFloat(element, "range", 1000.0f);
|
||||
|
||||
Enum.TryParse<SoundType>(ToolBox.GetAttributeString(element, "state", "Idle"), true, out Type);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user