• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Révision94be4bab0b1a434de72cfca303b0a5d98926f2ee (tree)
l'heure2019-07-19 21:45:22
AuteurKazuhiro Fujieda <fujieda@user...>
CommiterKazuhiro Fujieda

Message de Log

基地航空隊の制空値周りをリファクタリングする

Change Summary

Modification

--- a/KancolleSniffer.Test/SnifferTest.cs
+++ b/KancolleSniffer.Test/SnifferTest.cs
@@ -113,9 +113,9 @@ namespace KancolleSniffer.Test
113113 {
114114 var sniffer = new Sniffer();
115115 SniffLogFile(sniffer, "airbase_001");
116- PAssert.That(() => (int)sniffer.AirBase[0].AirCorps[0].CalcFighterPower().Max.AirCombat == 301);
116+ PAssert.That(() => sniffer.AirBase[0].AirCorps[0].CalcFighterPower().AirCombat.Max == 301);
117117 sniffer.AirBase[0].AirCorps[0].Action = 2; // 防空
118- PAssert.That(() => (int)sniffer.AirBase[0].AirCorps[0].CalcFighterPower().Max.Interception == 320);
118+ PAssert.That(() => sniffer.AirBase[0].AirCorps[0].CalcFighterPower().Interception.Max == 320);
119119 }
120120
121121 /// <summary>
@@ -126,7 +126,7 @@ namespace KancolleSniffer.Test
126126 {
127127 var sniffer = new Sniffer();
128128 SniffLogFile(sniffer, "airbase_002");
129- PAssert.That(() => (int)sniffer.AirBase[0].AirCorps[2].CalcFighterPower().Min.Interception == 353);
129+ PAssert.That(() => sniffer.AirBase[0].AirCorps[2].CalcFighterPower().Interception.Min == 353);
130130 }
131131
132132 /// <summary>
@@ -137,7 +137,7 @@ namespace KancolleSniffer.Test
137137 {
138138 var sniffer = new Sniffer();
139139 SniffLogFile(sniffer, "airbase_003");
140- PAssert.That(() => (int)sniffer.AirBase[1].AirCorps[0].CalcFighterPower().Min.AirCombat == 121);
140+ PAssert.That(() => sniffer.AirBase[1].AirCorps[0].CalcFighterPower().AirCombat.Min == 121);
141141 }
142142
143143 /// <summary>
@@ -159,7 +159,7 @@ namespace KancolleSniffer.Test
159159 {
160160 var sniffer = new Sniffer();
161161 SniffLogFile(sniffer, "airbase_004");
162- PAssert.That(() => (int)sniffer.AirBase[1].AirCorps[0].CalcFighterPower().Min.AirCombat == 328);
162+ PAssert.That(() => sniffer.AirBase[1].AirCorps[0].CalcFighterPower().AirCombat.Min == 328);
163163 }
164164
165165 /// <summary>
@@ -173,13 +173,13 @@ namespace KancolleSniffer.Test
173173
174174 // 二式陸上偵察機(熟練)
175175 var fp1 = sniffer.AirBase[0].AirCorps[0].CalcFighterPower();
176- PAssert.That(() => (int)fp1.Min.AirCombat == 274);
177- PAssert.That(() => (int)fp1.Min.Interception == 302);
176+ PAssert.That(() => fp1.AirCombat.Min == 274);
177+ PAssert.That(() => fp1.Interception.Min == 302);
178178
179179 // 二式陸上偵察機
180180 var fp3 = sniffer.AirBase[0].AirCorps[2].CalcFighterPower();
181- PAssert.That(() => (int)fp3.Min.AirCombat == 206);
182- PAssert.That(() => (int)fp3.Min.Interception == 310);
181+ PAssert.That(() => fp3.AirCombat.Min == 206);
182+ PAssert.That(() => fp3.Interception.Min == 310);
183183 }
184184
185185 /// <summary>
--- a/KancolleSniffer/KancolleSniffer.csproj
+++ b/KancolleSniffer/KancolleSniffer.csproj
@@ -54,7 +54,7 @@
5454 <Reference Include="System.Xml" />
5555 </ItemGroup>
5656 <ItemGroup>
57- <Compile Include="Model\AirBaseParams.cs" />
57+ <Compile Include="Model\AirCorpsFighterPower.cs" />
5858 <Compile Include="Model\QuestCounter.cs" />
5959 <Compile Include="Model\QuestCountList.cs" />
6060 <Compile Include="Model\QuestSpec.cs" />
--- a/KancolleSniffer/Model/AirBase.cs
+++ b/KancolleSniffer/Model/AirBase.cs
@@ -30,7 +30,7 @@ namespace KancolleSniffer.Model
3030 _itemInfo = item;
3131 }
3232
33- public BaseInfo[] AllAirCorps { get; set; }
33+ public BaseInfo[] AllBase { get; set; }
3434
3535 public class BaseInfo
3636 {
@@ -75,20 +75,21 @@ namespace KancolleSniffer.Model
7575 }
7676 }
7777
78- public AirBaseParams.Range CalcFighterPower()
78+ public AirCorpsFighterPower CalcFighterPower()
7979 {
80- var reconPlaneBonus = Planes.Aggregate(new AirBaseParams(), (max, plane) =>
80+ var reconPlaneBonus = Planes.Aggregate(new AirCorpsFighterPower.Pair(), (max, plane) =>
8181 {
8282 var bonus = plane.Slot.Spec.ReconPlaneAirBaseBonus;
83- return AirBaseParams.Max(max, bonus);
83+ return AirCorpsFighterPower.Pair.Max(max, bonus);
8484 });
85- return (Planes.Aggregate(new AirBaseParams.Range(), (previous, plane) =>
85+ var range = (Planes.Aggregate(new AirCorpsFighterPower.Range(), (previous, plane) =>
8686 {
8787 if (plane.State != 1)
8888 return previous;
8989 var current = plane.Slot.CalcFighterPowerInBase(plane.Count);
9090 return previous + current;
9191 }) * reconPlaneBonus).Floor();
92+ return new AirCorpsFighterPower(range);
9293 }
9394
9495 public int[] CostForSortie => Planes.Aggregate(new[] {0, 0}, (prev, plane) =>
@@ -135,12 +136,12 @@ namespace KancolleSniffer.Model
135136 }
136137 }
137138
138- public AirBaseParams.Range FighterPower => Slot.CalcFighterPowerInBase(Count);
139+ public AirCorpsFighterPower FighterPower => new AirCorpsFighterPower(Slot.CalcFighterPowerInBase(Count));
139140 }
140141
141142 public void Inspect(dynamic json)
142143 {
143- AllAirCorps = (from entry in (dynamic[])json
144+ AllBase = (from entry in (dynamic[])json
144145 group
145146 new AirCorpsInfo
146147 {
@@ -161,7 +162,7 @@ namespace KancolleSniffer.Model
161162
162163 public void InspectSetPlane(string request, dynamic json)
163164 {
164- if (AllAirCorps == null)
165+ if (AllBase == null)
165166 return;
166167 var values = HttpUtility.ParseQueryString(request);
167168 var airCorps = GetBaseInfo(values).AirCorps[int.Parse(values["api_base_id"]) - 1];
@@ -195,7 +196,7 @@ namespace KancolleSniffer.Model
195196
196197 public void InspectSetAction(string request)
197198 {
198- if (AllAirCorps == null)
199+ if (AllBase == null)
199200 return;
200201 var values = HttpUtility.ParseQueryString(request);
201202 var airCorps = GetBaseInfo(values).AirCorps;
@@ -224,7 +225,7 @@ namespace KancolleSniffer.Model
224225 private BaseInfo GetBaseInfo(NameValueCollection values)
225226 {
226227 var areaId = int.Parse(values["api_area_id"] ?? "0"); // 古いAPIに対応するため
227- return AllAirCorps.First(b => b.AreaId == areaId);
228+ return AllBase.First(b => b.AreaId == areaId);
228229 }
229230
230231 public void InspectPlaneInfo(dynamic json)
@@ -241,10 +242,10 @@ namespace KancolleSniffer.Model
241242
242243 public void SetItemHolder()
243244 {
244- if (AllAirCorps == null)
245+ if (AllBase == null)
245246 return;
246247 var name = new[] {"第一", "第二", "第三"};
247- foreach (var baseInfo in AllAirCorps.Select((data, i) => new {data, i}))
248+ foreach (var baseInfo in AllBase.Select((data, i) => new {data, i}))
248249 {
249250 var areaName = baseInfo.data.AreaName;
250251 foreach (var airCorps in baseInfo.data.AirCorps.Select((data, i) => new {data, i}))
--- a/KancolleSniffer/Model/AirBaseParams.cs
+++ /dev/null
@@ -1,95 +0,0 @@
1-// Copyright (C) 2019 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;
16-using KancolleSniffer.Util;
17-
18-namespace KancolleSniffer.Model
19-{
20- public struct AirBaseParams
21- {
22- public double AirCombat { get; }
23- public double Interception { get; }
24-
25- public AirBaseParams(double airCombat, double interception)
26- {
27- AirCombat = airCombat;
28- Interception = interception;
29- }
30-
31- public static AirBaseParams Max(AirBaseParams value1, AirBaseParams value2)
32- {
33- return new AirBaseParams(Math.Max(value1.AirCombat, value2.AirCombat),
34- Math.Max(value1.Interception, value2.Interception));
35- }
36-
37- public static AirBaseParams operator +(AirBaseParams lhs, AirBaseParams rhs)
38- {
39- return new AirBaseParams(lhs.AirCombat + rhs.AirCombat, lhs.Interception + rhs.Interception);
40- }
41-
42- public static AirBaseParams operator +(AirBaseParams lhs, double rhs)
43- {
44- return new AirBaseParams(lhs.AirCombat + rhs, lhs.Interception + rhs);
45- }
46-
47- public static AirBaseParams operator *(AirBaseParams lhs, AirBaseParams rhs)
48- {
49- return new AirBaseParams(lhs.AirCombat * rhs.AirCombat, lhs.Interception * rhs.Interception);
50- }
51-
52- public static AirBaseParams operator *(AirBaseParams lhs, double rhs)
53- {
54- return new AirBaseParams(lhs.AirCombat * rhs, lhs.Interception * rhs);
55- }
56-
57- public AirBaseParams Floor()
58- {
59- return new AirBaseParams((int)AirCombat, (int)Interception);
60- }
61-
62- public struct Range
63- {
64- public AirBaseParams Min { get; }
65- public AirBaseParams Max { get; }
66-
67- public Range(AirBaseParams min, AirBaseParams max)
68- {
69- Min = min;
70- Max = max;
71- }
72-
73- public Range(AirBaseParams base_, RangeD range)
74- {
75- Min = (base_ + range.Min).Floor();
76- Max = (base_ + range.Max).Floor();
77- }
78-
79- public static Range operator +(Range lhs, Range rhs)
80- {
81- return new Range(lhs.Min + rhs.Min, lhs.Max + rhs.Max);
82- }
83-
84- public static Range operator *(Range lhs, AirBaseParams rhs)
85- {
86- return new Range(lhs.Min * rhs, lhs.Max * rhs);
87- }
88-
89- public Range Floor()
90- {
91- return new Range(Min.Floor(), Max.Floor());
92- }
93- }
94- }
95-}
\ No newline at end of file
--- /dev/null
+++ b/KancolleSniffer/Model/AirCorpsFighterPower.cs
@@ -0,0 +1,108 @@
1+// Copyright (C) 2019 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;
16+
17+namespace KancolleSniffer.Model
18+{
19+ public class AirCorpsFighterPower
20+ {
21+ public Model.Range AirCombat;
22+ public Model.Range Interception;
23+ public bool Difference;
24+
25+ public AirCorpsFighterPower(Range fighterPower)
26+ {
27+ AirCombat = new Model.Range(fighterPower.Min.AirCombat, fighterPower.Max.AirCombat);
28+ Interception = new Model.Range(fighterPower.Min.Interception, fighterPower.Max.Interception);
29+ Difference = Interception.Min != AirCombat.Min;
30+ }
31+
32+ public struct Pair
33+ {
34+ public double AirCombat { get; }
35+ public double Interception { get; }
36+
37+ public Pair(double airCombat, double interception)
38+ {
39+ AirCombat = airCombat;
40+ Interception = interception;
41+ }
42+
43+ public static Pair Max(Pair value1, Pair value2)
44+ {
45+ return new Pair(Math.Max(value1.AirCombat, value2.AirCombat),
46+ Math.Max(value1.Interception, value2.Interception));
47+ }
48+
49+ public static Pair operator +(Pair lhs, Pair rhs)
50+ {
51+ return new Pair(lhs.AirCombat + rhs.AirCombat, lhs.Interception + rhs.Interception);
52+ }
53+
54+ public static Pair operator +(Pair lhs, double rhs)
55+ {
56+ return new Pair(lhs.AirCombat + rhs, lhs.Interception + rhs);
57+ }
58+
59+ public static Pair operator *(Pair lhs, Pair rhs)
60+ {
61+ return new Pair(lhs.AirCombat * rhs.AirCombat, lhs.Interception * rhs.Interception);
62+ }
63+
64+ public static Pair operator *(Pair lhs, double rhs)
65+ {
66+ return new Pair(lhs.AirCombat * rhs, lhs.Interception * rhs);
67+ }
68+
69+ public Pair Floor()
70+ {
71+ return new Pair((int)AirCombat, (int)Interception);
72+ }
73+ }
74+
75+ public struct Range
76+ {
77+ public Pair Min { get; }
78+ public Pair Max { get; }
79+
80+ public Range(Pair min, Pair max)
81+ {
82+ Min = min;
83+ Max = max;
84+ }
85+
86+ public Range(Pair base_, RangeD range)
87+ {
88+ Min = (base_ + range.Min).Floor();
89+ Max = (base_ + range.Max).Floor();
90+ }
91+
92+ public static Range operator +(Range lhs, Range rhs)
93+ {
94+ return new Range(lhs.Min + rhs.Min, lhs.Max + rhs.Max);
95+ }
96+
97+ public static Range operator *(Range lhs, Pair rhs)
98+ {
99+ return new Range(lhs.Min * rhs, lhs.Max * rhs);
100+ }
101+
102+ public Range Floor()
103+ {
104+ return new Range(Min.Floor(), Max.Floor());
105+ }
106+ }
107+ }
108+}
\ No newline at end of file
--- a/KancolleSniffer/Model/ItemSpec.cs
+++ b/KancolleSniffer/Model/ItemSpec.cs
@@ -204,21 +204,21 @@ namespace KancolleSniffer.Model
204204 }
205205 }
206206
207- public AirBaseParams ReconPlaneAirBaseBonus
207+ public AirCorpsFighterPower.Pair ReconPlaneAirBaseBonus
208208 {
209209 get
210210 {
211211 switch (Type)
212212 {
213213 case 9:
214- return new AirBaseParams(1.0, LoS <= 7 ? 1.2 : 1.3);
214+ return new AirCorpsFighterPower.Pair(1.0, LoS <= 7 ? 1.2 : 1.3);
215215 case 10:
216216 case 41:
217- return new AirBaseParams(1.0, LoS <= 7 ? 1.1 : LoS <= 8 ? 1.13 : 1.16);
217+ return new AirCorpsFighterPower.Pair(1.0, LoS <= 7 ? 1.1 : LoS <= 8 ? 1.13 : 1.16);
218218 case 49:
219- return new AirBaseParams(LoS <= 8 ? 1.15 : 1.18, LoS <= 8 ? 1.18 : 1.24);
219+ return new AirCorpsFighterPower.Pair(LoS <= 8 ? 1.15 : 1.18, LoS <= 8 ? 1.18 : 1.24);
220220 }
221- return new AirBaseParams(1.0, 1.0);
221+ return new AirCorpsFighterPower.Pair(1.0, 1.0);
222222 }
223223 }
224224
--- a/KancolleSniffer/Model/ItemStatus.cs
+++ b/KancolleSniffer/Model/ItemStatus.cs
@@ -56,14 +56,14 @@ namespace KancolleSniffer.Model
5656 }
5757 }
5858
59- public AirBaseParams.Range CalcFighterPowerInBase(int slot)
59+ public AirCorpsFighterPower.Range CalcFighterPowerInBase(int slot)
6060 {
6161 if (!Spec.IsAircraft || slot == 0)
62- return new AirBaseParams.Range();
62+ return new AirCorpsFighterPower.Range();
6363 var withoutAlv =
64- (new AirBaseParams(Spec.Interception * 1.5, Spec.AntiBomber * 2 + Spec.Interception) +
64+ (new AirCorpsFighterPower.Pair(Spec.Interception * 1.5, Spec.AntiBomber * 2 + Spec.Interception) +
6565 Spec.AntiAir + FighterPowerLevelBonus) * Math.Sqrt(slot);
66- return new AirBaseParams.Range(withoutAlv, AlvBonusInBase);
66+ return new AirCorpsFighterPower.Range(withoutAlv, AlvBonusInBase);
6767 }
6868
6969 private RangeD AlvBonusInBase
--- a/KancolleSniffer/Sniffer.cs
+++ b/KancolleSniffer/Sniffer.cs
@@ -657,7 +657,7 @@ namespace KancolleSniffer
657657
658658 public string MiscText => _miscTextInfo.Text;
659659
660- public AirBase.BaseInfo[] AirBase => _airBase.AllAirCorps;
660+ public AirBase.BaseInfo[] AirBase => _airBase.AllBase;
661661
662662 public CellInfo CellInfo => _cellInfo;
663663
--- a/KancolleSniffer/View/FleetSpec.cs
+++ b/KancolleSniffer/View/FleetSpec.cs
@@ -246,7 +246,7 @@ namespace KancolleSniffer.View
246246 {
247247 public AirCorpsRecord(AirBase.AirCorpsInfo airCorps, int number)
248248 {
249- var corpsFp = new AirCorpsFp(airCorps.CalcFighterPower());
249+ var corpsFp = airCorps.CalcFighterPower();
250250 string spec;
251251 string spec2;
252252 if (airCorps.Action == 2)
@@ -276,7 +276,7 @@ namespace KancolleSniffer.View
276276 {
277277 public CorpsPlaneRecord(AirBase.PlaneInfo plane)
278278 {
279- var planeFp = new AirCorpsFp(plane.FighterPower);
279+ var planeFp = plane.FighterPower;
280280 Equip = plane.State != 1 ? plane.StateName : GenEquipString(plane.Slot);
281281 Spec = plane.State != 1 ? "" : $"+{plane.Slot.Alv} {plane.Count}/{plane.MaxCount}";
282282 AircraftSpec =
@@ -286,20 +286,6 @@ namespace KancolleSniffer.View
286286 }
287287 }
288288
289- private class AirCorpsFp
290- {
291- public readonly Range AirCombat;
292- public readonly Range Interception;
293- public readonly bool Difference;
294-
295- public AirCorpsFp(AirBaseParams.Range fighterPower)
296- {
297- AirCombat = new Range(fighterPower.Min.AirCombat, fighterPower.Max.AirCombat);
298- Interception = new Range(fighterPower.Min.Interception, fighterPower.Min.Interception);
299- Difference = Interception.Min != AirCombat.Min;
300- }
301- }
302-
303289 private static string RangeString(Range range) => range.Diff ? range.RangeString : range.Min.ToString();
304290 }
305291 }