1 // Copyright (C) 2018 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.Text.RegularExpressions;
\r
19 using KancolleSniffer.Model;
\r
21 namespace KancolleSniffer.Log
\r
23 public class BattleLogProcessor : LogProcessor.Processor
\r
25 private readonly Dictionary<string, string> _mapDictionary;
\r
27 public BattleLogProcessor(Dictionary<string, string> mapDictionary = null)
\r
29 _mapDictionary = mapDictionary ?? new Dictionary<string, string>();
\r
32 public override string[] Process(string[] data)
\r
35 switch (data.Length)
\r
38 data = data.Concat(Enumerable.Repeat("", 3)).ToArray();
\r
41 map = _mapDictionary.TryGetValue(data[1], out var num) ? num : "";
\r
47 if (data[8] == "深海5" && data[9] == "500t級軽巡洋艦")
\r
49 data[8] = "深海5,500t級軽巡洋艦";
\r
50 Array.Copy(data, 10, data, 9, 30);
\r
54 data[21] = data[21] + "・" + data[23];
\r
55 data[22] = data[22] + "・" + data[24];
\r
56 Array.Copy(data, 24, data, 23, 15);
\r
63 if (data[5] == "T字戦(有利)")
\r
65 if (data[5] == "T字戦(不利)")
\r
67 if (data[6].EndsWith("航行序列"))
\r
68 data[6] = data[6].Substring(0, 4);
\r
69 if (data[7].EndsWith("航行序列"))
\r
70 data[7] = data[7].Substring(0, 4);
\r
71 data[37] = ShortenAirBattleResult(data[37]);
\r
72 var result = new string[41];
\r
73 var damage = GenerateDamagedShip(data);
\r
74 result[38] = damage[0];
\r
75 result[39] = damage[1];
\r
77 Array.Copy(data, result, 38);
\r
81 private static string ShortenAirBattleResult(string result)
\r
100 private static string[] GenerateDamagedShip(string[] data)
\r
102 var badly = new List<string>();
\r
103 var half = new List<string>();
\r
104 for (var i = 11; i < 11 + 12; i += 2)
\r
108 var ship = data[i] = StripKana(data[i]);
\r
109 var hp = data[i + 1];
\r
112 foreach (var entry in from entry in ship.Split('・').Zip(hp.Split('・'), (s, h) => new {s, h})
\r
113 where entry.h.Contains("/")
\r
114 let nm = entry.h.Split('/').Select(int.Parse).ToArray()
\r
115 let level = ShipStatus.CalcDamage(nm[0], nm[1])
\r
116 select new {level, name = entry.s})
\r
118 if (entry.level == ShipStatus.Damage.Half)
\r
119 half.Add(entry.name);
\r
120 else if (entry.level == ShipStatus.Damage.Badly)
\r
121 badly.Add(entry.name);
\r
124 catch (FormatException)
\r
126 return new[] {"", ""};
\r
129 return new []{string.Join("・", badly), string.Join("・", half)};
\r
132 private static readonly Regex Kana = new Regex(@"\([^)]+\)\(", RegexOptions.Compiled);
\r
134 private static string StripKana(string name)
\r
136 return Kana.Replace(name, "(");
\r