/// <summary> /// Gets a random name based on the specified settings /// </summary> /// <param name="gender">The gender.</param> /// <param name="components">The components.</param> /// <param name="separator">The separator.</param> /// <param name="forceSingleLetter">if set to <c>true</c> [force single letter].</param> /// <param name="lengthRestriction">Maximum number of characters in the returned string</param> /// <returns>System.String.</returns> /// <exception cref="ArgumentOutOfRangeException">components - null</exception> public string Get(NameGender gender = NameGender.Any, NameComponents components = NameComponents.FirstNameLastName, string separator = " ", bool forceSingleLetter = false, int lengthRestriction = 0) { char?forcedSingleLetter = Helpers.GetForcedSingleCharacter(forceSingleLetter, this.randomIndex); gender = this.DetermineGender(gender); int attempt = 0; while (true) //if there is a length restriction, retry a couple of times. If the string is still too long, just trim it { attempt++; var name = this.Get(gender, components, separator, forcedSingleLetter); if (lengthRestriction <= 0) { return(name); } else if (name.Length <= lengthRestriction) { return(name); } if (attempt >= 100) { return(name.Remove(lengthRestriction)); } } }
private string Get(NameGender gender, NameComponents components, string separator, char?forcedSingleLetter) { string firstName = components != NameComponents.LastNameOnly ? this.GetName(gender, forcedSingleLetter) : ""; string lastName = components != NameComponents.FirstNameOnly ? Helpers.GetToken(this.lastNames, this.randomIndex, forcedSingleLetter) : ""; string middleName = components == NameComponents.FirstNameMiddleNameLastName ? this.GetName(gender, forcedSingleLetter) : ""; switch (components) { case NameComponents.FirstNameLastName: return($"{firstName}{separator}{lastName}"); case NameComponents.FirstNameMiddleNameLastName: return($"{firstName}{separator}{middleName}{separator}{lastName}"); case NameComponents.FirstNameOnly: return(firstName); case NameComponents.LastNameOnly: return(lastName); case NameComponents.LastNameFirstName: return($"{lastName}{separator}{firstName}"); default: throw new ArgumentOutOfRangeException(nameof(components), components, null); } }
/// <summary> /// Gets an IEnumerable of random name based on the specified settings. /// <para>Enumerating the same result set multiple times will yield different results</para> /// </summary> /// <param name="numberOfNamesToReturn"></param> /// <param name="gender">The gender.</param> /// <param name="components">The components.</param> /// <param name="separator">The separator.</param> /// <param name="forceSingleLetter">if set to <c>true</c> [force single letter].</param> /// <param name="lengthRestriction">Maximum number of characters in the returned string</param> /// <returns>System.String.</returns> /// <exception cref="ArgumentOutOfRangeException">components - null</exception> public IEnumerable <string> Get(int numberOfNamesToReturn, NameGender gender = NameGender.Any, NameComponents components = NameComponents.FirstNameLastName, string separator = " ", bool forceSingleLetter = false, int lengthRestriction = 0) { for (int i = 0; i < numberOfNamesToReturn; i++) { yield return(this.Get(gender, components, separator, forceSingleLetter, lengthRestriction)); } }
public void DestroyEntity(Guid id) { Entity removal = this.Entities.Where(x => x.Id == id).FirstOrDefault(); if (removal != null) { Entities.Remove(removal); PositionComponents.Remove(id); VelocityComponents.Remove(id); DisplayComponents.Remove(id); AnimationComponents.Remove(id); SightRadiusComponents.Remove(id); LabelComponents.Remove(id); SkillLevelsComponents.Remove(id); TargetPositionComponents.Remove(id); DirectionComponents.Remove(id); TimeToLiveComponents.Remove(id); CollisionComponents.Remove(id); NameComponents.Remove(id); AICombatComponents.Remove(id); AIAlignmentComponents.Remove(id); AIStateComponents.Remove(id); AIFieldOfViewComponents.Remove(id); AISleepComponents.Remove(id); AIRoamComponents.Remove(id); AIFleeComponents.Remove(id); InputMovementComponents.Remove(id); EntityMessageComponents.Remove(id); AlternateFOVColorChangeComponents.Remove(id); HealthRegenerationComponents.Remove(id); OutlineComponents.Remove(id); SecondaryOutlineComponents.Remove(id); InventoryComponents.Remove(id); PickupComponents.Remove(id); StatModificationComponents.Remove(id); ValueComponents.Remove(id); ItemFunctionsComponents.Remove(id); PassivesComponents.Remove(id); ArtifactStatsComponents.Remove(id); BurningComponents.Remove(id); } }