コミットメタ情報

リビジョンc086c93acb189e83281c2bb184bbbb95cb39518b (tree)
日時2018-06-18 23:15:58
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

艦隊を表すクラスに艦隊の状態と編成を集約する

変更サマリ

差分

--- a/KancolleSniffer.Test/SnifferTest.cs
+++ b/KancolleSniffer.Test/SnifferTest.cs
@@ -432,7 +432,7 @@ namespace KancolleSniffer.Test
432432 {
433433 var sniffer = new Sniffer();
434434 SniffLogFile(sniffer, "deck_001");
435- var result = sniffer.GetDeck(0);
435+ var result = sniffer.Fleets[0].Deck;
436436 PAssert.That(() => new[] {756, 17204, 6156, 28806, 1069, -1}.SequenceEqual(result));
437437 }
438438
@@ -444,7 +444,7 @@ namespace KancolleSniffer.Test
444444 {
445445 var sniffer = new Sniffer();
446446 SniffLogFile(sniffer, "deck_005");
447- var result = sniffer.GetDeck(0);
447+ var result = sniffer.Fleets[0].Deck;
448448 PAssert.That(() => new[] {57391, 50, 24475, 113, -1, -1}.SequenceEqual(result));
449449 }
450450
@@ -457,18 +457,18 @@ namespace KancolleSniffer.Test
457457 var sniffer = new Sniffer();
458458
459459 SniffLogFile(sniffer, "deck_002");
460- var result0 = sniffer.GetDeck(0);
460+ var result0 = sniffer.Fleets[0].Deck;
461461 PAssert.That(() => new[] {1069, 6156, 756, 3223, -1, -1}.SequenceEqual(result0), "編成で艦隊内で艦娘と交換する");
462462
463463 SniffLogFile(sniffer, "deck_003");
464- var result10 = sniffer.GetDeck(0);
465- var result11 = sniffer.GetDeck(1);
464+ var result10 = sniffer.Fleets[0].Deck;
465+ var result11 = sniffer.Fleets[1].Deck;
466466 PAssert.That(() => new[] {1069, 6156, 14258, 3223, -1, -1}.SequenceEqual(result10) &&
467467 new[] {101, 4487, 756, 14613, 28806, -1}.SequenceEqual(result11), "002に続いて艦隊をまたがって交換する");
468468
469469 SniffLogFile(sniffer, "deck_004");
470- var result20 = sniffer.GetDeck(0);
471- var result21 = sniffer.GetDeck(1);
470+ var result20 = sniffer.Fleets[0].Deck;
471+ var result21 = sniffer.Fleets[1].Deck;
472472 PAssert.That(() => new[] {1069, 6156, 14258, 3223, 756, -1}.SequenceEqual(result20) &&
473473 new[] {101, 4487, 14613, 28806, -1, -1}.SequenceEqual(result21),
474474 "003に続いて空き番号にほかの艦隊の艦娘を配置する");
@@ -482,7 +482,7 @@ namespace KancolleSniffer.Test
482482 {
483483 var sniffer = new Sniffer();
484484 SniffLogFile(sniffer, "preset_001");
485- var result = sniffer.GetDeck(0);
485+ var result = sniffer.Fleets[0].Deck;
486486 PAssert.That(() => new[] {50510, 632, 39843, 113, 478, 47422}.SequenceEqual(result));
487487 }
488488
--- a/KancolleSniffer/AkashiTimer.cs
+++ b/KancolleSniffer/AkashiTimer.cs
@@ -182,7 +182,7 @@ namespace KancolleSniffer
182182
183183 private void CheckFleet(int fleet)
184184 {
185- var deck = _shipInfo.GetDeck(fleet).ToArray();
185+ var deck = _shipInfo.Fleets[fleet].Deck.ToArray();
186186 var repair = _repairStatuses[fleet];
187187 var fs = _shipInfo.GetStatus(deck[0]);
188188 repair.State = State.Continue;
--- a/KancolleSniffer/BattleInfo.cs
+++ b/KancolleSniffer/BattleInfo.cs
@@ -526,13 +526,13 @@ namespace KancolleSniffer
526526 var damaged = (int)json.api_escape.api_escape_idx[0] - 1;
527527 if (json.api_escape.api_tow_idx())
528528 {
529- _escapingShips.Add(_shipInfo.GetDeck(damaged / 6)[damaged % 6]);
529+ _escapingShips.Add(_shipInfo.Fleets[damaged / 6].Deck[damaged % 6]);
530530 var escort = (int)json.api_escape.api_tow_idx[0] - 1;
531- _escapingShips.Add(_shipInfo.GetDeck(escort / 6)[escort % 6]);
531+ _escapingShips.Add(_shipInfo.Fleets[escort / 6].Deck[escort % 6]);
532532 }
533533 else
534534 {
535- _escapingShips.Add(_shipInfo.GetDeck(2)[damaged]);
535+ _escapingShips.Add(_shipInfo.Fleets[2].Deck[damaged]);
536536 }
537537 }
538538
--- a/KancolleSniffer/ConditionTimer.cs
+++ b/KancolleSniffer/ConditionTimer.cs
@@ -80,7 +80,7 @@ namespace KancolleSniffer
8080
8181 public DateTime GetTimer(int fleet)
8282 {
83- if (_shipInfo.InMission[fleet] || _shipInfo.InSortie[fleet])
83+ if (_shipInfo.Fleets[fleet].State != FleetState.Port)
8484 return DateTime.MinValue;
8585 var cond = _shipInfo.GetShipStatuses(fleet).Select(s => s.Cond).DefaultIfEmpty(49).Min();
8686 if (cond >= 49)
@@ -96,7 +96,7 @@ namespace KancolleSniffer
9696 return result;
9797 for (var f = 0; f < result.Length; f++)
9898 {
99- if (_shipInfo.InMission[f] || _shipInfo.InSortie[f])
99+ if (_shipInfo.Fleets[f].State != FleetState.Port)
100100 continue;
101101 var timer = GetTimer(f);
102102 if (timer == DateTime.MinValue || prev < _lastUpdate)
--- a/KancolleSniffer/Logger.cs
+++ b/KancolleSniffer/Logger.cs
@@ -243,8 +243,8 @@ namespace KancolleSniffer
243243 int deckId = BattleInfo.DeckId(_battle);
244244 if (_battle.api_f_nowhps_combined())
245245 {
246- var main = _shipInfo.GetDeck(0);
247- var guard = _shipInfo.GetDeck(1);
246+ var main = _shipInfo.Fleets[0].Deck;
247+ var guard = _shipInfo.Fleets[1].Deck;
248248 return main.Zip(guard, (m, g) =>
249249 {
250250 if (m == -1 && g == -1)
@@ -268,7 +268,7 @@ namespace KancolleSniffer
268268 return name + "," + hp;
269269 }).ToList();
270270 }
271- var deck = _shipInfo.GetDeck(deckId);
271+ var deck = _shipInfo.Fleets[deckId].Deck;
272272 if (deck.Length > 6)
273273 {
274274 var result = new List<string>();
--- a/KancolleSniffer/MainForm.cs
+++ b/KancolleSniffer/MainForm.cs
@@ -614,14 +614,15 @@ namespace KancolleSniffer
614614
615615 private void SetCurrentFleet()
616616 {
617- var inSortie = _sniffer.InSortie;
618- if (_inSortie || !inSortie.Any(x => x))
617+ var states = _sniffer.Fleets.Select(fleet => fleet.State).ToArray();
618+ var inSortie = states.Any(state => state >= FleetState.Sortie);
619+ if (_inSortie || !inSortie)
619620 {
620- _inSortie = inSortie.Any(x => x);
621+ _inSortie = inSortie;
621622 return;
622623 }
623624 _inSortie = true;
624- if (inSortie[0] && inSortie[1])
625+ if (states[0] == FleetState.Sortie && states[1] == FleetState.Sortie)
625626 {
626627 _combinedFleet = true;
627628 _currentFleet = 0;
@@ -629,7 +630,7 @@ namespace KancolleSniffer
629630 else
630631 {
631632 _combinedFleet = false;
632- _currentFleet = Array.FindIndex(inSortie, x => x);
633+ _currentFleet = Array.FindIndex(states, state => state >= FleetState.Sortie);
633634 }
634635 }
635636
--- a/KancolleSniffer/ShipInfo.cs
+++ b/KancolleSniffer/ShipInfo.cs
@@ -51,17 +51,29 @@ namespace KancolleSniffer
5151 }
5252 }
5353
54+ public enum FleetState
55+ {
56+ Port,
57+ Mission,
58+ Sortie,
59+ Practice
60+ }
61+
62+ public class Fleet
63+ {
64+ public FleetState State { get; set; }
65+ public int[] Deck { get; set; } = Enumerable.Repeat(-1, ShipInfo.MemberCount).ToArray();
66+ }
67+
5468 public class ShipInfo
5569 {
5670 public const int FleetCount = 4;
5771 public const int MemberCount = 6;
5872
59- private readonly int[][] _decks;
73+ private readonly Fleet[] _fleets = Enumerable.Range(0, FleetCount).Select(x => new Fleet()).ToArray();
6074 private readonly Dictionary<int, ShipStatus> _shipInfo = new Dictionary<int, ShipStatus>();
6175 private readonly ShipMaster _shipMaster = new ShipMaster();
6276 private readonly ItemInfo _itemInfo;
63- private readonly bool[] _inMission = new bool[FleetCount];
64- private readonly bool[] _inSortie = new bool[FleetCount];
6577 private int _hqLevel;
6678 private readonly List<int> _escapedShips = new List<int>();
6779 private int _combinedFleetType;
@@ -85,7 +97,6 @@ namespace KancolleSniffer
8597 public ShipInfo(ItemInfo itemInfo)
8698 {
8799 _itemInfo = itemInfo;
88- _decks = Enumerable.Repeat(Enumerable.Repeat(-1, MemberCount).ToArray(), FleetCount).ToArray();
89100 ClearShipInfo();
90101 }
91102
@@ -100,7 +111,7 @@ namespace KancolleSniffer
100111 {
101112 ClearShipInfo();
102113 for (var i = 0; i < FleetCount; i++)
103- _inSortie[i] = false;
114+ _fleets[i].State = FleetState.Port;
104115 InspectDeck(json.api_deck_port);
105116 InspectShipData(json.api_ship);
106117 InspectBasic(json.api_basic);
@@ -130,9 +141,9 @@ namespace KancolleSniffer
130141
131142 public void SaveBattleResult()
132143 {
133- _battleResult = _decks.Where((deck, i) =>
134- _inSortie[i] && !GetStatus(deck[0]).Spec.IsRepairShip)
135- .SelectMany(deck => deck.Select(GetStatus)).ToArray();
144+ _battleResult = _fleets.Where(fleet =>
145+ fleet.State >= FleetState.Sortie && !GetStatus(fleet.Deck[0]).Spec.IsRepairShip)
146+ .SelectMany(fleet => fleet.Deck.Select(GetStatus)).ToArray();
136147 }
137148
138149 private void VerifyBattleResult()
@@ -146,8 +157,8 @@ namespace KancolleSniffer
146157
147158 public void SaveBattleStartStatus()
148159 {
149- BattleStartStatus = _decks.Where((deck, i) => _inSortie[i])
150- .SelectMany(deck => deck.Select(id => (ShipStatus)GetStatus(id).Clone())).ToArray();
160+ BattleStartStatus = _fleets.Where(fleet => fleet.State >= FleetState.Sortie)
161+ .SelectMany(fleet => fleet.Deck.Select(id => (ShipStatus)GetStatus(id).Clone())).ToArray();
151162 }
152163
153164 private void ClearShipInfo()
@@ -161,8 +172,9 @@ namespace KancolleSniffer
161172 foreach (var entry in json)
162173 {
163174 var fleet = (int)entry.api_id - 1;
164- _decks[fleet] = (int[])entry.api_ship;
165- _inMission[fleet] = (int)entry.api_mission[0] != 0;
175+ _fleets[fleet].Deck = (int[])entry.api_ship;
176+ if ((int)entry.api_mission[0] != 0)
177+ _fleets[fleet].State = FleetState.Mission;
166178 }
167179 }
168180
@@ -221,7 +233,7 @@ namespace KancolleSniffer
221233 var ship = int.Parse(values["api_ship_id"]);
222234 if (idx == -1)
223235 {
224- var deck = _decks[fleet];
236+ var deck = _fleets[fleet].Deck;
225237 for (var i = 1; i < deck.Length; i++)
226238 deck[i] = -1;
227239 return;
@@ -232,20 +244,20 @@ namespace KancolleSniffer
232244 return;
233245 }
234246 var of = FindFleet(ship, out var oi);
235- var orig = _decks[fleet][idx];
236- _decks[fleet][idx] = ship;
247+ var orig = _fleets[fleet].Deck[idx];
248+ _fleets[fleet].Deck[idx] = ship;
237249 if (of == -1)
238250 return;
239251 // 入れ替えの場合
240- if ((_decks[of][oi] = orig) == -1)
252+ if ((_fleets[of].Deck[oi] = orig) == -1)
241253 WithdrowShip(of, oi);
242254 }
243255
244256 private int FindFleet(int ship, out int idx)
245257 {
246- for (var f = 0; f < _decks.Length; f++)
258+ for (var f = 0; f < _fleets.Length; f++)
247259 {
248- idx = Array.FindIndex(_decks[f], id => id == ship);
260+ idx = Array.FindIndex(_fleets[f].Deck, id => id == ship);
249261 if (idx < 0)
250262 continue;
251263 return f;
@@ -256,7 +268,7 @@ namespace KancolleSniffer
256268
257269 private void WithdrowShip(int fleet, int idx)
258270 {
259- var deck = _decks[fleet];
271+ var deck = _fleets[fleet].Deck;
260272 var j = idx;
261273 for (var i = idx + 1; i < deck.Length; i++)
262274 {
@@ -321,15 +333,22 @@ namespace KancolleSniffer
321333 var fleet = int.Parse(values["api_deck_id"]) - 1;
322334 if (_combinedFleetType == 0 || fleet > 1)
323335 {
324- _inSortie[fleet] = true;
336+ _fleets[fleet].State = FleetState.Sortie;
325337 }
326338 else
327339 {
328- _inSortie[0] = _inSortie[1] = true;
340+ _fleets[0].State = _fleets[1].State = FleetState.Sortie;
329341 }
330342 SetBadlyDamagedShips();
331343 }
332344
345+ public void StartPractice(string request)
346+ {
347+ var values = HttpUtility.ParseQueryString(request);
348+ var fleet = int.Parse(values["api_deck_id"]) - 1;
349+ _fleets[fleet].State = FleetState.Practice;
350+ }
351+
333352 public void RepairShip(int id)
334353 {
335354 var s = _shipInfo[id];
@@ -339,10 +358,10 @@ namespace KancolleSniffer
339358
340359 public ShipStatus[] GetShipStatuses(int fleet)
341360 {
342- return _decks[fleet].Where(id => id != -1).Select(GetStatus).ToArray();
361+ return _fleets[fleet].Deck.Where(id => id != -1).Select(GetStatus).ToArray();
343362 }
344363
345- public int[] GetDeck(int fleet) => _decks[fleet];
364+ public Fleet[] Fleets => _fleets;
346365
347366 public ShipStatus GetStatus(int id)
348367 {
@@ -369,18 +388,14 @@ namespace KancolleSniffer
369388
370389 public ShipSpec GetSpec(int id) => _shipMaster.GetSpec(id);
371390
372- public bool[] InMission => _inMission;
373-
374- public bool[] InSortie => _inSortie;
375-
376391 public int CombinedFleetType => _combinedFleetType;
377392
378393 public ShipStatus[] ShipList => _shipInfo.Keys.Where(id => id != -1).Select(GetStatus).ToArray();
379394
380395 public ChargeStatus[] ChargeStatuses
381- => (from deck in _decks
382- let flag = new ChargeStatus(_shipInfo[deck[0]])
383- let others = (from id in deck.Skip(1)
396+ => (from fleet in _fleets
397+ let flag = new ChargeStatus(_shipInfo[fleet.Deck[0]])
398+ let others = (from id in fleet.Deck.Skip(1)
384399 select new ChargeStatus(_shipInfo[id]))
385400 .Aggregate(
386401 (result, next) =>
@@ -485,14 +500,11 @@ namespace KancolleSniffer
485500 public void SetBadlyDamagedShips()
486501 {
487502 BadlyDamagedShips =
488- _inSortie.SelectMany((flag, i) => !flag
489- ? new ShipStatus[0]
490- : _combinedFleetType > 0 && i == 1
491- ? GetShipStatuses(1).Skip(1) // 連合艦隊第二の旗艦を飛ばす
492- : GetShipStatuses(i))
493- .Where(s => !s.Escaped && s.DamageLevel == ShipStatus.Damage.Badly)
494- .Select(s => s.Name)
495- .ToArray();
503+ (from s in _fleets.Where(fleet => fleet.State == FleetState.Sortie)
504+ .SelectMany(fleet => fleet.Deck.Where(id => id != -1).Select(GetStatus))
505+ where !s.Escaped && s.DamageLevel == ShipStatus.Damage.Badly &&
506+ !(s.CombinedFleetType > 0 && s.Fleet == 1 && s.DeckIndex == 0) // 第二艦隊の旗艦を除く
507+ select s.Name).ToArray();
496508 }
497509
498510 public void ClearBadlyDamagedShips()
@@ -533,7 +545,7 @@ namespace KancolleSniffer
533545 var id = _shipInfo.Keys.Count + 1;
534546 var ships = nowhps.Zip(maxhps,
535547 (now, max) => new ShipStatus {Id = id++, NowHp = now, MaxHp = max}).ToArray();
536- _decks[deck] = (from ship in ships select ship.Id).ToArray();
548+ _fleets[deck].Deck = (from ship in ships select ship.Id).ToArray();
537549 foreach (var ship in ships)
538550 _shipInfo[ship.Id] = ship;
539551 foreach (var entry in ships.Zip(slots, (ship, slot) =>new {ship, slot}))
--- a/KancolleSniffer/Sniffer.cs
+++ b/KancolleSniffer/Sniffer.cs
@@ -339,7 +339,7 @@ namespace KancolleSniffer
339339 {
340340 if (url.EndsWith("/battle"))
341341 {
342- _shipInfo.InspectMapStart(request); // 演習を出撃中とみなす
342+ _shipInfo.StartPractice(request);
343343 _conditionTimer.InvalidateCond();
344344 RepeatingTimerController?.Suspend();
345345 }
@@ -556,9 +556,7 @@ namespace KancolleSniffer
556556
557557 public ShipStatus[] GetShipStatuses(int fleet) => _shipInfo.GetShipStatuses(fleet);
558558
559- public int[] GetDeck(int fleet) => _shipInfo.GetDeck(fleet);
560-
561- public bool[] InSortie => _shipInfo.InSortie;
559+ public Fleet[] Fleets => _shipInfo.Fleets;
562560
563561 public ShipInfo.ShipStatusPair[] BattleResultStatusDiff => _shipInfo.BattleResultDiff;
564562
旧リポジトリブラウザで表示