From e17b5a195c3a6353dcba9660a101b361c62d2aa1 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 14 Dec 2017 20:01:45 +0200 Subject: [PATCH 1/6] Increased the minimum distance between monster spawns and subs (20 000 units in monster events, 30% of the width of the level in monster missions). Closes #63 and closes #151 --- .../Source/Events/ArtifactEvent.cs | 2 +- .../Source/Events/Missions/MonsterMission.cs | 2 +- .../Source/Events/Missions/SalvageMission.cs | 2 +- .../Source/Events/MonsterEvent.cs | 2 +- .../BarotraumaShared/Source/Map/Levels/Level.cs | 17 ++++++++++------- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs index 41b8577c4..be7ca10b1 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs @@ -34,7 +34,7 @@ namespace Barotrauma base.Init(); Vector2 position = Level.Loaded.GetRandomItemPos( - Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 30.0f); + Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 10000.0f, 30.0f); item = new Item(itemPrefab, position, null); item.MoveWithLevel = true; diff --git a/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs b/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs index 315026dc8..bb2b00e00 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs @@ -28,7 +28,7 @@ namespace Barotrauma public override void Start(Level level) { Vector2 spawnPos; - Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, true, out spawnPos); + Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out spawnPos); monster = Character.Create(monsterFile, spawnPos, null, GameMain.Client != null, true, false); monster.Enabled = false; diff --git a/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs b/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs index b5c4fc7b1..0d430ad10 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs @@ -46,7 +46,7 @@ namespace Barotrauma public override void Start(Level level) { - Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, 30.0f); + Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, Level.Loaded.Size.X * 0.3f, 30.0f); item = new Item(itemPrefab, position, null); item.MoveWithLevel = true; diff --git a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs index 9c2ed6ec2..9b6d2c34e 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/MonsterEvent.cs @@ -85,7 +85,7 @@ namespace Barotrauma if (disallowed) return null; Vector2 spawnPos; - if (!Level.Loaded.TryGetInterestingPosition(true, spawnPosType, true, out spawnPos)) + if (!Level.Loaded.TryGetInterestingPosition(true, spawnPosType, 20000.0f, out spawnPos)) { //no suitable position found, disable the event repeat = false; diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs index 236cffcfe..74abdf6df 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs @@ -817,7 +817,7 @@ namespace Barotrauma //50% chance of placing the ruins at a cave if (Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.5f) { - TryGetInterestingPosition(true, PositionType.Cave, false, out ruinPos); + TryGetInterestingPosition(true, PositionType.Cave, 0.0f, out ruinPos); } ruinPos.Y = Math.Min(ruinPos.Y, borders.Y + borders.Height - ruinSize.Y / 2); @@ -894,7 +894,7 @@ namespace Barotrauma } } - public Vector2 GetRandomItemPos(PositionType spawnPosType, float randomSpread, float offsetFromWall = 10.0f) + public Vector2 GetRandomItemPos(PositionType spawnPosType, float randomSpread, float minDistFromSubs, float offsetFromWall = 10.0f) { if (!positionsOfInterest.Any()) return Size*0.5f; @@ -906,7 +906,7 @@ namespace Barotrauma do { Vector2 startPos; - Level.Loaded.TryGetInterestingPosition(true, spawnPosType, true, out startPos); + Loaded.TryGetInterestingPosition(true, spawnPosType, minDistFromSubs, out startPos); startPos += Rand.Vector(Rand.Range(0.0f, randomSpread, Rand.RandSync.Server), Rand.RandSync.Server); @@ -935,7 +935,7 @@ namespace Barotrauma - public bool TryGetInterestingPosition(bool useSyncedRand, PositionType positionType, bool avoidSubs, out Vector2 position) + public bool TryGetInterestingPosition(bool useSyncedRand, PositionType positionType, float minDistFromSubs, out Vector2 position) { if (!positionsOfInterest.Any()) { @@ -945,17 +945,20 @@ namespace Barotrauma var matchingPositions = positionsOfInterest.FindAll(p => positionType.HasFlag(p.PositionType)); - if (avoidSubs) + if (minDistFromSubs > 0.0f) { foreach (Submarine sub in Submarine.Loaded) { - float minDist = Math.Max(sub.Borders.Width, sub.Borders.Height); - matchingPositions.RemoveAll(p => Vector2.Distance(p.Position, sub.WorldPosition) < minDist); + matchingPositions.RemoveAll(p => Vector2.DistanceSquared(p.Position, sub.WorldPosition) < minDistFromSubs * minDistFromSubs); } } if (!matchingPositions.Any()) { +#if DEBUG + DebugConsole.ThrowError("Could not find a suitable position of interest. (PositionType: " + positionType + ", minDistFromSubs: " + minDistFromSubs + "\n" + Environment.StackTrace); +#endif + position = positionsOfInterest[Rand.Int(positionsOfInterest.Count, (useSyncedRand ? Rand.RandSync.Server : Rand.RandSync.Unsynced))].Position; return false; } From 8a7af2affdfedab2e7d2986776d05d0539402b17 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Fri, 15 Dec 2017 00:25:46 +0200 Subject: [PATCH 2/6] Players can't use other items when a railgun controller is selected. Prevents accidentally firing weapons or hitting people with something while using the railguns. Closes #94 --- .../Content/Items/Weapons/railgun.xml | 3 ++- .../BarotraumaShared/Source/Characters/Character.cs | 13 ++++++++----- .../BarotraumaShared/Source/Items/ItemPrefab.cs | 7 +++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Content/Items/Weapons/railgun.xml b/Barotrauma/BarotraumaShared/Content/Items/Weapons/railgun.xml index 969b6213c..50662afde 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Weapons/railgun.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Weapons/railgun.xml @@ -36,11 +36,12 @@ category="Machine" type="Controller" linkable="true" + disableitemusagewhenselected="true" > - + diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index a506e62d1..63a52738e 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -926,13 +926,16 @@ namespace Barotrauma } } - for (int i = 0; i < selectedItems.Length; i++ ) + if (SelectedConstruction == null || !SelectedConstruction.Prefab.DisableItemUsageWhenSelected) { - if (selectedItems[i] == null) continue; - if (i == 1 && selectedItems[0] == selectedItems[1]) continue; + for (int i = 0; i < selectedItems.Length; i++ ) + { + if (selectedItems[i] == null) continue; + if (i == 1 && selectedItems[0] == selectedItems[1]) continue; - if (IsKeyDown(InputType.Use)) selectedItems[i].Use(deltaTime, this); - if (IsKeyDown(InputType.Aim) && selectedItems[i] != null) selectedItems[i].SecondaryUse(deltaTime, this); + if (IsKeyDown(InputType.Use)) selectedItems[i].Use(deltaTime, this); + if (IsKeyDown(InputType.Aim) && selectedItems[i] != null) selectedItems[i].SecondaryUse(deltaTime, this); + } } if (selectedConstruction != null) diff --git a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs index a1ec49bbd..dba9dfd98 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs @@ -134,6 +134,13 @@ namespace Barotrauma private set; } + [Serialize(false, false)] + public bool DisableItemUsageWhenSelected + { + get; + private set; + } + public bool CanSpriteFlipX { get { return canSpriteFlipX; } From a68fd85ab0b33ad33d15d60ac4737b0deee5f8c9 Mon Sep 17 00:00:00 2001 From: Juan Pablo Arce Date: Fri, 15 Dec 2017 11:21:37 -0300 Subject: [PATCH 3/6] Improved giveperm/revokeperm commands --- .../BarotraumaShared/Source/DebugConsole.cs | 42 +++++++++++++++---- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index 12e257202..8eebab697 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -369,10 +369,14 @@ namespace Barotrauma } })); - commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) => + commands.Add(new Command("giveperm|giveperms", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) => { if (GameMain.Server == null) return; - if (args.Length < 1) return; + if (args.Length < 1) + { + NewMessage("giveperm [id]: Grants administrative permissions to the player with the specified client ID.", Color.Cyan); + return; + } int id; int.TryParse(args[0], out id); @@ -382,7 +386,13 @@ namespace Barotrauma ThrowError("Client id \"" + id + "\" not found."); return; } - + + NewMessage("Valid permissions are:",Color.White); + NewMessage(" - all",Color.White); + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) + { + NewMessage(" - " + permission.ToString(),Color.White); + } ShowQuestionPrompt("Permission to grant to \"" + client.Name + "\"?", (perm) => { ClientPermissions permission = ClientPermissions.None; @@ -392,7 +402,11 @@ namespace Barotrauma } else { - Enum.TryParse(perm, out permission); + if (!Enum.TryParse(perm, out permission)) + { + ThrowError("\"" + perm + "\" sn't a valid permission!"); + return; + } } client.SetPermissions(client.Permissions | permission); GameMain.Server.UpdateClientPermissions(client); @@ -400,10 +414,14 @@ namespace Barotrauma }); })); - commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) => + commands.Add(new Command("revokeperm|revokeperms", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) => { if (GameMain.Server == null) return; - if (args.Length < 1) return; + if (args.Length < 1) + { + NewMessage("revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", Color.Cyan); + return; + } int id; int.TryParse(args[0], out id); @@ -414,6 +432,12 @@ namespace Barotrauma return; } + NewMessage("Valid permissions are:", Color.White); + NewMessage(" - all", Color.White); + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) + { + NewMessage(" - " + permission.ToString(), Color.White); + } ShowQuestionPrompt("Permission to revoke from \"" + client.Name + "\"?", (perm) => { ClientPermissions permission = ClientPermissions.None; @@ -423,7 +447,11 @@ namespace Barotrauma } else { - Enum.TryParse(perm, out permission); + if (!Enum.TryParse(perm, out permission)) + { + ThrowError("\"" + perm + "\" isn't a valid permission!"); + return; + } } client.SetPermissions(client.Permissions & ~permission); GameMain.Server.UpdateClientPermissions(client); From ae344c89c595c965ad7c0402350df286722f4103 Mon Sep 17 00:00:00 2001 From: Juan Pablo Arce Date: Fri, 15 Dec 2017 11:25:21 -0300 Subject: [PATCH 4/6] Fixed indentation --- .../BarotraumaShared/Source/DebugConsole.cs | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index 8eebab697..a403ff2ce 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -369,14 +369,14 @@ namespace Barotrauma } })); - commands.Add(new Command("giveperm|giveperms", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) => + commands.Add(new Command("giveperm", "giveperm [id]: Grants administrative permissions to the player with the specified client ID.", (string[] args) => { if (GameMain.Server == null) return; - if (args.Length < 1) - { - NewMessage("giveperm [id]: Grants administrative permissions to the player with the specified client ID.", Color.Cyan); - return; - } + if (args.Length < 1) + { + NewMessage("giveperm [id]: Grants administrative permissions to the player with the specified client ID.", Color.Cyan); + return; + } int id; int.TryParse(args[0], out id); @@ -387,12 +387,12 @@ namespace Barotrauma return; } - NewMessage("Valid permissions are:",Color.White); - NewMessage(" - all",Color.White); - foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) - { - NewMessage(" - " + permission.ToString(),Color.White); - } + NewMessage("Valid permissions are:",Color.White); + NewMessage(" - all",Color.White); + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) + { + NewMessage(" - " + permission.ToString(),Color.White); + } ShowQuestionPrompt("Permission to grant to \"" + client.Name + "\"?", (perm) => { ClientPermissions permission = ClientPermissions.None; @@ -402,11 +402,11 @@ namespace Barotrauma } else { - if (!Enum.TryParse(perm, out permission)) - { - ThrowError("\"" + perm + "\" sn't a valid permission!"); - return; - } + if (!Enum.TryParse(perm, out permission)) + { + ThrowError("\"" + perm + "\" sn't a valid permission!"); + return; + } } client.SetPermissions(client.Permissions | permission); GameMain.Server.UpdateClientPermissions(client); @@ -414,14 +414,14 @@ namespace Barotrauma }); })); - commands.Add(new Command("revokeperm|revokeperms", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) => + commands.Add(new Command("revokeperm", "revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", (string[] args) => { if (GameMain.Server == null) return; if (args.Length < 1) - { - NewMessage("revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", Color.Cyan); - return; - } + { + NewMessage("revokeperm [id]: Revokes administrative permissions to the player with the specified client ID.", Color.Cyan); + return; + } int id; int.TryParse(args[0], out id); @@ -432,12 +432,12 @@ namespace Barotrauma return; } - NewMessage("Valid permissions are:", Color.White); - NewMessage(" - all", Color.White); - foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) - { - NewMessage(" - " + permission.ToString(), Color.White); - } + NewMessage("Valid permissions are:", Color.White); + NewMessage(" - all", Color.White); + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) + { + NewMessage(" - " + permission.ToString(), Color.White); + } ShowQuestionPrompt("Permission to revoke from \"" + client.Name + "\"?", (perm) => { ClientPermissions permission = ClientPermissions.None; @@ -447,11 +447,11 @@ namespace Barotrauma } else { - if (!Enum.TryParse(perm, out permission)) - { - ThrowError("\"" + perm + "\" isn't a valid permission!"); - return; - } + if (!Enum.TryParse(perm, out permission)) + { + ThrowError("\"" + perm + "\" isn't a valid permission!"); + return; + } } client.SetPermissions(client.Permissions & ~permission); GameMain.Server.UpdateClientPermissions(client); From e35fe18662813d2d3bff2b02e3117c2a95414192 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sun, 17 Dec 2017 19:33:53 +0200 Subject: [PATCH 5/6] Carrier's "dummy limb" with a light source cannot be severed. Closes #154 --- .../BarotraumaShared/Content/Characters/Carrier/carrier.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Barotrauma/BarotraumaShared/Content/Characters/Carrier/carrier.xml b/Barotrauma/BarotraumaShared/Content/Characters/Carrier/carrier.xml index 9377d3d06..81a8367e1 100644 --- a/Barotrauma/BarotraumaShared/Content/Characters/Carrier/carrier.xml +++ b/Barotrauma/BarotraumaShared/Content/Characters/Carrier/carrier.xml @@ -61,7 +61,7 @@ - + From a5d6da31a40eb88a008f7e9150c84f90207c1309 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sun, 17 Dec 2017 20:42:31 +0200 Subject: [PATCH 6/6] Holdable items can be held in any limb slot, not just hands. + Characters can hold a flashlight in their mouth. --- .../Content/Items/Tools/tools.xml | 6 +-- .../Animation/HumanoidAnimController.cs | 4 +- .../Items/Components/Holdable/Holdable.cs | 38 +++++++++++++++++-- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml b/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml index 0d6c81251..c59cedf22 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Tools/tools.xml @@ -218,8 +218,7 @@ @@ -231,12 +230,11 @@ - + - diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs b/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs index f6962526c..9dbaf2193 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Animation/HumanoidAnimController.cs @@ -1011,8 +1011,6 @@ namespace Barotrauma public override void HoldItem(float deltaTime, Item item, Vector2[] handlePos, Vector2 holdPos, Vector2 aimPos, bool aim, float holdAngle) { - Holdable holdable = item.GetComponent(); - if (character.IsUnconscious || character.Stun > 0.0f) aim = false; //calculate the handle positions @@ -1030,7 +1028,6 @@ namespace Barotrauma bool usingController = character.SelectedConstruction != null && character.SelectedConstruction.GetComponent() != null; - float itemAngle; if (Anim != Animation.Climbing && !usingController && character.Stun <= 0.0f && aim && itemPos != Vector2.Zero) { @@ -1042,6 +1039,7 @@ namespace Barotrauma itemAngle = (torso.body.Rotation + holdAngle * Dir); + Holdable holdable = item.GetComponent(); if (holdable.ControlPose) { head.body.SmoothRotate(itemAngle); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs index 73d99dedc..4c67bfcdf 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Holdable.cs @@ -184,8 +184,8 @@ namespace Barotrauma.Items.Components item.SetTransform(rightHand.SimPosition, 0.0f); } - bool alreadySelected = character.HasSelectedItem(item); - if (picker.TrySelectItem(item)) + bool alreadySelected = character.HasEquippedItem(item); + if (picker.TrySelectItem(item) || picker.HasEquippedItem(item)) { item.body.Enabled = true; IsActive = true; @@ -308,7 +308,7 @@ namespace Barotrauma.Items.Components public override void Update(float deltaTime, Camera cam) { if (item.body == null || !item.body.Enabled) return; - if (picker == null || !picker.HasSelectedItem(item)) + if (picker == null || !picker.HasEquippedItem(item)) { IsActive = false; return; @@ -320,7 +320,37 @@ namespace Barotrauma.Items.Components item.Submarine = picker.Submarine; - picker.AnimController.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle); + if (picker.HasSelectedItem(item)) + { + picker.AnimController.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle); + } + else + { + Limb equipLimb = null; + if (picker.Inventory.IsInLimbSlot(item, InvSlotType.Face) || picker.Inventory.IsInLimbSlot(item, InvSlotType.Head)) + { + equipLimb = picker.AnimController.GetLimb(LimbType.Head); + } + else if (picker.Inventory.IsInLimbSlot(item, InvSlotType.Torso)) + { + equipLimb = picker.AnimController.GetLimb(LimbType.Torso); + } + else if (picker.Inventory.IsInLimbSlot(item, InvSlotType.Legs)) + { + equipLimb = picker.AnimController.GetLimb(LimbType.Waist); + } + + if (equipLimb != null) + { + float itemAngle = (equipLimb.Rotation + holdAngle * picker.AnimController.Dir); + + Matrix itemTransfrom = Matrix.CreateRotationZ(equipLimb.Rotation); + Vector2 transformedHandlePos = Vector2.Transform(handlePos[0], itemTransfrom); + + item.body.ResetDynamics(); + item.SetTransform(equipLimb.SimPosition - transformedHandlePos, itemAngle); + } + } } protected void Flip(Item item)