コミットメタ情報

リビジョン2378341adab69e58fab6c199bb3816ddd90deae0 (tree)
日時2018-12-08 21:58:21
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

任務を達成したときに通知を出す

変更サマリ

差分

--- a/KancolleSniffer/Config.cs
+++ b/KancolleSniffer/Config.cs
@@ -103,7 +103,7 @@ namespace KancolleSniffer
103103 {
104104 public int Volume { get; set; } = 100;
105105
106- public string[] Files { get; set; } =
106+ public string[] Files =
107107 {
108108 "ensei.mp3",
109109 "nyuukyo.mp3",
@@ -114,7 +114,8 @@ namespace KancolleSniffer
114114 "20min.mp3",
115115 "syuuri.mp3",
116116 "syuuri2.mp3",
117- "hirou.mp3"
117+ "hirou.mp3",
118+ "ninmu.mp3"
118119 };
119120
120121 public string this[string name]
@@ -122,6 +123,15 @@ namespace KancolleSniffer
122123 get => Files[Config.NotificationIndex[name]];
123124 set => Files[Config.NotificationIndex[name]] = value;
124125 }
126+
127+ public void Upgrade()
128+ {
129+ var expected = Config.NotificationNames.Length;
130+ if (Files.Length == expected)
131+ return;
132+ Array.Resize(ref Files, expected);
133+ Files[expected - 1] = "ninmu.mp3";
134+ }
125135 }
126136
127137 [Flags]
@@ -176,15 +186,35 @@ namespace KancolleSniffer
176186 }
177187 }
178188
179- public void Normalization()
189+ public void Upgrade()
180190 {
181- Settings = Settings.Select(s =>
182- (s & NotificationType.Pushbullet) != 0
183- ? s ^ NotificationType.Pushbullet | NotificationType.Push
184- : s)
185- .ToArray();
186- RepeatIntervals = RepeatIntervals.Select(v => v < 0 ? 0 : v).ToArray();
187- PreliminaryPeriods = PreliminaryPeriods.Select(v => v < 0 ? 0 : v).ToArray();
191+ UpgradeSettings(ref Settings);
192+ UpgradeParameterArray(ref RepeatIntervals);
193+ UpgradeParameterArray(ref PreliminaryPeriods);
194+ }
195+
196+ private void UpgradeSettings(ref NotificationType[] settings)
197+ {
198+ for (var i = 0; i < settings.Length; i++)
199+ {
200+ if ((settings[i] & NotificationType.Pushbullet) != 0)
201+ settings[i] = settings[i] ^ NotificationType.Pushbullet | NotificationType.Push;
202+ }
203+ var expected = Config.NotificationNames.Length;
204+ if (expected == settings.Length)
205+ return;
206+ Array.Resize(ref settings, expected);
207+ settings[expected - 1] = NotificationType.All;
208+ }
209+
210+ private void UpgradeParameterArray(ref int[] array)
211+ {
212+ Array.Resize(ref array, Config.NotificationNames.Length);
213+ for (var i = 0; i < array.Length; i++)
214+ {
215+ if (array[i] < 0)
216+ array[i] = 0;
217+ }
188218 }
189219 }
190220
@@ -250,7 +280,7 @@ namespace KancolleSniffer
250280 public static readonly string[] NotificationNames =
251281 {
252282 "遠征終了", "入渠終了", "建造完了", "艦娘数超過", "装備数超過",
253- "大破警告", "泊地修理20分経過", "泊地修理進行", "泊地修理完了", "疲労回復"
283+ "大破警告", "泊地修理20分経過", "泊地修理進行", "泊地修理完了", "疲労回復", "任務達成"
254284 };
255285
256286 public static readonly Dictionary<string, int> NotificationIndex =
@@ -282,8 +312,9 @@ namespace KancolleSniffer
282312 config = (Config)serializer.Deserialize(file);
283313 foreach (var property in GetType().GetProperties())
284314 property.SetValue(this, property.GetValue(config, null), null);
285- Notifications.Normalization();
315+ Notifications.Upgrade();
286316 ComposeNotificationFlags();
317+ Sounds.Upgrade();
287318 if (AlwaysShowResultRank)
288319 {
289320 Spoilers = Spoiler.All;
--- a/KancolleSniffer/MainForm.cs
+++ b/KancolleSniffer/MainForm.cs
@@ -1126,6 +1126,12 @@ namespace KancolleSniffer
11261126 _toolTip.SetToolTip(count[i], "");
11271127 }
11281128 }
1129+ _sniffer.GetQuestNotifications(out var notify, out var stop);
1130+ foreach (var questName in notify)
1131+ SetNotification("任務達成", 0, questName);
1132+ foreach (var questName in stop)
1133+ _notificationManager.StopRepeat("任務達成", questName);
1134+ _notificationManager.Flash();
11291135 }
11301136
11311137 private void Alarm(string balloonTitle, string balloonMessage, string name)
--- a/KancolleSniffer/Model/QuestInfo.cs
+++ b/KancolleSniffer/Model/QuestInfo.cs
@@ -235,7 +235,7 @@ namespace KancolleSniffer.Model
235235 return "";
236236 }
237237
238- public bool Cleared => NowArray?.Zip(Spec.MaxArray, (n, m) => n >= m).All(x => x) ?? Now >= Spec.Max;
238+ public bool Cleared => NowArray?.Zip(Spec.MaxArray, (n, m) => n >= m).All(x => x) ?? Spec.Max != 0 && Now >= Spec.Max;
239239 }
240240
241241 // @formatter:off
@@ -390,6 +390,7 @@ namespace KancolleSniffer.Model
390390 private readonly BattleInfo _battleInfo;
391391 private readonly Func<DateTime> _nowFunc = () => DateTime.Now;
392392 private DateTime _lastReset;
393+ private IEnumerable<QuestStatus> _clearedQuest = new List<QuestStatus>();
393394
394395 private readonly Color[] _color =
395396 {
@@ -410,6 +411,27 @@ namespace KancolleSniffer.Model
410411 _nowFunc = nowFunc;
411412 }
412413
414+ public void GetNotifications(out string[] notify, out string[] stop)
415+ {
416+ var cleared = _quests.Values.Where(q => q.Count.Cleared).ToArray();
417+ notify = cleared.Except(_clearedQuest, new QuestComparer()).Select(q => q.Name).ToArray();
418+ stop = _clearedQuest.Except(cleared, new QuestComparer()).Select(q => q.Name).ToArray();
419+ _clearedQuest = cleared;
420+ }
421+
422+ private class QuestComparer : IEqualityComparer<QuestStatus>
423+ {
424+ public bool Equals(QuestStatus x, QuestStatus y)
425+ {
426+ return x?.Id == y?.Id;
427+ }
428+
429+ public int GetHashCode(QuestStatus obj)
430+ {
431+ return obj.Id;
432+ }
433+ }
434+
413435 public void InspectQuestList(dynamic json)
414436 {
415437 ResetQuests();
--- a/KancolleSniffer/NotificationManager.cs
+++ b/KancolleSniffer/NotificationManager.cs
@@ -79,6 +79,11 @@ namespace KancolleSniffer
7979 _notificationQueue.StopRepeat(key, fleet);
8080 }
8181
82+ public void StopRepeat(string key, string subject)
83+ {
84+ _notificationQueue.StopRepeat(key, subject);
85+ }
86+
8287 public void SuspendRepeat(string exception = "")
8388 {
8489 _notificationQueue.SuspendRepeat(exception);
@@ -180,6 +185,13 @@ namespace KancolleSniffer
180185 Title = "疲労が回復しました",
181186 Body = "%f艦隊"
182187 }
188+ },
189+ {
190+ "任務達成", new Message
191+ {
192+ Title = "任務を達成しました",
193+ Body = "%s"
194+ }
183195 }
184196 };
185197
@@ -319,6 +331,11 @@ namespace KancolleSniffer
319331 _queue.RemoveAll(n => IsMatch(n, key) && n.Fleet == fleet);
320332 }
321333
334+ public void StopRepeat(string key, string subject)
335+ {
336+ _queue.RemoveAll(n => IsMatch(n, key) && n.Subject == subject);
337+ }
338+
322339 private bool IsMatch(Notification n, string key) =>
323340 n.Key.Substring(0, 4) == key.Substring(0, 4) && n.Schedule != default;
324341
--- a/KancolleSniffer/Sniffer.cs
+++ b/KancolleSniffer/Sniffer.cs
@@ -621,6 +621,9 @@ namespace KancolleSniffer
621621
622622 public QuestStatus[] Quests => _questInfo.Quests;
623623
624+ public void GetQuestNotifications(out string[] notify, out string[] stop) =>
625+ _questInfo.GetNotifications(out notify, out stop);
626+
624627 public void ClearQuests() => _questInfo.ClearQuests();
625628
626629 public NameAndTimer[] Missions => _missionInfo.Missions;
Binary files /dev/null and b/Sounds/ninmu.mp3 differ
旧リポジトリブラウザで表示