public static string GenerateTag <T>(StateSnapshot snapshot = null) where T : ProfileBehavior { var result = string.Empty; var s = snapshot ?? StateSnapshot.Create(); if (s == null) { return(result); } var stateDict = s.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).ToDictionary(k => k.Name, v => v.GetValue(s)); result += $@" <{typeof(T).Name.TrimEnd("Tag")} questId=""{s.QuestId}"" stepId=""{s.QuestStep}"" "; foreach (var propertyInfo in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance)) { var xmlAttributes = propertyInfo.GetCustomAttributes <XmlAttributeAttribute>(); var attName = xmlAttributes.LastOrDefault()?.Name ?? string.Empty; if (string.IsNullOrEmpty(attName) || IgnoreXmlAttributeNames.Contains(attName)) { continue; } var valueMatch = stateDict.FirstOrDefault(i => string.Equals(propertyInfo.Name.ToLowerInvariant(), i.Key.ToLowerInvariant(), StringComparison.InvariantCultureIgnoreCase) || string.Equals(attName, i.Key.ToLowerInvariant(), StringComparison.InvariantCultureIgnoreCase)); var value = valueMatch.Value ?? GetDefaultValue(propertyInfo); if (value == null) { continue; } if (IsNumericType(propertyInfo.PropertyType) && !propertyInfo.Name.Contains("Id")) { value = Math.Round((decimal)Convert.ChangeType(value, typeof(decimal)), 3, MidpointRounding.AwayFromZero); result += $@"{attName}=""{value:0.##}"" "; } else { if (propertyInfo.PropertyType == typeof(bool)) { value = value.ToString().ToLowerInvariant(); } result += $@"{attName}=""{value}"" "; } } result += $@" worldSnoId=""{s.WorldSnoId}"" levelAreaSnoId=""{s.LevelAreaSnoId}"" />"; return(result); }
public static string GenerateMarkerTags <T>(Func <TrinityMarker, bool> markerSelector = null) where T : ProfileBehavior { var sb = new StringBuilder(); var s = StateSnapshot.Create(); foreach (var marker in Core.Markers.Where(a => markerSelector?.Invoke(a) ?? true)) { s.UpdateForMarker(marker); var actorMsg = s.ActorId != 0 ? $"Actor={s.ActorName} ({s.ActorId}) " : string.Empty; sb.AppendLine($" <!-- {marker.NameHash} {marker.MarkerType} Distance={marker.Distance} TextureId={marker.TextureId} WorldSnoId={marker.WorldSnoId} {actorMsg}-->"); sb.AppendLine(GenerateTag <T>(s)); sb.AppendLine(Environment.NewLine); } return(sb.ToString()); }
public static string GenerateActorTags <T>(Func <TrinityActor, bool> actorSelector) where T : ProfileBehavior { var sb = new StringBuilder(); var s = StateSnapshot.Create(); foreach (var actor in Core.Actors.Actors.Where(a => !a.IsMe && actorSelector(a)).OrderBy(a => a.Distance)) { s.UpdateForActor(actor); var minimapEntry = Core.Minimap.MinimapIcons.FirstOrDefault(m => m.Position.Distance(actor.Position) < 5f); var minimapMsg = minimapEntry != null ? $"MinimapName={minimapEntry.Name} " : string.Empty; var markerMsg = !string.IsNullOrEmpty(s.MarkerName) ? $"Marker={s.MarkerName} ({s.MarkerHash}, {s.MarkerType}) " : string.Empty; sb.AppendLine($" <!-- {actor.Name} ({actor.ActorSnoId}) {actor.ActorSnoId} Distance={actor.Distance} Type={actor.Type} Anim={actor.Animation} {minimapMsg}{markerMsg}-->"); sb.AppendLine(GenerateTag <T>(s)); sb.AppendLine(Environment.NewLine); } return(sb.ToString()); }