Skip to content

Commit 578ec20

Browse files
committed
34-2 のようなランダムボス編成に対応したつもり
1 parent 0effc0c commit 578ec20

File tree

9 files changed

+241
-114
lines changed

9 files changed

+241
-114
lines changed

EventMapHpViewer/EventMapHpViewer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
<Compile Include="Models\Raw\map_select_eventmap_rank.cs" />
148148
<Compile Include="Models\Raw\member_mapinfo.cs" />
149149
<Compile Include="Models\Raw\map_start_next.cs" />
150+
<Compile Include="Models\RemainingCount.cs" />
150151
<Compile Include="Properties\AssemblyInfo.cs" />
151152
<Compile Include="ToolView.xaml.cs">
152153
<DependentUpon>ToolView.xaml</DependentUpon>

EventMapHpViewer/MapHpViewer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace EventMapHpViewer
1515
public class MapHpViewer : IPlugin, ITool
1616
{
1717
internal const string title = "MapHPViewer";
18-
internal const string version = "3.1.2";
18+
internal const string version = "3.2.0";
1919
private ToolViewModel vm;
2020

2121
public void Initialize()

EventMapHpViewer/Models/MapData.cs

Lines changed: 44 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Net;
@@ -41,92 +41,94 @@ public int Current
4141
{
4242
get
4343
{
44-
if (this.IsExBoss == 1) return this.Master.RequiredDefeatCount - this.DefeatCount; //ゲージ有り通常海域
45-
return this.Eventmap?.NowMapHp /*イベント海域*/?? 1 /*ゲージ無し通常海域*/;
44+
if (this.IsExBoss == 1) return this.Master.RequiredDefeatCount - this.DefeatCount; //ゲージ有り通常海域
45+
return this.Eventmap?.NowMapHp /*イベント海域*/?? 1 /*ゲージ無し通常海域*/;
4646
}
4747
}
4848

49-
private int[] remoteBossHpCache;
49+
private Raw.map_exboss[] remoteBossDataCache;
5050

5151
/// <summary>
52-
/// 残回数。輸送の場合はA勝利の残回数。
52+
/// 残回数。輸送の場合はA勝利の残回数。
5353
/// </summary>
54-
public async Task<int> GetRemainingCount(bool useCache = false)
54+
public async Task<RemainingCount> GetRemainingCount(bool useCache = false)
5555
{
56-
if (this.IsCleared == 1) return 0;
56+
if (this.IsCleared == 1) return RemainingCount.Zero;
5757

58-
if (this.IsExBoss == 1) return this.Current; //ゲージ有り通常海域
58+
if (this.IsExBoss == 1) return new RemainingCount(this.Current); //ゲージ有り通常海域
5959

60-
if (this.Eventmap == null) return 1; //ゲージ無し通常海域
60+
if (this.Eventmap == null) return new RemainingCount(1); //ゲージ無し通常海域
6161

6262
if (this.Eventmap.GaugeType == GaugeType.Transport)
6363
{
6464
var capacityA = KanColleClient.Current.Homeport.Organization.TransportationCapacity();
65-
if (capacityA == 0) return int.MaxValue; //ゲージ減らない
66-
return (int)Math.Ceiling((double)this.Current / capacityA);
65+
if (capacityA == 0) return RemainingCount.MaxValue; //ゲージ減らない
66+
return new RemainingCount((int)Math.Ceiling((double)this.Current / capacityA));
6767
}
6868

69-
if (this.Eventmap.SelectedRank == 0) return -1; //難易度未選択
69+
if (this.Eventmap.SelectedRank == 0) return null; //難易度未選択
7070

7171
if (!useCache)
72-
this.remoteBossHpCache = await GetEventBossHp(this.Id, this.Eventmap.SelectedRank);
72+
this.remoteBossDataCache = await GetEventBossHp(this.Id, this.Eventmap.SelectedRank);
73+
74+
if (this.remoteBossDataCache != null && this.remoteBossDataCache.Any())
75+
return this.CalculateRemainingCount(this.remoteBossDataCache); //イベント海域(リモートデータ)
7376

74-
var remoteBossHp = this.remoteBossHpCache;
75-
if (remoteBossHp != null && remoteBossHp.Any())
76-
return this.CalculateRemainingCount(remoteBossHp); //イベント海域(リモートデータ)
77+
return null; //未対応
78+
}
7779

78-
try
79-
{
80-
// リモートデータがない場合、ローカルデータを使う
81-
return this.CalculateRemainingCount(eventBossHpDictionary[this.Eventmap.SelectedRank][this.Id]); //イベント海域
82-
}
83-
catch (KeyNotFoundException)
84-
{
85-
return -1; //未対応
86-
}
80+
private RemainingCount CalculateRemainingCount(Raw.map_exboss[] data)
81+
{
82+
return new RemainingCount(
83+
CalculateRemainingCount(
84+
data.Where(x => !x.isLast).Min(x => x.ship.maxhp),
85+
data.Where(x => x.isLast).Min(x => x.ship.maxhp)
86+
),
87+
CalculateRemainingCount(
88+
data.Where(x => !x.isLast).Max(x => x.ship.maxhp),
89+
data.Where(x => x.isLast).Max(x => x.ship.maxhp)
90+
));
8791
}
8892

89-
private int CalculateRemainingCount(int[] bossHPs)
93+
private int CalculateRemainingCount(int normalBossHp, int lastBossHp)
9094
{
91-
var lastBossHp = bossHPs.Last();
92-
var normalBossHp = bossHPs.First();
93-
if (this.Current <= lastBossHp) return 1; //最後の1回
95+
if (this.Current <= lastBossHp) return 1; //最後の1回
9496
return (int)Math.Ceiling((double)(this.Current - lastBossHp) / normalBossHp) + 1;
9597
}
9698

9799
/// <summary>
98-
/// 輸送ゲージのS勝利時の残回数
100+
/// 輸送ゲージのS勝利時の残回数
99101
/// </summary>
100102
public int RemainingCountTransportS
101103
{
102104
get
103105
{
104106
if (this.Eventmap?.GaugeType != GaugeType.Transport) return -1;
105107
var capacity = KanColleClient.Current.Homeport.Organization.TransportationCapacity(true);
106-
if (capacity == 0) return int.MaxValue; //ゲージ減らない
108+
if (capacity == 0) return int.MaxValue; //ゲージ減らない
107109
return (int)Math.Ceiling((double)this.Current / capacity);
108110
}
109111
}
110112

111113
/// <summary>
112-
/// 艦これ戦術データ・リンクからボス情報を取得する。
113-
/// 取得できなかった場合は null を返す。
114+
/// 艦これ戦術データ・リンクからボス情報を取得する。
115+
/// 取得できなかった場合は null を返す。
114116
/// </summary>
115117
/// <param name="mapId"></param>
116118
/// <param name="rank"></param>
117119
/// <returns></returns>
118-
private static async Task<int[]> GetEventBossHp(int mapId, int rank)
120+
private static async Task<Raw.map_exboss[]> GetEventBossHp(int mapId, int rank)
119121
{
120122
using (var client = new HttpClient(GetProxyConfiguredHandler()))
121123
{
122124
client.DefaultRequestHeaders
123125
.TryAddWithoutValidation("User-Agent", $"{MapHpViewer.title}/{MapHpViewer.version}");
124126
try {
125-
// rank の後ろの"1"はサーバー上手動メンテデータを加味するかどうかのフラグ
126-
var response = await client.GetAsync($"https://kctadil.azurewebsites.net/map/exboss/{mapId}/{rank}/1");
127+
// rank の後ろの"1"はサーバー上手動メンテデータを加味するかどうかのフラグ
128+
var response = await client.GetAsync($"https://kctadil.azurewebsites.net/map/maphp/v3.2/{mapId}/{rank}");
127129
if (!response.IsSuccessStatusCode)
128130
{
129-
// 200 じゃなかった
131+
// 200 じゃなかった
130132
return null;
131133
}
132134

@@ -136,24 +138,21 @@ private static async Task<int[]> GetEventBossHp(int mapId, int rank)
136138
|| !parsed.Any(x => x.isLast)
137139
|| !parsed.Any(x => !x.isLast))
138140
{
139-
// データが揃っていない
141+
// データが揃っていない
140142
return null;
141143
}
142-
return parsed
143-
.OrderBy(x => x.isLast) // 最終編成が後ろに来るようにする
144-
.Select(x => x.ship.maxhp)
145-
.ToArray();
144+
return parsed;
146145
}
147146
catch (HttpRequestException)
148147
{
149-
// HTTP リクエストに失敗した
148+
// HTTP リクエストに失敗した
150149
return null;
151150
}
152151
}
153152
}
154153

155154
/// <summary>
156-
/// 本体のプロキシ設定を組み込んだHttpClientHandlerを返す。
155+
/// 本体のプロキシ設定を組み込んだHttpClientHandlerを返す。
157156
/// </summary>
158157
/// <returns></returns>
159158
private static HttpClientHandler GetProxyConfiguredHandler()
@@ -187,43 +186,5 @@ private static HttpClientHandler GetProxyConfiguredHandler()
187186
return new HttpClientHandler();
188187
}
189188
}
190-
191-
/// <summary>
192-
/// 手動メンテデータ用。
193-
/// いずれ削除される見込み。
194-
/// </summary>
195-
private static readonly IReadOnlyDictionary<int, IReadOnlyDictionary<int, int[]>> eventBossHpDictionary
196-
= new Dictionary<int, IReadOnlyDictionary<int, int[]>>
197-
{
198-
{ //難易度未選択
199-
0, new Dictionary<int, int[]>
200-
{
201-
}
202-
},
203-
{ //丙
204-
1, new Dictionary<int, int[]>
205-
{
206-
{ 331, new[] { 110 } },
207-
{ 332, new[] { 600, 380 } },
208-
{ 333, new[] { 350, 370 } },
209-
}
210-
},
211-
{ //乙
212-
2, new Dictionary<int, int[]>
213-
{
214-
{ 331, new[] { 110, 130 } },
215-
{ 332, new[] { 600, 430 } },
216-
{ 333, new[] { 350, 380 } },
217-
}
218-
},
219-
{ //甲
220-
3, new Dictionary<int, int[]>
221-
{
222-
{ 331, new[] { 130, 160 } },
223-
{ 332, new[] { 600, 480 } },
224-
{ 333, new[] { 350, 390 } },
225-
}
226-
},
227-
};
228189
}
229-
}
190+
}

EventMapHpViewer/Models/MapInfoProxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public MapInfoProxy()
5959
.TryParse<map_select_eventmap_rank>()
6060
.Subscribe(x =>
6161
{
62-
Debug.WriteLine("MapInfoProxy - member_mapinfo");
62+
Debug.WriteLine("MapInfoProxy - select_eventmap_rank");
6363
this.Maps.MapList = this.UpdateRank(x);
6464
this.RaisePropertyChanged(() => this.Maps);
6565
});
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace EventMapHpViewer.Models
8+
{
9+
public class RemainingCount
10+
{
11+
public int Min { get; set; }
12+
public int Max { get; set; }
13+
14+
public RemainingCount()
15+
{
16+
this.Min = 0;
17+
this.Max = 0;
18+
}
19+
public RemainingCount(int min, int max)
20+
{
21+
this.Min = min;
22+
this.Max = max;
23+
}
24+
public RemainingCount(int value)
25+
{
26+
this.Min = value;
27+
this.Max = value;
28+
}
29+
30+
public bool IsSingleValue => this.Min == this.Max;
31+
32+
public override bool Equals(object obj)
33+
{
34+
return obj is RemainingCount && this.Equals((RemainingCount)obj);
35+
}
36+
37+
public override int GetHashCode()
38+
{
39+
unchecked
40+
{
41+
return (this.Min.GetHashCode() * 397) ^ this.Max.GetHashCode();
42+
}
43+
}
44+
45+
public override string ToString()
46+
{
47+
return $"{this.Min}-{this.Max}";
48+
}
49+
50+
public static bool operator ==(RemainingCount value1, RemainingCount value2)
51+
{
52+
if (ReferenceEquals(value1, value2)) return true;
53+
return value1?.Equals(value2) ?? false;
54+
}
55+
56+
public static bool operator !=(RemainingCount id1, RemainingCount id2)
57+
{
58+
return !(id1 == id2);
59+
}
60+
61+
private bool Equals(RemainingCount other)
62+
{
63+
if (ReferenceEquals(null, other)) return false;
64+
if (ReferenceEquals(this, other)) return true;
65+
return this.Min == other.Min
66+
&& this.Max == other.Max;
67+
}
68+
69+
public static readonly RemainingCount MaxValue = new RemainingCount(int.MaxValue);
70+
public static readonly RemainingCount Zero = new RemainingCount(0);
71+
}
72+
}

EventMapHpViewer/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@
4343
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
4444
// 既定値にすることができます:
4545
// [assembly: AssemblyVersion("1.0.*")]
46-
[assembly: AssemblyVersion("3.1.2.0")]
46+
[assembly: AssemblyVersion("3.2.0.0")]

0 commit comments

Comments
 (0)