diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/LevelResource.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/LevelResource.cs index 8a73e7e2e..b7951ce7d 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/LevelResource.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/LevelResource.cs @@ -7,7 +7,7 @@ namespace Barotrauma.Items.Components { public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { - DeattachTimer = msg.ReadSingle(); + deattachTimer = msg.ReadSingle(); if (deattachTimer >= DeattachDuration) { holdable.DeattachFromWall(); diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/RepairTool.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/RepairTool.cs index 9b14effac..f8f82df50 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/RepairTool.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/RepairTool.cs @@ -1,6 +1,7 @@ using Barotrauma.Particles; using FarseerPhysics; using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; using System.Linq; @@ -11,12 +12,21 @@ using System.Xml.Linq; namespace Barotrauma.Items.Components { partial class RepairTool +#if DEBUG + : IDrawableComponent +#endif { public ParticleEmitter ParticleEmitter { get; private set; } +#if DEBUG + public Vector2 DrawSize + { + get { return GameMain.DebugDraw ? Vector2.One * Range : Vector2.Zero; } + } +#endif private List ParticleEmitterHitStructure = new List(); private List ParticleEmitterHitCharacter = new List(); @@ -122,5 +132,17 @@ namespace Barotrauma.Items.Components emitter.Second.Emit(deltaTime, particlePos, item.CurrentHull, particleAngle + MathHelper.Pi, -particleAngle + MathHelper.Pi); } } +#if DEBUG + public void Draw(SpriteBatch spriteBatch, bool editing) + { + if (GameMain.DebugDraw && IsActive) + { + GUI.DrawLine(spriteBatch, + new Vector2(debugRayStartPos.X, -debugRayStartPos.Y), + new Vector2(debugRayEndPos.X, -debugRayEndPos.Y), + Color.Yellow); + } + } +#endif } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/LevelResource.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/LevelResource.cs index 458bf0c57..90a7a0665 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/LevelResource.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/LevelResource.cs @@ -2,12 +2,15 @@ using Lidgren.Network; using Microsoft.Xna.Framework; using System; +using System.Linq; using System.Xml.Linq; namespace Barotrauma.Items.Components { partial class LevelResource : ItemComponent, IServerSerializable { + private float lastSentDeattachTimer; + [Serialize(1.0f, false)] public float DeattachDuration { @@ -21,12 +24,29 @@ namespace Barotrauma.Items.Components get { return deattachTimer; } set { - deattachTimer = Math.Max(0.0f, value); //clients don't deattach the item until the server says so (handled in ClientRead) - if ((GameMain.NetworkMember == null || !GameMain.NetworkMember.IsClient) && deattachTimer >= DeattachDuration) + if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) + { + return; + } + deattachTimer = Math.Max(0.0f, value); +#if SERVER + if (deattachTimer >= DeattachDuration) + { + if (holdable.Attached){ item.CreateServerEvent(this); } + holdable.DeattachFromWall(); + } + else if (Math.Abs(lastSentDeattachTimer - deattachTimer) > 0.1f) + { + item.CreateServerEvent(this); + lastSentDeattachTimer = deattachTimer; + } +#else + if (deattachTimer >= DeattachDuration) { holdable.DeattachFromWall(); } +#endif } } @@ -67,7 +87,10 @@ namespace Barotrauma.Items.Components return; } holdable.Reattachable = false; - holdable.PickingTime = float.MaxValue; + if (requiredItems.Any()) + { + holdable.PickingTime = float.MaxValue; + } var body = item.body ?? holdable.Body; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs index 274c99569..153e694ef 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/RepairTool.cs @@ -17,6 +17,8 @@ namespace Barotrauma.Items.Components private readonly List fixableEntities; private Vector2 pickedPosition; private float activeTimer; + + private Vector2 debugRayStartPos, debugRayEndPos; [Serialize(0.0f, false)] public float Range { get; set; } @@ -121,10 +123,19 @@ namespace Barotrauma.Items.Components Vector2 rayStart = ConvertUnits.ToSimUnits(item.WorldPosition); Vector2 rayEnd = ConvertUnits.ToSimUnits(targetPosition); + debugRayStartPos = item.WorldPosition; + debugRayEndPos = ConvertUnits.ToDisplayUnits(rayEnd); + if (character.Submarine == null) { foreach (Submarine sub in Submarine.Loaded) { + Rectangle subBorders = sub.Borders; + subBorders.Location += new Point((int)sub.WorldPosition.X, (int)sub.WorldPosition.Y - sub.Borders.Height); + if (!MathUtils.CircleIntersectsRectangle(item.WorldPosition, Range * 5.0f, subBorders)) + { + continue; + } Repair(rayStart - sub.SimPosition, rayEnd - sub.SimPosition, deltaTime, character, degreeOfSuccess, ignoredBodies); } Repair(rayStart, rayEnd, deltaTime, character, degreeOfSuccess, ignoredBodies); @@ -238,6 +249,7 @@ namespace Barotrauma.Items.Components var levelResource = targetItem.GetComponent(); if (levelResource != null && levelResource.IsActive && + levelResource.requiredItems.Any() && levelResource.HasRequiredItems(user, addMessage: false)) { levelResource.DeattachTimer += deltaTime; diff --git a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs index c298546ab..81355ef74 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/ItemPrefab.cs @@ -503,386 +503,6 @@ namespace Barotrauma break; } } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); - - if (sprite == null) - { - DebugConsole.ThrowError("Item \"" + Name + "\" has no sprite!"); -#if SERVER - sprite = new Sprite("", Vector2.Zero); - sprite.SourceRect = new Rectangle(0, 0, 32, 32); -#else - sprite = new Sprite(TextureLoader.PlaceHolderTexture, null, null) - { - Origin = TextureLoader.PlaceHolderTexture.Bounds.Size.ToVector2() / 2 - }; -#endif - size = sprite.size; - sprite.EntityID = identifier; - } - - if (!category.HasFlag(MapEntityCategory.Legacy) && string.IsNullOrEmpty(identifier)) - { - DebugConsole.ThrowError( - "Item prefab \"" + name + "\" has no identifier. All item prefabs have a unique identifier string that's used to differentiate between items during saving and loading."); - } - if (!string.IsNullOrEmpty(identifier)) - { - MapEntityPrefab existingPrefab = List.Find(e => e.Identifier == identifier); - if (existingPrefab != null) - { - DebugConsole.ThrowError( - "Map entity prefabs \"" + name + "\" and \"" + existingPrefab.Name + "\" have the same identifier!"); - } - } - - AllowedLinks = element.GetAttributeStringArray("allowedlinks", new string[0], convertToLowerInvariant: true).ToList(); if (sprite == null) {