private static void HandleSlain(string part, double currentTime, int optionalIndex) { string test = null; string killer = null; if (part.Length > 16 && part.StartsWith("You have slain ", StringComparison.Ordinal) && part[part.Length - 1] == '!') { test = part.Substring(15, part.Length - 15 - 1); killer = ConfigUtil.PlayerName; } else if (optionalIndex > 9) { test = part.Substring(0, optionalIndex - 9); if (test.Length == 4 && test[3] == ' ') { test = ConfigUtil.PlayerName; } } // Gotcharms has been slain by an animated mephit! if (test != null && test.Length > 0) { if (!SlainQueue.Contains(test) && DataManager.Instance.GetFight(test) != null) { SlainQueue.Add(test); SlainTime = currentTime; } if (!InIgnoreList(test)) { if (killer != ConfigUtil.PlayerName && part.IndexOf(" by ", StringComparison.Ordinal) is int byIndex && byIndex > -1) { int len = part.Length - byIndex - 4 - 1; killer = (len + byIndex + 4) <= part.Length ? part.Substring(byIndex + 4, len) : ""; if (string.IsNullOrEmpty(killer)) { killer = "!"; } } if (test == ConfigUtil.PlayerName) { DataManager.Instance.ClearActiveAdps(); } var death = new DeathRecord() { Killed = string.Intern(test), Killer = string.Intern(killer) }; DataManager.Instance.AddDeathRecord(death, currentTime); } } }
private static bool UpdateSlain(string slain, string killer, LineData lineData) { bool handled = false; if (!string.IsNullOrEmpty(slain) && killer != null && !InIgnoreList(slain)) // killer may not be known so empty string is OK { killer = killer.Length > 2 ? PlayerManager.Instance.ReplacePlayer(killer, killer) : killer; slain = PlayerManager.Instance.ReplacePlayer(slain, slain); // clear your ADPS if you died if (slain == ConfigUtil.PlayerName) { DataManager.Instance.ClearActiveAdps(); } double currentTime = DateUtil.ParseLogDate(lineData.Line, out _); if (!double.IsNaN(currentTime)) { CheckSlainQueue(currentTime); lock (SlainQueue) { if (!SlainQueue.Contains(slain) && DataManager.Instance.GetFight(slain) != null) { SlainQueue.Add(slain); SlainTime = currentTime; } } var death = new DeathRecord() { Killed = string.Intern(slain), Killer = killer }; DataManager.Instance.AddDeathRecord(death, currentTime); handled = true; } } return(handled); }
public static void Process(LineData lineData) { string line = lineData.Line; try { var actionPart = line.Substring(LineParsing.ACTIONINDEX); var timeString = line.Substring(1, 24); var currentTime = DateUtil.ParseDate(timeString); // handle Slain queue if (!double.IsNaN(SlainTime) && currentTime > SlainTime) { SlainQueue.ForEach(slain => { if (!DataManager.Instance.RemoveActiveFight(slain) && char.IsUpper(slain[0])) { DataManager.Instance.RemoveActiveFight(char.ToLower(slain[0], CultureInfo.CurrentCulture) + slain.Substring(1)); } }); SlainQueue.Clear(); SlainTime = double.NaN; } int index; if (line.Length >= 40 && line.IndexOf(" damage", LineParsing.ACTIONINDEX + 13, StringComparison.Ordinal) > -1) { DamageRecord record = ParseDamage(actionPart); if (record != null) { DamageProcessedEvent e = new DamageProcessedEvent() { Record = record, OrigTimeString = timeString, BeginTime = currentTime }; EventsDamageProcessed?.Invoke(record, e); if (record.Type == Labels.DD) { if (SpecialCodes.Keys.FirstOrDefault(special => !string.IsNullOrEmpty(record.SubType) && record.SubType.Contains(special)) is string key && !string.IsNullOrEmpty(key)) { DataManager.Instance.AddSpecial(new SpecialSpell() { Code = SpecialCodes[key], Player = record.Attacker, BeginTime = currentTime }); } } } } else if (line.Length >= 49 && (index = line.IndexOf(", but miss", LineParsing.ACTIONINDEX + 22, StringComparison.Ordinal)) > -1) { DamageRecord record = ParseMiss(actionPart, index); if (record != null) { DamageProcessedEvent e = new DamageProcessedEvent() { Record = record, OrigTimeString = timeString, BeginTime = currentTime }; EventsDamageProcessed?.Invoke(record, e); } } else if (line.Length > 35 && line.EndsWith(" died.", StringComparison.Ordinal)) { var test = line.Substring(LineParsing.ACTIONINDEX, line.Length - LineParsing.ACTIONINDEX - 6); if (!SlainQueue.Contains(test) && DataManager.Instance.GetFight(test) != null) { SlainQueue.Add(test); SlainTime = currentTime; } if (test == "You") { test = ConfigUtil.PlayerName; DataManager.Instance.ClearActiveAdps(); } var death = new DeathRecord() { Killed = string.Intern(test), Killer = "" }; DataManager.Instance.AddDeathRecord(death, currentTime); } else if (line.Length > 30 && line.Length < 102 && (index = line.IndexOf(" slain ", LineParsing.ACTIONINDEX, StringComparison.Ordinal)) > -1) { HandleSlain(actionPart, currentTime, index - LineParsing.ACTIONINDEX); } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) #pragma warning restore CA1031 // Do not catch general exception types { if (e is ArgumentNullException || e is NullReferenceException || e is ArgumentOutOfRangeException || e is ArgumentException) { LOG.Error(e); } } }
internal void AddDeathRecord(DeathRecord record, double beginTime) => Helpers.AddAction(AllDeathBlocks, record, beginTime);