public virtual void ParseName() { RetCode rc; var command = NextState as ICommand; Debug.Assert(command != null); if (ObjData.Name == null) { ObjData.Name = ""; while (string.IsNullOrWhiteSpace(ObjData.Name)) { if (CurrToken < Tokens.Length && PrepTokenIndex < 0) { PrepTokenIndex = command.IsDobjPrepEnabled || command.IsIobjEnabled ? gEngine.FindIndex(Tokens, token => gEngine.Preps.FirstOrDefault(prep => string.Equals(prep.Name, token, StringComparison.OrdinalIgnoreCase) && command.IsPrepEnabled(prep)) != null) : -1; Prep = PrepTokenIndex >= 0 ? gEngine.Preps.FirstOrDefault(prep => string.Equals(prep.Name, Tokens[PrepTokenIndex], StringComparison.OrdinalIgnoreCase) && command.IsPrepEnabled(prep)) : null; if (((ObjData == DobjData && command.IsDobjPrepEnabled) || (ObjData == IobjData && command.IsIobjEnabled)) && PrepTokenIndex == CurrToken) { command.Prep = Globals.CloneInstance(Prep); command.ContainerType = Prep.ContainerType; var numTokens = Tokens.Length - CurrToken; ObjData.Name = string.Join(" ", Tokens.Skip((int)(CurrToken + 1)).Take((int)(numTokens - 1))); CurrToken += numTokens; } else if ((ObjData == DobjData && command.IsIobjEnabled) && PrepTokenIndex > CurrToken) { command.Prep = Globals.CloneInstance(Prep); command.ContainerType = Prep.ContainerType; var numTokens = PrepTokenIndex - CurrToken; ObjData.Name = string.Join(" ", Tokens.Skip((int)CurrToken).Take((int)numTokens)); CurrToken += numTokens; } else { PrepTokenIndex = -1; Prep = null; ObjData.Name = string.Join(" ", Tokens.Skip((int)CurrToken)); CurrToken = Tokens.Length; } } if (ObjData == IobjData && CurrToken < Tokens.Length && PrepTokenIndex >= 0) { CurrToken = PrepTokenIndex + 1; } if (CurrToken < Tokens.Length && string.IsNullOrWhiteSpace(ObjData.Name)) { ObjData.Name = string.Join(" ", Tokens.Skip((int)CurrToken)); CurrToken = Tokens.Length; } if (string.IsNullOrWhiteSpace(ObjData.Name)) { Debug.Assert(ActorMonster.IsCharacterMonster()); if (ObjData == DobjData) { if (ObjData.QueryDescFunc == null) { ObjData.QueryDescFunc = () => string.Format("{0}{1} {2}who or what? ", Environment.NewLine, command.Verb.FirstCharToUpper(), command.IsDobjPrepEnabled && command.Prep != null && Enum.IsDefined(typeof(ContainerType), command.Prep.ContainerType) ? gEngine.EvalContainerType(command.Prep.ContainerType, "inside ", "on ", "under ", "behind ") : ""); } } else { Debug.Assert(ObjData.QueryDescFunc != null); } gOut.Write(ObjData.QueryDescFunc()); Globals.Buf.SetFormat("{0}", Globals.In.ReadLine()); Globals.Buf = ReplacePrepositions(Globals.Buf); if (command.ShouldStripTrailingPunctuation()) { Globals.Buf.SetFormat("{0}", Globals.Buf.TrimEndPunctuationMinusPound().ToString().Trim()); } Tokens = Tokens.Concat(Globals.Buf.ToString().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)).ToArray(); } else { var mySeen = false; Globals.Buf.SetFormat("{0}", ObjData.Name); rc = gEngine.StripPrepsAndArticles(Globals.Buf, ref mySeen); Debug.Assert(gEngine.IsSuccess(rc)); ObjData.Name = Globals.Buf.ToString().Trim(); } } } }