コミットメタ情報

リビジョン18bd104466d3f7a81d5ae7aa66986bc37e3ca54b (tree)
日時2018-07-22 18:34:48
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

ドロップした艦娘と装備を出撃中にカウントする

変更サマリ

差分

--- /dev/null
+++ b/Data/NumEquips.csv
@@ -0,0 +1,214 @@
1+1,睦月,2
2+2,如月,1
3+6,長月,1
4+7,三日月,1
5+9,吹雪,2
6+10,白雪,1
7+11,深雪,1
8+12,磯波,1
9+13,綾波,2
10+14,敷波,1
11+15,曙,1
12+16,潮,1
13+17,陽炎,2
14+18,不知火,1
15+19,黒潮,1
16+20,雪風,2
17+21,長良,2
18+22,五十鈴,1
19+23,由良,1
20+24,大井,2
21+25,北上,2
22+26,扶桑,3
23+27,山城,3
24+28,皐月,1
25+29,文月,1
26+30,菊月,1
27+31,望月,1
28+32,初雪,1
29+33,叢雲,1
30+34,暁,2
31+35,響,1
32+36,雷,1
33+37,電,1
34+38,初春,2
35+39,子日,1
36+40,若葉,1
37+41,初霜,1
38+42,白露,2
39+43,時雨,1
40+44,村雨,1
41+45,夕立,1
42+46,五月雨,1
43+47,涼風,2
44+48,霰,1
45+49,霞,1
46+50,島風,2
47+51,天龍,2
48+52,龍田,2
49+53,名取,1
50+54,川内,2
51+55,神通,1
52+56,那珂,1
53+59,古鷹,2
54+60,加古,1
55+61,青葉,2
56+62,妙高,2
57+63,那智,1
58+64,足柄,1
59+65,羽黒,1
60+66,高雄,2
61+67,愛宕,2
62+68,摩耶,1
63+69,鳥海,1
64+70,最上,2
65+71,利根,2
66+72,筑摩,2
67+74,祥鳳,2
68+75,飛鷹,3
69+76,龍驤,2
70+77,伊勢,3
71+78,金剛,3
72+79,榛名,3
73+80,長門,3
74+81,陸奥,3
75+83,赤城,3
76+84,加賀,3
77+85,霧島,3
78+86,比叡,3
79+87,日向,3
80+89,鳳翔,1
81+90,蒼龍,3
82+91,飛龍,3
83+92,隼鷹,3
84+93,朧,1
85+94,漣,1
86+95,朝潮,2
87+96,大潮,1
88+97,満潮,1
89+98,荒潮,1
90+99,球磨,2
91+100,多摩,1
92+101,木曾,1
93+102,千歳,2
94+103,千代田,2
95+110,翔鶴,3
96+111,瑞鶴,3
97+113,鬼怒,1
98+114,阿武隈,1
99+115,夕張,2
100+116,瑞鳳,2
101+120,三隈,2
102+122,舞風,2
103+123,衣笠,2
104+124,鈴谷,2
105+125,熊野,2
106+126,伊168,0
107+127,伊58,0
108+128,伊8,0
109+131,大和,3
110+132,秋雲,2
111+133,夕雲,2
112+134,巻雲,2
113+135,長波,2
114+137,阿賀野,2
115+138,能代,2
116+139,矢矧,2
117+140,酒匂,2
118+143,武蔵,3
119+153,大鳳,3
120+154,香取,3
121+155,伊401,0
122+161,あきつ丸,2
123+162,神威,0
124+163,まるゆ,0
125+164,弥生,1
126+165,卯月,1
127+167,磯風,2
128+168,浦風,2
129+169,谷風,2
130+170,浜風,2
131+171,Bismarck,2
132+174,Z1,1
133+175,Z3,1
134+176,Prinz Eugen,2
135+181,天津風,3
136+182,明石,2
137+183,大淀,3
138+184,大鯨,2
139+186,時津風,2
140+190,初風,2
141+191,伊19,0
142+331,天城,2
143+332,葛城,2
144+404,雲龍,2
145+405,春雨,2
146+409,早霜,2
147+410,清霜,2
148+413,朝雲,2
149+414,山雲,2
150+415,野分,2
151+421,秋月,3
152+422,照月,3
153+423,初月,3
154+424,高波,2
155+425,朝霜,2
156+431,U-511,1
157+432,Graf Zeppelin,2
158+433,Saratoga,2
159+439,Warspite,1
160+440,Iowa,2
161+441,Littorio,3
162+442,Roma,3
163+443,Libeccio,1
164+444,Aquila,1
165+445,秋津洲,2
166+448,Zara,1
167+449,Pola,1
168+451,瑞穂,2
169+452,沖波,2
170+453,風雲,2
171+454,嵐,2
172+455,萩風,2
173+456,親潮,2
174+457,山風,1
175+458,海風,1
176+459,江風,1
177+460,速吸,2
178+465,鹿島,3
179+471,神風,2
180+472,朝風,2
181+473,春風,2
182+474,松風,2
183+475,旗風,2
184+479,天霧,1
185+480,狭霧,1
186+481,水無月,1
187+483,伊26,0
188+484,浜波,2
189+485,藤波,2
190+486,浦波,2
191+491,Commandant Teste,1
192+492,Richelieu,2
193+493,伊400,0
194+494,伊13,0
195+495,伊14,0
196+511,Гангут,2
197+515,Ark Royal,2
198+516,Ташкент,3
199+517,占守,2
200+518,国後,2
201+519,Jervis,1
202+521,春日丸,1
203+524,択捉,2
204+525,松輪,2
205+531,佐渡,2
206+532,涼月,3
207+535,Luigi Torelli,0
208+540,対馬,2
209+544,Gambier Bay,1
210+549,Intrepid,1
211+551,日振,2
212+552,大東,2
213+561,Samuel B.Roberts,1
214+565,福江,2
--- a/KancolleSniffer.Test/LoggerTest.cs
+++ b/KancolleSniffer.Test/LoggerTest.cs
@@ -21,6 +21,8 @@ using Moq;
2121
2222 namespace KancolleSniffer.Test
2323 {
24+ using Sniffer = SnifferTest.TestingSniffer;
25+
2426 [TestClass]
2527 public class LoggerTest
2628 {
--- a/KancolleSniffer.Test/SnifferTest.cs
+++ b/KancolleSniffer.Test/SnifferTest.cs
@@ -22,6 +22,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
2222
2323 namespace KancolleSniffer.Test
2424 {
25+ using Sniffer = SnifferTest.TestingSniffer;
26+
2527 [TestClass]
2628 public class SnifferTest
2729 {
@@ -32,6 +34,14 @@ namespace KancolleSniffer.Test
3234 .GlobalAssertionConfiguration.WithPrintedListLengthLimit(200).WithMaximumValueLength(1000);
3335 }
3436
37+ public class TestingSniffer : KancolleSniffer.Sniffer
38+ {
39+ public TestingSniffer(bool start = false) : base(start)
40+ {
41+ AdditionalData.UseNumEquipsFile = false;
42+ }
43+ }
44+
3545 public static StreamReader OpenLogFile(string name)
3646 {
3747 var dir = Path.GetDirectoryName(Path.GetDirectoryName(Environment.CurrentDirectory));
@@ -846,5 +856,30 @@ namespace KancolleSniffer.Test
846856 PAssert.That(() =>
847857 sniffer.MiscText == "[獲得アイテム]\r\n弾薬: 150\r\n開発資材: 1", "途中でリロードして再出撃");
848858 }
859+
860+ /// <summary>
861+ /// 新規のドロップ艦の初期装備数を登録する
862+ /// </summary>
863+ [TestMethod]
864+ public void RecordNumEqipsOfNewDropShip()
865+ {
866+ var sniffer = new Sniffer();
867+ SniffLogFile(sniffer, "dropship_001");
868+ PAssert.That(() => sniffer.AdditionalData.NumEquips(565) == 2);
869+ PAssert.That(() => sniffer.ShipList.First(s => s.Spec.Id == 565).Spec.NumEquips == 2);
870+ }
871+
872+ /// <summary>
873+ /// 既知のドロップ艦とその装備をカウントする
874+ /// </summary>
875+ [TestMethod]
876+ public void CountDropShip()
877+ {
878+ var sniffer = new Sniffer();
879+ sniffer.AdditionalData.RecordNumEquips(11, "", 1);
880+ SniffLogFile(sniffer, "dropship_002");
881+ PAssert.That(() => sniffer.Item.NowShips == 250);
882+ PAssert.That(() => sniffer.Item.NowEquips == 1159);
883+ }
849884 }
850885 }
\ No newline at end of file
--- a/KancolleSniffer.Test/logs
+++ b/KancolleSniffer.Test/logs
@@ -1 +1 @@
1-Subproject commit f536d67271f300eb34b6e2bcc1f077ae19d08d8b
1+Subproject commit dcb6cd982f57c262ff5280f13873595f3cc4864e
--- a/KancolleSniffer/AdditionalData.cs
+++ b/KancolleSniffer/AdditionalData.cs
@@ -67,5 +67,35 @@ namespace KancolleSniffer
6767
6868 public double ItemTp(int id) =>
6969 _tpSpec != null ? _tpSpec.TryGetValue(id, out var tp) ? tp : -1 : -1;
70+
71+ private static readonly string NumEquipsFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NumEquips.csv");
72+
73+ private Dictionary<int, int> _numEquips = new Dictionary<int, int>();
74+
75+ public bool UseNumEquipsFile { get; set; } = true;
76+
77+ public void LoadNumEquips()
78+ {
79+ try
80+ {
81+ if (!UseNumEquipsFile)
82+ return;
83+ _numEquips = File.ReadLines(NumEquipsFile)
84+ .Select(line => line.Split(','))
85+ .ToDictionary(f => int.Parse(f[0]), f => int.Parse(f[2]));
86+ }
87+ catch (IOException)
88+ {
89+ }
90+ }
91+
92+ public int NumEquips(int id) => _numEquips.TryGetValue(id, out var num) ? num : -1;
93+
94+ public void RecordNumEquips(int id, string name, int numEquips)
95+ {
96+ _numEquips[id] = numEquips;
97+ if (UseNumEquipsFile)
98+ File.AppendAllText(NumEquipsFile, $"{id},{name},{numEquips}\r\n");
99+ }
70100 }
71101 }
\ No newline at end of file
--- a/KancolleSniffer/BattleInfo.cs
+++ b/KancolleSniffer/BattleInfo.cs
@@ -478,6 +478,7 @@ namespace KancolleSniffer
478478 BattleState = BattleState.Result;
479479 ShowResult(!_lastCell);
480480 _shipInfo.SaveBattleResult();
481+ _shipInfo.DropShipId = json.api_get_ship() ? (int)json.api_get_ship.api_ship_id : -1;
481482 VerifyResultRank(json);
482483 CleanupResult();
483484 SetEscapeShips(json);
--- a/KancolleSniffer/ItemInfo.cs
+++ b/KancolleSniffer/ItemInfo.cs
@@ -159,13 +159,13 @@ namespace KancolleSniffer
159159 }
160160 }
161161
162- public Func<int, double?> GetItemTp { private get; set; }
162+ public Func<double> GetItemTp { get; set; }
163163
164164 public double TransportPoint
165165 {
166166 get
167167 {
168- var tp = GetItemTp?.Invoke(Id);
168+ var tp = GetItemTp?.Invoke();
169169 if (tp >= 0)
170170 return (double)tp;
171171 switch (Id)
@@ -632,7 +632,7 @@ namespace KancolleSniffer
632632 public int NowEquips
633633 {
634634 get => _nowEquips;
635- private set
635+ set
636636 {
637637 if (MaxEquips != 0)
638638 {
@@ -667,13 +667,14 @@ namespace KancolleSniffer
667667 var dict = new Dictionary<int, string>();
668668 foreach (var entry in json.api_mst_slotitem_equiptype)
669669 dict[(int)entry.api_id] = entry.api_name;
670- AdditionalData?.LoadTpSpec();
670+ AdditionalData.LoadTpSpec();
671671 foreach (var entry in json.api_mst_slotitem)
672672 {
673673 var type = (int)entry.api_type[2];
674+ var id = (int)entry.api_id;
674675 _itemSpecs[(int)entry.api_id] = new ItemSpec
675676 {
676- Id = (int)entry.api_id,
677+ Id = id,
677678 Name = (string)entry.api_name,
678679 Type = type,
679680 TypeName = dict.TryGetValue(type, out var typeName) ? typeName : "不明",
@@ -687,7 +688,7 @@ namespace KancolleSniffer
687688 Interception = type == 48 ? (int)entry.api_houk : 0, // 局地戦闘機は回避の値が迎撃
688689 AntiBomber = type == 48 ? (int)entry.api_houm : 0, // 〃命中の値が対爆
689690 Distance = entry.api_distance() ? (int)entry.api_distance : 0,
690- GetItemTp = id => AdditionalData?.ItemTp(id)
691+ GetItemTp = () => AdditionalData.ItemTp(id)
691692 };
692693 }
693694 _itemSpecs[-1] = _itemSpecs[0] = new ItemSpec();
--- a/KancolleSniffer/ShipInfo.cs
+++ b/KancolleSniffer/ShipInfo.cs
@@ -31,10 +31,25 @@ namespace KancolleSniffer
3131 private readonly ItemInfo _itemInfo;
3232 private readonly List<int> _escapedShips = new List<int>();
3333 private ShipStatus[] _battleResult = new ShipStatus[0];
34+ private readonly NumEquipsChecker _numEquipsChecker = new NumEquipsChecker();
3435 public int HqLevel { get; private set; }
3536 public ShipStatusPair[] BattleResultDiff { get; private set; } = new ShipStatusPair[0];
3637 public bool IsBattleResultError => BattleResultDiff.Length > 0;
3738 public ShipStatus[] BattleStartStatus { get; private set; } = new ShipStatus[0];
39+ public int DropShipId { private get; set; } = -1;
40+
41+ private class NumEquipsChecker
42+ {
43+ public int MaxId { private get; set; } = int.MaxValue;
44+
45+ public void Check(ShipStatus ship)
46+ {
47+ var spec = ship.Spec;
48+ if (spec.NumEquips != -1 || ship.Id <= MaxId)
49+ return;
50+ spec.NumEquips = ship.Slot.Count(item => item.Id != -1);
51+ }
52+ }
3853
3954 public class ShipStatusPair
4055 {
@@ -59,6 +74,7 @@ namespace KancolleSniffer
5974 public void InspectMaster(dynamic json)
6075 {
6176 _shipMaster.Inspect(json);
77+ ClearShipInfo();
6278 }
6379
6480 public void InspectShip(dynamic json)
@@ -78,21 +94,28 @@ namespace KancolleSniffer
7894 }
7995 else if (json.api_data()) // ship2
8096 {
81- // 一隻分のデータしか来ないことがあるので艦娘数を数えない
8297 InspectDeck(json.api_data_deck);
8398 InspectShipData(json.api_data);
8499 }
85100 else if (json.api_ship_data()) // ship3とship_deck
86101 {
87- // 一隻分のデータしか来ないことがあるので艦娘数を数えない
88102 InspectDeck(json.api_deck_data);
89103 InspectShipData(json.api_ship_data);
90104 VerifyBattleResult();
105+ // ship_deckでドロップ艦を反映する
106+ if (DropShipId != -1)
107+ {
108+ _itemInfo.NowShips++;
109+ var num = _shipMaster.GetSpec(DropShipId).NumEquips;
110+ if (num > 0)
111+ _itemInfo.NowEquips += num;
112+ }
91113 }
92114 else if (json.api_ship()) // getshipとpowerup
93115 {
94116 InspectShipData(new[] {json.api_ship});
95117 }
118+ DropShipId = -1;
96119 }
97120
98121 public void SaveBattleResult()
@@ -138,9 +161,10 @@ namespace KancolleSniffer
138161 {
139162 foreach (var entry in json)
140163 {
141- _shipInfo[(int)entry.api_id] = new ShipStatus
164+ var id = (int)entry.api_id;
165+ var ship = new ShipStatus
142166 {
143- Id = (int)entry.api_id,
167+ Id = id,
144168 Spec = _shipMaster.GetSpec((int)entry.api_ship_id),
145169 Level = (int)entry.api_lv,
146170 ExpToNext = (int)entry.api_exp[1],
@@ -150,7 +174,7 @@ namespace KancolleSniffer
150174 Fuel = (int)entry.api_fuel,
151175 Bull = (int)entry.api_bull,
152176 OnSlot = (int[])entry.api_onslot,
153- Slot = ((int[])entry.api_slot).Select(id => new ItemStatus(id)).ToArray(),
177+ Slot = ((int[])entry.api_slot).Select(item => new ItemStatus(item)).ToArray(),
154178 SlotEx = entry.api_slot_ex() ? new ItemStatus((int)entry.api_slot_ex) : new ItemStatus(0),
155179 NdockTime = (int)entry.api_ndock_time,
156180 NdockItem = (int[])entry.api_ndock_item,
@@ -162,7 +186,10 @@ namespace KancolleSniffer
162186 Lucky = (int)entry.api_lucky[0],
163187 Locked = entry.api_locked() && entry.api_locked == 1
164188 };
189+ _shipInfo[id] = ship;
190+ _numEquipsChecker.Check(ship);
165191 }
192+ _numEquipsChecker.MaxId = _shipInfo.Keys.Max();
166193 }
167194
168195 private void InspectBasic(dynamic json)
--- a/KancolleSniffer/ShipMaster.cs
+++ b/KancolleSniffer/ShipMaster.cs
@@ -31,7 +31,8 @@ namespace KancolleSniffer
3131 foreach (var entry in json.api_mst_stype)
3232 dict[entry.api_id] = entry.api_name;
3333 dict[8] = "巡洋戦艦";
34- AdditionalData?.LoadEnemySlot();
34+ AdditionalData.LoadEnemySlot();
35+ AdditionalData.LoadNumEquips();
3536 foreach (var entry in json.api_mst_ship)
3637 {
3738 var shipSpec = _shipSpecs[(int)entry.api_id] = new ShipSpec
@@ -53,7 +54,9 @@ namespace KancolleSniffer
5354 }
5455 shipSpec.GetMaxEq = entry.api_maxeq()
5556 ? (Func<int[]>)(() => entry.api_maxeq)
56- : () => AdditionalData?.EnemySlot(shipSpec.Id);
57+ : () => AdditionalData.EnemySlot(shipSpec.Id);
58+ shipSpec.GetNumEquips = () => AdditionalData.NumEquips(shipSpec.Id);
59+ shipSpec.SetNumEquips = num => AdditionalData.RecordNumEquips(shipSpec.Id, shipSpec.Name,num);
5760 }
5861 _shipSpecs[-1] = new ShipSpec();
5962 SetRemodelBaseAndStep();
@@ -117,6 +120,15 @@ namespace KancolleSniffer
117120 public int SlotNum { get; set; }
118121 public Func<int[]> GetMaxEq { get; set; }
119122 public int[] MaxEq => GetMaxEq?.Invoke();
123+ public Func<int> GetNumEquips { get; set; }
124+ public Action<int> SetNumEquips { get; set; }
125+
126+ public int NumEquips
127+ {
128+ get => GetNumEquips();
129+ set => SetNumEquips(value);
130+ }
131+
120132 public int ShipType { get; set; }
121133 public int ShipClass { get; set; }
122134 public string ShipTypeName { get; set; }
--- a/KancolleSniffer/Sniffer.cs
+++ b/KancolleSniffer/Sniffer.cs
@@ -250,7 +250,7 @@ namespace KancolleSniffer
250250 _shipInfo.InspectShip(data);
251251 _akashiTimer.CheckFleet();
252252 _battleInfo.BattleState = BattleState.None;
253- return Update.Ship | Update.Battle;
253+ return Update.Ship | Update.Battle | Update.Item;
254254 }
255255 if (url.EndsWith("api_get_member/ship3"))
256256 {
旧リポジトリブラウザで表示