Révision | 28336d02272415cd3503d0c9e9c8ec3bfe4cb5ec (tree) |
---|---|
l'heure | 2019-07-22 20:50:09 |
Auteur | Kazuhiro Fujieda <fujieda@user...> |
Commiter | Kazuhiro Fujieda |
BattleLoggerのマップの処理の抽象度を上げる
@@ -214,6 +214,8 @@ namespace KancolleSniffer.Test | ||
214 | 214 | == result); |
215 | 215 | } |
216 | 216 | |
217 | + private JsonObject Js(object obj) => JsonObject.CreateJsonObject(obj); | |
218 | + | |
217 | 219 | [TestMethod] |
218 | 220 | public void Achievement() |
219 | 221 | { |
@@ -238,9 +240,9 @@ namespace KancolleSniffer.Test | ||
238 | 240 | return (DateTime)dateEnum.Current; |
239 | 241 | }); |
240 | 242 | for (var i = 0; i < 6; i++) |
241 | - logger.InspectBasic(JsonParser.Parse($"{{\"api_experience\": {i * 1000}}}")); | |
242 | - logger.InspectBattleResult(JsonParser.Parse("{\"api_get_exmap_rate\": \"100\"}")); | |
243 | - logger.InspectMapNext(JsonParser.Parse("{\"api_get_eo_rate\": 75}")); | |
243 | + logger.InspectBasic(Js(new{api_experience = i * 1000})); | |
244 | + logger.InspectBattleResult(Js(new {api_get_exmap_rate = "100"})); | |
245 | + logger.InspectMapNext(Js(new {api_maparea_id = 0, api_mapinfo_no = 0, api_no = 0, api_event_id = 0, api_get_eo_rate = 75})); | |
244 | 246 | PAssert.That(() => |
245 | 247 | "2017-03-31 21:00:00,0,0|2017-03-31 21:00:00,0,0|2017-03-31 22:00:00,1000,0|" + |
246 | 248 | "2017-04-01 03:00:00,4000,0|2017-04-02 02:00:00,5000,0|" + |
@@ -26,8 +26,7 @@ namespace KancolleSniffer.Log | ||
26 | 26 | private readonly BattleInfo _battleInfo; |
27 | 27 | private readonly Action<string, string, string> _writer; |
28 | 28 | private dynamic _battle; |
29 | - private dynamic _map; | |
30 | - private bool _start; | |
29 | + private readonly CellData _cell = new CellData(); | |
31 | 30 | |
32 | 31 | public BattleLogger(ShipInfo shipInfo, ItemInfo itemInfo, BattleInfo battleInfo, Action<string, string, string> writer) |
33 | 32 | { |
@@ -37,16 +36,35 @@ namespace KancolleSniffer.Log | ||
37 | 36 | _writer = writer; |
38 | 37 | } |
39 | 38 | |
39 | + private class CellData | |
40 | + { | |
41 | + public bool Start; | |
42 | + public bool Boss; | |
43 | + public int Id; | |
44 | + public int Area; | |
45 | + public int Map; | |
46 | + public int Cell; | |
47 | + | |
48 | + public void Set(dynamic json) | |
49 | + { | |
50 | + Area = (int)json.api_maparea_id; | |
51 | + Map = (int)json.api_mapinfo_no; | |
52 | + Cell = json.api_no() ? (int)json.api_no : 0; | |
53 | + Boss = (int)json.api_event_id == 5; | |
54 | + Id = Area * 10 + Map; | |
55 | + } | |
56 | + } | |
57 | + | |
40 | 58 | public void InspectMapStart(dynamic json) |
41 | 59 | { |
42 | - _start = true; | |
43 | - _map = json; | |
60 | + _cell.Start = true; | |
61 | + _cell.Set(json); | |
44 | 62 | _battle = null; |
45 | 63 | } |
46 | 64 | |
47 | 65 | public void InspectMapNext(dynamic json) |
48 | 66 | { |
49 | - _map = json; | |
67 | + _cell.Set(json); | |
50 | 68 | } |
51 | 69 | |
52 | 70 | public void InspectBattle(dynamic json) |
@@ -58,19 +76,18 @@ namespace KancolleSniffer.Log | ||
58 | 76 | |
59 | 77 | public void InspectBattleResult(dynamic result) |
60 | 78 | { |
61 | - if (result.disabled() || _map == null || _battle == null) | |
79 | + if (result.disabled() || _battle == null) | |
62 | 80 | { |
63 | - _map = _battle = null; | |
81 | + _battle = null; | |
64 | 82 | return; |
65 | 83 | } |
66 | 84 | var fShips = GenerateFriendShipList(); |
67 | 85 | var eShips = GenerateEnemyShipList(); |
68 | - var cell = (int)_map.api_no; | |
69 | 86 | var boss = ""; |
70 | - if (_start) | |
87 | + if (_cell.Start) | |
71 | 88 | boss = "出撃"; |
72 | - if (cell == (int)_map.api_bosscell_no || (int)_map.api_event_id == 5) | |
73 | - boss = _start ? "出撃&ボス" : "ボス"; | |
89 | + if (_cell.Boss) | |
90 | + boss = _cell.Start ? "出撃&ボス" : "ボス"; | |
74 | 91 | var dropType = result.api_get_ship() ? result.api_get_ship.api_ship_type : ""; |
75 | 92 | if (result.api_get_useitem()) |
76 | 93 | { |
@@ -92,7 +109,7 @@ namespace KancolleSniffer.Log | ||
92 | 109 | var fPower = fp.Diff ? fp.RangeString : fp.Min.ToString(); |
93 | 110 | _writer("海戦・ドロップ報告書", string.Join(",", |
94 | 111 | result.api_quest_name, |
95 | - cell, boss, | |
112 | + _cell.Cell, boss, | |
96 | 113 | result.api_win_rank, |
97 | 114 | BattleFormationName((int)_battle.api_formation[2]), |
98 | 115 | FormationName(_battle.api_formation[0]), |
@@ -103,14 +120,14 @@ namespace KancolleSniffer.Log | ||
103 | 120 | string.Join(",", eShips), |
104 | 121 | fPower, _battleInfo.EnemyFighterPower.AirCombat + _battleInfo.EnemyFighterPower.UnknownMark, |
105 | 122 | AirControlLevelName(_battle), |
106 | - $"{(int)_map.api_maparea_id}-{(int)_map.api_mapinfo_no}"), | |
123 | + $"{_cell.Area}-{_cell.Map}"), | |
107 | 124 | "日付,海域,マス,ボス,ランク,艦隊行動,味方陣形,敵陣形,敵艦隊,ドロップ艦種,ドロップ艦娘," + |
108 | 125 | "味方艦1,味方艦1HP,味方艦2,味方艦2HP,味方艦3,味方艦3HP,味方艦4,味方艦4HP,味方艦5,味方艦5HP,味方艦6,味方艦6HP," + |
109 | 126 | "敵艦1,敵艦1HP,敵艦2,敵艦2HP,敵艦3,敵艦3HP,敵艦4,敵艦4HP,敵艦5,敵艦5HP,敵艦6,敵艦6HP," + |
110 | 127 | "味方制空値,敵制空値,制空状態,マップ" |
111 | 128 | ); |
112 | - _map = _battle = null; | |
113 | - _start = false; | |
129 | + _battle = null; | |
130 | + _cell.Start = false; | |
114 | 131 | } |
115 | 132 | |
116 | 133 | private IEnumerable<string> GenerateFriendShipList() |