OSDN Git Service

出撃から戻ったときに装備数が更新されないのを直す
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Sniffer.cs
index f4b2a95..2632c7e 100644 (file)
@@ -1,19 +1,16 @@
 // Copyright (C) 2013, 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
 // \r
-// This program is part of KancolleSniffer.\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
 //\r
-// KancolleSniffer is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU General Public License as published by\r
-// the Free Software Foundation, either version 3 of the License, or\r
-// (at your option) any later version.\r
+//    http://www.apache.org/licenses/LICENSE-2.0\r
 //\r
-// This program is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-// GNU General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License\r
-// along with this program; if not, see <http://www.gnu.org/licenses/>.\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
 \r
 using System;\r
 using System.Collections.Generic;\r
@@ -89,8 +86,10 @@ namespace KancolleSniffer
 \r
         public Update Sniff(string url, string request, dynamic json)\r
         {\r
-            if (!json.api_result() || (int)json.api_result != 1)\r
+            if (!json.api_result())\r
                 return Update.Error;\r
+            if ((int)json.api_result != 1)\r
+                return Update.None;\r
             var data = json.api_data() ? json.api_data : new object();\r
 \r
             if (url.EndsWith("api_start2"))\r
@@ -127,6 +126,7 @@ namespace KancolleSniffer
             _logger.InspectBasic(data.api_basic);\r
             _logger.InspectMaterial(data.api_material);\r
             _shipInfo.InspectShip(data);\r
+            _shipInfo.ClearBadlyDamagedShips();\r
             _conditionTimer.CalcRegenTime();\r
             _missionInfo.InspectDeck(data.api_deck_port);\r
             _dockInfo.InspectNDock(data.api_ndock);\r
@@ -136,7 +136,6 @@ namespace KancolleSniffer
                 _questInfo.QuestCount = (int)data.api_parallel_quest_count;\r
             _battleInfo.CleanupResult();\r
             _battleInfo.InBattle = false;\r
-            _battleInfo.HasDamagedShip = false;\r
             _shipInfo.ClearEscapedShips();\r
             _miscTextInfo.ClearIfNeeded();\r
             SaveState();\r
@@ -147,6 +146,12 @@ namespace KancolleSniffer
         {\r
             var data = json.api_data() ? json.api_data : new object();\r
 \r
+            if (url.EndsWith("api_get_member/require_info"))\r
+            {\r
+                _itemInfo.InspectSlotItem(data.api_slot_item, true);\r
+                _dockInfo.InspectKDock(data.api_kdock);\r
+                return Update.Timer;\r
+            }\r
             if (url.EndsWith("api_get_member/basic"))\r
             {\r
                 _itemInfo.InspectBasic(data);\r
@@ -156,7 +161,7 @@ namespace KancolleSniffer
             if (url.EndsWith("api_get_member/slot_item"))\r
             {\r
                 _itemInfo.InspectSlotItem(data, true);\r
-                return Update.None;\r
+                return Update.Item;\r
             }\r
             if (url.EndsWith("api_get_member/kdock"))\r
             {\r
@@ -173,7 +178,7 @@ namespace KancolleSniffer
             }\r
             if (url.EndsWith("api_get_member/questlist"))\r
             {\r
-                _questInfo.Inspect(data);\r
+                _questInfo.InspectQuestList(data);\r
                 return Update.QuestList;\r
             }\r
             if (url.EndsWith("api_get_member/deck"))\r
@@ -285,7 +290,7 @@ namespace KancolleSniffer
         {\r
             if (IsNormalBattleAPI(url))\r
             {\r
-                _battleInfo.InspectBattle(data);\r
+                _battleInfo.InspectBattle(data, url);\r
                 _logger.InspectBattle(data);\r
                 return Update.Ship | Update.Battle;\r
             }\r
@@ -293,11 +298,11 @@ namespace KancolleSniffer
             {\r
                 if (url.EndsWith("/battle"))\r
                 {\r
-                    _shipInfo.StartSortie(request); // 演習を出撃中とみなす\r
+                    _shipInfo.InspectMapStart(request); // 演習を出撃中とみなす\r
                     _conditionTimer.InvalidateCond();\r
                     _miscTextInfo.ClearFlag = true;\r
                 }\r
-                _battleInfo.InspectBattle(data);\r
+                _battleInfo.InspectBattle(data, url);\r
                 return Update.Ship | Update.Battle | Update.Timer;\r
             }\r
             if (url.EndsWith("api_req_sortie/battleresult"))\r
@@ -314,7 +319,7 @@ namespace KancolleSniffer
             }\r
             if (IsCombinedBattleAPI(url))\r
             {\r
-                _battleInfo.InspectCombinedBattle(data, url.EndsWith("battle_water"));\r
+                _battleInfo.InspectCombinedBattle(data, url);\r
                 _logger.InspectBattle(data);\r
                 return Update.Ship | Update.Battle;\r
             }\r
@@ -336,6 +341,7 @@ namespace KancolleSniffer
         {\r
             return url.EndsWith("api_req_sortie/battle") ||\r
                    url.EndsWith("api_req_sortie/airbattle") ||\r
+                   url.EndsWith("api_req_sortie/ld_airbattle") ||\r
                    url.EndsWith("api_req_battle_midnight/battle") ||\r
                    url.EndsWith("api_req_battle_midnight/sp_midnight");\r
         }\r
@@ -344,6 +350,7 @@ namespace KancolleSniffer
         {\r
             return url.EndsWith("api_req_combined_battle/battle") ||\r
                    url.EndsWith("api_req_combined_battle/airbattle") ||\r
+                   url.EndsWith("api_req_combined_battle/ld_airbattle") ||\r
                    url.EndsWith("api_req_combined_battle/battle_water") ||\r
                    url.EndsWith("api_req_combined_battle/midnight_battle") ||\r
                    url.EndsWith("api_req_combined_battle/sp_midnight");\r
@@ -368,6 +375,11 @@ namespace KancolleSniffer
                 _shipInfo.InspectPresetRegister(data);\r
                 return Update.None;\r
             }\r
+            if (url.EndsWith("api_req_hensei/preset_delete"))\r
+            {\r
+                _shipInfo.InspectPresetDelete(request);\r
+                return Update.Timer;\r
+            }\r
             if (url.EndsWith("api_req_hensei/combined"))\r
             {\r
                 _shipInfo.InspectCombined(request);\r
@@ -391,6 +403,11 @@ namespace KancolleSniffer
                 _shipInfo.InspectSlotExchange(request, data);\r
                 return Update.Ship;\r
             }\r
+            if (url.EndsWith("api_req_kaisou/slot_deprive"))\r
+            {\r
+                _shipInfo.InspectSlotDeprive(data);\r
+                return Update.Ship;\r
+            }\r
             if (url.EndsWith("api_req_nyukyo/start"))\r
             {\r
                 _dockInfo.InspectNyukyo(request);\r
@@ -406,15 +423,16 @@ namespace KancolleSniffer
             }\r
             if (url.EndsWith("api_req_map/start"))\r
             {\r
-                _shipInfo.StartSortie(request);\r
+                _shipInfo.InspectMapStart(request); // 出撃中判定が必要なので_conditionTimerより前\r
                 _conditionTimer.InvalidateCond();\r
                 _exMapInfo.InspectMapStart(data);\r
                 _logger.InspectMapStart(data);\r
                 _miscTextInfo.ClearFlag = true;\r
-                return Update.Timer;\r
+                return Update.Timer | Update.Ship;\r
             }\r
             if (url.EndsWith("api_req_map/next"))\r
             {\r
+                _battleInfo.InspectMapNext(request);\r
                 _exMapInfo.InspectMapNext(data);\r
                 _logger.InspectMapNext(data);\r
                 return Update.None;\r
@@ -425,6 +443,26 @@ namespace KancolleSniffer
                 _logger.InspectMissionResult(data);\r
                 return Update.Item;\r
             }\r
+            if (url.EndsWith("api_req_quest/stop"))\r
+            {\r
+                _questInfo.InspectStop(request);\r
+                return Update.QuestList;\r
+            }\r
+            if (url.EndsWith("api_req_quest/clearitemget"))\r
+            {\r
+                _questInfo.InspectClearItemGet(request);\r
+                return Update.QuestList;\r
+            }\r
+            if (url.EndsWith("api_req_air_corps/supply"))\r
+            {\r
+                _materialInfo.InspectAirCorpsSupply(data);\r
+                return Update.Item;\r
+            }\r
+            if (url.EndsWith("api_req_air_corps/set_plane"))\r
+            {\r
+                _materialInfo.InspectAirCorpsSetPlane(data);\r
+                return Update.Item;\r
+            }\r
             return Update.None;\r
         }\r
 \r
@@ -452,7 +490,9 @@ namespace KancolleSniffer
 \r
         public ChargeStatus[] ChargeStatuses => _shipInfo.ChargeStatuses;\r
 \r
-        public int GetFighterPower(int fleet, bool withBonus) => _shipInfo.GetFighterPower(fleet, withBonus);\r
+        public int[] GetFighterPower(int fleet) => _shipInfo.GetFighterPower(fleet);\r
+\r
+        public double GetContactTriggerRate(int fleet) => _shipInfo.GetContactTriggerRate(fleet);\r
 \r
         public double GetFleetLineOfSights(int fleet) => _shipInfo.GetLineOfSights(fleet);\r
 \r
@@ -460,6 +500,8 @@ namespace KancolleSniffer
 \r
         public ShipStatus[] ShipList => _shipInfo.ShipList;\r
 \r
+        public string[] BadlyDamagedShips => _shipInfo.BadlyDamagedShips;\r
+\r
         public ItemStatus[] ItemList => _itemInfo.GetItemListWithOwner(ShipList);\r
 \r
         public AkashiTimer AkashiTimer => _akashiTimer;\r
@@ -552,5 +594,10 @@ namespace KancolleSniffer
             if (prev > _spare && _spare >= Rest)\r
                 NeedRing = true;\r
         }\r
+\r
+        public string ToString(bool finish = false)\r
+            => EndTime == DateTime.MinValue\r
+                ? ""\r
+                : finish ? EndTime.ToString(@"dd\ HH\:mm") : $@"{(int)Rest.TotalHours:d2}:{Rest:mm\:ss}";\r
     }\r
 }
\ No newline at end of file