From 6ddcd65f185ae793747cab3e39183e38fc69a2ba Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 5 Mar 2018 12:34:21 +0200 Subject: [PATCH] RepairTools can do damage to characters by hitting the collider. Closes #299 --- .../Source/Characters/Animation/Ragdoll.cs | 4 +++- .../Source/Items/Components/Holdable/RepairTool.cs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs index 4ce8540ae..ea802d3d3 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/Ragdoll.cs @@ -336,6 +336,7 @@ namespace Barotrauma case "collider": collider.Add(new PhysicsBody(subElement, scale)); + collider[collider.Count - 1].UserData = character; collider[collider.Count - 1].FarseerBody.Friction = 0.05f; collider[collider.Count - 1].FarseerBody.Restitution = 0.05f; collider[collider.Count - 1].FarseerBody.FixedRotation = true; @@ -350,8 +351,9 @@ namespace Barotrauma if (collider[0] == null) { - DebugConsole.ThrowError("No collider configured for \""+character.Name+"\"!"); + DebugConsole.ThrowError("No collider configured for \"" + character.Name + "\"!"); collider[0] = new PhysicsBody(0.0f, 0.0f, 0.5f, 5.0f); + collider[0].UserData = character; collider[0].BodyType = BodyType.Dynamic; collider[0].CollisionCategories = Physics.CollisionCharacter; collider[0].FarseerBody.AngularDamping = 5.0f; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs index 500fa3e22..01b71ea0e 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs @@ -211,6 +211,7 @@ namespace Barotrauma.Items.Components pickedPosition = Submarine.LastPickedPosition; Structure targetStructure; + Character targetCharacter; Limb targetLimb; Item targetItem; if ((targetStructure = (targetBody.UserData as Structure)) != null) @@ -261,6 +262,19 @@ namespace Barotrauma.Items.Components } } } + else if ((targetCharacter = (targetBody.UserData as Character)) != null) + { + targetCharacter.AddDamage(CauseOfDeath.Damage, -LimbFixAmount * degreeOfSuccess, user); +#if CLIENT + Vector2 particlePos = ConvertUnits.ToDisplayUnits(pickedPosition); + if (targetCharacter.Submarine != null) particlePos += targetCharacter.Submarine.DrawPosition; + foreach (var emitter in ParticleEmitterHitCharacter) + { + float particleAngle = item.body.Rotation + ((item.body.Dir > 0.0f) ? 0.0f : MathHelper.Pi); + emitter.Emit(deltaTime, particlePos, item.CurrentHull, particleAngle + MathHelper.Pi, -particleAngle + MathHelper.Pi); + } +#endif + } else if ((targetLimb = (targetBody.UserData as Limb)) != null) { targetLimb.character.AddDamage(CauseOfDeath.Damage, -LimbFixAmount * degreeOfSuccess, user);