From 7ed95c430b514e59fd020767b2d3a4202d968bd1 Mon Sep 17 00:00:00 2001 From: Regalis Date: Tue, 30 Aug 2016 19:04:06 +0300 Subject: [PATCH] Option to choose which character to control with the console command when there are multiple characters with the same name --- Subsurface/Source/DebugConsole.cs | 43 +++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 308dbada2..1135aa8ca 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -363,8 +363,47 @@ namespace Barotrauma case "controlcharacter": case "control": if (commands.Length < 2) break; - string name = string.Join(" ", commands.Skip(1)).ToLowerInvariant(); - Character.Controlled = Character.CharacterList.Find(c => !c.IsNetworkPlayer && c.Name.ToLowerInvariant() == name); + + int characterIndex; + string characterName; + if (int.TryParse(commands.Last(), out characterIndex)) + { + characterName = string.Join(" ", commands.Skip(1).Take(commands.Length-2)).ToLowerInvariant(); + } + else + { + characterName = string.Join(" ", commands.Skip(1)).ToLowerInvariant(); + characterIndex = -1; + } + + var matchingCharacters = Character.CharacterList.FindAll(c => !c.IsNetworkPlayer && c.Name.ToLowerInvariant() == characterName); + + if (!matchingCharacters.Any()) + { + ThrowError("Matching characters not found"); + return; + } + + if (characterIndex==-1) + { + Character.Controlled = matchingCharacters.First(); + if (matchingCharacters.Count > 1) + { + NewMessage( + "Found multiple matching characters. "+ + "Use \"control [charactername] [0-"+(matchingCharacters.Count-1)+"]\" to choose which character to control.", + Color.LightGray); + } + } + else if (characterIndex<0 || characterIndex>= matchingCharacters.Count) + { + ThrowError("Character index out of range. Select an index between 0 and " + (matchingCharacters.Count - 1)); + } + else + { + Character.Controlled = matchingCharacters[characterIndex]; + } + break; case "godmode": if (Submarine.MainSub == null) return;