From 32a2b38112b5dd1f065f7052468ce08efe3b81dc Mon Sep 17 00:00:00 2001 From: Alex Noir Date: Sat, 30 Dec 2017 13:46:59 +0300 Subject: [PATCH] Removed DamageSoundType and replaced it with a string "tag" instead to allow mod creators to create custom damage sounds Fixed damagemodifier sounds being completely ignored due to a variable misname Added structure damage possibility for melee weapons so you can break down windows with a crowbar in spectacular fashion (it's clearly a very inferior method to plasma cutters though) Clown hitsounds are in now which is awesome. Beat up some clowns! --- .../Source/Characters/Animation/Ragdoll.cs | 2 +- .../Source/Sounds/SoundPlayer.cs | 18 ++++--------- .../Content/Items/Jobgear/misc.xml | 3 +-- .../Content/Items/Tools/tools.xml | 4 +-- .../Animation/HumanoidAnimController.cs | 2 +- .../Source/Characters/DamageModifier.cs | 4 +-- .../Source/Characters/Limb.cs | 6 ++--- .../Source/Items/Components/Door.cs | 2 +- .../Items/Components/Holdable/MeleeWeapon.cs | 26 ++++++++++++++----- .../BarotraumaShared/Source/Map/Structure.cs | 4 +-- .../Source/Map/SubmarineBody.cs | 2 +- 11 files changed, 39 insertions(+), 34 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/Animation/Ragdoll.cs b/Barotrauma/BarotraumaClient/Source/Characters/Animation/Ragdoll.cs index 14edcee1e..fa8066d54 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/Animation/Ragdoll.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/Animation/Ragdoll.cs @@ -35,7 +35,7 @@ namespace Barotrauma { if (impact > ImpactTolerance) { - SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, Collider); + SoundPlayer.PlayDamageSound("LimbBlunt", strongestImpact, Collider); } } diff --git a/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs b/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs index 0bc96bace..2b2649893 100644 --- a/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs +++ b/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs @@ -10,26 +10,19 @@ using System.Xml.Linq; namespace Barotrauma { - public enum DamageSoundType - { - None, - StructureBlunt, StructureSlash, - LimbBlunt, LimbSlash, LimbArmor - } - public struct DamageSound { //the range of inflicted damage where the sound can be played //(10.0f, 30.0f) would be played when the inflicted damage is between 10 and 30 public readonly Vector2 damageRange; - public readonly DamageSoundType damageType; + public readonly string damageType; public readonly Sound sound; public readonly string requiredTag; - public DamageSound(Sound sound, Vector2 damageRange, DamageSoundType damageType, string requiredTag = "") + public DamageSound(Sound sound, Vector2 damageRange, string damageType, string requiredTag = "") { this.sound = sound; this.damageRange = damageRange; @@ -161,8 +154,7 @@ namespace Barotrauma Sound damageSound = Sound.Load(subElement.GetAttributeString("file", ""), false); if (damageSound == null) continue; - DamageSoundType damageSoundType = DamageSoundType.None; - Enum.TryParse(subElement.GetAttributeString("damagesoundtype", "None"), false, out damageSoundType); + string damageSoundType = subElement.GetAttributeString("damagesoundtype", "None"); damageSounds.Add(new DamageSound( damageSound, @@ -442,14 +434,14 @@ namespace Barotrauma SplashSounds[splashIndex].Play(1.0f, 800.0f, worldPosition); } - public static void PlayDamageSound(DamageSoundType damageType, float damage, PhysicsBody body) + public static void PlayDamageSound(string damageType, float damage, PhysicsBody body) { Vector2 bodyPosition = body.DrawPosition; PlayDamageSound(damageType, damage, bodyPosition, 800.0f); } - public static void PlayDamageSound(DamageSoundType damageType, float damage, Vector2 position, float range = 2000.0f, List tags = null) + public static void PlayDamageSound(string damageType, float damage, Vector2 position, float range = 2000.0f, List tags = null) { damage = MathHelper.Clamp(damage+Rand.Range(-10.0f, 10.0f), 0.0f, 100.0f); var sounds = damageSounds.FindAll(s => diff --git a/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml b/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml index efd6af51d..88e1051a6 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Jobgear/misc.xml @@ -88,9 +88,8 @@ - + diff --git a/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml b/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml index 359b48473..580b856f0 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml @@ -181,7 +181,7 @@ - + @@ -198,7 +198,7 @@ - + diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs index dd7d675c5..241c61a44 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs @@ -1000,7 +1000,7 @@ namespace Barotrauma { target.AddDamage(CauseOfDeath.Bloodloss, 1.0f, character); #if CLIENT - SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, 25.0f, targetTorso.body); + SoundPlayer.PlayDamageSound("LimbBlunt", 25.0f, targetTorso.body); for (int i = 0; i < 4; i++) { diff --git a/Barotrauma/BarotraumaShared/Source/Characters/DamageModifier.cs b/Barotrauma/BarotraumaShared/Source/Characters/DamageModifier.cs index e97d57971..2710e7a48 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/DamageModifier.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/DamageModifier.cs @@ -49,8 +49,8 @@ namespace Barotrauma #if CLIENT - [Serialize(DamageSoundType.None, false)] - public DamageSoundType DamageSoundType + [Serialize("", false)] + public string DamageSound { get; private set; diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Limb.cs b/Barotrauma/BarotraumaShared/Source/Characters/Limb.cs index a130ddb68..442d65a9d 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Limb.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Limb.cs @@ -372,13 +372,13 @@ namespace Barotrauma #if CLIENT if (playSound) { - DamageSoundType damageSoundType = (damageType == DamageType.Blunt) ? DamageSoundType.LimbBlunt : DamageSoundType.LimbSlash; + string damageSoundType = (damageType == DamageType.Blunt) ? "LimbBlunt" : "LimbSlash"; foreach (DamageModifier damageModifier in appliedDamageModifiers) { - if (damageModifier.DamageSoundType != DamageSoundType.None) + if (!string.IsNullOrWhiteSpace(damageModifier.DamageSound)) { - damageSoundType = damageModifier.DamageSoundType; + damageSoundType = damageModifier.DamageSound; break; } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs index ee5ac9e65..c78fe89b2 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Door.cs @@ -384,7 +384,7 @@ namespace Barotrauma.Items.Components if (Math.Sign(diff) != dir) { #if CLIENT - SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, 1.0f, body); + SoundPlayer.PlayDamageSound("LimbBlunt", 1.0f, body); #endif if (isHorizontal) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs index 38f8ca61a..ce564e36b 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/MeleeWeapon.cs @@ -215,6 +215,7 @@ namespace Barotrauma.Items.Components { Character targetCharacter = null; Limb targetLimb = null; + Structure targetStructure = null; if (f2.Body.UserData is Limb) { @@ -224,8 +225,12 @@ namespace Barotrauma.Items.Components } else if (f2.Body.UserData is Character) { - targetCharacter = (Character)f2.Body.UserData; + targetLimb = targetCharacter.AnimController.GetLimb(LimbType.Torso); //Otherwise armor can be bypassed in strange ways + } + else if (f2.Body.UserData is Structure) + { + targetStructure = (Structure)f2.Body.UserData; } else { @@ -236,14 +241,22 @@ namespace Barotrauma.Items.Components if (attack != null) { - if (targetLimb == null) + if (targetLimb != null) { attack.DoDamageToLimb(user, targetLimb, item.WorldPosition, 1.0f); } - else + else if (targetCharacter != null) { attack.DoDamage(user, targetCharacter, item.WorldPosition, 1.0f); } + else if (targetStructure != null) + { + attack.DoDamage(user, targetStructure, item.WorldPosition, 1.0f); + } + else + { + return false; + } } RestoreCollision(); @@ -251,7 +264,7 @@ namespace Barotrauma.Items.Components if (GameMain.Client != null) return true; - if (GameMain.Server != null) + if (GameMain.Server != null && targetCharacter != null) //TODO: Log structure hits { GameMain.Server.CreateEntityEvent(item, new object[] { Networking.NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnUse, targetCharacter.ID }); @@ -263,8 +276,9 @@ namespace Barotrauma.Items.Components logStr += " on " + targetCharacter.LogName + "."; Networking.GameServer.Log(logStr, Networking.ServerLog.MessageType.Attack); } - - ApplyStatusEffects(ActionType.OnUse, 1.0f, targetLimb.character); + + if (targetCharacter != null) //TODO: Allow OnUse to happen on structures too maybe?? + ApplyStatusEffects(ActionType.OnUse, 1.0f, targetCharacter != null ? targetCharacter : null); return true; } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs index beb737fb9..73b7d1dd3 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs @@ -507,7 +507,7 @@ namespace Barotrauma float impact = Vector2.Dot(f2.Body.LinearVelocity, -normal)*f2.Body.Mass*0.1f; #if CLIENT - SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact, + SoundPlayer.PlayDamageSound("StructureBlunt", impact, new Vector2( sections[section].rect.X + sections[section].rect.Width / 2, sections[section].rect.Y - sections[section].rect.Height / 2), tags: Tags); @@ -663,7 +663,7 @@ namespace Barotrauma if (playSound)// && !SectionBodyDisabled(i)) { - DamageSoundType damageSoundType = (attack.DamageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash; + string damageSoundType = (attack.DamageType == DamageType.Blunt) ? "StructureBlunt" : "StructureSlash"; SoundPlayer.PlayDamageSound(damageSoundType, damageAmount, worldPosition, tags: Tags); } #endif diff --git a/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs b/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs index fb1bd935a..1de24ff7d 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/SubmarineBody.cs @@ -665,7 +665,7 @@ namespace Barotrauma if (maxDamageStructure != null) { SoundPlayer.PlayDamageSound( - DamageSoundType.StructureBlunt, + "StructureBlunt", impact * 10.0f, ConvertUnits.ToDisplayUnits(lastContactPoint), MathHelper.Clamp(maxDamage * 4.0f, 1000.0f, 4000.0f),