1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
4
using System . Net ;
@@ -41,92 +41,94 @@ public int Current
41
41
{
42
42
get
43
43
{
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 /*ゲージ無し通常海域*/ ;
46
46
}
47
47
}
48
48
49
- private int [ ] remoteBossHpCache ;
49
+ private Raw . map_exboss [ ] remoteBossDataCache ;
50
50
51
51
/// <summary>
52
- /// 残回数。輸送の場合はA勝利の残回数。
52
+ /// 残回数。輸送の場合はA勝利の残回数。
53
53
/// </summary>
54
- public async Task < int > GetRemainingCount ( bool useCache = false )
54
+ public async Task < RemainingCount > GetRemainingCount ( bool useCache = false )
55
55
{
56
- if ( this . IsCleared == 1 ) return 0 ;
56
+ if ( this . IsCleared == 1 ) return RemainingCount . Zero ;
57
57
58
- if ( this . IsExBoss == 1 ) return this . Current ; //ゲージ有り通常海域
58
+ if ( this . IsExBoss == 1 ) return new RemainingCount ( this . Current ) ; //ゲージ有り通常海域
59
59
60
- if ( this . Eventmap == null ) return 1 ; //ゲージ無し通常海域
60
+ if ( this . Eventmap == null ) return new RemainingCount ( 1 ) ; //ゲージ無し通常海域
61
61
62
62
if ( this . Eventmap . GaugeType == GaugeType . Transport )
63
63
{
64
64
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 ) ) ;
67
67
}
68
68
69
- if ( this . Eventmap . SelectedRank == 0 ) return - 1 ; //難易度未選択
69
+ if ( this . Eventmap . SelectedRank == 0 ) return null ; //難易度未選択
70
70
71
71
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 ) ; //イベント海域(リモートデータ)
73
76
74
- var remoteBossHp = this . remoteBossHpCache ;
75
- if ( remoteBossHp != null && remoteBossHp . Any ( ) )
76
- return this . CalculateRemainingCount ( remoteBossHp ) ; //イベント海域(リモートデータ)
77
+ return null ; //未対応
78
+ }
77
79
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
+ ) ) ;
87
91
}
88
92
89
- private int CalculateRemainingCount ( int [ ] bossHPs )
93
+ private int CalculateRemainingCount ( int normalBossHp , int lastBossHp )
90
94
{
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回
94
96
return ( int ) Math . Ceiling ( ( double ) ( this . Current - lastBossHp ) / normalBossHp ) + 1 ;
95
97
}
96
98
97
99
/// <summary>
98
- /// 輸送ゲージのS勝利時の残回数
100
+ /// 輸送ゲージのS勝利時の残回数
99
101
/// </summary>
100
102
public int RemainingCountTransportS
101
103
{
102
104
get
103
105
{
104
106
if ( this . Eventmap ? . GaugeType != GaugeType . Transport ) return - 1 ;
105
107
var capacity = KanColleClient . Current . Homeport . Organization . TransportationCapacity ( true ) ;
106
- if ( capacity == 0 ) return int . MaxValue ; //ゲージ減らない
108
+ if ( capacity == 0 ) return int . MaxValue ; //ゲージ減らない
107
109
return ( int ) Math . Ceiling ( ( double ) this . Current / capacity ) ;
108
110
}
109
111
}
110
112
111
113
/// <summary>
112
- /// 艦これ戦術データ・リンクからボス情報を取得する。
113
- /// 取得できなかった場合は null を返す。
114
+ /// 艦これ戦術データ・リンクからボス情報を取得する。
115
+ /// 取得できなかった場合は null を返す。
114
116
/// </summary>
115
117
/// <param name="mapId"></param>
116
118
/// <param name="rank"></param>
117
119
/// <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 )
119
121
{
120
122
using ( var client = new HttpClient ( GetProxyConfiguredHandler ( ) ) )
121
123
{
122
124
client . DefaultRequestHeaders
123
125
. TryAddWithoutValidation ( "User-Agent" , $ "{ MapHpViewer . title } /{ MapHpViewer . version } ") ;
124
126
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 } ") ;
127
129
if ( ! response . IsSuccessStatusCode )
128
130
{
129
- // 200 じゃなかった
131
+ // 200 じゃなかった
130
132
return null ;
131
133
}
132
134
@@ -136,24 +138,21 @@ private static async Task<int[]> GetEventBossHp(int mapId, int rank)
136
138
|| ! parsed . Any ( x => x . isLast )
137
139
|| ! parsed . Any ( x => ! x . isLast ) )
138
140
{
139
- // データが揃っていない
141
+ // データが揃っていない
140
142
return null ;
141
143
}
142
- return parsed
143
- . OrderBy ( x => x . isLast ) // 最終編成が後ろに来るようにする
144
- . Select ( x => x . ship . maxhp )
145
- . ToArray ( ) ;
144
+ return parsed ;
146
145
}
147
146
catch ( HttpRequestException )
148
147
{
149
- // HTTP リクエストに失敗した
148
+ // HTTP リクエストに失敗した
150
149
return null ;
151
150
}
152
151
}
153
152
}
154
153
155
154
/// <summary>
156
- /// 本体のプロキシ設定を組み込んだHttpClientHandlerを返す。
155
+ /// 本体のプロキシ設定を組み込んだHttpClientHandlerを返す。
157
156
/// </summary>
158
157
/// <returns></returns>
159
158
private static HttpClientHandler GetProxyConfiguredHandler ( )
@@ -187,43 +186,5 @@ private static HttpClientHandler GetProxyConfiguredHandler()
187
186
return new HttpClientHandler ( ) ;
188
187
}
189
188
}
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
- } ;
228
189
}
229
- }
190
+ }
0 commit comments