From e7e858c05ba390b249335cb6695707e6ce79f78c Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 11 Apr 2019 18:25:58 +0300 Subject: [PATCH] (db7e4d6d5) Fix "crawler balling" caused by crawlers taking damage when targeting the sub and not yet latched on it. --- .../Source/Networking/GameClient.cs | 4 +--- .../Source/Networking/GameServer.cs | 13 ++++++++----- .../Source/Characters/AI/LatchOntoAI.cs | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index fa4a2d3b4..636cd27d4 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -1114,9 +1114,7 @@ namespace Barotrauma.Networking if (campaign == null) { - GameMain.GameSession = missionIndex < 0 ? - new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode, MissionType.None) : - new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode, MissionPrefab.List[missionIndex]); + GameMain.GameSession = new GameSession(GameMain.NetLobbyScreen.SelectedSub, "", gameMode, missionIndex < 0 ? null : MissionPrefab.List[missionIndex]); GameMain.GameSession.StartRound(levelSeed, levelDifficulty, loadSecondSub); } else diff --git a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs index d9137afc7..60d7c1e95 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/GameServer.cs @@ -1754,10 +1754,11 @@ namespace Barotrauma.Networking Log("Game mode: " + selectedMode.Name, ServerLog.MessageType.ServerMessage); Log("Submarine: " + selectedSub.Name, ServerLog.MessageType.ServerMessage); Log("Level seed: " + GameMain.NetLobbyScreen.LevelSeed, ServerLog.MessageType.ServerMessage); - } + } - MissionMode missionMode = GameMain.GameSession.GameMode as MissionMode; - bool missionAllowRespawn = campaign == null && (missionMode?.Mission == null || missionMode.Mission.AllowRespawn); + bool missionAllowRespawn = campaign == null && + (!(GameMain.GameSession.GameMode is MissionMode) || + ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn); if (serverSettings.AllowRespawn && missionAllowRespawn) respawnManager = new RespawnManager(this, usingShuttle ? selectedShuttle : null); @@ -1940,8 +1941,10 @@ namespace Barotrauma.Networking MultiPlayerCampaign campaign = GameMain.GameSession?.GameMode as MultiPlayerCampaign; - MissionMode missionMode = GameMain.GameSession.GameMode as MissionMode; - bool missionAllowRespawn = campaign == null && (missionMode?.Mission == null || missionMode.Mission.AllowRespawn); + bool missionAllowRespawn = campaign == null && + (!(GameMain.GameSession.GameMode is MissionMode) || + ((MissionMode)GameMain.GameSession.GameMode).Mission.AllowRespawn); + msg.Write(serverSettings.AllowRespawn && missionAllowRespawn); msg.Write(Submarine.MainSubs[1] != null); //loadSecondSub diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/LatchOntoAI.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/LatchOntoAI.cs index fe5304a4c..8670544d6 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/LatchOntoAI.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/LatchOntoAI.cs @@ -207,10 +207,10 @@ namespace Barotrauma break; } - if (attachTargetBody != null && deattachTimer < 0.0f) + if (IsAttached && attachTargetBody != null && deattachTimer < 0.0f) { Entity entity = attachTargetBody.UserData as Entity; - Submarine attachedSub = entity is Submarine ? (Submarine)entity : entity?.Submarine; + Submarine attachedSub = entity is Submarine sub ? sub : entity?.Submarine; if (attachedSub != null) { float velocity = attachedSub.Velocity == Vector2.Zero ? 0.0f : attachedSub.Velocity.Length();