OSDN Git Service

バージョン8.9の準備
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / AkashiTimer.cs
index ee1e787..0b75143 100644 (file)
@@ -1,24 +1,20 @@
 // Copyright (C) 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
 using System.Linq;\r
-using System.Web;\r
 \r
 namespace KancolleSniffer\r
 {\r
@@ -54,11 +50,6 @@ namespace KancolleSniffer
 \r
             public State State { get; set; }\r
 \r
-            public void Invalidate()\r
-            {\r
-                _target = new ShipStatus[0];\r
-            }\r
-\r
             public bool IsRepaired(ShipStatus[] target) => _target.Zip(target, (a, b) => a.NowHp < b.NowHp).Any(x => x);\r
 \r
             public bool DeckChanged(IEnumerable<int> deck) => !_deck.SequenceEqual(deck);\r
@@ -188,28 +179,39 @@ namespace KancolleSniffer
             var repair = _repairStatuses[fleet];\r
             var fs = _shipInfo.GetStatus(deck[0]);\r
             repair.State = State.Continue;\r
-            if (!fs.Name.StartsWith("明石"))\r
+            if (!fs.Spec.IsRepairShip)\r
             {\r
-                repair.Invalidate();\r
+                repair.UpdateTarget(new ShipStatus[0]);\r
                 repair.Deck = deck;\r
                 return;\r
             }\r
-            var cap = fs.Slot.Count(item => item.Spec.Name == "艦艇修理施設") + 2;\r
+            if (repair.DeckChanged(deck))\r
+            {\r
+                repair.State = State.Reset;\r
+                repair.Deck = deck;\r
+            }\r
+            var target = RepairTarget(deck);\r
+            if (repair.IsRepaired(target))\r
+                repair.State = State.Reset;\r
+            repair.UpdateTarget(target);\r
+        }\r
+\r
+        private ShipStatus[] RepairTarget(int[] deck)\r
+        {\r
+            var fs = _shipInfo.GetStatus(deck[0]);\r
+            if (!fs.Spec.IsRepairShip || _dockInfo.InNDock(fs.Id) || fs.DamageLevel >= ShipStatus.Damage.Half)\r
+                return new ShipStatus[0];\r
+            var cap = fs.Slot.Count(item => item.Spec.IsRepairFacility) + 2;\r
             /*\r
              * 泊地修理の条件を満たさない艦はMaxHp==NowHpのダミーを設定する。\r
              * - 入渠中の艦娘は終わったときに回復扱いされないようNowHp=MaxHpに\r
              * - 中破以上でNowHp=MaxHpにすると回復扱いされるのでNowHp=MaxHp=0に\r
             */\r
-            var target = (from id in deck.Take(cap)\r
+            return (from id in deck.Take(cap)\r
                 let s = _shipInfo.GetStatus(id)\r
                 let full = new ShipStatus {NowHp = s.MaxHp, MaxHp = s.MaxHp}\r
                 let zero = new ShipStatus()\r
                 select _dockInfo.InNDock(id) ? full : s.DamageLevel >= ShipStatus.Damage.Half ? zero : s).ToArray();\r
-            repair.State = State.Continue;\r
-            if (repair.DeckChanged(deck) || repair.IsRepaired(target))\r
-                repair.State = State.Reset;\r
-            repair.UpdateTarget(target);\r
-            repair.Deck = deck;\r
         }\r
 \r
         public RepairSpan[] GetTimers(int fleet)\r
@@ -221,16 +223,19 @@ namespace KancolleSniffer
             {\r
                 if (_start == DateTime.MinValue)\r
                     return TimeSpan.MinValue;\r
-                var r = _start + TimeSpan.FromMinutes(20) - DateTime.Now;\r
+                var r = TimeSpan.FromMinutes(20) - TimeSpan.FromSeconds((int)(DateTime.Now - _start).TotalSeconds);\r
                 return r >= TimeSpan.Zero ? r : TimeSpan.Zero;\r
             }\r
         }\r
 \r
-\r
         public bool CheckReparing(int fleet) => GetTimers(fleet).Any(r => r.Span != TimeSpan.MinValue);\r
 \r
         public bool CheckReparing() => Enumerable.Range(0, ShipInfo.FleetCount).Any(CheckReparing);\r
 \r
+        public bool CheckPresetReparing()\r
+            => _shipInfo.PresetDeck.Where(deck => deck != null)\r
+                .Any(deck => RepairTarget(deck).Any(s => s.NowHp < s.MaxHp));\r
+\r
         public Notice[] GetNotice()\r
         {\r
             var now = DateTime.Now;\r