OSDN Git Service

その他情報に出撃中の獲得資材を表示する
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Thu, 11 Jan 2018 10:37:11 +0000 (19:37 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 11 Mar 2018 14:51:02 +0000 (23:51 +0900)
KancolleSniffer.Test/SnifferTest.cs
KancolleSniffer.Test/logs
KancolleSniffer/MiscTextInfo.cs
KancolleSniffer/Sniffer.cs

index a8383a3..8d80fa4 100644 (file)
@@ -25,6 +25,13 @@ namespace KancolleSniffer.Test
     [TestClass]\r
     public class SnifferTest\r
     {\r
+        [TestInitialize]\r
+        public void Intialize()\r
+        {\r
+            ExpressionToCodeConfiguration.GlobalAssertionConfiguration = ExpressionToCodeConfiguration\r
+                .GlobalAssertionConfiguration.WithPrintedListLengthLimit(200).WithMaximumValueLength(1000);\r
+        }\r
+\r
         public static StreamReader OpenLogFile(string name)\r
         {\r
             var dir = Path.GetDirectoryName(Path.GetDirectoryName(Environment.CurrentDirectory));\r
@@ -693,5 +700,32 @@ namespace KancolleSniffer.Test
             SniffLogFile(sniffer, "ship2_001");\r
             PAssert.That(() => sniffer.Item.NowShips == 243);\r
         }\r
+\r
+        /// <summary>\r
+        /// 出撃中にアイテムを取得する\r
+        /// </summary>\r
+        [TestMethod]\r
+        public void ItemGetInSortie()\r
+        {\r
+            var sniffer = new Sniffer();\r
+            SniffLogFile(sniffer, "itemget_001");\r
+            PAssert.That(() => sniffer.MiscText ==\r
+                               "[獲得アイテム]\r\n" +\r
+                               "燃料: 1115\r\n" +\r
+                               "弾薬: 25\r\n" +\r
+                               "鋼材: 70\r\n" +\r
+                               "家具箱(大): 1\r\n" +\r
+                               "給糧艦「間宮」: 1\r\n" +\r
+                               "勲章: 1\r\n" +\r
+                               "給糧艦「伊良湖」: 3\r\n" +\r
+                               "プレゼント箱: 1\r\n" +\r
+                               "補強増設: 2\r\n" +\r
+                               "戦闘詳報: 1\r\n" +\r
+                               "瑞雲(六三一空): 1\r\n" +\r
+                               "夜間作戦航空要員: 1\r\n" +\r
+                               "130mm B-13連装砲: 1\r\n" +\r
+                               "潜水空母な桐箪笥: 1\r\n" +\r
+                               "Gambier Bay: 1");\r
+        }\r
     }\r
 }
\ No newline at end of file
index 0ebb22b..72d069b 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 0ebb22b0cd295619a123246592c28a613a63fc5f
+Subproject commit 72d069b78e32039f40e69fdaeb008a58612d9971
index daf04a4..810d78b 100644 (file)
 // limitations under the License.\r
 \r
 using System.Collections.Generic;\r
+using System.Linq;\r
 using static System.Math;\r
 \r
 namespace KancolleSniffer\r
 {\r
     public class MiscTextInfo\r
     {\r
-        private const string GuideText = "[海域ゲージ情報]\r\n 海域選択画面に進むと表示します。\r\n[演習情報]\r\n 演習相手を選ぶと表示します。";\r
+        private readonly ShipInfo _shipInfo;\r
+        private readonly ItemInfo _itemInfo;\r
+\r
+        private const string GuideText =\r
+            "[海域ゲージ情報]\r\n 海域選択画面に進むと表示します。\r\n[演習情報]\r\n 演習相手を選ぶと表示します。\r\n[獲得アイテム]\r\n 帰投したときに表示します。";\r
+\r
         public string Text { get; private set; } = GuideText;\r
-        public bool ClearFlag { private get; set; }\r
+        public bool SortieStarted { private get; set; }\r
 \r
-        public void ClearIfNeeded()\r
+        public MiscTextInfo(ShipInfo shipInfo, ItemInfo itemInfo)\r
         {\r
-            if (!ClearFlag)\r
-                return;\r
-            Text = GuideText;\r
-            ClearFlag = false;\r
+            _shipInfo = shipInfo;\r
+            _itemInfo = itemInfo;\r
+        }\r
+\r
+        public void Port()\r
+        {\r
+            if (SortieStarted)\r
+            {\r
+                SortieStarted = false;\r
+                var text = GenerateItemGetText();\r
+                Text = text == "" ? GuideText : "[獲得アイテム]\r\n" + text;\r
+            }\r
         }\r
 \r
         private readonly Dictionary<int, int> _required = new Dictionary<int, int>\r
@@ -95,9 +109,109 @@ namespace KancolleSniffer
             var ships = json.api_deck.api_ships;\r
             var s1 = (int)ships[0].api_id != -1 ? (int)ships[0].api_level : 1;\r
             var s2 = (int)ships[1].api_id != -1 ? (int)ships[1].api_level : 1;\r
-            var raw = _expTable[Min(s1, _expTable.Length) - 1] / 100.0 + _expTable[Min(s2, _expTable.Length) - 1] / 300.0;\r
+            var raw = _expTable[Min(s1, _expTable.Length) - 1] / 100.0 +\r
+                      _expTable[Min(s2, _expTable.Length) - 1] / 300.0;\r
             var exp = raw >= 500 ? 500 + (int)Sqrt(raw - 500) : (int)raw;\r
             Text += $"獲得経験値 : {exp}\r\nS勝利 : {(int)(exp * 1.2)}";\r
         }\r
+\r
+        public void InspectMapNext(dynamic json)\r
+        {\r
+            if (json.api_itemget())\r
+            {\r
+                var items = json.api_itemget.IsArray ? json.api_itemget : new[] {json.api_itemget};\r
+                foreach (var item in items)\r
+                    AddItemCount((int)item.api_usemst, (int)item.api_id, (int)item.api_getcount);\r
+            }\r
+            if (json.api_itemget_eo_result())\r
+            {\r
+                var eo = json.api_itemget_eo_result;\r
+                AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);\r
+            }\r
+            if (json.api_itemget_eo_comment())\r
+            {\r
+                var eo = json.api_itemget_eo_comment;\r
+                AddItemCount((int)eo.api_usemst, (int)eo.api_id, (int)eo.api_getcount);\r
+            }\r
+            if (json.api_eventmap() && json.api_eventmap.api_itemget())\r
+            {\r
+                foreach (var item in json.api_eventmap.api_itemget)\r
+                {\r
+                    var type = (int)item.api_type;\r
+                    type = type == 1 ? 5 :\r
+                        type == 5 ? 6 : type;\r
+                    AddItemCount(type, (int)item.api_id, (int)item.api_value);\r
+                }\r
+            }\r
+        }\r
+\r
+        public void InspectMapStart(dynamic json)\r
+        {\r
+            InspectMapNext(json);\r
+        }\r
+\r
+        public void InspectBattleResult(dynamic json)\r
+        {\r
+            if (json.api_get_eventitem())\r
+            {\r
+                foreach (var item in json.api_get_eventitem)\r
+                {\r
+                    var type = (int)item.api_type;\r
+                    type = type == 1 ? 5 :\r
+                        type == 5 ? 6 : type;\r
+                    var id = (int)item.api_id;\r
+                    AddItemCount(type, id, (int)item.api_value);\r
+                }\r
+            }\r
+        }\r
+\r
+        private readonly Dictionary<int, SortedDictionary<int, int>> _items =\r
+            new Dictionary<int, SortedDictionary<int, int>>();\r
+\r
+        private void AddItemCount(int type, int id, int count)\r
+        {\r
+            if (!_items.ContainsKey(type))\r
+                _items[type] = new SortedDictionary<int, int>();\r
+            var dict = _items[type];\r
+            if (!dict.ContainsKey(id))\r
+                dict[id] = 0;\r
+            dict[id] += count;\r
+        }\r
+\r
+        private readonly Dictionary<int, string> _furniture = new Dictionary<int, string>();\r
+\r
+        public void InspectMaster(dynamic json)\r
+        {\r
+            if (!json.api_mst_furniture())\r
+                return;\r
+            foreach (var entry in json.api_mst_furniture)\r
+                _furniture[(int)entry.api_id] = (string)entry.api_title;\r
+        }\r
+\r
+        private string GetName(int type, int id)\r
+        {\r
+            switch (type)\r
+            {\r
+                case 2:\r
+                    return _shipInfo.GetSpec(id).Name;\r
+                case 3:\r
+                    return _itemInfo.GetSpecByItemId(id).Name;\r
+                case 4:\r
+                    return new[] {"燃料", "弾薬", "鋼材", "ボーキサイト", "高速建造材", "高速修復材", "開発資材", "改修資材"}[id - 1];\r
+                case 5:\r
+                    return _itemInfo.GetUseItemName(id);\r
+                case 6:\r
+                    return _furniture[id];\r
+                default:\r
+                    return "";\r
+            }\r
+        }\r
+\r
+        private string GenerateItemGetText()\r
+        {\r
+            return string.Join("\r\n",\r
+                       new[] {4, 5, 3, 6, 2}.Where(_items.ContainsKey).SelectMany(type =>\r
+                           _items[type].Select(pair => GetName(type, pair.Key) + ": " + pair.Value)));\r
+        }\r
     }\r
 }
\ No newline at end of file
index bce50f6..16df547 100644 (file)
@@ -33,7 +33,7 @@ namespace KancolleSniffer
         private readonly BattleInfo _battleInfo;\r
         private readonly Logger _logger;\r
         private readonly ExMapInfo _exMapInfo = new ExMapInfo();\r
-        private readonly MiscTextInfo _miscTextInfo = new MiscTextInfo();\r
+        private readonly MiscTextInfo _miscTextInfo;\r
         private readonly BaseAirCoprs _baseAirCoprs;\r
         private readonly PresetDeck _presetDeck = new PresetDeck();\r
         private readonly Status _status = new Status();\r
@@ -77,6 +77,7 @@ namespace KancolleSniffer
             _logger = new Logger(_shipInfo, _itemInfo, _battleInfo);\r
             _questInfo = new QuestInfo(_itemInfo, _battleInfo);\r
             _baseAirCoprs = new BaseAirCoprs(_itemInfo);\r
+            _miscTextInfo = new MiscTextInfo(_shipInfo, _itemInfo);\r
             _haveState = new List<IHaveState> {_achievement, _materialInfo, _conditionTimer, _exMapInfo, _questInfo};\r
         }\r
 \r
@@ -131,6 +132,7 @@ namespace KancolleSniffer
             _missionInfo.InspectMaster(data.api_mst_mission);\r
             _itemInfo.InspectMaster(data);\r
             _exMapInfo.ResetIfNeeded();\r
+            _miscTextInfo.InspectMaster(data);\r
             _start = true;\r
             return Update.Start;\r
         }\r
@@ -158,7 +160,7 @@ namespace KancolleSniffer
             _battleInfo.CleanupResult();\r
             _battleInfo.BattleState = BattleState.None;\r
             _shipInfo.ClearEscapedShips();\r
-            _miscTextInfo.ClearIfNeeded();\r
+            _miscTextInfo.Port();\r
             SaveState();\r
             RepeatingTimerController?.Resume();\r
             foreach (var s in new[] {"遠征終了", "入渠終了", "疲労回復", "泊地修理"})\r
@@ -339,7 +341,6 @@ namespace KancolleSniffer
                 {\r
                     _shipInfo.InspectMapStart(request); // 演習を出撃中とみなす\r
                     _conditionTimer.InvalidateCond();\r
-                    _miscTextInfo.ClearFlag = true;\r
                     RepeatingTimerController?.Suspend();\r
                 }\r
                 _battleInfo.InspectBattle(url, request, data);\r
@@ -351,6 +352,7 @@ namespace KancolleSniffer
                 _exMapInfo.InspectBattleResult(data);\r
                 _logger.InspectBattleResult(data);\r
                 _questInfo.InspectBattleResult(data);\r
+                _miscTextInfo.InspectBattleResult(data);\r
                 return Update.Ship | Update.QuestList;\r
             }\r
             if (url.EndsWith("api_req_practice/battle_result"))\r
@@ -470,7 +472,7 @@ namespace KancolleSniffer
                 _exMapInfo.InspectMapStart(data);\r
                 _battleInfo.InspectMapStart(data);\r
                 _logger.InspectMapStart(data);\r
-                _miscTextInfo.ClearFlag = true;\r
+                _miscTextInfo.SortieStarted = true;\r
                 _questInfo.InspectMapStart(data);\r
                 RepeatingTimerController?.Suspend();\r
                 return Update.Timer | Update.Ship;\r
@@ -481,6 +483,7 @@ namespace KancolleSniffer
                 _battleInfo.InspectMapNext(data);\r
                 _logger.InspectMapNext(data);\r
                 _questInfo.InspectMapNext(data);\r
+                _miscTextInfo.InspectMapNext(data);\r
                 return Update.None;\r
             }\r
             if (url.EndsWith("api_req_mission/start"))\r