From 33747a63b0633591f229cec7ed07f5c279ec460f Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 29 Apr 2019 21:05:21 +0300 Subject: [PATCH] (3340f2f90) Don't do impact damage to structures in Structure.OnWallCollision. Impact damage was disabled when a character hits the sub from the outside (implemented in SubmarineBody), but should've been done here as well. --- .../Source/Characters/CharacterHUD.cs | 4 ++- .../Source/Items/CharacterInventory.cs | 3 +- .../Source/Items/Inventory.cs | 20 +++++++++---- .../BarotraumaClient/Source/Map/Structure.cs | 23 +++++++++++++++ .../Source/Events/Missions/MonsterMission.cs | 29 ++++--------------- .../BarotraumaShared/Source/Map/Structure.cs | 21 ++------------ 6 files changed, 50 insertions(+), 50 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs b/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs index 441ae6a6e..e180f44e6 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/CharacterHUD.cs @@ -85,7 +85,8 @@ namespace Barotrauma { if (character.Inventory != null) { - if (!character.LockHands && character.Stun < 0.1f) + if (!character.LockHands && character.Stun < 0.1f && + (character.SelectedConstruction == null || character.SelectedConstruction.GetComponent() == null)) { character.Inventory.Update(deltaTime, cam); } @@ -320,6 +321,7 @@ namespace Barotrauma } if (character.Inventory != null && !character.LockHands) { + character.Inventory.Locked = (character.SelectedConstruction != null && character.SelectedConstruction.GetComponent() != null); character.Inventory.DrawOwn(spriteBatch); character.Inventory.CurrentLayout = CharacterHealth.OpenHealthWindow == null && character.SelectedCharacter == null ? CharacterInventory.Layout.Default : diff --git a/Barotrauma/BarotraumaClient/Source/Items/CharacterInventory.cs b/Barotrauma/BarotraumaClient/Source/Items/CharacterInventory.cs index 71b3d07d0..0ea60b4a5 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/CharacterInventory.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/CharacterInventory.cs @@ -793,7 +793,7 @@ namespace Barotrauma base.Draw(spriteBatch); - if (hideButton != null && hideButton.Visible) + if (hideButton != null && hideButton.Visible && !Locked) { hideButton.DrawManually(spriteBatch, alsoChildren: true); } @@ -835,6 +835,7 @@ namespace Barotrauma color = Color.White; highlightedQuickUseSlot = slots[i]; } + if (Locked) { color *= 0.3f; } var quickUseIndicator = Items[i].AllowedSlots.Any(a => a == InvSlotType.Any) ? EquipIndicator : DropIndicator; diff --git a/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs b/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs index 8fb30030a..e3c4ea985 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs @@ -820,8 +820,9 @@ namespace Barotrauma else { Sprite slotSprite = slot.SlotSprite ?? slotSpriteSmall; - - spriteBatch.Draw(slotSprite.Texture, rect, slotSprite.SourceRect, slot.IsHighlighted ? Color.White : Color.White * 0.8f); + Color slotColor = slot.IsHighlighted ? Color.White : Color.White * 0.8f; + if (inventory != null && inventory.Locked) { slotColor = Color.Gray * 0.5f; } + spriteBatch.Draw(slotSprite.Texture, rect, slotSprite.SourceRect, slotColor); if (item != null && drawItem) { @@ -873,14 +874,17 @@ namespace Barotrauma } indicatorSprite.Draw(spriteBatch, containedIndicatorArea.Center.ToVector2(), - Color.DarkGray * 0.9f, + (inventory != null && inventory.Locked) ? Color.DarkGray * 0.5f : Color.DarkGray * 0.9f, origin: indicatorSprite.size / 2, rotate: 0.0f, scale: indicatorScale); - + + Color indicatorColor = ToolBox.GradientLerp(containedState, Color.Red, Color.Orange, Color.Green); + if (inventory != null && inventory.Locked) { indicatorColor *= 0.5f; } + spriteBatch.Draw(indicatorSprite.Texture, containedIndicatorArea.Center.ToVector2(), sourceRectangle: new Rectangle(indicatorSprite.SourceRect.Location, new Point((int)(indicatorSprite.SourceRect.Width * containedState), indicatorSprite.SourceRect.Height)), - color: ToolBox.GradientLerp(containedState, Color.Red, Color.Orange, Color.Green), + color: indicatorColor, rotation: 0.0f, origin: indicatorSprite.size / 2, scale: indicatorScale, @@ -920,6 +924,7 @@ namespace Barotrauma } Color spriteColor = sprite == item.Sprite ? item.GetSpriteColor() : item.GetInventoryIconColor(); + if (inventory != null && inventory.Locked) { spriteColor *= 0.5f; } if (CharacterHealth.OpenHealthWindow != null && !item.UseInHealthInterface) { spriteColor = Color.Lerp(spriteColor, Color.TransparentBlack, 0.5f); @@ -931,7 +936,10 @@ namespace Barotrauma sprite.Draw(spriteBatch, itemPos, spriteColor, rotation, scale); } - if (inventory != null && Character.Controlled?.Inventory == inventory && slot.QuickUseKey != Keys.None) + if (inventory != null && + !inventory.Locked && + Character.Controlled?.Inventory == inventory && + slot.QuickUseKey != Keys.None) { GUI.DrawString(spriteBatch, rect.Location.ToVector2(), slot.QuickUseKey.ToString().Substring(1, 1), diff --git a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs index 11e85a147..99b7bbedd 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Structure.cs @@ -1,6 +1,9 @@ using Barotrauma.Extensions; using Barotrauma.Lights; using Barotrauma.Networking; +using FarseerPhysics; +using FarseerPhysics.Dynamics; +using FarseerPhysics.Dynamics.Contacts; using Lidgren.Network; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -158,6 +161,26 @@ namespace Barotrauma return editingHUD; } + + partial void OnImpactProjSpecific(Fixture f1, Fixture f2, Contact contact) + { + if (!Prefab.Platform && Prefab.StairDirection == Direction.None) + { + Vector2 pos = ConvertUnits.ToDisplayUnits(f2.Body.Position); + + int section = FindSectionIndex(pos); + if (section > -1) + { + Vector2 normal = contact.Manifold.LocalNormal; + + float impact = Vector2.Dot(f2.Body.LinearVelocity, -normal) * f2.Body.Mass * 0.1f; + if (impact > 10.0f) + { + SoundPlayer.PlayDamageSound("StructureBlunt", impact, SectionPosition(section, true), tags: Tags); + } + } + } + } public override bool IsVisible(Rectangle worldView) { diff --git a/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs b/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs index 6e8445416..01905d2cf 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/Missions/MonsterMission.cs @@ -34,33 +34,14 @@ namespace Barotrauma { Level.Loaded.TryGetInterestingPosition(true, Level.PositionType.MainPath, Level.Loaded.Size.X * 0.3f, out Vector2 spawnPos); - //bool isClient = GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient; - //for (int i = 0; i < monsterCount; i++) - //{ - // monsters.Add(Character.Create(monsterFile, spawnPos, ToolBox.RandomSeed(8), null, isClient, true, false)); - //} - //monsters.ForEach(m => m.Enabled = false); - //SwarmBehavior.CreateSwarm(monsters.Cast()); - //sonarPositions.Add(spawnPos); - - float offsetAmount = 500; + bool isClient = GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient; for (int i = 0; i < monsterCount; i++) { - CoroutineManager.InvokeAfter(() => - { - bool isClient = GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient; - var monster = Character.Create(monsterFile, spawnPos + Rand.Vector(offsetAmount, Rand.RandSync.Server), i.ToString(), null, isClient, true, true); - monster.Enabled = false; - monsters.Add(monster); - if (monsters.Count == monsterCount) - { - //this will do nothing if the monsters have no swarm behavior defined, - //otherwise it'll make the spawned characters act as a swarm - SwarmBehavior.CreateSwarm(monsters.Cast()); - sonarPositions.Add(spawnPos); - } - }, Rand.Range(0f, monsterCount / 2, Rand.RandSync.Server)); + monsters.Add(Character.Create(monsterFile, spawnPos, ToolBox.RandomSeed(8), null, isClient, true, false)); } + monsters.ForEach(m => m.Enabled = false); + SwarmBehavior.CreateSwarm(monsters.Cast()); + sonarPositions.Add(spawnPos); } public override void Update(float deltaTime) diff --git a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs index 022ce6b33..38dcb8a64 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs @@ -635,29 +635,14 @@ namespace Barotrauma var character = ((Limb)f2.Body.UserData).character; if (character.DisableImpactDamageTimer > 0.0f || ((Limb)f2.Body.UserData).Mass < 100.0f) return true; } - - if (!Prefab.Platform && Prefab.StairDirection == Direction.None) - { - Vector2 pos = ConvertUnits.ToDisplayUnits(f2.Body.Position); - - int section = FindSectionIndex(pos); - if (section > -1) - { - Vector2 normal = contact.Manifold.LocalNormal; - - float impact = Vector2.Dot(f2.Body.LinearVelocity, -normal) * f2.Body.Mass * 0.1f; - if (impact < 10.0f) return true; -#if CLIENT - SoundPlayer.PlayDamageSound("StructureBlunt", impact, SectionPosition(section, true), tags: Tags); -#endif - AddDamage(section, impact); - } - } + OnImpactProjSpecific(f1, f2, contact); return true; } + partial void OnImpactProjSpecific(Fixture f1, Fixture f2, Contact contact); + public WallSection GetSection(int sectionIndex) { if (sectionIndex < 0 || sectionIndex >= Sections.Length) return null;