/// <summary> /// ログとマッチングする /// </summary> /// <param name="logLines">ログ行</param> public static void Match( string[] logLines) { var telops = OnePointTelopTable.Default.EnabledTable; // 不要になったWindowを閉じる var removeWindowList = new List <OnePointTelopWindow>(); foreach (var window in telopWindowList.Values) { if (!telops.Any(x => x.ID == window.DataSource.ID)) { removeWindowList.Add(window); } } foreach (var window in removeWindowList) { ActInvoker.Invoke(() => { window.DataSource.Left = window.Left; window.DataSource.Top = window.Top; window.Close(); }); telopWindowList.Remove(window.DataSource.ID); } foreach (var telop in telops.AsParallel()) { var regex = telop.Regex; var regexToHide = telop.RegexToHide; var isForceHide = false; foreach (var log in logLines) { // 通常マッチ if (regex == null) { var keyword = LogBuffer.MakeKeyword(telop.Keyword); if (!string.IsNullOrWhiteSpace(keyword)) { if (log.ToUpper().Contains( keyword.ToUpper())) { if (!telop.AddMessageEnabled) { telop.MessageReplaced = telop.Message; } else { telop.MessageReplaced += string.IsNullOrWhiteSpace(telop.MessageReplaced) ? telop.Message : Environment.NewLine + telop.Message; } telop.MatchDateTime = DateTime.Now; telop.Delayed = false; telop.MatchedLog = log; SoundController.Default.Play(telop.MatchSound); SoundController.Default.Play(telop.MatchTextToSpeak); continue; } } } // 正規表現マッチ if (regex != null) { if (regex.IsMatch(log)) { if (!telop.AddMessageEnabled) { telop.MessageReplaced = regex.Replace(log, telop.Message); } else { telop.MessageReplaced += string.IsNullOrWhiteSpace(telop.MessageReplaced) ? regex.Replace(log, telop.Message) : Environment.NewLine + regex.Replace(log, telop.Message); } telop.MatchDateTime = DateTime.Now; telop.Delayed = false; telop.MatchedLog = log; SoundController.Default.Play(telop.MatchSound); if (!string.IsNullOrWhiteSpace(telop.MatchTextToSpeak)) { var tts = regex.Replace(log, telop.MatchTextToSpeak); SoundController.Default.Play(tts); } continue; } } // 通常マッチ(強制非表示) if (regexToHide == null) { var keyword = LogBuffer.MakeKeyword(telop.KeywordToHide); if (!string.IsNullOrWhiteSpace(keyword)) { if (log.ToUpper().Contains( keyword.ToUpper())) { isForceHide = true; continue; } } } // 正規表現マッチ(強制非表示) if (regexToHide != null) { if (regexToHide.IsMatch(log)) { isForceHide = true; continue; } } } // end loop logLines // ディレイ時間が経過した? if (!telop.Delayed && telop.MatchDateTime > DateTime.MinValue && telop.Delay > 0) { var delayed = telop.MatchDateTime.AddSeconds(telop.Delay); if (DateTime.Now >= delayed) { telop.Delayed = true; SoundController.Default.Play(telop.DelaySound); var tts = regex != null && !string.IsNullOrWhiteSpace(telop.DelayTextToSpeak) ? regex.Replace(telop.MatchedLog, telop.DelayTextToSpeak) : telop.DelayTextToSpeak; SoundController.Default.Play(tts); } } var w = telopWindowList.ContainsKey(telop.ID) ? telopWindowList[telop.ID] : null; if (w == null) { w = new OnePointTelopWindow() { Title = "OnePointTelop - " + telop.Title, DataSource = telop }; if (Settings.Default.ClickThroughEnabled) { w.ToTransparentWindow(); } w.Opacity = 0; w.Show(); telopWindowList.Add(telop.ID, w); } // telopの位置を保存する if (DateTime.Now.Second == 0) { telop.Left = w.Left; telop.Top = w.Top; OnePointTelopTable.Default.Save(); } if (Settings.Default.OverlayVisible && Settings.Default.TelopAlwaysVisible) { // ドラッグ中じゃない? if (!w.IsDragging) { w.Refresh(); w.ShowOverlay(); } continue; } if (telop.MatchDateTime > DateTime.MinValue) { var start = telop.MatchDateTime.AddSeconds(telop.Delay); var end = telop.MatchDateTime.AddSeconds(telop.Delay + telop.DisplayTime); if (start <= DateTime.Now && DateTime.Now <= end) { w.Refresh(); w.ShowOverlay(); } else { w.HideOverlay(); if (DateTime.Now > end) { telop.MatchDateTime = DateTime.MinValue; telop.MessageReplaced = string.Empty; } } if (isForceHide) { w.HideOverlay(); telop.MatchDateTime = DateTime.MinValue; telop.MessageReplaced = string.Empty; } } else { w.HideOverlay(); telop.MessageReplaced = string.Empty; } } // end loop telops }
/// <summary> /// Spellをマッチングする /// </summary> /// <param name="spells">Spell</param> /// <param name="logLines">ログ</param> private void MatchSpells( SpellTimer[] spells, string[] logLines) { // Spellを舐める foreach (var spell in spells.AsParallel()) { var regex = spell.Regex; // マッチする? foreach (var logLine in logLines) { // 正規表現が無効? if (!spell.RegexEnabled || regex == null) { var keyword = LogBuffer.MakeKeyword(spell.Keyword); if (string.IsNullOrWhiteSpace(keyword)) { continue; } // キーワードが含まれるか? if (logLine.ToUpper().Contains( keyword.ToUpper())) { // ヒットしたログを格納する spell.MatchedLog = logLine; spell.SpellTitleReplaced = spell.SpellTitle; spell.MatchDateTime = DateTime.Now; spell.OverDone = false; spell.TimeupDone = false; // マッチ時点のサウンドを再生する this.Play(spell.MatchSound); this.Play(spell.MatchTextToSpeak); } continue; } // 正規表現でマッチングする if (regex.IsMatch(logLine)) { // ヒットしたログを格納する spell.MatchedLog = logLine; // 置換したスペル名を格納する spell.SpellTitleReplaced = regex.Replace( logLine, spell.SpellTitle); spell.MatchDateTime = DateTime.Now; spell.OverDone = false; spell.TimeupDone = false; // マッチ時点のサウンドを再生する this.Play(spell.MatchSound); if (!string.IsNullOrWhiteSpace(spell.MatchTextToSpeak)) { var tts = regex.Replace(logLine, spell.MatchTextToSpeak); this.Play(tts); } } } // Repeat対象のSpellを更新する if (spell.RepeatEnabled && spell.MatchDateTime > DateTime.MinValue) { if (DateTime.Now >= spell.MatchDateTime.AddSeconds(spell.RecastTime)) { spell.MatchDateTime = DateTime.Now; spell.OverDone = false; spell.TimeupDone = false; } } // n秒後のSoundを再生する if (spell.OverTime > 0 && !spell.OverDone && spell.MatchDateTime > DateTime.MinValue) { var over = spell.MatchDateTime.AddSeconds(spell.OverTime); if (DateTime.Now >= over) { this.Play(spell.OverSound); if (!string.IsNullOrWhiteSpace(spell.OverTextToSpeak)) { var tts = spell.RegexEnabled && regex != null? regex.Replace(spell.MatchedLog, spell.OverTextToSpeak) : spell.OverTextToSpeak; this.Play(tts); } spell.OverDone = true; } } // リキャスト完了のSoundを再生する if (spell.RecastTime > 0 && !spell.TimeupDone && spell.MatchDateTime > DateTime.MinValue) { var recast = spell.MatchDateTime.AddSeconds(spell.RecastTime); if (DateTime.Now >= recast) { this.Play(spell.TimeupSound); if (!string.IsNullOrWhiteSpace(spell.TimeupTextToSpeak)) { var tts = spell.RegexEnabled && regex != null? regex.Replace(spell.MatchedLog, spell.TimeupTextToSpeak) : spell.TimeupTextToSpeak; this.Play(tts); } spell.TimeupDone = true; } } } }