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
46 case 40: // 七隻分のログが出力されている
\r
47 data[21] = data[21] + "・" + data[23];
\r
48 data[22] = data[22] + "・" + data[24];
\r
49 Array.Copy(data, 24, data, 23, 15);
\r
56 if (data[5] == "T字戦(有利)")
\r
58 if (data[5] == "T字戦(不利)")
\r
60 if (data[6].EndsWith("航行序列"))
\r
61 data[6] = data[6].Substring(0, 4);
\r
62 if (data[7].EndsWith("航行序列"))
\r
63 data[7] = data[7].Substring(0, 4);
\r
64 data[37] = ShortenAirBattleResult(data[37]);
\r
65 var result = new string[41];
\r
66 var damage = GenerateDamagedShip(data);
\r
67 result[38] = damage[0];
\r
68 result[39] = damage[1];
\r
70 Array.Copy(data, result, 38);
\r
74 private static string ShortenAirBattleResult(string result)
\r
93 private static string[] GenerateDamagedShip(string[] data)
\r
95 var badly = new List<string>();
\r
96 var half = new List<string>();
\r
97 for (var i = 11; i < 11 + 12; i += 2)
\r
101 var ship = data[i] = StripKana(data[i]);
\r
102 var hp = data[i + 1];
\r
105 foreach (var entry in from entry in ship.Split('・').Zip(hp.Split('・'), (s, h) => new {s, h})
\r
106 where entry.h.Contains("/")
\r
107 let nm = entry.h.Split('/').Select(int.Parse).ToArray()
\r
108 let level = ShipStatus.CalcDamage(nm[0], nm[1])
\r
109 select new {level, name = entry.s})
\r
111 if (entry.level == ShipStatus.Damage.Half)
\r
112 half.Add(entry.name);
\r
113 else if (entry.level == ShipStatus.Damage.Badly)
\r
114 badly.Add(entry.name);
\r
117 catch (FormatException)
\r
119 return new[] {"", ""};
\r
122 return new []{string.Join("・", badly), string.Join("・", half)};
\r
125 private static readonly Regex Kana = new Regex(@"\([^)]+\)\(", RegexOptions.Compiled);
\r
127 private static string StripKana(string name)
\r
129 return Kana.Replace(name, "(");
\r