From 2efcd200f56c9fbae4c5ad7f4637275f5e9c4d8c Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 8 Apr 2019 13:36:30 +0300 Subject: [PATCH] (17490598f) Don't allow putting items into locked inventories by double-clicking (causes them to be dropped in multiplayer) --- .../BarotraumaClient/Source/GameMain.cs | 2 +- .../Source/Items/CharacterInventory.cs | 18 ++- .../AI/Objectives/AIObjectiveIdle.cs | 119 +++++++----------- 3 files changed, 57 insertions(+), 82 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GameMain.cs b/Barotrauma/BarotraumaClient/Source/GameMain.cs index 14fe0e948..10fa40667 100644 --- a/Barotrauma/BarotraumaClient/Source/GameMain.cs +++ b/Barotrauma/BarotraumaClient/Source/GameMain.cs @@ -61,7 +61,7 @@ namespace Barotrauma if (vanillaContent == null) { // TODO: Dynamic method for defining and finding the vanilla content package. - vanillaContent = SelectedPackages.SingleOrDefault(cp => Path.GetFileName(cp.Path).ToLowerInvariant() == "vanilla 0.9.xml"); + vanillaContent = ContentPackage.List.SingleOrDefault(cp => Path.GetFileName(cp.Path).ToLowerInvariant() == "vanilla 0.9.xml"); } return vanillaContent; } diff --git a/Barotrauma/BarotraumaClient/Source/Items/CharacterInventory.cs b/Barotrauma/BarotraumaClient/Source/Items/CharacterInventory.cs index 2cbac70b9..44ac24a05 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/CharacterInventory.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/CharacterInventory.cs @@ -539,7 +539,11 @@ namespace Barotrauma if (item.ParentInventory != this) { //in another inventory -> attempt to place in the character's inventory - if (allowInventorySwap) + if (item.ParentInventory.Locked) + { + return QuickUseAction.None; + } + else if (allowInventorySwap) { return item.ParentInventory is CharacterInventory ? QuickUseAction.TakeFromCharacter : QuickUseAction.TakeFromContainer; @@ -548,18 +552,24 @@ namespace Barotrauma else { var selectedContainer = character.SelectedConstruction?.GetComponent(); - if (selectedContainer != null && selectedContainer.Inventory != null && allowInventorySwap) + if (selectedContainer != null && + selectedContainer.Inventory != null && + !selectedContainer.Inventory.Locked && + allowInventorySwap) { //player has selected the inventory of another item -> attempt to move the item there return QuickUseAction.PutToContainer; } - else if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null && allowInventorySwap) + else if (character.SelectedCharacter != null && + character.SelectedCharacter.Inventory != null && + !character.SelectedCharacter.Inventory.Locked && + allowInventorySwap) { //player has selected the inventory of another character -> attempt to move the item there return QuickUseAction.PutToCharacter; } else if (character.SelectedBy != null && Character.Controlled == character.SelectedBy && - character.SelectedBy.Inventory != null && allowInventorySwap) + character.SelectedBy.Inventory != null && !character.SelectedBy.Inventory.Locked && allowInventorySwap) { return QuickUseAction.TakeFromCharacter; } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveIdle.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveIdle.cs index 30248ca2e..bad0fcffd 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveIdle.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/Objectives/AIObjectiveIdle.cs @@ -62,24 +62,9 @@ namespace Barotrauma newTargetTimer = 0; standStillTimer = 0; } - else if (character.IsClimbing) + if (character.AnimController.InWater || character.IsClimbing) { - if (currentTarget == null) - { - newTargetTimer = 0; - } - else - { - // Don't allow new targets when climbing. - newTargetTimer = Math.Max(newTargetIntervalMin, newTargetTimer); - } - } - else if (character.AnimController.InWater) - { - if (currentTarget == null) - { - newTargetTimer = 0; - } + standStillTimer = 0; } if (newTargetTimer <= 0.0f) { @@ -137,28 +122,23 @@ namespace Barotrauma // - if reached the end of the path // - if the target is unreachable // - if the path requires going outside - if (!character.IsClimbing) + if (SteeringManager != PathSteering || (PathSteering.CurrentPath != null && + (PathSteering.CurrentPath.NextNode == null || PathSteering.CurrentPath.Unreachable || PathSteering.CurrentPath.HasOutdoorsNodes))) { - if (SteeringManager != PathSteering || (PathSteering.CurrentPath != null && - (PathSteering.CurrentPath.NextNode == null || PathSteering.CurrentPath.Unreachable || PathSteering.CurrentPath.HasOutdoorsNodes))) + standStillTimer -= deltaTime; + if (standStillTimer > 0.0f) { - if (!character.AnimController.InWater) - { - standStillTimer -= deltaTime; - if (standStillTimer > 0.0f) - { - walkDuration = Rand.Range(walkDurationMin, walkDurationMax); - PathSteering.Reset(); - return; - } - if (standStillTimer < -walkDuration) - { - standStillTimer = Rand.Range(standStillMin, standStillMax); - } - } - Wander(deltaTime); + walkDuration = Rand.Range(walkDurationMin, walkDurationMax); + PathSteering.Reset(); return; } + if (standStillTimer < -walkDuration) + { + standStillTimer = Rand.Range(standStillMin, standStillMax); + } + + Wander(deltaTime); + return; } if (currentTarget != null) @@ -169,54 +149,44 @@ namespace Barotrauma public void Wander(float deltaTime) { - if (character.IsClimbing) { return; } //steer away from edges of the hull - var currentHull = character.CurrentHull; - if (currentHull != null) + if (character.AnimController.CurrentHull != null && !character.IsClimbing) { - float roomWidth = currentHull.Rect.Width; - if (roomWidth < WallAvoidDistance * 4) + float leftDist = character.Position.X - character.AnimController.CurrentHull.Rect.X; + float rightDist = character.AnimController.CurrentHull.Rect.Right - character.Position.X; + if (leftDist < WallAvoidDistance && rightDist < WallAvoidDistance) { - PathSteering.Reset(); + if (Math.Abs(rightDist - leftDist) > WallAvoidDistance / 2) + { + PathSteering.SteeringManual(deltaTime, Vector2.UnitX * Math.Sign(rightDist - leftDist)); + } + else + { + PathSteering.Reset(); + } + } + else if (leftDist < WallAvoidDistance) + { + //PathSteering.SteeringManual(deltaTime, Vector2.UnitX * (WallAvoidDistance - leftDist) / WallAvoidDistance); + PathSteering.SteeringManual(deltaTime, Vector2.UnitX); + PathSteering.WanderAngle = 0.0f; + } + else if (rightDist < WallAvoidDistance) + { + //PathSteering.SteeringManual(deltaTime, -Vector2.UnitX * (WallAvoidDistance - rightDist) / WallAvoidDistance); + PathSteering.SteeringManual(deltaTime, -Vector2.UnitX); + PathSteering.WanderAngle = MathHelper.Pi; } else { - float leftDist = character.Position.X - currentHull.Rect.X; - float rightDist = currentHull.Rect.Right - character.Position.X; - if (leftDist < WallAvoidDistance && rightDist < WallAvoidDistance) - { - if (Math.Abs(rightDist - leftDist) > WallAvoidDistance / 2) - { - PathSteering.SteeringManual(deltaTime, Vector2.UnitX * Math.Sign(rightDist - leftDist)); - } - else - { - PathSteering.Reset(); - } - } - else if (leftDist < WallAvoidDistance) - { - float speed = (WallAvoidDistance - leftDist) / WallAvoidDistance; - PathSteering.SteeringManual(deltaTime, Vector2.UnitX * MathHelper.Clamp(speed, 0.25f, 1)); - PathSteering.WanderAngle = 0.0f; - } - else - { - float speed = (WallAvoidDistance - rightDist) / WallAvoidDistance; - PathSteering.SteeringManual(deltaTime, -Vector2.UnitX * MathHelper.Clamp(speed, 0.25f, 1)); - PathSteering.WanderAngle = MathHelper.Pi; - } - else - { - SteeringManager.SteeringWander(); - } + SteeringManager.SteeringWander(); } } else { SteeringManager.SteeringWander(); } - if (!character.AnimController.InWater) + if (!character.IsClimbing && !character.AnimController.InWater) { //reset vertical steering to prevent dropping down from platforms etc character.AIController.SteeringManager.ResetY(); @@ -251,12 +221,7 @@ namespace Barotrauma if (!targetHulls.Contains(hull)) { targetHulls.Add(hull); - float weight = hull.Volume; - // Prefer rooms that are closer. Avoid rooms that are not in the same level. - float dist = Math.Abs(character.WorldPosition.X - hull.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - hull.WorldPosition.Y) * 5.0f; - float distanceFactor = MathHelper.Lerp(1, 0.1f, MathUtils.InverseLerp(0, 2500, dist)); - weight *= distanceFactor; - hullWeights.Add(weight); + hullWeights.Add(hull.Volume); } }