From 7e67c20ccd0edd78c41cf666929c3b367f289279 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 1 Apr 2019 14:26:01 +0300 Subject: [PATCH] (b99c0ef39) Fix the enemies not selecting another attack if they cannot reach the target. --- .../BarotraumaClient/Source/GameSettings.cs | 14 +-- .../Source/Screens/MainMenuScreen.cs | 45 ++++----- .../Source/Networking/GameServerLogin.cs | 10 +- .../Source/Networking/ServerSettings.cs | 91 ++++++------------- .../Data/permissionpresets.xml | 9 -- .../Source/Characters/AI/EnemyAIController.cs | 11 ++- 6 files changed, 64 insertions(+), 116 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GameSettings.cs b/Barotrauma/BarotraumaClient/Source/GameSettings.cs index e8d6e8cfe..6205c6796 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSettings.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSettings.cs @@ -72,7 +72,7 @@ namespace Barotrauma private void CreateSettingsFrame() { - settingsFrame = new GUIFrame(new RectTransform(new Vector2(0.8f, 0.8f), GUI.Canvas, Anchor.Center)); + settingsFrame = new GUIFrame(new RectTransform(new Point(1024, 768), GUI.Canvas, Anchor.Center)); var settingsFramePadding = new GUIFrame(new RectTransform(new Vector2(0.95f, 0.9f), settingsFrame.RectTransform, Anchor.TopCenter) { RelativeOffset = new Vector2(0.0f, 0.05f) }, style: null); @@ -85,12 +85,13 @@ namespace Barotrauma var generalLayoutGroup = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 1.0f), leftPanel.RectTransform, Anchor.TopLeft)); - new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), generalLayoutGroup.RectTransform), TextManager.Get("ContentPackages")); + //new GUITextBlock(new RectTransform(new Vector2(1.0f, 0.05f), generalLayoutGroup.RectTransform), TextManager.Get("ContentPackages")); var contentPackageList = new GUIListBox(new RectTransform(new Vector2(1.0f, 0.75f), generalLayoutGroup.RectTransform)) { CanBeFocused = false }; + foreach (ContentPackage contentPackage in ContentPackage.List) { var tickBox = new GUITickBox(new RectTransform(new Vector2(1.0f, 0.067f), contentPackageList.Content.RectTransform, minSize: new Point(0, 15)), contentPackage.Name) @@ -611,9 +612,8 @@ namespace Barotrauma for (int i = 0; i < inputNames.Length; i++) { var inputContainer = new GUILayoutGroup(new RectTransform(new Vector2(1.0f, 0.06f), inputFrame.RectTransform)) { Stretch = true, IsHorizontal = true, RelativeSpacing = 0.05f }; - new GUITextBlock(new RectTransform(new Vector2(0.3f, 1.0f), inputContainer.RectTransform, Anchor.TopLeft) { MinSize = new Point(150, 0) }, - TextManager.Get("InputType." + ((InputType)i)) + ": ", font: GUI.SmallFont) { ForceUpperCase = true }; - var keyBox = new GUITextBox(new RectTransform(new Vector2(0.7f, 1.0f), inputContainer.RectTransform), + new GUITextBlock(new RectTransform(new Vector2(0.25f, 1.0f), inputContainer.RectTransform, Anchor.TopLeft), TextManager.Get("InputType." + ((InputType)i)) + ": ", font: GUI.SmallFont) { ForceUpperCase = true }; + var keyBox = new GUITextBox(new RectTransform(new Vector2(1.0f, 1.0f), inputContainer.RectTransform), text: keyMapping[i].ToString(), font: GUI.SmallFont) { UserData = i @@ -641,7 +641,7 @@ namespace Barotrauma new GUIFrame(new RectTransform(new Vector2(1.0f, 0.02f), generalLayoutGroup.RectTransform), style: null); new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomLeft), - TextManager.Get("Cancel"), style: "GUIButtonLarge") + TextManager.Get("Cancel")) { IgnoreLayoutGroups = true, OnClicked = (x, y) => @@ -657,7 +657,7 @@ namespace Barotrauma }; applyButton = new GUIButton(new RectTransform(new Vector2(0.4f, 1.0f), buttonArea.RectTransform, Anchor.BottomRight), - TextManager.Get("ApplySettingsButton"), style: "GUIButtonLarge") + TextManager.Get("ApplySettingsButton")) { IgnoreLayoutGroups = true, Enabled = false diff --git a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs index 01fba6b49..c46668705 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/MainMenuScreen.cs @@ -51,7 +51,7 @@ namespace Barotrauma new GUIImage(new RectTransform(new Vector2(0.35f, 0.2f), Frame.RectTransform, Anchor.BottomRight) { RelativeOffset = new Vector2(0.05f, 0.05f) }, style: "TitleText"); - buttonsParent = new GUILayoutGroup(new RectTransform(new Vector2(0.3f, 0.85f), parent: Frame.RectTransform, anchor: Anchor.BottomLeft, pivot: Pivot.BottomLeft) + buttonsParent = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.85f), parent: Frame.RectTransform, anchor: Anchor.BottomLeft, pivot: Pivot.BottomLeft) { AbsoluteOffset = new Point(50, 0) }) @@ -61,7 +61,7 @@ namespace Barotrauma }; // === CAMPAIGN - var campaignHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.1f, 0.0f) }, isHorizontal: true); + var campaignHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.1f, 0.0f) }, isHorizontal: true); new GUIImage(new RectTransform(new Vector2(0.2f, 0.7f), campaignHolder.RectTransform), "MainMenuCampaignIcon") { @@ -107,7 +107,7 @@ namespace Barotrauma }; // === MULTIPLAYER - var multiplayerHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.0f) }, isHorizontal: true); + var multiplayerHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.05f, 0.0f) }, isHorizontal: true); new GUIImage(new RectTransform(new Vector2(0.2f, 0.7f), multiplayerHolder.RectTransform), "MainMenuMultiplayerIcon") { @@ -152,7 +152,7 @@ namespace Barotrauma }; // === CUSTOMIZE - var customizeHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.15f, 0.0f) }, isHorizontal: true); + var customizeHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 1.0f), parent: buttonsParent.RectTransform) { RelativeOffset = new Vector2(0.15f, 0.0f) }, isHorizontal: true); new GUIImage(new RectTransform(new Vector2(0.2f, 0.7f), customizeHolder.RectTransform), "MainMenuCustomizeIcon") { @@ -209,7 +209,7 @@ namespace Barotrauma } // === OPTION - var optionHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.9f, 0.5f), parent: buttonsParent.RectTransform), isHorizontal: true); + var optionHolder = new GUILayoutGroup(new RectTransform(new Vector2(0.5f, 0.5f), parent: buttonsParent.RectTransform), isHorizontal: true); new GUIImage(new RectTransform(new Vector2(0.15f, 0.6f), optionHolder.RectTransform), "MainMenuOptionIcon") { @@ -219,7 +219,7 @@ namespace Barotrauma //spacing new GUIFrame(new RectTransform(new Vector2(0.01f, 0.0f), optionHolder.RectTransform), style: null); - var optionButtons = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 1.0f), parent: optionHolder.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.15f) }); + var optionButtons = new GUILayoutGroup(new RectTransform(new Vector2(0.55f, 1.0f), parent: optionHolder.RectTransform) { RelativeOffset = new Vector2(0.0f, 0.15f) }); var optionList = new GUILayoutGroup(new RectTransform(new Vector2(0.8f, 0.15f), parent: optionButtons.RectTransform)) { @@ -241,7 +241,7 @@ namespace Barotrauma //debug button for quickly starting a new round #if DEBUG - new GUIButton(new RectTransform(new Vector2(0.8f, 0.1f), buttonsParent.RectTransform, Anchor.TopLeft, Pivot.BottomLeft) { AbsoluteOffset = new Point(0, -40) }, + new GUIButton(new RectTransform(new Vector2(0.5f, 0.1f), buttonsParent.RectTransform, Anchor.TopLeft, Pivot.BottomLeft) { AbsoluteOffset = new Point(0, -40) }, "Quickstart (dev)", style: "GUIButtonLarge", color: Color.Red) { IgnoreLayoutGroups = true, @@ -255,7 +255,7 @@ namespace Barotrauma #endif var minButtonSize = new Point(120, 20); - var maxButtonSize = new Point(480, 80); + var maxButtonSize = new Point(240, 40); /*new GUIButton(new RectTransform(new Vector2(1.0f, 0.1f), buttonsParent.RectTransform), TextManager.Get("TutorialButton"), style: "GUIButtonLarge") { @@ -270,21 +270,16 @@ namespace Barotrauma SetupButtons(buttons); buttons.ForEach(b => b.TextBlock.SetTextPos());*/ - var relativeSize = new Vector2(0.6f, 0.5f); + var relativeSize = new Vector2(0.5f, 0.5f); var minSize = new Point(600, 400); - var maxSize = new Point(2000, 1500); - var anchor = Anchor.CenterRight; - var pivot = Pivot.CenterRight; - Vector2 relativeSpacing = new Vector2(0.05f, 0.0f); - + var maxSize = new Point(900, 600); + var anchor = Anchor.Center; + var pivot = Pivot.Center; menuTabs = new GUIFrame[Enum.GetValues(typeof(Tab)).Length + 1]; - - menuTabs[(int)Tab.Settings] = new GUIFrame(new RectTransform(new Vector2(relativeSize.X, 0.8f), GUI.Canvas, anchor, pivot, minSize, maxSize) { RelativeOffset = relativeSpacing }, - style: null); - - menuTabs[(int)Tab.NewGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize) { RelativeOffset = relativeSpacing }); + + menuTabs[(int)Tab.NewGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize)); var paddedNewGame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), menuTabs[(int)Tab.NewGame].RectTransform, Anchor.Center), style: null); - menuTabs[(int)Tab.LoadGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize) { RelativeOffset = relativeSpacing }); + menuTabs[(int)Tab.LoadGame] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize)); var paddedLoadGame = new GUIFrame(new RectTransform(new Vector2(0.9f, 0.9f), menuTabs[(int)Tab.LoadGame].RectTransform, Anchor.Center), style: null); campaignSetupUI = new CampaignSetupUI(false, paddedNewGame, paddedLoadGame, Submarine.SavedSubmarines) @@ -295,13 +290,13 @@ namespace Barotrauma var hostServerScale = new Vector2(0.7f, 1.0f); menuTabs[(int)Tab.HostServer] = new GUIFrame(new RectTransform( - Vector2.Multiply(relativeSize, hostServerScale), GUI.Canvas, anchor, pivot, minSize.Multiply(hostServerScale), maxSize.Multiply(hostServerScale)) { RelativeOffset = relativeSpacing }); + Vector2.Multiply(relativeSize, hostServerScale), GUI.Canvas, anchor, pivot, minSize.Multiply(hostServerScale), maxSize.Multiply(hostServerScale))); CreateHostServerFields(); //---------------------------------------------------------------------- - menuTabs[(int)Tab.Tutorials] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize) { RelativeOffset = relativeSpacing }); + menuTabs[(int)Tab.Tutorials] = new GUIFrame(new RectTransform(relativeSize, GUI.Canvas, anchor, pivot, minSize, maxSize)); //PLACEHOLDER var tutorialList = new GUIListBox( @@ -382,7 +377,6 @@ namespace Barotrauma return false; } - GameMain.Config.ResetSettingsFrame(); selectedTab = (Tab)obj; switch (selectedTab) @@ -395,9 +389,8 @@ namespace Barotrauma campaignSetupUI.UpdateLoadMenu(); break; case Tab.Settings: - menuTabs[(int)Tab.Settings].RectTransform.ClearChildren(); - GameMain.Config.SettingsFrame.RectTransform.Parent = menuTabs[(int)Tab.Settings].RectTransform; - GameMain.Config.SettingsFrame.RectTransform.RelativeSize = Vector2.One; + GameMain.Config.ResetSettingsFrame(); + menuTabs[(int)Tab.Settings] = GameMain.Config.SettingsFrame; break; case Tab.JoinServer: GameMain.ServerListScreen.Select(); diff --git a/Barotrauma/BarotraumaServer/Source/Networking/GameServerLogin.cs b/Barotrauma/BarotraumaServer/Source/Networking/GameServerLogin.cs index 2d720f969..4bd7a0077 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/GameServerLogin.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/GameServerLogin.cs @@ -494,15 +494,7 @@ namespace Barotrauma.Networking } else { - var defaultPerms = PermissionPreset.List.Find(p => p.Name == "None"); - if (defaultPerms != null) - { - newClient.SetPermissions(defaultPerms.Permissions, defaultPerms.PermittedCommands); - } - else - { - newClient.SetPermissions(ClientPermissions.None, new List()); - } + newClient.SetPermissions(ClientPermissions.None, new List()); } } diff --git a/Barotrauma/BarotraumaServer/Source/Networking/ServerSettings.cs b/Barotrauma/BarotraumaServer/Source/Networking/ServerSettings.cs index ec80a70d9..a9a354d94 100644 --- a/Barotrauma/BarotraumaServer/Source/Networking/ServerSettings.cs +++ b/Barotrauma/BarotraumaServer/Source/Networking/ServerSettings.cs @@ -337,56 +337,37 @@ namespace Barotrauma.Networking continue; } + string permissionsStr = clientElement.GetAttributeString("permissions", ""); ClientPermissions permissions = Networking.ClientPermissions.None; - List permittedCommands = new List(); - - if (clientElement.Attribute("preset") == null) + if (permissionsStr.ToLowerInvariant() == "all") { - string permissionsStr = clientElement.GetAttributeString("permissions", ""); - if (permissionsStr.ToLowerInvariant() == "all") + foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) { - foreach (ClientPermissions permission in Enum.GetValues(typeof(ClientPermissions))) - { - permissions |= permission; - } - } - else if (!Enum.TryParse(permissionsStr, out permissions)) - { - DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + permissionsStr + "\" is not a valid client permission."); - continue; - } - - if (permissions.HasFlag(Networking.ClientPermissions.ConsoleCommands)) - { - foreach (XElement commandElement in clientElement.Elements()) - { - if (commandElement.Name.ToString().ToLowerInvariant() != "command") continue; - - string commandName = commandElement.GetAttributeString("name", ""); - DebugConsole.Command command = DebugConsole.FindCommand(commandName); - if (command == null) - { - DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + commandName + "\" is not a valid console command."); - continue; - } - - permittedCommands.Add(command); - } + permissions |= permission; } } - else + else if (!Enum.TryParse(permissionsStr, out permissions)) { - string presetName = clientElement.GetAttributeString("preset", ""); - PermissionPreset preset = PermissionPreset.List.Find(p => p.Name == presetName); - if (preset == null) + DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + permissionsStr + "\" is not a valid client permission."); + continue; + } + + List permittedCommands = new List(); + if (permissions.HasFlag(Networking.ClientPermissions.ConsoleCommands)) + { + foreach (XElement commandElement in clientElement.Elements()) { - DebugConsole.ThrowError("Failed to restore saved permissions to the client \"" + clientName + "\". Permission preset \"" + presetName + "\" not found."); - return; - } - else - { - permissions = preset.Permissions; - permittedCommands = preset.PermittedCommands.ToList(); + if (commandElement.Name.ToString().ToLowerInvariant() != "command") continue; + + string commandName = commandElement.GetAttributeString("name", ""); + DebugConsole.Command command = DebugConsole.FindCommand(commandName); + if (command == null) + { + DebugConsole.ThrowError("Error in " + ClientPermissionsFile + " - \"" + commandName + "\" is not a valid console command."); + continue; + } + + permittedCommands.Add(command); } } @@ -459,14 +440,9 @@ namespace Barotrauma.Networking foreach (SavedClientPermission clientPermission in ClientPermissions) { - var matchingPreset = PermissionPreset.List.Find(p => p.MatchesPermissions(clientPermission.Permissions, clientPermission.PermittedCommands)); - if (matchingPreset != null && matchingPreset.Name == "None") - { - continue; - } - XElement clientElement = new XElement("Client", - new XAttribute("name", clientPermission.Name)); + new XAttribute("name", clientPermission.Name), + new XAttribute("permissions", clientPermission.Permissions.ToString())); if (clientPermission.SteamID > 0) { @@ -477,21 +453,14 @@ namespace Barotrauma.Networking clientElement.Add(new XAttribute("ip", clientPermission.IP)); } - if (matchingPreset == null) + if (clientPermission.Permissions.HasFlag(Barotrauma.Networking.ClientPermissions.ConsoleCommands)) { - clientElement.Add(new XAttribute("permissions", clientPermission.Permissions.ToString())); - if (clientPermission.Permissions.HasFlag(Networking.ClientPermissions.ConsoleCommands)) + foreach (DebugConsole.Command command in clientPermission.PermittedCommands) { - foreach (DebugConsole.Command command in clientPermission.PermittedCommands) - { - clientElement.Add(new XElement("command", new XAttribute("name", command.names[0]))); - } + clientElement.Add(new XElement("command", new XAttribute("name", command.names[0]))); } } - else - { - clientElement.Add(new XAttribute("preset", matchingPreset.Name)); - } + doc.Root.Add(clientElement); } diff --git a/Barotrauma/BarotraumaShared/Data/permissionpresets.xml b/Barotrauma/BarotraumaShared/Data/permissionpresets.xml index 3187fe94a..49e953433 100644 --- a/Barotrauma/BarotraumaShared/Data/permissionpresets.xml +++ b/Barotrauma/BarotraumaShared/Data/permissionpresets.xml @@ -13,13 +13,6 @@ - - - - - - - @@ -35,8 +28,6 @@ - - diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs index be09c3888..cc21a1ad1 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/EnemyAIController.cs @@ -631,8 +631,7 @@ namespace Barotrauma else { // If the secondary cooldown is defined and expired, check if we can switch the attack - var previousLimb = AttackingLimb; - var newLimb = GetAttackLimb(attackWorldPos, previousLimb); + var newLimb = GetAttackLimb(attackWorldPos, AttackingLimb); if (newLimb != null) { // Attack with the new limb @@ -680,8 +679,7 @@ namespace Barotrauma else { // If the secondary cooldown is defined and expired, check if we can switch the attack - var previousLimb = AttackingLimb; - var newLimb = GetAttackLimb(attackWorldPos, previousLimb); + var newLimb = GetAttackLimb(attackWorldPos, AttackingLimb); if (newLimb != null) { // Attack with the new limb @@ -725,6 +723,11 @@ namespace Barotrauma // Check that we can reach the target distance = Vector2.Distance(AttackingLimb.WorldPosition, attackWorldPos); canAttack = distance < AttackingLimb.attack.Range; + if (!canAttack && !IsCoolDownRunning) + { + // If not, reset the attacking limb, if the cooldown is not running + AttackingLimb = null; + } } // If the attacking limb is a hand or claw, for example, using it as the steering limb can end in the result where the character circles around the target. For example the Hammerhead steering with the claws when it should use the torso.