1 // Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
16 using System.Collections.Generic;
\r
18 using System.Xml.Serialization;
\r
19 using KancolleSniffer.Util;
\r
21 namespace KancolleSniffer.Model
\r
23 public class QuestCount
\r
25 public int Id { get; set; }
\r
26 public int Now { get; set; }
\r
27 public int[] NowArray { get; set; }
\r
30 public QuestSpec Spec { get; set; }
\r
32 public bool AdjustCount(int progress)
\r
34 if (!Spec.AdjustCount)
\r
36 if (NowArray != null)
\r
38 if (progress != 100)
\r
40 NowArray = NowArray.Zip(Spec.MaxArray, Math.Max).ToArray();
\r
59 var now = Now + Spec.Shift;
\r
60 var max = Spec.Max + Spec.Shift;
\r
61 var low = (int)Math.Ceiling(max * progress / 100.0);
\r
62 if (low >= max && progress != 100)
\r
64 var high = (int)Math.Ceiling(max * next / 100.0);
\r
67 Now = low - Spec.Shift;
\r
72 Now = high - 1 - Spec.Shift;
\r
78 public override string ToString()
\r
80 if (Id == 280 || Id == 284 || Id == 426 || Id == 845 || Id == 854 || Id == 872 || Id == 873 || Id == 888 || Id == 894)
\r
81 return $"{NowArray.Count(n => n >= 1)}/{Spec.MaxArray.Length}";
\r
82 return NowArray != null
\r
83 ? string.Join(" ", NowArray.Zip(Spec.MaxArray, (n, m) => $"{n}/{m}"))
\r
84 : $"{Now}/{Spec.Max}";
\r
87 public QuestCount Clone()
\r
89 var clone = (QuestCount)MemberwiseClone();
\r
90 if (NowArray != null)
\r
91 clone.NowArray = (int[])NowArray.Clone();
\r
95 public bool Equals(QuestCount other)
\r
99 if (NowArray == null)
\r
100 return Now == other.Now;
\r
101 return NowArray.SequenceEqual(other.NowArray);
\r
104 public string ToToolTip()
\r
109 return string.Join(" ",
\r
110 new[] {"1-2", "1-3", "1-4", "2-1"}.Zip(NowArray, (map, n) => n >= 1 ? map : "")
\r
111 .Where(s => !string.IsNullOrEmpty(s)));
\r
113 return string.Join(" ",
\r
114 new[] {"1-4", "2-1", "2-2", "2-3"}.Zip(NowArray, (map, n) => n >= 1 ? map : "")
\r
115 .Where(s => !string.IsNullOrEmpty(s)));
\r
117 return string.Join(" ",
\r
118 new[] {"警備任務", "対潜警戒任務", "海上護衛任務", "強硬偵察任務"}
\r
119 .Zip(NowArray, (mission, n) => n >= 1 ? mission : "")
\r
120 .Where(s => !string.IsNullOrEmpty(s)));
\r
122 return string.Join(" ",
\r
123 new[] {"対潜警戒任務", "海峡警備行動", "長時間対潜警戒"}.Zip(NowArray, (mission, n) => n >= 1 ? mission + n : "")
\r
124 .Where(s => !string.IsNullOrEmpty(s)));
\r
126 return string.Join(" ",
\r
127 new[] {"4-1", "4-2", "4-3", "4-4", "4-5"}.Zip(NowArray, (map, n) => n >= 1 ? map : "")
\r
128 .Where(s => !string.IsNullOrEmpty(s)));
\r
130 return string.Join(" ",
\r
131 new[] {"2-4", "6-1", "6-3", "6-4"}.Zip(NowArray, (map, n) => n >= 1 ? map : "")
\r
132 .Where(s => !string.IsNullOrEmpty(s)));
\r
134 return string.Join(" ",
\r
135 new[] {"7-2M", "5-5", "6-2", "6-5"}.Zip(NowArray, (map, n) => n >= 1 ? map : "")
\r
136 .Where(s => !string.IsNullOrEmpty(s)));
\r
138 return string.Join(" ",
\r
139 new[] {"3-1", "3-2", "3-3"}.Zip(NowArray, (map, n) => n >= 1 ? map : "")
\r
140 .Where(s => !string.IsNullOrEmpty(s)));
\r
142 return string.Join(" ",
\r
143 new[] {"5-1", "5-3", "5-4"}.Zip(NowArray, (map, n) => n >= 1 ? map : "")
\r
144 .Where(s => !string.IsNullOrEmpty(s)));
\r
146 return string.Join(" ",
\r
147 new[] {"艦戦", "艦爆", "艦攻", "水偵"}.Zip(NowArray, (type, n) => n >= 1 ? type + n : "")
\r
148 .Where(s => !string.IsNullOrEmpty(s)));
\r
150 return string.Join(" ",
\r
151 new[] {"1-5", "7-1", "7-2G", "7-2M"}.Zip(NowArray, (map, n) => n >= 1 ? $"{map}:{n}" : "")
\r
152 .Where(s => !string.IsNullOrEmpty(s)));
\r
154 return string.Join(" ",
\r
155 new[] {"1-3", "1-4", "2-1", "2-2", "2-3"}.Zip(NowArray, (map, n) => n >= 1 ? map : "")
\r
156 .Where(s => !string.IsNullOrEmpty(s)));
\r
161 public bool Cleared => NowArray?.Zip(Spec.MaxArray, (n, m) => n >= m).All(x => x) ??
\r
162 Spec.Max != 0 && Now >= Spec.Max;
\r
165 public class QuestCounter
\r
167 private readonly QuestInfo _questInfo;
\r
168 private readonly ItemInfo _itemInfo;
\r
169 private readonly BattleInfo _battleInfo;
\r
170 private readonly SortedDictionary<int, QuestStatus> _quests;
\r
172 private bool _boss;
\r
174 private class ResultShipSpecs
\r
176 public ResultShipSpecs(BattleInfo battleInfo)
\r
178 Specs = battleInfo.Result?.Friend.Main.Where(s => s.NowHp > 0).Select(ship => ship.Spec).ToArray() ??
\r
180 Ids = Specs.Select(spec => spec.Id).ToArray();
\r
181 Types = Specs.Select(spec => spec.ShipType).ToArray();
\r
182 Classes = Specs.Select(spec => spec.ShipClass).ToArray();
\r
183 Flagship = Specs.FirstOrDefault();
\r
184 FlagshipType = Types.FirstOrDefault();
\r
187 public ShipSpec[] Specs { get; }
\r
188 public int[] Ids { get; }
\r
189 public int[] Types { get; }
\r
190 public int[] Classes { get; }
\r
191 public ShipSpec Flagship { get; }
\r
192 public int FlagshipType { get; }
\r
195 public QuestCounter(QuestInfo questInfo, ItemInfo itemInfo, BattleInfo battleInfo)
\r
197 _questInfo = questInfo;
\r
198 _quests = questInfo.QuestDictionary;
\r
199 _itemInfo = itemInfo;
\r
200 _battleInfo = battleInfo;
\r
203 private bool NeedSave
\r
205 set => _questInfo.NeedSave = value;
\r
208 public void InspectMapStart(dynamic json)
\r
210 if (_quests.TryGetValue(214, out var ago)) // あ号
\r
211 ago.Count.NowArray[0]++;
\r
212 InspectMapNext(json);
\r
215 public void InspectMapNext(dynamic json)
\r
217 _map = (int)json.api_maparea_id * 10 + (int)json.api_mapinfo_no;
\r
220 var cell = json.api_no() ? (int)json.api_no : 0;
\r
227 _boss = (int)json.api_event_id == 5;
\r
229 if (_quests.TryGetValue(861, out var q861) && _map == 16 && (int)json.api_event_id == 8)
\r
231 if (new ResultShipSpecs(_battleInfo).Types.Count(s => s == 10 || s == 22) == 2)
\r
232 Increment(q861.Count);
\r
236 public void InspectBattleResult(dynamic json)
\r
238 var rank = json.api_win_rank;
\r
239 foreach (var count in _quests.Values.Select(q => q.Count))
\r
241 switch (count.Spec)
\r
243 case QuestSortie sortie:
\r
244 if (!FleetCheck(count.Id))
\r
246 if (!_boss && count.Id == 216)
\r
251 if (sortie.Count(count, rank, _map, _boss))
\r
254 case QuestEnemyType enemyType:
\r
255 var num = enemyType.CountResult(
\r
256 _battleInfo.Result.Enemy.Main.Concat(_battleInfo.Result.Enemy.Guard));
\r
261 if (count.Id == 214)
\r
262 CountAgo(count, rank);
\r
266 private void CountAgo(QuestCount count, string rank)
\r
268 if (QuestSortie.CompareRank(rank, "S") == 0)
\r
269 IncrementNth(count, 1);
\r
272 IncrementNth(count, 2);
\r
273 if (QuestSortie.CompareRank(rank, "B") <= 0)
\r
274 IncrementNth(count, 3);
\r
277 private bool FleetCheck(int id)
\r
279 var specs = new ResultShipSpecs(_battleInfo);
\r
283 return specs.Ids.Intersect(new[] {62, 63, 64, 265, 266, 268, 319, 192, 194}).Count() == 3;
\r
285 return specs.FlagshipType == 3 && specs.Types.Count(s => s == 3) <= 3 &&
\r
286 specs.Types.All(s => s == 2 || s == 3);
\r
288 return specs.Types.Count(type => type == 3) > 0 && specs.Classes.Count(c => new[]
\r
294 }.Contains(c)) == 3;
\r
296 return specs.Types.Count(type => type == 2) >= 2 &&
\r
297 specs.Specs.Count(spec => spec.IsAircraftCarrier) >= 2;
\r
299 return specs.FlagshipType == 2 &&
\r
300 specs.Types.OrderBy(x => x).SequenceEqual(new[] {2, 2, 2, 2, 3, 5});
\r
303 return specs.Types.Count(type => type == 1 || type == 2) >= 3 &&
\r
304 specs.Types.Intersect(new[] {3, 4, 7, 21}).Any();
\r
306 return specs.Types.Count(s => s == 3) >= 2 && specs.Types.Count(s => s == 16) >= 1;
\r
308 return specs.Types.Count(type => type == 3) >= 1;
\r
310 return specs.Ids.Contains(543) &&
\r
311 specs.Ids.Intersect(new[]
\r
319 return specs.Ids.Intersect(new[]
\r
321 69, 272, 427, // 鳥海
\r
323 123, 295, 142, // 衣笠
\r
324 59, 262, 416, // 古鷹
\r
325 60, 263, 417, // 加古
\r
326 51, 213, 477, // 天龍
\r
330 return specs.Specs.Any(spec => spec.IsAircraftCarrier);
\r
332 return specs.Types.Count(type => type == 3) >= 2;
\r
334 return specs.Flagship.IsAircraftCarrier &&
\r
335 specs.Specs.Count(spec => spec.IsAircraftCarrier) >= 2 &&
\r
336 specs.Types.Count(type => type == 2) >= 2;
\r
338 return specs.Ids.Intersect(new[]
\r
340 17, 225, 566, // 陽炎
\r
341 18, 226, 567, // 不知火
\r
350 private int _questFleet;
\r
352 public void StartPractice(string request)
\r
354 var values = HttpUtility.ParseQueryString(request);
\r
355 _questFleet = int.Parse(values["api_deck_id"]) - 1;
\r
358 public void InspectPracticeResult(dynamic json)
\r
360 foreach (var count in _quests.Values.Select(q => q.Count))
\r
362 if (!FleetCheck(count.Id))
\r
364 if (count.Id == 318 && _questFleet != 0)
\r
366 if (!(count.Spec is QuestPractice practice))
\r
368 if (practice.Check(json.api_win_rank))
\r
373 private readonly int[] _missionId = new int[ShipInfo.FleetCount];
\r
375 public void InspectDeck(dynamic json)
\r
377 foreach (var entry in json)
\r
378 _missionId[(int)entry.api_id - 1] = (int)entry.api_mission[1];
\r
381 public void InspectMissionResult(string request, dynamic json)
\r
383 var values = HttpUtility.ParseQueryString(request);
\r
384 var deck = int.Parse(values["api_deck_id"]);
\r
385 if ((int)json.api_clear_result == 0)
\r
387 var mid = _missionId[deck - 1];
\r
388 foreach (var count in _quests.Values.Select(q => q.Count))
\r
390 if (!(count.Spec is QuestMission mission))
\r
392 if (mission.Count(count, mid))
\r
397 public void CountNyukyo() => Increment(503);
\r
399 public void CountCharge() => Increment(504);
\r
401 public void InspectCreateItem(string request)
\r
403 var values = HttpUtility.ParseQueryString(request);
\r
404 var count = values["api_multiple_flag"] == "1" ? 3 : 1;
\r
409 public void CountCreateShip()
\r
415 public void InspectDestroyShip(string request)
\r
417 Add(609, HttpUtility.ParseQueryString(request)["api_ship_id"].Split(',').Length);
\r
420 public void CountRemodelSlot() => Increment(619);
\r
422 public void InspectDestroyItem(string request, dynamic json)
\r
424 var values = HttpUtility.ParseQueryString(request);
\r
425 var items = values["api_slotitem_ids"].Split(',')
\r
426 .Select(id => _itemInfo.GetStatus(int.Parse(id)).Spec).ToArray();
\r
427 Increment(613); // 613: 資源の再利用
\r
428 foreach (var quest in _quests.Values)
\r
430 var count = quest.Count;
\r
431 if (count.Spec is QuestDestroyItem destroy)
\r
433 if (destroy.Count(count, items))
\r
437 if (quest.Id == 680)
\r
439 count.NowArray[0] += items.Count(spec => spec.Type == 21);
\r
440 count.NowArray[1] += items.Count(spec => spec.Type == 12 || spec.Type == 13);
\r
446 public void InspectPowerUp(dynamic json)
\r
448 if ((int)json.api_powerup_flag == 0)
\r
450 foreach (var quest in _quests.Values)
\r
452 var count = quest.Count;
\r
453 if (!(count.Spec is QuestPowerUp))
\r
459 public void Increment(QuestCount count)
\r
464 public void Add(QuestCount count, int value)
\r
466 count.Now += value;
\r
470 public void Increment(int id)
\r
475 public void Add(int id, int value)
\r
477 if (!_quests.TryGetValue(id, out var quest))
\r
479 quest.Count.Now += value;
\r
483 public void IncrementNth(QuestCount count, int n)
\r
485 count.NowArray[n]++;
\r