This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.go
475 lines (405 loc) · 15 KB
/
player.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
package gotanking
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
)
// Account represents data from the account/list endpoint
type Account struct {
Data []AccountRecord `json:"data"`
}
// AccountRecord holds one search result from the account/list endpoint
type AccountRecord struct {
Nickname string `json:"nickname"`
AccountID int `json:"account_id"`
}
// AccountInput holds display filters
type AccountInput struct {
// Fields you want displayed. Valid values are:
//
// * nickname
// * account_id
Fields []string
// Language in which you want the results. Valid values are:
//
// "en" — English (by default)
// "ru" — Русский
// "pl" — Polski
// "de" — Deutsch
// "fr" — Français
// "es" — Español
// "zh-cn" — 简体中文
// "zh-tw" — 繁體中文
// "tr" — Türkçe
// "cs" — Čeština
// "th" — ไทย
// "vi" — Tiếng Việt
// "ko" — 한국어
Language string
// Limit the number of returned entries, up to 100
Limit string
// Type of search matching. Valid values are:
//
// * startswith (by default)
// * exact
SearchType string
}
// PlayerPersonalData holds the response data from the /account/info endpoint
type PlayerPersonalData struct {
Data map[string]PlayerPersonalDataRec `json:"data"`
}
// PlayerPersonalDataRec is one player record from the /account/info endpoint
type PlayerPersonalDataRec struct {
ClientLanguage string `json:"client_language"`
LastBattleTime int `json:"last_battle_time"`
AccountID int `json:"account_id"`
CreatedAt int `json:"created_at"`
UpdatedAt int `json:"updated_at"`
Private string `json:"private"`
GlobalRating int `json:"global_rating"`
ClanID int `json:"clan_id"`
Statistics PlayerStats `json:"statistics"`
Nickname string `json:"nickname"`
LogoutAt int `json:"logout_at"`
}
// PlayerStats contains the stats for a single player
type PlayerStats struct {
Clan map[string]PlayerStatsRec `json:"clan"`
All map[string]PlayerStatsRec `json:"all"`
RegularTeam map[string]PlayerStatsRec `json:"regular_team"`
TreesCut int `json:"trees_cut"`
Company map[string]PlayerStatsRec `json:"company"`
StrongholdSkirmish map[string]PlayerStatsRec `json:"stronghold_skirmish"`
StrongholdDefense map[string]PlayerStatsRec `json:"stronghold_defense"`
Historical map[string]PlayerStatsRec `json:"historical"`
Team map[string]PlayerStatsRec `json:"team"`
Frags int `json:"frags"`
}
// PlayerStatsRec holds the statistics for a single player and single category, returned from the /account/info endpoint
type PlayerStatsRec struct {
Spotted int `json:"spotted"`
BattlesOnStunningVehicles int `json:"battles_on_stunning_vehicles"`
AvgDamageBlocked float32 `json:"average_damage_blocked"`
DirectHitsReceived int `json:"direct_hits_received"`
ExplosionHits int `json:"explosion_hits"`
PiercingsReceived int `json:"piercings_received"`
Piercings int `json:"piercings"`
XP int `json:"xp"`
SurvivedBattles int `json:"survived_battles"`
DroppedCapturePoints int `json:"dropped_capture_points"`
HitsPercents int `json:"hits_percents"`
Draws int `json:"draws"`
Battles int `json:"battles"`
DamageReceived int `json:"damage_received"`
AvgDamageAssisted float32 `json:"avg_damage_assisted"`
AvgDamageAssistedTrack float32 `json:"avg_damage_assisted_track"`
Frags int `json:"frags"`
StunNumber int `json:"stun_number"`
AvgDamageAssistedRadio float32 `json:"avg_damage_assisted_radio"`
CapturePoints int `json:"capture_points"`
StunAssistedDamage int `json:"stun_assisted_damage"`
Hits int `json:"hits"`
BattleAvgXP int `json:"battle_avg_xp"`
Wins int `json:"wins"`
Losses int `json:"losses"`
DamageDealt int `json:"damage_dealt"`
NoDamageDirectHitsReceived int `json:"no_damage_direct_hits_received"`
Shots int `json:"shots"`
ExplosionHitsReceived int `json:"explosion_hits_received"`
TankingFactor float32 `json:"tanking_factor"`
}
// PlayerPersonalDataInput holds filters and query parameters for player details
type PlayerPersonalDataInput struct {
// Access token for private data.
AccessToken string
// Extra fields that are added to the response. See https://developers.wargaming.net/reference/all/wot/account/info for full list.
Extra []string
// Fields you want displayed. See https://developers.wargaming.net/reference/all/wot/account/info for full list.
Fields []string
}
// PlayerVehicles contains all tanks owned by a player
type PlayerVehicles struct {
Data map[string][]PlayerVehiclesRec
}
// PlayerVehiclesRec contains a record of a particular vehicle
type PlayerVehiclesRec struct {
Statistics struct {
Wins int `json:"wins"`
Battles int `json:"battles"`
}
MarkOfMastery int `json:"mark_of_mastery"`
TankID int `json:"tank_id"`
}
// PlayerVehiclesInput holds filters and query parameters for vehicle details
type PlayerVehiclesInput struct {
// Access token for private data.
AccessToken string
// Fields you want displayed. Valid values are:
//
// * mark_of_mastery (0: none, 1: 3rd class, 2: 2nd class, 3: 1st class, 4: ace tanker)
// * tank_id
// * statistics
// * statistics.battles
// * statistics.wins
Fields []string
// Language in which you want the results. Valid values are:
//
// "en" — English (by default)
// "ru" — Русский
// "pl" — Polski
// "de" — Deutsch
// "fr" — Français
// "es" — Español
// "zh-cn" — 简体中文
// "zh-tw" — 繁體中文
// "tr" — Türkçe
// "cs" — Čeština
// "th" — ไทย
// "vi" — Tiếng Việt
// "ko" — 한국어
Language string
// Tank or Tanks ID
TankID []int
}
// PlayerAchievements holds a player's achievements
type PlayerAchievements struct {
Data map[string]PlayerAchievementsData `json:"data"`
}
// PlayerAchievementsData contains all the achievement categories
type PlayerAchievementsData struct {
Achievements PlayerAchievementsRec `json:"achievements"`
Frags PlayerFragsRec `json:"frags"`
MaxSeries PlayerMaxSeriesRec `json:"max_series"`
}
// PlayerAchievementsRec contains all earned achievements
type PlayerAchievementsRec struct {
CariusMedal int `json:"medalCarius"`
Aimer int `json:"aimer"`
Invader int `json:"invader"`
ShootToKill int `json:"shootToKill"`
June20 int `json:"june20"`
MedalEkins int `json:"medalEkins"`
WtHunterWins int `json:"wtHunterWins"`
Duelist int `json:"duelist"`
TitleSniper int `json:"titleSniper"`
LeClercMedal int `json:"medalLeClerc"`
Demolition int `json:"demolition"`
Supporter int `json:"supporter"`
SteelWall int `json:"steelwall"`
LehvaslaihoMedal int `json:"medalLehvaslaiho"`
AbramsMedal int `json:"medalAbrams"`
September20 int `json:"september20"`
PoppelMedal int `json:"medalPoppel"`
PascucciMedal int `json:"medalPascucci"`
ReliableComrade int `json:"reliableComrade"`
MainGun int `json:"mainGun"`
Kamikaze int `json:"kamikaze"`
TenYearsCoundownParticipation int `json:"TenYearsCountdownParticipation"`
TenYearsCountdownStageMedal int `json:"TenYearsCountdownStageMedal"`
FirstMerit int `json:"firstMerit"`
Warrior int `json:"warrior"`
ArmorPiercer int `json:"armorPiercer"`
Even int `json:"even"`
WtBossWins int `json:"wtBossWins"`
Arsonist int `json:"arsonist"`
BrothersInArmMedal int `json:"medalBrothersInArms"`
IronMan int `json:"ironMan"`
ReadyForBattleMT int `json:"readyForBattleMT"`
Sniper2 int `json:"sniper2"`
OskinMedal int `json:"medalOskin"`
Charmed int `json:"charmed"`
October20 int `json:"october20"`
Fighter int `json:"fighter"`
LavrinenkoMedal int `json:"medalLavrinenko"`
Impenetrable int `json:"impenetrable"`
Sturdy int `json:"sturdy"`
KayMedal int `json:"medalKay"`
FiveYearsOfService int `json:"05YearsOfService"`
HandOfDeath int `json:"handOfDeath"`
BoneCrusher int `json:"bonecrusher"`
WFC2014 int `json:"WFC2014"`
DumitruMedal int `json:"medalDumitru"`
EvilEye int `json:"evileye"`
KnispelMedal int `json:"medalKnispel"`
}
// PlayerFragsRec contains achievement progress
type PlayerFragsRec struct {
CrucialShotMedal int `json:"crucialShotMedal"`
InfiltratorMedal int `json:"infiltratorMedal"`
SentinelMedal int `json:"sentinelMedal"`
PrematureDetonationMedal int `json:"prematureDetonationMedal"`
FightingReconMedal int `json:"fightingReconnaissanceMedal"`
FireAndSteelMedal int `json:"fireAndSteelMedal"`
RangerMedal int `json:"rangerMedal"`
ReliableComrade int `json:"reliableComrade"`
WolfAmongSheepMedal int `json:"wolfAmongSheepMedal"`
HeavyFireMedal int `json:"heavyFireMedal"`
BruteForceMedal int `json:"bruteForceMedal"`
GuerrillaMedal int `json:"guerrilaMedal"`
PromisingFighterMedal int `json:"promisingFighterMedal"`
PyromaniacMedal int `json:"pyromaniacMedal"`
GeniusForWarMedal int `json:"geniusForWarMedal"`
Sinai int `json:"sinai"`
BeastHunter int `json:"beastHunter"`
PattonValley int `json:"pattonValley"`
}
// PlayerAchievementsInput holds filters and query parameters for player achievements
type PlayerAchievementsInput struct {
// Fields you want displayed. Valid values are:
//
// * achievements
// * frags
// * max_series
Fields []string
// Language for the results
Language string
}
// PlayerMaxSeriesRec contains the maximum achievement series values
type PlayerMaxSeriesRec struct {
ArmorPiercer int `json:"armorPiercer"`
Aimer int `json:"aimer"`
TitleSniper int `json:"titleSniper"`
TacticalBreakthrough int `json:"tacticalBreakthrough"`
Invincible int `json:"invincible"`
VictoryMarch int `json:"victoryMarch"`
DeathTrack int `json:"deathTrack"`
EFC2016 int `json:"EFC2016"`
DieHard int `json:"dieHard"`
WFC2014 int `json:"WFC2014"`
HandOfDeath int `json:"handOfDeath"`
}
// GetAccount fetches a player's account record
func (c *WOTClient) GetAccount(search string, input *AccountInput) (*Account, error) {
endpoint := "/account/list/"
var account Account
v := url.Values{}
v.Set("application_id", c.ApplicationID)
v.Set("search", search)
if input != nil {
v.Set("language", input.Language)
v.Set("limit", input.Limit)
v.Set("type", input.SearchType)
var fields string
for _, i := range input.Fields {
fields = fields + "," + i
}
v.Set("fields", fields)
}
resp, err := http.Get(c.baseURL + endpoint + "?" + v.Encode())
if err != nil {
return &account, err
}
body := new(bytes.Buffer)
body.ReadFrom(resp.Body)
b := body.Bytes()
err = json.Unmarshal(b, &account)
if err != nil {
return &account, err
}
return &account, nil
}
// GetAccountID is a convenience method to retrieve a player's account_id
func (c *WOTClient) GetAccountID(search string) int {
resp, err := c.GetAccount(search, nil)
if err != nil {
panic(err)
}
return resp.Data[0].AccountID
}
// GetPlayerPersonalData returns player details
func (c *WOTClient) GetPlayerPersonalData(accountID int, input *PlayerPersonalDataInput) (*PlayerPersonalData, error) {
endpoint := "/account/info/"
var playerData PlayerPersonalData
v := url.Values{}
v.Set("application_id", c.ApplicationID)
v.Set("account_id", fmt.Sprint(accountID))
if input != nil {
v.Set("access_token", input.AccessToken)
var extra string
for _, i := range input.Extra {
extra = extra + "," + i
}
v.Set("extra", extra)
var fields string
for _, i := range input.Fields {
fields = fields + "," + i
}
v.Set("fields", fields)
}
resp, err := http.Get(c.baseURL + endpoint + "?" + v.Encode())
if err != nil {
return &playerData, err
}
body := new(bytes.Buffer)
body.ReadFrom(resp.Body)
b := body.Bytes()
err = json.Unmarshal(b, &playerData)
if err != nil {
return &playerData, err
}
return &playerData, nil
}
// GetPlayerVehicles returns all tanks owned by a player
func (c *WOTClient) GetPlayerVehicles(accountID int, input *PlayerVehiclesInput) (*PlayerVehicles, error) {
endpoint := "/account/tanks/"
var playerVehicles PlayerVehicles
v := url.Values{}
v.Set("application_id", c.ApplicationID)
v.Set("account_id", fmt.Sprint(accountID))
if input != nil {
v.Set("access_token", input.AccessToken)
var tanks string
for _, i := range input.TankID {
tanks = tanks + "," + fmt.Sprint(i)
}
v.Set("tank_id", tanks)
var fields string
for _, i := range input.Fields {
fields = fields + "," + i
}
v.Set("fields", fields)
v.Set("language", input.Language)
}
resp, err := http.Get(c.baseURL + endpoint + "?" + v.Encode())
if err != nil {
return &playerVehicles, err
}
body := new(bytes.Buffer)
body.ReadFrom(resp.Body)
b := body.Bytes()
err = json.Unmarshal(b, &playerVehicles)
if err != nil {
return &playerVehicles, err
}
return &playerVehicles, nil
}
// GetPlayerAchievements returns player achievements
func (c *WOTClient) GetPlayerAchievements(accountID int, input *PlayerAchievementsInput) (*PlayerAchievements, error) {
endpoint := "/account/achievements/"
var playerAchievements PlayerAchievements
v := url.Values{}
v.Set("application_id", c.ApplicationID)
v.Set("account_id", fmt.Sprint(accountID))
if input != nil {
var fields string
for _, i := range input.Fields {
fields = fields + "," + i
}
v.Set("fields", fields)
v.Set("language", input.Language)
}
resp, err := http.Get(c.baseURL + endpoint + "?" + v.Encode())
if err != nil {
return &playerAchievements, err
}
body := new(bytes.Buffer)
body.ReadFrom(resp.Body)
b := body.Bytes()
err = json.Unmarshal(b, &playerAchievements)
if err != nil {
return &playerAchievements, err
}
return &playerAchievements, nil
}