forked from yasvisu/gw2api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wvw.go
124 lines (111 loc) · 3.42 KB
/
wvw.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
package gw2api
import (
"net/url"
"strconv"
"time"
)
// TeamAssoc Points/Kills/Deaths per team
type TeamAssoc struct {
Green int `json:"green"`
Blue int `json:"blue"`
Red int `json:"red"`
}
// TeamMulti Used in multi association for teams
type TeamMulti struct {
Green []int `json:"green"`
Blue []int `json:"blue"`
Red []int `json:"red"`
}
// Bonus - Map bonuses and current owner indetified by Color/Neutral
type Bonus struct {
Owner string `json:"owner"`
Type string `json:"type"`
}
// MatchObjective - Map objectives such as towers, keeps, etc
type MatchObjective struct {
ID string `json:"id"`
Type string `json:"type"`
Owner string `json:"owner"`
LastFlipped string `json:"last_flipped"`
ClaimedBy string `json:"claimed_by"`
ClaimedAt string `json:"claimed_at"`
}
// MapWvW - One of the four maps and their status
type MapWvW struct {
ID int `json:"id"`
Type string `json:"type"`
Scores TeamAssoc `json:"scores"`
Bonuses []Bonus `json:"bonuses"`
Deaths TeamAssoc `json:"deaths"`
Kills TeamAssoc `json:"kills"`
Objectives []MatchObjective `json:"objectives"`
}
// Match including overall stats and indivdual maps with stats
type Match struct {
ID string `json:"id"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Scores TeamAssoc `json:"scores"`
Worlds TeamAssoc `json:"worlds"`
AllWorlds TeamMulti `json:"all_worlds"`
Deaths TeamAssoc `json:"deaths"`
Kills TeamAssoc `json:"kills"`
Maps []MapWvW `json:"maps"`
}
// Matches returns a list of all current match ids in the form of %d-%d
func (gw2 *GW2Api) Matches() (res []string, err error) {
ver := "v2"
tag := "wvw/matches"
err = gw2.fetchEndpoint(ver, tag, nil, &res)
return
}
// MatchIds returns matches as requested by ids in the form
// provided by Matches(). Use special id `all` for every match in US/EU
func (gw2 *GW2Api) MatchIds(ids ...string) (match []Match, err error) {
ver := "v2"
tag := "wvw/matches"
params := url.Values{}
params.Add("ids", commaList(ids))
err = gw2.fetchEndpoint(ver, tag, params, &match)
return
}
// MatchWorld finds the match the server id is participating in
func (gw2 *GW2Api) MatchWorld(worldID int) (match Match, err error) {
ver := "v2"
tag := "wvw/matches"
params := url.Values{}
params.Add("world", strconv.Itoa(worldID))
err = gw2.fetchEndpoint(ver, tag, params, &match)
return
}
// Objective - Map objectives such as towers, keeps, etc
type Objective struct {
ID string `json:"id"`
Name string `json:"name"`
SectorID int `json:"sector_id"`
Type string `json:"type"`
MapType string `json:"map_type"`
MapID int `json:"map_id"`
Coord []float32 `json:"coord"`
Marker string `json:"marker"`
}
// Objectives returns a list of all objectives on wvw maps
func (gw2 *GW2Api) Objectives() (res []string, err error) {
ver := "v2"
tag := "wvw/objectives"
err = gw2.fetchEndpoint(ver, tag, nil, &res)
return
}
// ObjectiveIds returns a list of objectives as request by ids. Use special id
// `all` to request all objectives
func (gw2 *GW2Api) ObjectiveIds(lang string, ids ...string) (objs []Objective, err error) {
ver := "v2"
tag := "wvw/objectives"
params := url.Values{}
if lang != "" {
params.Add("lang", lang)
}
params.Add("ids", commaList(ids))
err = gw2.fetchEndpoint(ver, tag, params, &objs)
return
}