コミットメタ情報

リビジョン93627460fcb424343429fcc6590fa61bac8e6a5e (tree)
日時2018-05-15 19:53:12
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

FleetPanelのリファクタリング

変更サマリ

差分

--- a/KancolleSniffer/FleetPanel.cs
+++ b/KancolleSniffer/FleetPanel.cs
@@ -59,25 +59,43 @@ namespace KancolleSniffer
5959 ResumeLayout();
6060 }
6161
62+ private class Total
63+ {
64+ public int Drum;
65+ public int DrumShips;
66+ public int Level;
67+ public int FirePower;
68+ public int AntiSubmarine;
69+ public int AntiAir;
70+ public int LoS;
71+ public int Fuel;
72+ public int Bull;
73+
74+ public void Add(ShipStatus s)
75+ {
76+ var drum = s.Slot.Count(item => item.Spec.Name == "ドラム缶(輸送用)");
77+ DrumShips += drum != 0 ? 1 : 0;
78+ Drum += drum;
79+ Level += s.Level;
80+ FirePower += s.Firepower;
81+ AntiSubmarine += s.MissionAntiSubmarine;
82+ AntiAir += s.AntiAir;
83+ LoS += s.LoS;
84+ Fuel += s.EffectiveFuelMax;
85+ Bull += s.EffectiveBullMax;
86+ }
87+ }
88+
6289 private void CreateTable(Sniffer sniffer)
6390 {
6491 var list = new List<Record>();
6592 var fn = new[] {"第一", "第二", "第三", "第四"};
6693 for (var f = 0; f < fn.Length; f++)
6794 {
68- var drumTotal = 0;
69- var drumShips = 0;
70- var levelTotal = 0;
71- var fpTotal = 0;
72- var aswTotal = 0;
73- var antiAirTotal = 0;
74- var fuelTotal = 0;
75- var bullTotal = 0;
76- var losTotal = 0;
95+ var total = new Total();
7796 var ships = new List<Record>();
7897 foreach (var s in sniffer.GetShipStatuses(f))
7998 {
80- var drum = 0;
8199 var equips = new List<Record>();
82100 for (var i = 0; i < s.Slot.Length; i++)
83101 {
@@ -86,8 +104,6 @@ namespace KancolleSniffer
86104 var max = s.Spec.MaxEq[i];
87105 if (item.Id == -1)
88106 continue;
89- if (item.Spec.Name == "ドラム缶(輸送用)")
90- drum++;
91107 var airspec = "";
92108 if (item.Spec.IsDiveBomber) // 爆撃
93109 {
@@ -99,7 +115,6 @@ namespace KancolleSniffer
99115 var normal = 25 + item.Spec.Torpedo * Math.Sqrt(onslot);
100116 airspec = "航空戦 " + (int)(normal * 0.8) + "/" + (int)(normal * 1.5);
101117 }
102-
103118 equips.Add(new Record
104119 {
105120 Equip = GenEquipString(item),
@@ -113,16 +128,7 @@ namespace KancolleSniffer
113128 var item = s.SlotEx;
114129 equips.Add(new Record {Equip = GenEquipString(item), Color = item.Spec.Color});
115130 }
116- if (drum != 0)
117- drumShips++;
118- drumTotal += drum;
119- levelTotal += s.Level;
120- fpTotal += s.Firepower;
121- aswTotal += s.MissionAntiSubmarine;
122- antiAirTotal += s.AntiAir;
123- losTotal += s.LoS;
124- fuelTotal += Math.Max((int)(s.Spec.FuelMax * (s.Level >= 100 ? 0.85 : 1.0)), 1);
125- bullTotal += Math.Max((int)(s.Spec.BullMax * (s.Level >= 100 ? 0.85 : 1.0)), 1);
131+ total.Add(s);
126132 var fire = s.EffectiveFirepower;
127133 var subm = s.EffectiveAntiSubmarine;
128134 var torp = s.EffectiveTorpedo;
@@ -133,10 +139,8 @@ namespace KancolleSniffer
133139 Ship = (s.Escaped ? "[避]" : "") + s.Name + " Lv" + s.Level,
134140 Ship2 = "",
135141 Id = s.Id,
136- // ReSharper disable CompareOfFloatsByEqualityOperator
137- Spec = (fire == 0 ? "" : $"砲{fire:f1}") + (subm == 0 ? "" : $" 潜{subm:f1}{oasa}"),
138- Spec2 = (torp == 0 ? "" : $"雷{torp:f1}") + (night == 0 ? "" : $" 夜{night:f1}")
139- // ReSharper restore CompareOfFloatsByEqualityOperator
142+ Spec = HideIfZero("砲", fire) + HideIfZero(" 潜", subm) + oasa,
143+ Spec2 = HideIfZero("雷", torp) + HideIfZero(" 夜", night)
140144 };
141145 if (ship.Spec == "")
142146 {
@@ -152,15 +156,15 @@ namespace KancolleSniffer
152156 tp += sniffer.GetTransportPoint(1);
153157 list.Add(new Record
154158 {
155- Fleet = fn[f] + (levelTotal == 0 ? "" : " Lv" + levelTotal) +
156- (drumTotal == 0 ? "" : " ドラム缶" + drumTotal + "(" + drumShips + "隻)") +
157- (daihatsu > 0 ? $" 大発{daihatsu * 100:f1}%" : ""),
159+ Fleet = fn[f] + HideIfZero(" Lv", total.Level) +
160+ HideIfZero(" ドラム缶", total.Drum) + HideIfZero("(", total.DrumShips, "隻)") +
161+ HideIfZero(" 大発", daihatsu * 100, "%"),
158162 Fleet2 = "計:" +
159- "火" + CutOverFlow(fpTotal) +
160- " 空" + CutOverFlow(antiAirTotal) +
161- " 潜" + CutOverFlow(aswTotal) +
162- " 索" + CutOverFlow(losTotal) + "\r\n" +
163- $"戦闘:燃{fuelTotal / 5}弾{bullTotal / 5} 支援:燃{fuelTotal / 2}弾{(int)(bullTotal * 0.8)}" +
163+ "火" + CutOverFlow(total.FirePower) +
164+ " 空" + CutOverFlow(total.AntiAir) +
165+ " 潜" + CutOverFlow(total.AntiSubmarine) +
166+ " 索" + CutOverFlow(total.LoS) + "\r\n" +
167+ $"戦闘:燃{total.Fuel / 5}弾{total.Bull / 5} 支援:燃{total.Fuel / 2}弾{(int)(total.Bull * 0.8)}" +
164168 (sniffer.CombinedFleetType != 0 && f == 1 ? "" : $"\r\nTP:S{(int)tp} A{(int)(tp * 0.7)}")
165169 });
166170 list.AddRange(ships);
@@ -220,6 +224,16 @@ namespace KancolleSniffer
220224
221225 private int CutOverFlow(int value) => value > 999 ? 999 : value;
222226
227+ private string HideIfZero(string name, double value, string suffix = "")
228+ {
229+ return value > 0 ? name + value.ToString("f1") + suffix : "";
230+ }
231+
232+ private string HideIfZero(string name, int value, string suffix = "")
233+ {
234+ return value > 0 ? name + value + suffix : "";
235+ }
236+
223237 private string GenEquipString(ItemStatus item)
224238 {
225239 var name = item.Spec.Name;
--- a/KancolleSniffer/ShipStatus.cs
+++ b/KancolleSniffer/ShipStatus.cs
@@ -320,6 +320,10 @@ namespace KancolleSniffer
320320
321321 public int EffectiveAntiAirForFleet => (int)AllSlot.Sum(item => item.EffectiveAntiAirForFleet);
322322
323+ public int EffectiveFuelMax => Max((int)(Spec.FuelMax * (Level >= 100 ? 0.85 : 1.0)), 1);
324+
325+ public int EffectiveBullMax => Max((int)(Spec.BullMax * (Level >= 100 ? 0.85 : 1.0)), 1);
326+
323327 public object Clone()
324328 {
325329 var r = (ShipStatus)MemberwiseClone();
旧リポジトリブラウザで表示