diff --git a/EventMapHpViewer/EventMapHpViewer.csproj b/EventMapHpViewer/EventMapHpViewer.csproj index f53fcc5..6c3b29d 100644 --- a/EventMapHpViewer/EventMapHpViewer.csproj +++ b/EventMapHpViewer/EventMapHpViewer.csproj @@ -147,6 +147,7 @@ + ToolView.xaml diff --git a/EventMapHpViewer/MapHpViewer.cs b/EventMapHpViewer/MapHpViewer.cs index a20fbec..a1fdc74 100644 --- a/EventMapHpViewer/MapHpViewer.cs +++ b/EventMapHpViewer/MapHpViewer.cs @@ -15,7 +15,7 @@ namespace EventMapHpViewer public class MapHpViewer : IPlugin, ITool { internal const string title = "MapHPViewer"; - internal const string version = "3.1.2"; + internal const string version = "3.2.0"; private ToolViewModel vm; public void Initialize() diff --git a/EventMapHpViewer/Models/MapData.cs b/EventMapHpViewer/Models/MapData.cs index ea47897..8c1a6ae 100644 --- a/EventMapHpViewer/Models/MapData.cs +++ b/EventMapHpViewer/Models/MapData.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -41,61 +41,63 @@ public int Current { get { - if (this.IsExBoss == 1) return this.Master.RequiredDefeatCount - this.DefeatCount; //ƒQ[ƒW—L‚è’ÊíŠCˆæ - return this.Eventmap?.NowMapHp /*ƒCƒxƒ“ƒgŠCˆæ*/?? 1 /*ƒQ[ƒW–³‚µ’ÊíŠCˆæ*/; + if (this.IsExBoss == 1) return this.Master.RequiredDefeatCount - this.DefeatCount; //ゲージ有り通常海域 + return this.Eventmap?.NowMapHp /*イベント海域*/?? 1 /*ゲージ無ã—通常海域*/; } } - private int[] remoteBossHpCache; + private Raw.map_exboss[] remoteBossDataCache; /// - /// Žc‰ñ”B—A‘—‚ÌꇂÍAŸ—˜‚ÌŽc‰ñ”B + /// 残回数。輸é€ã®å ´åˆã¯Aå‹åˆ©ã®æ®‹å›žæ•°ã€‚ /// - public async Task GetRemainingCount(bool useCache = false) + public async Task GetRemainingCount(bool useCache = false) { - if (this.IsCleared == 1) return 0; + if (this.IsCleared == 1) return RemainingCount.Zero; - if (this.IsExBoss == 1) return this.Current; //ƒQ[ƒW—L‚è’ÊíŠCˆæ + if (this.IsExBoss == 1) return new RemainingCount(this.Current); //ゲージ有り通常海域 - if (this.Eventmap == null) return 1; //ƒQ[ƒW–³‚µ’ÊíŠCˆæ + if (this.Eventmap == null) return new RemainingCount(1); //ゲージ無ã—通常海域 if (this.Eventmap.GaugeType == GaugeType.Transport) { var capacityA = KanColleClient.Current.Homeport.Organization.TransportationCapacity(); - if (capacityA == 0) return int.MaxValue; //ƒQ[ƒWŒ¸‚ç‚È‚¢ - return (int)Math.Ceiling((double)this.Current / capacityA); + if (capacityA == 0) return RemainingCount.MaxValue; //ゲージ減らãªã„ + return new RemainingCount((int)Math.Ceiling((double)this.Current / capacityA)); } - if (this.Eventmap.SelectedRank == 0) return -1; //“ïˆÕ“x–¢‘I‘ð + if (this.Eventmap.SelectedRank == 0) return null; //難易度未é¸æŠž if (!useCache) - this.remoteBossHpCache = await GetEventBossHp(this.Id, this.Eventmap.SelectedRank); + this.remoteBossDataCache = await GetEventBossHp(this.Id, this.Eventmap.SelectedRank); + + if (this.remoteBossDataCache != null && this.remoteBossDataCache.Any()) + return this.CalculateRemainingCount(this.remoteBossDataCache); //イベント海域(リモートデータ) - var remoteBossHp = this.remoteBossHpCache; - if (remoteBossHp != null && remoteBossHp.Any()) - return this.CalculateRemainingCount(remoteBossHp); //ƒCƒxƒ“ƒgŠCˆæ(ƒŠƒ‚[ƒgƒf[ƒ^) + return null; //未対応 + } - try - { - // ƒŠƒ‚[ƒgƒf[ƒ^‚ª‚È‚¢ê‡Aƒ[ƒJƒ‹ƒf[ƒ^‚ðŽg‚¤ - return this.CalculateRemainingCount(eventBossHpDictionary[this.Eventmap.SelectedRank][this.Id]); //ƒCƒxƒ“ƒgŠCˆæ - } - catch (KeyNotFoundException) - { - return -1; //–¢‘Ήž - } + private RemainingCount CalculateRemainingCount(Raw.map_exboss[] data) + { + return new RemainingCount( + CalculateRemainingCount( + data.Where(x => !x.isLast).Min(x => x.ship.maxhp), + data.Where(x => x.isLast).Min(x => x.ship.maxhp) + ), + CalculateRemainingCount( + data.Where(x => !x.isLast).Max(x => x.ship.maxhp), + data.Where(x => x.isLast).Max(x => x.ship.maxhp) + )); } - private int CalculateRemainingCount(int[] bossHPs) + private int CalculateRemainingCount(int normalBossHp, int lastBossHp) { - var lastBossHp = bossHPs.Last(); - var normalBossHp = bossHPs.First(); - if (this.Current <= lastBossHp) return 1; //ÅŒã‚Ì1‰ñ + if (this.Current <= lastBossHp) return 1; //最後ã®1回 return (int)Math.Ceiling((double)(this.Current - lastBossHp) / normalBossHp) + 1; } /// - /// —A‘—ƒQ[ƒW‚ÌSŸ—˜Žž‚ÌŽc‰ñ” + /// 輸é€ã‚²ãƒ¼ã‚¸ã®Så‹åˆ©æ™‚ã®æ®‹å›žæ•° /// public int RemainingCountTransportS { @@ -103,30 +105,30 @@ public int RemainingCountTransportS { if (this.Eventmap?.GaugeType != GaugeType.Transport) return -1; var capacity = KanColleClient.Current.Homeport.Organization.TransportationCapacity(true); - if (capacity == 0) return int.MaxValue; //ƒQ[ƒWŒ¸‚ç‚È‚¢ + if (capacity == 0) return int.MaxValue; //ゲージ減らãªã„ return (int)Math.Ceiling((double)this.Current / capacity); } } /// - /// ŠÍ‚±‚êípƒf[ƒ^EƒŠƒ“ƒN‚©‚çƒ{ƒXî•ñ‚ðŽæ“¾‚·‚éB - /// Žæ“¾‚Å‚«‚È‚©‚Á‚½ê‡‚Í null ‚ð•Ô‚·B + /// 艦ã“れ戦術データ・リンクã‹ã‚‰ãƒœã‚¹æƒ…報をå–å¾—ã™ã‚‹ã€‚ + /// å–å¾—ã§ããªã‹ã£ãŸå ´åˆã¯ null ã‚’è¿”ã™ã€‚ /// /// /// /// - private static async Task GetEventBossHp(int mapId, int rank) + private static async Task GetEventBossHp(int mapId, int rank) { using (var client = new HttpClient(GetProxyConfiguredHandler())) { client.DefaultRequestHeaders .TryAddWithoutValidation("User-Agent", $"{MapHpViewer.title}/{MapHpViewer.version}"); try { - // rank ‚ÌŒã‚ë‚Ì"1"‚̓T[ƒo[ãŽè“®ƒƒ“ƒeƒf[ƒ^‚ð‰Á–¡‚·‚é‚©‚Ç‚¤‚©‚̃tƒ‰ƒO - var response = await client.GetAsync($"https://kctadil.azurewebsites.net/map/exboss/{mapId}/{rank}/1"); + // rank ã®å¾Œã‚ã®"1"ã¯ã‚µãƒ¼ãƒãƒ¼ä¸Šæ‰‹å‹•ãƒ¡ãƒ³ãƒ†ãƒ‡ãƒ¼ã‚¿ã‚’加味ã™ã‚‹ã‹ã©ã†ã‹ã®ãƒ•ãƒ©ã‚° + var response = await client.GetAsync($"https://kctadil.azurewebsites.net/map/maphp/v3.2/{mapId}/{rank}"); if (!response.IsSuccessStatusCode) { - // 200 ‚¶‚á‚È‚©‚Á‚½ + // 200 ã˜ã‚ƒãªã‹ã£ãŸ return null; } @@ -136,24 +138,21 @@ private static async Task GetEventBossHp(int mapId, int rank) || !parsed.Any(x => x.isLast) || !parsed.Any(x => !x.isLast)) { - // ƒf[ƒ^‚ª‘µ‚Á‚Ä‚¢‚È‚¢ + // データãŒæƒã£ã¦ã„ãªã„ return null; } - return parsed - .OrderBy(x => x.isLast) // ÅI•Ò¬‚ªŒã‚ë‚É—ˆ‚é‚悤‚É‚·‚é - .Select(x => x.ship.maxhp) - .ToArray(); + return parsed; } catch (HttpRequestException) { - // HTTP ƒŠƒNƒGƒXƒg‚ÉŽ¸”s‚µ‚½ + // HTTP リクエストã«å¤±æ•—ã—㟠return null; } } } /// - /// –{‘̂̃vƒƒLƒVÝ’è‚ð‘g‚Ýž‚ñ‚¾HttpClientHandler‚ð•Ô‚·B + /// 本体ã®ãƒ—ロキシ設定を組ã¿è¾¼ã‚“ã HttpClientHandlerã‚’è¿”ã™ã€‚ /// /// private static HttpClientHandler GetProxyConfiguredHandler() @@ -187,43 +186,5 @@ private static HttpClientHandler GetProxyConfiguredHandler() return new HttpClientHandler(); } } - - /// - /// Žè“®ƒƒ“ƒeƒf[ƒ^—pB - /// ‚¢‚¸‚ê휂³‚ê‚錩ž‚ÝB - /// - private static readonly IReadOnlyDictionary> eventBossHpDictionary - = new Dictionary> - { - { //“ïˆÕ“x–¢‘I‘ð - 0, new Dictionary - { - } - }, - { //•¸ - 1, new Dictionary - { - { 331, new[] { 110 } }, - { 332, new[] { 600, 380 } }, - { 333, new[] { 350, 370 } }, - } - }, - { //‰³ - 2, new Dictionary - { - { 331, new[] { 110, 130 } }, - { 332, new[] { 600, 430 } }, - { 333, new[] { 350, 380 } }, - } - }, - { //b - 3, new Dictionary - { - { 331, new[] { 130, 160 } }, - { 332, new[] { 600, 480 } }, - { 333, new[] { 350, 390 } }, - } - }, - }; } -} \ No newline at end of file +} diff --git a/EventMapHpViewer/Models/MapInfoProxy.cs b/EventMapHpViewer/Models/MapInfoProxy.cs index e3cbb84..7a1b634 100644 --- a/EventMapHpViewer/Models/MapInfoProxy.cs +++ b/EventMapHpViewer/Models/MapInfoProxy.cs @@ -59,7 +59,7 @@ public MapInfoProxy() .TryParse() .Subscribe(x => { - Debug.WriteLine("MapInfoProxy - member_mapinfo"); + Debug.WriteLine("MapInfoProxy - select_eventmap_rank"); this.Maps.MapList = this.UpdateRank(x); this.RaisePropertyChanged(() => this.Maps); }); diff --git a/EventMapHpViewer/Models/RemainingCount.cs b/EventMapHpViewer/Models/RemainingCount.cs new file mode 100644 index 0000000..b212a6c --- /dev/null +++ b/EventMapHpViewer/Models/RemainingCount.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EventMapHpViewer.Models +{ + public class RemainingCount + { + public int Min { get; set; } + public int Max { get; set; } + + public RemainingCount() + { + this.Min = 0; + this.Max = 0; + } + public RemainingCount(int min, int max) + { + this.Min = min; + this.Max = max; + } + public RemainingCount(int value) + { + this.Min = value; + this.Max = value; + } + + public bool IsSingleValue => this.Min == this.Max; + + public override bool Equals(object obj) + { + return obj is RemainingCount && this.Equals((RemainingCount)obj); + } + + public override int GetHashCode() + { + unchecked + { + return (this.Min.GetHashCode() * 397) ^ this.Max.GetHashCode(); + } + } + + public override string ToString() + { + return $"{this.Min}-{this.Max}"; + } + + public static bool operator ==(RemainingCount value1, RemainingCount value2) + { + if (ReferenceEquals(value1, value2)) return true; + return value1?.Equals(value2) ?? false; + } + + public static bool operator !=(RemainingCount id1, RemainingCount id2) + { + return !(id1 == id2); + } + + private bool Equals(RemainingCount other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return this.Min == other.Min + && this.Max == other.Max; + } + + public static readonly RemainingCount MaxValue = new RemainingCount(int.MaxValue); + public static readonly RemainingCount Zero = new RemainingCount(0); + } +} diff --git a/EventMapHpViewer/Properties/AssemblyInfo.cs b/EventMapHpViewer/Properties/AssemblyInfo.cs index 1aa073c..3cb5ac5 100644 --- a/EventMapHpViewer/Properties/AssemblyInfo.cs +++ b/EventMapHpViewer/Properties/AssemblyInfo.cs @@ -43,4 +43,4 @@ // ã™ã¹ã¦ã®å€¤ã‚’指定ã™ã‚‹ã‹ã€ä¸‹ã®ã‚ˆã†ã« '*' を使ã£ã¦ãƒ“ルドãŠã‚ˆã³ãƒªãƒ“ジョン番å·ã‚’ // 既定値ã«ã™ã‚‹ã“ã¨ãŒã§ãã¾ã™: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("3.1.2.0")] +[assembly: AssemblyVersion("3.2.0.0")] diff --git a/EventMapHpViewer/SampleData/ToolViewModelSampleData.xaml b/EventMapHpViewer/SampleData/ToolViewModelSampleData.xaml index 6895c90..296d4c4 100644 --- a/EventMapHpViewer/SampleData/ToolViewModelSampleData.xaml +++ b/EventMapHpViewer/SampleData/ToolViewModelSampleData.xaml @@ -8,15 +8,19 @@ @@ -24,15 +28,19 @@ @@ -40,15 +48,19 @@ @@ -58,15 +70,18 @@ Max="444" SelectedRank="甲" SelectedRankVisibility="Visible" - RemainingCount="7" + RemainingCountMin="7" + RemainingCountMax="7" + IsSingleRemainingCount="True" MapNumber="30-5" AreaName="イベント海域" Name="未対応海域" IsCleared="False" IsRankSelected="True" IsSupported="True" + IsUnSupportedVisibility="Collapsed" IsInfinity="False" - IsCountVisible="True" + IsInfinityVisibility="Collapsed" GaugeType="Event"> @@ -76,15 +91,18 @@ Max="444" SelectedRank="ä¹™" SelectedRankVisibility="Visible" - RemainingCount="7" + RemainingCountMin="7" + RemainingCountMax="7" + IsSingleRemainingCount="True" MapNumber="30-5" AreaName="イベント海域" Name="未対応海域" + IsCountVisibility="Collapsed" IsCleared="False" IsRankSelected="True" IsSupported="False" IsInfinity="False" - IsCountVisible="False" + IsInfinityVisibility="Collapsed" GaugeType="Event"> @@ -94,7 +112,9 @@ Max="444" SelectedRank="ä¹™" SelectedRankVisibility="Visible" - RemainingCount="7" + RemainingCountMin="7" + RemainingCountMax="7" + IsSingleRemainingCount="True" RemainingCountTransportS="5" MapNumber="30-5" AreaName="イベント海域" @@ -102,8 +122,9 @@ IsCleared="False" IsRankSelected="True" IsSupported="True" + IsUnSupportedVisibility="Collapsed" IsInfinity="False" - IsCountVisible="True" + IsInfinityVisibility="Collapsed" GaugeType="Transport"> @@ -113,20 +134,43 @@ Max="444" SelectedRank="ä¹™" SelectedRankVisibility="Visible" - RemainingCount="7" + RemainingCountMin="7" + RemainingCountMax="7" + IsSingleRemainingCount="True" RemainingCountTransportS="5" MapNumber="30-5" AreaName="イベント海域" Name="ç„¡é™è¼¸é€" + IsCountVisibility="Collapsed" IsCleared="False" IsRankSelected="True" IsSupported="True" + IsUnSupportedVisibility="Collapsed" IsInfinity="True" - IsCountVisible="False" GaugeType="Transport"> + + + + + diff --git a/EventMapHpViewer/ToolView.xaml b/EventMapHpViewer/ToolView.xaml index 9b12cbd..931d44c 100644 --- a/EventMapHpViewer/ToolView.xaml +++ b/EventMapHpViewer/ToolView.xaml @@ -198,7 +198,7 @@ - @@ -207,6 +207,26 @@ + + + + + + + + + + + + + + + @@ -215,7 +235,7 @@ - diff --git a/EventMapHpViewer/ViewModels/MapViewModel.cs b/EventMapHpViewer/ViewModels/MapViewModel.cs index fd1204d..b871e53 100644 --- a/EventMapHpViewer/ViewModels/MapViewModel.cs +++ b/EventMapHpViewer/ViewModels/MapViewModel.cs @@ -131,23 +131,45 @@ public string SelectedRank public Visibility SelectedRankVisibility => string.IsNullOrEmpty(this.SelectedRank) ? Visibility.Collapsed : Visibility.Visible; - #region RemainingCount変更通知プロパティ - private string _RemainingCount; + #region RemainingCountMin 変更通知プロパティ + private string _RemainingCountMin; - public string RemainingCount + public string RemainingCountMin { get - { return this._RemainingCount; } + { return this._RemainingCountMin; } set { - if (this._RemainingCount == value) + if (this._RemainingCountMin == value) return; - this._RemainingCount = value; + this._RemainingCountMin = value; this.RaisePropertyChanged(); + this.RaisePropertyChanged(nameof(this.IsSingleRemainingCount)); } } #endregion + #region RemainingCountMax 変更通知プロパティ + private string _RemainingCountMax; + + public string RemainingCountMax + { + get + { return this._RemainingCountMax; } + set + { + if (this._RemainingCountMax == value) + return; + this._RemainingCountMax = value; + this.RaisePropertyChanged(); + this.RaisePropertyChanged(nameof(this.IsSingleRemainingCount)); + } + } + #endregion + + public bool IsSingleRemainingCount + => this.RemainingCountMin == this.RemainingCountMax; + #region RemainingCountTransportS変更通知プロパティ private string _RemainingCountTransportS; @@ -324,7 +346,7 @@ public MapViewModel(MapData info) this.IsSupported = true; this.IsInfinity = false; this.IsLoading = true; - + this.UpdateRemainingCount(info); } @@ -347,7 +369,7 @@ private void UpdateRemainingCount(MapData info, bool useCache = false) } } - private void Update(int remainingCount, bool useCache) + private void Update(RemainingCount remainingCount, bool useCache) { Application.Current.Dispatcher.Invoke(() => { @@ -355,11 +377,18 @@ private void Update(int remainingCount, bool useCache) { this.IsLoading = false; } - this.RemainingCount = remainingCount.ToString(); + this.IsSupported = remainingCount != null; + if (!this.IsSupported) + { + this.GaugeColor = red; + return; + } + + this.RemainingCountMin = remainingCount.Min.ToString(); + this.RemainingCountMax = remainingCount.Max.ToString(); this.RemainingCountTransportS = this._source.RemainingCountTransportS.ToString(); - this.IsSupported = 0 < remainingCount; - this.IsInfinity = remainingCount == int.MaxValue; - this.GaugeColor = remainingCount < 2 ? red : green; + this.IsInfinity = remainingCount == RemainingCount.MaxValue; + this.GaugeColor = remainingCount.Min < 2 ? red : green; }); }