diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs index 2ca2c5f43..d8bb9ede3 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterNetworking.cs @@ -109,6 +109,10 @@ namespace Barotrauma TransformCursorPos(); } + bool ragdollInput = msg.ReadBoolean(); + keys[(int)InputType.Ragdoll].Held = ragdollInput; + keys[(int)InputType.Ragdoll].SetState(false, ragdollInput); + facingRight = msg.ReadBoolean(); } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index 40ba7328f..14bb8779c 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -13,9 +13,9 @@ namespace Barotrauma partial class Character : Entity, IDamageable, ISerializableEntity, IClientSerializable, IServerSerializable { public static List CharacterList = new List(); - + public static bool DisableControls; - + private bool enabled = true; public bool Enabled { @@ -68,7 +68,7 @@ namespace Barotrauma } protected Key[] keys; - + private Item selectedConstruction; private Item[] selectedItems; @@ -99,7 +99,7 @@ namespace Barotrauma private bool isDead; private CauseOfDeath lastAttackCauseOfDeath; private CauseOfDeath causeOfDeath; - + public readonly bool IsHumanoid; //the name of the species (e.q. human) @@ -113,16 +113,16 @@ namespace Barotrauma { get; set; - } + } private CharacterInfo info; public CharacterInfo Info { get - { + { return info; } - set + set { if (info != null && info != value) info.Remove(); @@ -154,7 +154,7 @@ namespace Barotrauma { get { return inventory; } } - + private Color speechBubbleColor; private float speechBubbleTimer; @@ -184,8 +184,8 @@ namespace Barotrauma public Vector2 CursorPosition { get { return cursorPosition; } - set - { + set + { if (!MathUtils.IsValid(value)) return; cursorPosition = value; } @@ -246,6 +246,9 @@ namespace Barotrauma } } + public bool IsRagdolled; + public bool IsForceRagdolled; + public bool IsUnconscious { get { return (needsAir && oxygen <= 0.0f) || health <= 0.0f; } @@ -661,6 +664,8 @@ namespace Barotrauma return dequeuedInput.HasFlag(InputNetFlags.Select); //TODO: clean up the way this input is registered case InputType.Use: return !(dequeuedInput.HasFlag(InputNetFlags.Use)) && (prevDequeuedInput.HasFlag(InputNetFlags.Use)); + case InputType.Ragdoll: + return !(dequeuedInput.HasFlag(InputType.Ragdoll)) && (prevDequeuedInput.HasFlag(InputType.Ragdoll)); default: return false; } @@ -695,6 +700,8 @@ namespace Barotrauma return dequeuedInput.HasFlag(InputNetFlags.Use); case InputType.Attack: return dequeuedInput.HasFlag(InputNetFlags.Attack); + case InputType.Ragdoll: + return dequeuedInput.HasFlag(InputNetFlags.Ragdoll); } return false; } @@ -1435,7 +1442,22 @@ namespace Barotrauma UpdateUnconscious(deltaTime); return; } - + + if (IsForceRagdolled) + IsRagdolled = IsForceRagdolled; + else if (!IsRagdolled || AnimController.Collider.LinearVelocity.Length() < 1f) //Keep us ragdolled if we were forced or we're too speedy to unragdoll + IsRagdolled = IsKeyDown(InputType.Ragdoll); //Handle this here instead of Control because we can stop being ragdolled ourselves + + if (IsRagdolled) + { + ((HumanoidAnimController)AnimController).Crouching = false; + Stun = Math.Max(0.1f, Stun); + + AnimController.ResetPullJoints(); + selectedConstruction = null; + return; + } + Control(deltaTime, cam); if (controlled != this && (!(this is AICharacter) || IsRemotePlayer)) { diff --git a/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs b/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs index bd6d8c1c8..32bba197f 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/CharacterNetworking.cs @@ -52,8 +52,9 @@ namespace Barotrauma Use = 0x100, Aim = 0x200, Attack = 0x400, + Ragdoll = 0x800, - MaxVal = 0x7FF + MaxVal = 0xFFF } private InputNetFlags dequeuedInput = 0; private InputNetFlags prevDequeuedInput = 0; @@ -208,6 +209,7 @@ namespace Barotrauma if (IsKeyDown(InputType.Use)) newInput |= InputNetFlags.Use; if (IsKeyDown(InputType.Aim)) newInput |= InputNetFlags.Aim; if (IsKeyDown(InputType.Attack)) newInput |= InputNetFlags.Attack; + if (IsKeyDown(InputType.Ragdoll)) newInput |= InputNetFlags.Ragdoll; if (AnimController.TargetDir == Direction.Left) newInput |= InputNetFlags.FacingLeft; @@ -438,6 +440,7 @@ namespace Barotrauma Vector2 relativeCursorPos = cursorPosition - (ViewTarget == null ? AnimController.AimSourcePos : ViewTarget.Position); tempBuffer.Write((UInt16)(65535.0 * Math.Atan2(relativeCursorPos.Y, relativeCursorPos.X) / (2.0 * Math.PI))); } + tempBuffer.Write(IsRagdolled); tempBuffer.Write(AnimController.TargetDir == Direction.Right); } diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index ce339de4c..0471548ec 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -647,6 +647,24 @@ namespace Barotrauma if (Character.Controlled != null) Character.Controlled.AnimController.Frozen = !Character.Controlled.AnimController.Frozen; })); + commands.Add(new Command("ragdoll", "ragdoll [character name]: Force-ragdoll the specified character. If the name parameter is omitted, the controlled character will be ragdolled.", (string[] args) => + { + Character ragdolledCharacter = null; + if (args.Length == 0) + { + ragdolledCharacter = Character.Controlled; + } + else + { + ragdolledCharacter = FindMatchingCharacter(args); + } + + if (ragdolledCharacter != null) + { + ragdolledCharacter.IsForceRagdolled = !ragdolledCharacter.IsForceRagdolled; + } + })); + commands.Add(new Command("freecamera|freecam", "freecam: Detach the camera from the controlled character.", (string[] args) => { Character.Controlled = null; diff --git a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs index 6c7938757..93d14d3f2 100644 --- a/Barotrauma/BarotraumaShared/Source/PlayerInput.cs +++ b/Barotrauma/BarotraumaShared/Source/PlayerInput.cs @@ -11,7 +11,8 @@ namespace Barotrauma Up, Down, Left, Right, Attack, Run, Crouch, - Chat, RadioChat, CrewOrders + Chat, RadioChat, CrewOrders, + Ragdoll } public class KeyOrMouse diff --git a/Barotrauma/BarotraumaShared/config.xml b/Barotrauma/BarotraumaShared/config.xml index 336ba9c4c..ec9028ff6 100644 --- a/Barotrauma/BarotraumaShared/config.xml +++ b/Barotrauma/BarotraumaShared/config.xml @@ -2,7 +2,7 @@ - + />