コミットメタ情報

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

ログメッセージ

艦隊に関する責務をShipInfoからFleetクラスに移す

変更サマリ

差分

--- a/KancolleSniffer.Test/BattleTest.cs
+++ b/KancolleSniffer.Test/BattleTest.cs
@@ -52,7 +52,7 @@ namespace KancolleSniffer.Test
5252 _battleInfo.InspectBattle(logs[0], logs[1], battle);
5353 dynamic result = JsonParser.Parse(logs[5]);
5454 _battleInfo.InspectBattleResult(result);
55- PAssert.That(() => _shipInfo.GetShipStatuses(2)[4].NowHp == 31);
55+ PAssert.That(() => _shipInfo.Fleets[2].Ships[4].NowHp == 31);
5656 }
5757
5858 /// <summary>
@@ -66,7 +66,7 @@ namespace KancolleSniffer.Test
6666 _shipInfo.InjectShips(battle, JsonParser.Parse(logs[0]));
6767 _battleInfo.InspectBattle(logs[1], logs[2], battle);
6868 _battleInfo.InspectBattleResult(JsonParser.Parse(logs[6]));
69- PAssert.That(() => _shipInfo.GetShipStatuses(0)[3].NowHp == 12);
69+ PAssert.That(() => _shipInfo.Fleets[0].Ships[3].NowHp == 12);
7070 }
7171
7272 private dynamic Data(string json) => ((dynamic)JsonParser.Parse(json)).api_data;
--- a/KancolleSniffer.Test/SnifferTest.cs
+++ b/KancolleSniffer.Test/SnifferTest.cs
@@ -83,7 +83,7 @@ namespace KancolleSniffer.Test
8383 private void AssertEqualBattleResult(Sniffer sniffer, IEnumerable<int> expected, IEnumerable<int> enemy,
8484 string msg = null)
8585 {
86- var result = sniffer.GetShipStatuses(0).Select(s => s.NowHp);
86+ var result = sniffer.Fleets[0].Ships.Select(s => s.NowHp);
8787 PAssert.That(() => expected.SequenceEqual(result), msg);
8888 var enemyResult = sniffer.Battle.Result.Enemy.Main.Select(s => s.NowHp);
8989 PAssert.That(() => enemy.SequenceEqual(enemyResult), msg);
@@ -186,8 +186,9 @@ namespace KancolleSniffer.Test
186186 {
187187 var sniffer = new Sniffer();
188188 SniffLogFile(sniffer, "escape_001");
189- PAssert.That(() => sniffer.GetShipStatuses(0)[5].Escaped &&
190- sniffer.GetShipStatuses(1)[2].Escaped);
189+ var fleets = sniffer.Fleets;
190+ PAssert.That(() => fleets[0].Ships[5].Escaped &&
191+ fleets[1].Ships[2].Escaped);
191192 }
192193
193194 /// <summary>
@@ -220,7 +221,7 @@ namespace KancolleSniffer.Test
220221 {
221222 var sniffer = new Sniffer();
222223 SniffLogFile(sniffer, "escape_002");
223- PAssert.That(() => sniffer.GetShipStatuses(2)[1].Escaped);
224+ PAssert.That(() => sniffer.Fleets[2].Ships[1].Escaped);
224225 PAssert.That(() => !sniffer.IsBattleResultStatusError);
225226 }
226227
@@ -254,9 +255,10 @@ namespace KancolleSniffer.Test
254255 {
255256 var sniffer = new Sniffer();
256257 SniffLogFile(sniffer, "fighterpower_001");
257- PAssert.That(() => sniffer.GetFighterPower(0).SequenceEqual(new[] {156, 159}));
258+ var fleet = sniffer.Fleets[0];
259+ PAssert.That(() => fleet.FighterPower.SequenceEqual(new[] {156, 159}));
258260 SniffLogFile(sniffer, "fighterpower_002");
259- PAssert.That(() => sniffer.GetFighterPower(0).SequenceEqual(new[] {140, 143}), "全滅したスロットがある");
261+ PAssert.That(() => fleet.FighterPower.SequenceEqual(new[] {140, 143}), "全滅したスロットがある");
260262 }
261263
262264 /// <summary>
@@ -267,7 +269,7 @@ namespace KancolleSniffer.Test
267269 {
268270 var sniffer = new Sniffer();
269271 SniffLogFile(sniffer, "fighterpower_003");
270- PAssert.That(() => sniffer.GetFighterPower(0).SequenceEqual(new[] {135, 135}));
272+ PAssert.That(() => sniffer.Fleets[0].FighterPower.SequenceEqual(new[] {135, 135}));
271273 }
272274
273275 /// <summary>
@@ -335,11 +337,12 @@ namespace KancolleSniffer.Test
335337 {
336338 var sniffer = new Sniffer();
337339 SniffLogFile(sniffer, "lineofsight_001");
338- PAssert.That(() => Math.Abs(sniffer.GetFleetLineOfSights(0, 1) - 39.45) < 0.01);
339- PAssert.That(() => Math.Abs(sniffer.GetFleetLineOfSights(0, 3) - 115.19) < 0.01);
340- PAssert.That(() => Math.Abs(sniffer.GetFleetLineOfSights(0, 4) - 153.06) < 0.01);
340+ var fleet = sniffer.Fleets[0];
341+ PAssert.That(() => Math.Abs(fleet.GetLineOfSights(1) - 39.45) < 0.01);
342+ PAssert.That(() => Math.Abs(fleet.GetLineOfSights(3) - 115.19) < 0.01);
343+ PAssert.That(() => Math.Abs(fleet.GetLineOfSights(4) - 153.06) < 0.01);
341344 SniffLogFile(sniffer, "lineofsight_002");
342- PAssert.That(() => Math.Abs(sniffer.GetFleetLineOfSights(0, 1) - -25.10) < 0.01, "艦隊に空きがある");
345+ PAssert.That(() => Math.Abs(fleet.GetLineOfSights(1) - -25.10) < 0.01, "艦隊に空きがある");
343346 }
344347
345348 /// <summary>
@@ -350,7 +353,7 @@ namespace KancolleSniffer.Test
350353 {
351354 var sniffer = new Sniffer();
352355 SniffLogFile(sniffer, "contact_001");
353- PAssert.That(() => Math.Abs(sniffer.GetContactTriggerRate(0) - 1.8182) < 0.0001);
356+ PAssert.That(() => Math.Abs(sniffer.Fleets[0].ContactTriggerRate - 1.8182) < 0.0001);
354357 }
355358
356359 /// <summary>
@@ -368,7 +371,7 @@ namespace KancolleSniffer.Test
368371 var sniffer = new Sniffer();
369372 SniffLogFile(sniffer, "transportpoint_00" + (i + 1));
370373 var j = i;
371- PAssert.That(() => (int)sniffer.GetShipStatuses(0).Sum(s => s.TransportPoint) == results[j], msgs[j]);
374+ PAssert.That(() => (int)sniffer.Fleets[0].TransportPoint == results[j], msgs[j]);
372375 }
373376 }
374377
@@ -380,7 +383,7 @@ namespace KancolleSniffer.Test
380383 {
381384 var sniffer = new Sniffer();
382385 SniffLogFile(sniffer, "antiairfire_001");
383- var ships = sniffer.GetShipStatuses(0);
386+ var ships = sniffer.Fleets[0].Ships;
384387 PAssert.That(() => ships.Sum(ship => ship.EffectiveAntiAirForFleet) == 88);
385388 PAssert.That(
386389 () =>
@@ -396,7 +399,7 @@ namespace KancolleSniffer.Test
396399 {
397400 var sniffer = new Sniffer();
398401 SniffLogFile(sniffer, "nightbattlepower_001");
399- var ships = sniffer.GetShipStatuses(0);
402+ var ships = sniffer.Fleets[0].Ships;
400403 PAssert.That(() =>
401404 ships.Select(ship => (int)(ship.NightBattlePower * 100))
402405 .SequenceEqual(new[] {11202, 14985, 20092, 17354}));
@@ -418,9 +421,10 @@ namespace KancolleSniffer.Test
418421 {
419422 var sniffer = new Sniffer();
420423 SniffLogFile(sniffer, "firepower_001");
424+ var fleet = sniffer.Fleets[0];
421425 // ReSharper disable CompareOfFloatsByEqualityOperator
422- PAssert.That(() => sniffer.GetShipStatuses(0)[0].EffectiveFirepower == 93.5);
423- PAssert.That(() => sniffer.GetShipStatuses(0)[1].EffectiveFirepower == 82.5);
426+ PAssert.That(() => fleet.Ships[0].EffectiveFirepower == 93.5);
427+ PAssert.That(() => fleet.Ships[1].EffectiveFirepower == 82.5);
424428 // ReSharper restore CompareOfFloatsByEqualityOperator
425429 }
426430
@@ -504,7 +508,7 @@ namespace KancolleSniffer.Test
504508 {
505509 var sniffer = new Sniffer();
506510 SniffLogFile(sniffer, "slot_exchange_001");
507- var result = sniffer.GetShipStatuses(0)[0].Slot.Select(item => item.Id);
511+ var result = sniffer.Fleets[0].Ships[0].Slot.Select(item => item.Id);
508512 PAssert.That(() => new[] {26096, 30571, 77694, 61383, -1}.SequenceEqual(result));
509513 }
510514
@@ -516,7 +520,7 @@ namespace KancolleSniffer.Test
516520 {
517521 var sniffer = new Sniffer();
518522 SniffLogFile(sniffer, "powerup_001");
519- PAssert.That(() => Math.Abs(sniffer.GetShipStatuses(0)[0].EffectiveFirepower - 30) < 0.0001);
523+ PAssert.That(() => Math.Abs(sniffer.Fleets[0].Ships[0].EffectiveFirepower - 30) < 0.0001);
520524 }
521525
522526 /// <summary>
@@ -743,7 +747,7 @@ namespace KancolleSniffer.Test
743747 var sniffer = new Sniffer(true);
744748 SniffLogFile(sniffer, "twofleets_001");
745749 var expected = Enumerable.Repeat(new ChargeStatus(5, 5), ShipInfo.FleetCount);
746- PAssert.That(() => expected.SequenceEqual(sniffer.ChargeStatuses));
750+ PAssert.That(() => expected.SequenceEqual(sniffer.Fleets.Select(f => f.ChargeStatus)));
747751 }
748752
749753 /// <summary>
--- a/KancolleSniffer/AntiAirPanel.cs
+++ b/KancolleSniffer/AntiAirPanel.cs
@@ -56,7 +56,7 @@ namespace KancolleSniffer
5656 var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};
5757 for (var f = 0; f < fn.Length; f++)
5858 {
59- var ships = sniffer.GetShipStatuses(f);
59+ var ships = sniffer.Fleets[f].Ships;
6060 var rawForFleet = ships.Sum(ship => ship.EffectiveAntiAirForFleet);
6161 var forFleet = new[] {1.0, 1.2, 1.6}.Select(r => (int)(rawForFleet * r) * 2 / 1.3).ToArray();
6262 _table.Add(new Record {Fleet = fn[f] + " : " + string.Join("/", forFleet.Select(x => x.ToString("f1")))});
--- a/KancolleSniffer/BattleInfo.cs
+++ b/KancolleSniffer/BattleInfo.cs
@@ -128,11 +128,12 @@ namespace KancolleSniffer
128128 return;
129129 _shipInfo.SaveBattleStartStatus();
130130 _fleet = DeckId(json);
131- var fstats = _shipInfo.GetShipStatuses(_fleet);
131+ var fleets = _shipInfo.Fleets;
132+ var fstats = fleets[_fleet].Ships;
132133 FlagshipRecovery(request, fstats[0]);
133134 _friend = Record.Setup(fstats, practice);
134135 _guard = json.api_f_nowhps_combined()
135- ? Record.Setup(_shipInfo.GetShipStatuses(1), practice)
136+ ? Record.Setup(fleets[1].Ships, practice)
136137 : new Record[0];
137138 _enemy = Record.Setup((int[])json.api_e_nowhps,
138139 ((int[])json.api_ship_ke).Select(_shipInfo.GetSpec).ToArray(),
@@ -220,9 +221,10 @@ namespace KancolleSniffer
220221
221222 private int[] CalcFighterPower()
222223 {
224+ var fleets = _shipInfo.Fleets;
223225 if (_guard.Length > 0 && _enemyGuard.Length > 0)
224- return _shipInfo.GetFighterPower(0).Zip(_shipInfo.GetFighterPower(1), (a, b) => a + b).ToArray();
225- return _shipInfo.GetFighterPower(_fleet);
226+ return fleets[0].FighterPower.Zip(fleets[1].FighterPower, (a, b) => a + b).ToArray();
227+ return fleets[_fleet].FighterPower;
226228 }
227229
228230 private EnemyFighterPower CalcEnemyFighterPower(dynamic json)
@@ -507,9 +509,10 @@ namespace KancolleSniffer
507509 {
508510 if (_friend == null)
509511 return;
512+ var fleets = _shipInfo.Fleets;
510513 var ships = _guard.Length > 0
511- ? _shipInfo.GetShipStatuses(0).Concat(_shipInfo.GetShipStatuses(1)).ToArray()
512- : _shipInfo.GetShipStatuses(_fleet);
514+ ? fleets[0].Ships.Concat(fleets[1].Ships)
515+ : fleets[_fleet].Ships;
513516 foreach (var entry in ships.Zip(_friend.Concat(_guard), (ship, now) => new {ship, now}))
514517 entry.now.UpdateShipStatus(entry.ship);
515518 if (warnDamagedShip)
--- a/KancolleSniffer/ConditionTimer.cs
+++ b/KancolleSniffer/ConditionTimer.cs
@@ -80,9 +80,10 @@ namespace KancolleSniffer
8080
8181 public DateTime GetTimer(int fleet)
8282 {
83- if (_shipInfo.Fleets[fleet].State != FleetState.Port)
83+ var target = _shipInfo.Fleets[fleet];
84+ if (target.State != FleetState.Port)
8485 return DateTime.MinValue;
85- var cond = _shipInfo.GetShipStatuses(fleet).Select(s => s.Cond).DefaultIfEmpty(49).Min();
86+ var cond = target.Ships.Select(s => s.Cond).DefaultIfEmpty(49).Min();
8687 if (cond >= 49)
8788 return DateTime.MinValue;
8889 var nextRegen = NextRegenTime(_lastUpdate);
--- /dev/null
+++ b/KancolleSniffer/Fleet.cs
@@ -0,0 +1,171 @@
1+// Copyright (C) 2018 Kazuhiro Fujieda <fujieda@users.osdn.me>
2+//
3+// Licensed under the Apache License, Version 2.0 (the "License");
4+// you may not use this file except in compliance with the License.
5+// You may obtain a copy of the License at
6+//
7+// http://www.apache.org/licenses/LICENSE-2.0
8+//
9+// Unless required by applicable law or agreed to in writing, software
10+// distributed under the License is distributed on an "AS IS" BASIS,
11+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+// See the License for the specific language governing permissions and
13+// limitations under the License.
14+
15+using System.Collections.Generic;
16+using System.Linq;
17+using static System.Math;
18+
19+namespace KancolleSniffer
20+{
21+ public struct ChargeStatus
22+ {
23+ public int Fuel { get; set; }
24+ public int Bull { get; set; }
25+
26+ public ChargeStatus(ShipStatus status) : this()
27+ {
28+ Fuel = CalcChargeState(status.Fuel, status.Spec.FuelMax);
29+ Bull = CalcChargeState(status.Bull, status.Spec.BullMax);
30+ }
31+
32+ public ChargeStatus(int fuel, int bull) : this()
33+ {
34+ Fuel = fuel;
35+ Bull = bull;
36+ }
37+
38+ private int CalcChargeState(int now, int full)
39+ {
40+ if (full == 0 || now == full)
41+ return 0;
42+ var ratio = (double)now / full;
43+ if (ratio >= 7.0 / 9)
44+ return 1;
45+ if (ratio >= 3.0 / 9)
46+ return 2;
47+ if (ratio > 0)
48+ return 3;
49+ return 4;
50+ }
51+ }
52+
53+ public enum FleetState
54+ {
55+ Port,
56+ Mission,
57+ Sortie,
58+ Practice
59+ }
60+
61+ public class Fleet
62+ {
63+ private readonly ShipInfo _shipInfo;
64+ public FleetState State { get; set; }
65+ public int[] Deck { get; set; } = Enumerable.Repeat(-1, ShipInfo.MemberCount).ToArray();
66+ public ShipStatus[] Ships => Deck.Where(id => id != -1).Select(_shipInfo.GetStatus).ToArray();
67+
68+ public Fleet(ShipInfo shipInfo)
69+ {
70+ _shipInfo = shipInfo;
71+ }
72+
73+ public ChargeStatus ChargeStatus
74+ {
75+ get
76+ {
77+ var fs = new ChargeStatus(_shipInfo.GetStatus(Deck[0]));
78+ var others = (from id in Deck.Skip(1) select new ChargeStatus(_shipInfo.GetStatus(id))).Aggregate(
79+ (result, next) => new ChargeStatus(Max(result.Fuel, next.Fuel), Max(result.Bull, next.Bull)));
80+ return new ChargeStatus(fs.Fuel != 0 ? fs.Fuel : others.Fuel + 5, fs.Bull != 0 ? fs.Bull : others.Bull + 5);
81+ }
82+ }
83+
84+ public int[] FighterPower
85+ => Ships.Where(ship => !ship.Escaped).SelectMany(ship =>
86+ ship.Slot.Zip(ship.OnSlot, (slot, onslot) => slot.CalcFighterPower(onslot)))
87+ .Aggregate(new[] {0, 0}, (prev, cur) => new[] {prev[0] + cur[0], prev[1] + cur[1]});
88+
89+ public double ContactTriggerRate
90+ => Ships.Where(ship => !ship.Escaped).SelectMany(ship =>
91+ ship.Slot.Zip(ship.OnSlot, (slot, onslot) =>
92+ slot.Spec.ContactTriggerRate * slot.Spec.LoS * Sqrt(onslot))).Sum();
93+
94+ public double GetLineOfSights(int factor)
95+ {
96+ var result = 0.0;
97+ var emptyBonus = 6;
98+ foreach (var s in Ships.Where(s => !s.Escaped))
99+ {
100+ emptyBonus--;
101+ var itemLoS = 0;
102+ foreach (var item in s.Slot)
103+ {
104+ var spec = item.Spec;
105+ itemLoS += spec.LoS;
106+ result += (spec.LoS + item.LoSLevelBonus) * spec.LoSScaleFactor * factor;
107+ }
108+ result += Sqrt(s.LoS - itemLoS);
109+ }
110+ return result > 0 ? result - Ceiling(_shipInfo.HqLevel * 0.4) + emptyBonus * 2 : 0.0;
111+ }
112+
113+ public double DaihatsuBonus
114+ {
115+ get
116+ {
117+ var tokudaiBonus = new[,]
118+ {
119+ {0.00, 0.00, 0.00, 0.00, 0.00},
120+ {0.02, 0.02, 0.02, 0.02, 0.02},
121+ {0.04, 0.04, 0.04, 0.04, 0.04},
122+ {0.05, 0.05, 0.052, 0.054, 0.054},
123+ {0.054, 0.056, 0.058, 0.059, 0.06}
124+ };
125+ var daihatsu = 0;
126+ var tokudai = 0;
127+ var bonus = 0.0;
128+ var level = 0;
129+ var sum = 0;
130+ foreach (var ship in Ships)
131+ {
132+ if (ship.Name == "鬼怒改二")
133+ bonus += 0.05;
134+ foreach (var item in ship.Slot)
135+ {
136+ switch (item.Spec.Name)
137+ {
138+ case "大発動艇":
139+ level += item.Level;
140+ sum++;
141+ daihatsu++;
142+ bonus += 0.05;
143+ break;
144+ case "特大発動艇":
145+ level += item.Level;
146+ sum++;
147+ tokudai++;
148+ bonus += 0.05;
149+ break;
150+ case "大発動艇(八九式中戦車&陸戦隊)":
151+ level += item.Level;
152+ sum++;
153+ bonus += 0.02;
154+ break;
155+ case "特二式内火艇":
156+ level += item.Level;
157+ sum++;
158+ bonus += 0.01;
159+ break;
160+ }
161+ }
162+ }
163+ var levelAverage = sum == 0 ? 0.0 : (double)level / sum;
164+ bonus = Min(bonus, 0.2);
165+ return bonus + 0.01 * bonus * levelAverage + tokudaiBonus[Min(tokudai, 4), Min(daihatsu, 4)];
166+ }
167+ }
168+
169+ public double TransportPoint => Ships.Where(ship => !ship.Escaped).Sum(ship => ship.TransportPoint);
170+ }
171+}
\ No newline at end of file
--- a/KancolleSniffer/FleetPanel.cs
+++ b/KancolleSniffer/FleetPanel.cs
@@ -89,12 +89,14 @@ namespace KancolleSniffer
8989 private void CreateTable(Sniffer sniffer)
9090 {
9191 var list = new List<Record>();
92+ var fleets = sniffer.Fleets;
9293 var fn = new[] {"第一", "第二", "第三", "第四"};
9394 for (var f = 0; f < fn.Length; f++)
9495 {
9596 var total = new Total();
9697 var ships = new List<Record>();
97- foreach (var s in sniffer.GetShipStatuses(f))
98+ var fleet = fleets[f];
99+ foreach (var s in fleet.Ships)
98100 {
99101 var equips = new List<Record>();
100102 for (var i = 0; i < s.Slot.Length; i++)
@@ -150,10 +152,10 @@ namespace KancolleSniffer
150152 ships.Add(ship);
151153 ships.AddRange(equips);
152154 }
153- var daihatsu = sniffer.GetDaihatsuBonus(f);
154- var tp = sniffer.GetTransportPoint(f);
155+ var daihatsu = fleet.DaihatsuBonus;
156+ var tp = fleet.TransportPoint;
155157 if (sniffer.CombinedFleetType != 0 && f == 0)
156- tp += sniffer.GetTransportPoint(1);
158+ tp += fleets[1].TransportPoint;
157159 list.Add(new Record
158160 {
159161 Fleet = fn[f] + HideIfZero(" Lv", total.Level) +
--- a/KancolleSniffer/KancolleSniffer.csproj
+++ b/KancolleSniffer/KancolleSniffer.csproj
@@ -83,6 +83,7 @@
8383 </Compile>
8484 <Compile Include="CUDColor.cs" />
8585 <Compile Include="DockInfo.cs" />
86+ <Compile Include="Fleet.cs" />
8687 <Compile Include="FleetPanel.cs">
8788 <SubType>Component</SubType>
8889 </Compile>
--- a/KancolleSniffer/Logger.cs
+++ b/KancolleSniffer/Logger.cs
@@ -214,7 +214,7 @@ namespace KancolleSniffer
214214 else
215215 dropName += "+" + itemName;
216216 }
217- var fp = _shipInfo.GetFighterPower(BattleInfo.DeckId(_battle));
217+ var fp = _shipInfo.Fleets[BattleInfo.DeckId(_battle)].FighterPower;
218218 var fpower = fp[0] == fp[1] ? fp[0].ToString() : fp[0] + "~" + fp[1];
219219 _writer("海戦・ドロップ報告書", string.Join(",", FormatDateTime(_nowFunc()),
220220 result.api_quest_name,
@@ -495,7 +495,7 @@ namespace KancolleSniffer
495495
496496 private string Secretary()
497497 {
498- var ship = _shipInfo.GetShipStatuses(0)[0];
498+ var ship = _shipInfo.Fleets[0].Ships[0];
499499 return ship.Name + "(" + ship.Level + ")";
500500 }
501501
@@ -550,7 +550,7 @@ namespace KancolleSniffer
550550 diff[i] = _currentMaterial[i] - after[i];
551551 var ship1 = Secretary();
552552 var ship2 = "";
553- var ships = _shipInfo.GetShipStatuses(0);
553+ var ships = _shipInfo.Fleets[0].Ships;
554554 if (ships.Length >= 2)
555555 ship2 = ships[1].Name + "(" + ships[1].Level + ")";
556556 _writer("改修報告書",
--- a/KancolleSniffer/MainForm.cs
+++ b/KancolleSniffer/MainForm.cs
@@ -519,10 +519,10 @@ namespace KancolleSniffer
519519 if (!_listForm.Visible)
520520 return;
521521 var idx = (int)((Control)sender).Tag;
522- var statuses = _sniffer.GetShipStatuses(_currentFleet);
523- if (statuses.Length <= idx)
522+ var ships = _sniffer.Fleets[_currentFleet].Ships;
523+ if (ships.Length <= idx)
524524 return;
525- _listForm.ShowShip(statuses[idx].Id);
525+ _listForm.ShowShip(ships[idx].Id);
526526 }
527527
528528 private void UpdateItemInfo()
@@ -636,15 +636,16 @@ namespace KancolleSniffer
636636
637637 private void UpdatePanelShipInfo()
638638 {
639- var statuses = _sniffer.GetShipStatuses(_currentFleet);
640- panel7Ships.Visible = statuses.Length == 7;
641- _mainLabels.SetShipLabels(statuses);
639+ var fleets = _sniffer.Fleets;
640+ var ships = fleets[_currentFleet].Ships;
641+ panel7Ships.Visible = ships.Length == 7;
642+ _mainLabels.SetShipLabels(ships);
642643 if (_sniffer.CombinedFleetType == 0)
643644 _combinedFleet = false;
644645 labelFleet1.Text = _combinedFleet ? "連合" : "第一";
645646 panelCombinedFleet.Visible = _combinedFleet;
646647 if (_combinedFleet)
647- _mainLabels.SetCombinedShipLabels(_sniffer.GetShipStatuses(0), _sniffer.GetShipStatuses(1));
648+ _mainLabels.SetCombinedShipLabels(fleets[0].Ships, fleets[1].Ships);
648649 for (var i = 0; i < _labelCheckFleets.Length; i++)
649650 _labelCheckFleets[i].Visible = _currentFleet == i;
650651 UpdateAkashiTimer();
@@ -664,13 +665,14 @@ namespace KancolleSniffer
664665
665666 public void UpdateFighterPower(bool combined)
666667 {
668+ var fleets = _sniffer.Fleets;
667669 var fp = combined
668- ? _sniffer.GetFighterPower(0).Zip(_sniffer.GetFighterPower(1), (a, b) => a + b).ToArray()
669- : _sniffer.GetFighterPower(_currentFleet);
670+ ? fleets[0].FighterPower.Zip(fleets[1].FighterPower, (a, b) => a + b).ToArray()
671+ : fleets[_currentFleet].FighterPower;
670672 labelFighterPower.Text = fp[0].ToString("D");
671673 var cr = combined
672- ? _sniffer.GetContactTriggerRate(0) + _sniffer.GetContactTriggerRate(1)
673- : _sniffer.GetContactTriggerRate(_currentFleet);
674+ ? fleets[0].ContactTriggerRate + fleets[1].ContactTriggerRate
675+ : fleets[_currentFleet].ContactTriggerRate;
674676 var text = "制空: " + (fp[0] == fp[1] ? $"{fp[0]}" : $"{fp[0]}~{fp[1]}") +
675677 $" 触接: {cr * 100:f1}";
676678 _toolTip.SetToolTip(labelFighterPower, text);
@@ -679,9 +681,10 @@ namespace KancolleSniffer
679681
680682 private void UpdateLoS()
681683 {
682- labelLoS.Text = RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 1)).ToString("F1");
683- var text = $"係数3: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 3)):F1}\r\n" +
684- $"係数4: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 4)):F1}";
684+ var fleet = _sniffer.Fleets[_currentFleet];
685+ labelLoS.Text = RoundDown(fleet.GetLineOfSights(1)).ToString("F1");
686+ var text = $"係数3: {RoundDown(fleet.GetLineOfSights(3)):F1}\r\n" +
687+ $"係数4: {RoundDown(fleet.GetLineOfSights(4)):F1}";
685688 _toolTip.SetToolTip(labelLoS, text);
686689 _toolTip.SetToolTip(labelLoSCaption, text);
687690 }
@@ -751,7 +754,7 @@ namespace KancolleSniffer
751754
752755 for (var i = 0; i < fuelSq.Length; i++)
753756 {
754- var stat = _sniffer.ChargeStatuses[i];
757+ var stat = _sniffer.Fleets[i].ChargeStatus;
755758 fuelSq[i].ImageIndex = stat.Fuel;
756759 bullSq[i].ImageIndex = stat.Bull;
757760 }
@@ -908,8 +911,7 @@ namespace KancolleSniffer
908911 {
909912 if (_config.UsePresetAkashi)
910913 UpdatePresetAkashiTimer();
911- var statuses = _sniffer.GetShipStatuses(_currentFleet);
912- _mainLabels.SetAkashiTimer(statuses,
914+ _mainLabels.SetAkashiTimer(_sniffer.Fleets[_currentFleet].Ships,
913915 _sniffer.AkashiTimer.GetTimers(_currentFleet));
914916 }
915917
--- a/KancolleSniffer/MiscTextInfo.cs
+++ b/KancolleSniffer/MiscTextInfo.cs
@@ -113,7 +113,7 @@ namespace KancolleSniffer
113113 var raw = _expTable[Min(s1, _expTable.Length) - 1] / 100.0 +
114114 _expTable[Min(s2, _expTable.Length) - 1] / 300.0;
115115 var exp = raw >= 500 ? 500 + (int)Sqrt(raw - 500) : (int)raw;
116- var bonus = 1 + TrainingCruiserBonus(_shipInfo.GetShipStatuses(0));
116+ var bonus = 1 + TrainingCruiserBonus(_shipInfo.Fleets[0].Ships);
117117 Text += $"獲得経験値 : {(int)(exp * bonus)}\r\nS勝利 : {(int)((int)(exp * 1.2) * bonus)}";
118118 }
119119
--- a/KancolleSniffer/ShipInfo.cs
+++ b/KancolleSniffer/ShipInfo.cs
@@ -19,65 +19,20 @@ using static System.Math;
1919
2020 namespace KancolleSniffer
2121 {
22- public struct ChargeStatus
23- {
24- public int Fuel { get; set; }
25- public int Bull { get; set; }
26-
27- public ChargeStatus(ShipStatus status) : this()
28- {
29- Fuel = CalcChargeState(status.Fuel, status.Spec.FuelMax);
30- Bull = CalcChargeState(status.Bull, status.Spec.BullMax);
31- }
32-
33- public ChargeStatus(int fuel, int bull) : this()
34- {
35- Fuel = fuel;
36- Bull = bull;
37- }
38-
39- private int CalcChargeState(int now, int full)
40- {
41- if (full == 0 || now == full)
42- return 0;
43- var ratio = (double)now / full;
44- if (ratio >= 7.0 / 9)
45- return 1;
46- if (ratio >= 3.0 / 9)
47- return 2;
48- if (ratio > 0)
49- return 3;
50- return 4;
51- }
52- }
53-
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- }
6722
6823 public class ShipInfo
6924 {
7025 public const int FleetCount = 4;
7126 public const int MemberCount = 6;
7227
73- private readonly Fleet[] _fleets = Enumerable.Range(0, FleetCount).Select(x => new Fleet()).ToArray();
28+ private readonly Fleet[] _fleets;
7429 private readonly Dictionary<int, ShipStatus> _shipInfo = new Dictionary<int, ShipStatus>();
7530 private readonly ShipMaster _shipMaster = new ShipMaster();
7631 private readonly ItemInfo _itemInfo;
77- private int _hqLevel;
7832 private readonly List<int> _escapedShips = new List<int>();
7933 private int _combinedFleetType;
8034 private ShipStatus[] _battleResult = new ShipStatus[0];
35+ public int HqLevel { get; private set; }
8136 public ShipStatusPair[] BattleResultDiff { get; private set; } = new ShipStatusPair[0];
8237 public bool IsBattleResultError => BattleResultDiff.Length > 0;
8338 public ShipStatus[] BattleStartStatus { get; private set; } = new ShipStatus[0];
@@ -96,6 +51,7 @@ namespace KancolleSniffer
9651
9752 public ShipInfo(ItemInfo itemInfo)
9853 {
54+ _fleets = Enumerable.Range(0, FleetCount).Select(x => new Fleet(this)).ToArray();
9955 _itemInfo = itemInfo;
10056 ClearShipInfo();
10157 }
@@ -211,7 +167,7 @@ namespace KancolleSniffer
211167
212168 private void InspectBasic(dynamic json)
213169 {
214- _hqLevel = (int)json.api_level;
170+ HqLevel = (int)json.api_level;
215171 }
216172
217173 public void InspectCharge(dynamic json)
@@ -356,11 +312,6 @@ namespace KancolleSniffer
356312 s.Cond = Max(40, s.Cond);
357313 }
358314
359- public ShipStatus[] GetShipStatuses(int fleet)
360- {
361- return _fleets[fleet].Deck.Where(id => id != -1).Select(GetStatus).ToArray();
362- }
363-
364315 public Fleet[] Fleets => _fleets;
365316
366317 public ShipStatus GetStatus(int id)
@@ -392,109 +343,11 @@ namespace KancolleSniffer
392343
393344 public ShipStatus[] ShipList => _shipInfo.Keys.Where(id => id != -1).Select(GetStatus).ToArray();
394345
395- public ChargeStatus[] ChargeStatuses
396- => (from fleet in _fleets
397- let flag = new ChargeStatus(_shipInfo[fleet.Deck[0]])
398- let others = (from id in fleet.Deck.Skip(1)
399- select new ChargeStatus(_shipInfo[id]))
400- .Aggregate(
401- (result, next) =>
402- new ChargeStatus(Max(result.Fuel, next.Fuel), Max(result.Bull, next.Bull)))
403- select new ChargeStatus(flag.Fuel != 0 ? flag.Fuel : others.Fuel + 5,
404- flag.Bull != 0 ? flag.Bull : others.Bull + 5)).ToArray();
405-
406- public int[] GetFighterPower(int fleet)
407- => GetShipStatuses(fleet).Where(ship => !ship.Escaped).SelectMany(ship =>
408- ship.Slot.Zip(ship.OnSlot, (slot, onslot) => slot.CalcFighterPower(onslot)))
409- .Aggregate(new[] {0, 0}, (prev, cur) => new[] {prev[0] + cur[0], prev[1] + cur[1]});
410-
411- public double GetContactTriggerRate(int fleet)
412- => GetShipStatuses(fleet).Where(ship => !ship.Escaped).SelectMany(ship =>
413- ship.Slot.Zip(ship.OnSlot, (slot, onslot) =>
414- slot.Spec.ContactTriggerRate * slot.Spec.LoS * Sqrt(onslot))).Sum();
415-
416346 public ShipStatus[] GetRepairList(DockInfo dockInfo)
417347 => (from s in ShipList
418348 where s.NowHp < s.MaxHp && !dockInfo.InNDock(s.Id)
419349 select s).OrderByDescending(s => s.RepairTime).ToArray();
420350
421- public double GetLineOfSights(int fleet, int factor)
422- {
423- var result = 0.0;
424- var emptyBonus = 6;
425- foreach (var s in GetShipStatuses(fleet).Where(s => !s.Escaped))
426- {
427- emptyBonus--;
428- var itemLoS = 0;
429- foreach (var item in s.Slot)
430- {
431- var spec = item.Spec;
432- itemLoS += spec.LoS;
433- result += (spec.LoS + item.LoSLevelBonus) * spec.LoSScaleFactor * factor;
434- }
435- result += Sqrt(s.LoS - itemLoS);
436- }
437- return result > 0 ? result - Ceiling(_hqLevel * 0.4) + emptyBonus * 2 : 0.0;
438- }
439-
440- public double GetDaihatsuBonus(int fleet)
441- {
442- var tokudaiBonus = new[,]
443- {
444- {0.00, 0.00, 0.00, 0.00, 0.00},
445- {0.02, 0.02, 0.02, 0.02, 0.02},
446- {0.04, 0.04, 0.04, 0.04, 0.04},
447- {0.05, 0.05, 0.052, 0.054, 0.054},
448- {0.054, 0.056, 0.058, 0.059, 0.06}
449- };
450- var daihatsu = 0;
451- var tokudai = 0;
452- var bonus = 0.0;
453- var level = 0;
454- var sum = 0;
455- foreach (var ship in GetShipStatuses(fleet))
456- {
457- if (ship.Name == "鬼怒改二")
458- bonus += 0.05;
459- foreach (var item in ship.Slot)
460- {
461- switch (item.Spec.Name)
462- {
463- case "大発動艇":
464- level += item.Level;
465- sum++;
466- daihatsu++;
467- bonus += 0.05;
468- break;
469- case "特大発動艇":
470- level += item.Level;
471- sum++;
472- tokudai++;
473- bonus += 0.05;
474- break;
475- case "大発動艇(八九式中戦車&陸戦隊)":
476- level += item.Level;
477- sum++;
478- bonus += 0.02;
479- break;
480- case "特二式内火艇":
481- level += item.Level;
482- sum++;
483- bonus += 0.01;
484- break;
485- }
486- }
487- }
488- var levelAverage = sum == 0 ? 0.0 : (double)level / sum;
489- bonus = Min(bonus, 0.2);
490- return bonus + 0.01 * bonus * levelAverage + tokudaiBonus[Min(tokudai, 4), Min(daihatsu, 4)];
491- }
492-
493- public double GetTransportPoint(int fleet)
494- {
495- return GetShipStatuses(fleet).Where(ship => !ship.Escaped).Sum(ship => ship.TransportPoint);
496- }
497-
498351 public string[] BadlyDamagedShips { get; private set; } = new string[0];
499352
500353 public void SetBadlyDamagedShips()
--- a/KancolleSniffer/Sniffer.cs
+++ b/KancolleSniffer/Sniffer.cs
@@ -554,8 +554,6 @@ namespace KancolleSniffer
554554
555555 public int[] GetConditionNotice(DateTime prev, DateTime now) => _conditionTimer.GetNotice(prev, now);
556556
557- public ShipStatus[] GetShipStatuses(int fleet) => _shipInfo.GetShipStatuses(fleet);
558-
559557 public Fleet[] Fleets => _shipInfo.Fleets;
560558
561559 public ShipInfo.ShipStatusPair[] BattleResultStatusDiff => _shipInfo.BattleResultDiff;
@@ -566,24 +564,12 @@ namespace KancolleSniffer
566564
567565 public int CombinedFleetType => _shipInfo.CombinedFleetType;
568566
569- public ChargeStatus[] ChargeStatuses => _shipInfo.ChargeStatuses;
570-
571- public int[] GetFighterPower(int fleet) => _shipInfo.GetFighterPower(fleet);
572-
573- public double GetContactTriggerRate(int fleet) => _shipInfo.GetContactTriggerRate(fleet);
574-
575- public double GetFleetLineOfSights(int fleet, int factor) => _shipInfo.GetLineOfSights(fleet, factor);
576-
577567 public ShipStatus[] RepairList => _shipInfo.GetRepairList(_dockInfo);
578568
579569 public ShipStatus[] ShipList => _shipInfo.ShipList;
580570
581571 public string[] BadlyDamagedShips => _shipInfo.BadlyDamagedShips;
582572
583- public double GetDaihatsuBonus(int fleet) => _shipInfo.GetDaihatsuBonus(fleet);
584-
585- public double GetTransportPoint(int fleet) => _shipInfo.GetTransportPoint(fleet);
586-
587573 public ItemStatus[] ItemList
588574 {
589575 get
--- a/KancolleSniffer/TextGenerator.cs
+++ b/KancolleSniffer/TextGenerator.cs
@@ -72,18 +72,19 @@ namespace KancolleSniffer
7272
7373 private static StringBuilder GenerateFleetData(Sniffer sniffer, int fleet, ItemName dict)
7474 {
75+ var target = sniffer.Fleets[fleet];
7576 var sb = new StringBuilder();
7677 var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};
7778 sb.Append(fn[fleet] + "\r\n");
78- sb.Append(string.Concat(from s in sniffer.GetShipStatuses(fleet)
79+ sb.Append(string.Concat(from s in target.Ships
7980 select ($"{s.Name} Lv{s.Level} " +
8081 string.Join(",",
8182 from item in s.AllSlot
8283 where item.Id != -1
8384 select dict[item.Spec.Name] + ItemStatusString(item))).TrimEnd(' ') + "\r\n"));
84- var fp = sniffer.GetFighterPower(fleet);
85+ var fp = target.FighterPower;
8586 sb.Append($"制空: {(fp[0] == fp[1] ? fp[0].ToString() : fp[0] + "~" + fp[1])} " +
86- $"索敵: {sniffer.GetFleetLineOfSights(fleet, 1):F1}\r\n");
87+ $"索敵: {target.GetLineOfSights(1):F1}\r\n");
8788 return sb;
8889 }
8990
@@ -144,7 +145,7 @@ namespace KancolleSniffer
144145 if (f != 0)
145146 sb.Append(",");
146147 sb.Append($"\"f{f + 1}\":{{");
147- var ships = sniffer.GetShipStatuses(f);
148+ var ships = sniffer.Fleets[f].Ships;
148149 for (var s = 0; s < ships.Length; s++)
149150 {
150151 if (s != 0)
旧リポジトリブラウザで表示