private LinkedList <string> CallChildren(Console.ConsoleMessage message, CombatConfiguration configuration, LinkedList <string> accumulator) { if (!message.IsVerboseEmpty) { string basic = ReplaceTags(message.m_message, configuration); string advanced = ReplaceTags(message.m_verbosemessage, configuration); accumulator.AddLast($"Combat message:\n{basic}Tooltip:\n{advanced}"); } else { accumulator.AddLast(ReplaceTags(message.m_message, configuration)); } Main.Log(accumulator.Last.Value); if (message.Children?.Count > 0) { foreach (Console.ConsoleMessage childMessage in message.Children) { accumulator = CallChildren(childMessage, configuration, accumulator); } } return(accumulator); }
/// <summary> /// Return both the basic and tooltip combat information /// </summary> /// <param name="message">The combat message</param> /// <param name="configuration">The configuration for the combat log exporter</param> /// <returns>The formated combat message</returns> public override string HandleMessage(Console.ConsoleMessage message, CombatConfiguration configuration) { LinkedList <string> stringList = new LinkedList <string>(); LinkedList <string> listOfStrings = CallChildren(message, configuration, stringList); return(string.Join("\n", listOfStrings.ToArray())); }
/// <summary> /// Replace the various tags that is contained in the combat messages - formating them in a pleasing manner /// </summary> /// <param name="messageAsString">The message to format</param> /// <param name="configuration">The configuration for the combat log exporter</param> /// <returns>The message with tags correctly formatted</returns> protected String ReplaceTags(String messageAsString, CombatConfiguration configuration) { /* * // Fix cases that involves sprites in the console message * var matches = configuration.GetSpriteNameRegex.Matches(messageAsString); * * foreach (Match match in matches) * { * string uppername = match.Groups[1].Value.CapitalizeFirst(); * * // Armor is abrivated as ar, so we need to make this something more understandable * uppername = uppername.Replace("Ar", "Armor"); * * messageAsString = configuration.FullSpriteRegex.Replace(messageAsString, " " + uppername, 1, 0); * } */ // Remove all the color information messageAsString = configuration.RemoveTagsRegex.Replace(messageAsString, ""); // Remove multiple instances of the word Health Health var healthRepetition = new Regex(@"Health[\s]*Health"); while (healthRepetition.IsMatch(messageAsString)) { messageAsString = healthRepetition.Replace(messageAsString, "Health", 1); } // Remove all double spaces while (messageAsString.Contains(" ")) { messageAsString = messageAsString.Replace(" ", " "); } // Check whether we need to exclude the message bool ignoreMessage = false; foreach (string exclude in configuration.ExcludeWordList) { if (messageAsString.Contains(exclude)) { ignoreMessage = true; break; } } if (!ignoreMessage) { return(messageAsString + "\n"); } else { return(null); } }
/// <summary> /// Write the logs /// </summary> /// <param name="stringsToWrite">The string that is to be written</param> /// <param name="configuration">The configuration for the combat log exporter</param> public void WriteLogs(StringBuilder stringsToWrite, CombatConfiguration configuration, SkirmishInformation skirmish) { // Write the combat log to a file string dateTimeName = $"{configuration.CombatLogWriteLocation}{skirmish.MapName} - {skirmish.StartOfCombatTime}.log"; try { File.WriteAllText(dateTimeName, stringsToWrite.ToString()); } catch (Exception e) { Game.Console.AddMessage($"Exception in Combat Log Exporter: {e}"); } }
/// <summary> /// Return both the basic and tooltip combat information /// </summary> /// <param name="message">The combat message</param> /// <param name="configuration">The configuration for the combat log exporter</param> /// <returns>The formated combat message</returns> public override string HandleMessage(ConsoleMessage message, CombatConfiguration configuration) { if (!message.IsVerboseEmpty) { string basic = ReplaceTags(message.Message, configuration); string advanced = ReplaceTags(message.VerboseMessage, configuration); return($"Combat message:\n{basic}Tooltip:\n{advanced}"); } else { return(ReplaceTags(message.Message, configuration)); } }
/// <summary> /// The constructor initializes the configuration, log writer and the instance that makes and formats the combat report /// </summary> public CombatLogExporterManager() { configuration = new FileReaderConfiguration(); logWriter = new LogFileWriter(); if (configuration.TooltipReporting) { combatReporting = new TooltipReporting(); } else { combatReporting = new BasicReporting(); } }
/// <summary> /// Write the logs /// </summary> /// <param name="stringsToWrite">The string that is to be written</param> /// <param name="configuration">The configuration for the combat log exporter</param> public void WriteLogs(StringBuilder stringsToWrite, CombatConfiguration configuration, SkirmishInformation skirmish) { // Write the combat log to a file string dateTimeName = $"{configuration.CombatLogWriteLocation}{skirmish.MapName} - {skirmish.StartOfCombatTime}.log"; try { File.WriteAllText(dateTimeName, stringsToWrite.ToString()); } catch (Exception e) { Main.LogError(e); } }
/// <summary> /// Return the basic combat information /// </summary> /// <param name="message">The combat message</param> /// <param name="configuration">The configuration for the combat log exporter</param> /// <returns>The formated combat message</returns> public override string HandleMessage(ConsoleMessage message, CombatConfiguration configuration) { return(ReplaceTags(message.Message, configuration)); }
/// <summary> /// Recieve and format the combat message /// </summary> /// <param name="messageAsString">The message to format</param> /// <param name="configuration">The configuration for the combat log exporter</param> /// <returns>The message correctly formatted</returns> public abstract String HandleMessage(ConsoleMessage message, CombatConfiguration configuration);