public void Add(Determinative subjectDeterminative, string subj, string verb, Determinative objectDeterminative, string obj, Punctuation punctuation = Punctuation.Period, bool noInterrupt = false, bool requireMorePrompt = false) { sb.Append(Grammar.Get(subjectDeterminative, subj, verb)); if (obj != null) { sb.Append(" "); sb.Append(Grammar.Get(objectDeterminative, obj)); } if (punctuation == Punctuation.Period) { sb.Append("."); } else if (punctuation == Punctuation.ExclamationPoint) { sb.Append("!"); } else if (punctuation == Punctuation.Ellipsis) { sb.Append("..."); } else if (punctuation == Punctuation.QuestionMark) { sb.Append("?"); } sb.Append(" "); string message = sb.ToString(); sb.Clear(); Add(message, noInterrupt, requireMorePrompt); }
//todo, extra strings? public void Add(Determinative subjectDeterminative, Creature subj, string verb, Determinative objectDeterminative, Creature obj, Punctuation punctuation = Punctuation.Period, Visibility visibility = Visibility.RequireEither, bool assumeSubjectVisible = false, bool assumeObjectVisible = false, bool noInterrupt = false, bool requireMorePrompt = false) { bool subjectVisible = OmniscienceEnabled || assumeSubjectVisible || Player.CanSee(subj); bool objectVisible = obj != null && (OmniscienceEnabled || assumeObjectVisible || Player.CanSee(obj)); if (visibility == Visibility.RequireEither && !subjectVisible && !objectVisible) { return; } if (visibility == Visibility.RequireBoth && (!subjectVisible || !objectVisible)) { return; } if (visibility == Visibility.RequireSubject && !subjectVisible) { return; } if (visibility == Visibility.RequireObject && !objectVisible) { return; } string subjectName = subjectVisible? Names.Get(subj.OriginalType) : "something"; string objectName = objectVisible? Names.Get(obj.OriginalType) : (obj == null)? null : "something"; Add(subjectDeterminative, subjectName, verb, objectDeterminative, objectName, punctuation, noInterrupt, requireMorePrompt); }
// AddSimple for any sentence which has no object. // Each method also has an overload without Determinatives. These methods assume that "the" should be used. public void AddSimple(Determinative subjectDeterminative, Creature subj, string verb, Punctuation punctuation = Punctuation.Period, Visibility visibility = Visibility.RequireSubject, bool assumeSubjectVisible = false, bool noInterrupt = false, bool requireMorePrompt = false) => Add(subjectDeterminative, subj, verb, Determinative.None, null, punctuation, visibility, assumeSubjectVisible, false, noInterrupt, requireMorePrompt);
///<summary>Construct and return a sentence fragment from the given info.</summary> /// <param name="extraText">If present, will be added to the result string before the verb, but after everything else. /// For example, if extraText is "(unaware)", the result string could be "the goblin (unaware) trips". (This allows additional text /// to be included while still using the value of 'noun' to perform the lookup.)</param> /// <param name="excludeQuantity">If true, the value of 'quantity' will only be used to determine singular vs. plural, but /// will not be included in the result string.</param> public string Get(Determinative determinative, string noun, string verb = null, string extraText = null, int quantity = 1, bool excludeQuantity = false, bool possessive = false) { NounInfo nounInfo; nouns.TryGetValue(noun, out nounInfo); bool noArticles = nounInfo != null && nounInfo.NoArticles; // Default false bool uncountable = nounInfo != null && nounInfo.Uncountable; // Default false if (!noArticles) { if (determinative == Determinative.The) { sb.Append("the "); if (!excludeQuantity && quantity != 1) { sb.Append(quantity); sb.Append(" "); } } else if (determinative == Determinative.AAn) { if (uncountable) { sb.Append("some "); } else { if (quantity != 1) { if (!excludeQuantity) { sb.Append(quantity); sb.Append(" "); } } else { bool usesAn; if (nounInfo != null) { usesAn = nounInfo.UsesAn; } else { usesAn = StartsWithVowel(noun); } if (usesAn) { sb.Append("an "); } else { sb.Append("a "); } } } } else if (determinative == Determinative.ThisThese) { if (quantity != 1) { sb.Append("these "); if (!excludeQuantity) { sb.Append(quantity); sb.Append(" "); } } else { sb.Append("this "); } } else if (determinative == Determinative.ThatThose) { if (quantity != 1) { sb.Append("those "); if (!excludeQuantity) { sb.Append(quantity); sb.Append(" "); } } else { sb.Append("that "); } } else if (determinative == Determinative.Your) { sb.Append("your "); if (!excludeQuantity) { sb.Append(quantity); sb.Append(" "); } } } if (quantity == 1 || uncountable || noArticles) { sb.Append(noun); } else { if (nounInfo != null) { sb.Append(nounInfo.Plural); } else { AppendWithS(noun); } } if (possessive) { if (noun == "you" || noun == "You") { sb.Append("r"); // "your" } else { sb.Append("'s"); } } if (extraText != null) { sb.Append(" "); // Add this space only if needed, to avoid trailing spaces on the returned value. sb.Append(extraText); } if (verb != null) { sb.Append(" "); if (quantity != 1 || noun == "you" || noun == "You") { sb.Append(verb); } else { string thirdPersonSingular; if (verbs.TryGetValue(verb, out thirdPersonSingular)) { sb.Append(thirdPersonSingular); } else { AppendWithS(verb); } } } string result = sb.ToString(); sb.Clear(); return(result); }