/// <returns></returns> CreatureData GetCreatureDataFromAnyLogEvent(string line, bool searchEntireDb) { var creaturesQuery = context.Creatures; if (!searchEntireDb) { var selectedHerds = context.Herds.Where(x => x.Selected).Select(x => x.HerdId).ToArray(); creaturesQuery = creaturesQuery.Where(x => selectedHerds.Contains(x.Herd)).ToArray(); } if (UseServerAsCreatureId) { var server = playerManager.CurrentServer; if (server == null) { logger.Info( "GetCreatureDataFromAnyLogEvent skipped processing log line, " + "due to unknown current server and UseServerAsCreatureId is enabled."); creaturesQuery = new CreatureEntity[0]; } else { creaturesQuery = creaturesQuery.Where( entity => string.IsNullOrEmpty(entity.ServerName) || server.ServerName.Matches(entity.ServerName)); } } var filteredCreatures = creaturesQuery.Where(x => line.Contains(x.Name, StringComparison.OrdinalIgnoreCase)).ToArray(); var result = new CreatureData(); foreach (CreatureEntity creatureEntity in filteredCreatures) { result.SecondaryInfo = null; Match match = Regex.Match(line, @"(\w+) (\w+) " + creatureEntity.Name, RegexOptions.IgnoreCase); if (match.Success) { result.Age = CreatureAge.CreateAgeFromRawCreatureName(match.Groups[1].Value); if (result.Age.CreatureAgeId != CreatureAgeId.Unknown) { result.SecondaryInfo = match.Groups[2].Value; } else { match = Regex.Match(line, @"(\w+) " + creatureEntity.Name, RegexOptions.IgnoreCase); if (match.Success) { result.Age = CreatureAge.CreateAgeFromRawCreatureName(match.Groups[1].Value); if (result.Age.CreatureAgeId != CreatureAgeId.Unknown) { result.SecondaryInfo = String.Empty; } } } if (result.Age.CreatureAgeId != CreatureAgeId.Unknown) { result.Creature = creatureEntity; // Attempting to advance age, unless it's ambiguous. var prevAge = result.Creature.Age.CreatureAgeId; var newAge = result.Age.CreatureAgeId; if (prevAge == CreatureAgeId.YoungFoal) { // Ambiguous: young foal or young mature, keep old value if (newAge == CreatureAgeId.Young) { result.Age = new CreatureAge(prevAge); } // Ambiguous: adolescent foal or adolescent mature, keep old value if (newAge == CreatureAgeId.Adolescent) { result.Age = new CreatureAge(prevAge); } } if (prevAge == CreatureAgeId.AdolescentFoal) { // Acceptable: young in this context can only mean young mature if (newAge == CreatureAgeId.Young) { result.Age = new CreatureAge(CreatureAgeId.Young); } // Ambiguous: adolescent foal or adolescent mature, keep old value if (newAge == CreatureAgeId.Adolescent) { result.Age = new CreatureAge(prevAge); } } break; } } } if (result.Creature == null) { return(null); } var existingCreaturesInQuery = filteredCreatures.Where(x => x.Name == result.Creature.Name).ToArray(); if (existingCreaturesInQuery.Length == 1) { return(result); } else if (existingCreaturesInQuery.Length > 1) { result.TooManyCreaturesFound = true; return(result); } return(null); }