From 1af407a037cad2d55c69e812b79fcf1b95ebea57 Mon Sep 17 00:00:00 2001 From: lasedark Date: Thu, 23 Jul 2020 12:23:38 +0800 Subject: [PATCH] further work on repairship counter --- .../Models/RepairShipRepairingDuration.cs | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/source/Grabacr07.KanColleWrapper/Models/RepairShipRepairingDuration.cs b/source/Grabacr07.KanColleWrapper/Models/RepairShipRepairingDuration.cs index 5a74e4bce..ff91d1a40 100644 --- a/source/Grabacr07.KanColleWrapper/Models/RepairShipRepairingDuration.cs +++ b/source/Grabacr07.KanColleWrapper/Models/RepairShipRepairingDuration.cs @@ -42,19 +42,31 @@ private set internal void Update(Ship[] s) { - var isOnlyEquipChange = false; - if (this.ships != null) isOnlyEquipChange = Enumerable.SequenceEqual(s.Select(x => x.Id), this.ships.Select(y => y.Id)); + var isOnlyEquipChanged = false; + if (this.ships != null) isOnlyEquipChanged = Enumerable.SequenceEqual(s.Select(x => x.Id), this.ships.Select(y => y.Id)); this.ships = s; - if (isOnlyEquipChange) return; - - var n = Math.Min(2 + s[0].EquippedItems.Count(x => x.Item.Info.EquipType.Id == 31), s.Length); - var isRepairing = s.Take(n).Any(x => + if (isOnlyEquipChanged) { - var percentage = x.HP.Maximum == 0 ? 0.0 : x.HP.Current / (double)x.HP.Maximum; - return (0.5 < percentage) && (percentage < 1.0); - }); + if (this.StartTime.HasValue) + { + if (DateTimeOffset.Now.Subtract(this.StartTime.Value) >= TimeSpan.FromMinutes(20)) + { + this.StartTime = DateTimeOffset.Now; + } + } + return; + } + + var isRepairing = s.Take(Math.Min(2 + s[0].EquippedItems.Count(x => x.Item.Info.EquipType.Id == 31), + s.Length)) + .Any(x => + { + var percentage = x.HP.Maximum == 0 ? 0.0 : x.HP.Current / (double)x.HP.Maximum; + return (0.5 < percentage) && (percentage < 1.0); + }); + var isEnabled = (s[0].HP.Current / (double)s[0].HP.Maximum) > 0.5; - if (isRepairing) + if (isRepairing && isEnabled) { this.StartTime = DateTimeOffset.Now; }