-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchallenges.go
More file actions
183 lines (158 loc) · 6.26 KB
/
challenges.go
File metadata and controls
183 lines (158 loc) · 6.26 KB
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
package rlapi
import (
"context"
)
type ChallengeID int
// Challenge represents an in-game challenge (eg, season challenges, weekly challenges, etc.)
type Challenge struct {
ID ChallengeID `json:"ID"`
Title string `json:"Title"`
Description string `json:"Description"`
Sort int `json:"Sort"`
GroupID int `json:"GroupID"`
XPUnlockLevel int `json:"XPUnlockLevel"`
IsRepeatable bool `json:"bIsRepeatable"`
RepeatLimit int `json:"RepeatLimit"`
IconURL string `json:"IconURL"`
BackgroundURL *string `json:"BackgroundURL"`
BackgroundColor int `json:"BackgroundColor"`
Requirements []ChallengeRequirement `json:"Requirements"`
Rewards ChallengeRewards `json:"Rewards"`
AutoClaimRewards bool `json:"bAutoClaimRewards"`
IsPremium bool `json:"bIsPremium"`
UnlockChallengeIDs []ChallengeID `json:"UnlockChallengeIDs"`
}
type ChallengeRequirement struct {
RequiredCount int `json:"RequiredCount"`
}
// ChallengeRewards represents rewards for completing a challenge
type ChallengeRewards struct {
XP int `json:"XP"`
Currency []interface{} `json:"Currency"`
Products []ChallengeRewardProduct `json:"Products"`
Pips int `json:"Pips"`
}
// ChallengeRewardProduct represents a product reward from a challenge
type ChallengeRewardProduct struct {
ID string `json:"ID"`
ChallengeID ChallengeID `json:"ChallengeID"`
ProductID int `json:"ProductID"`
InstanceID *string `json:"InstanceID"`
OriginalInstanceID *string `json:"OriginalInstanceID"`
Attributes []ProductAttribute `json:"Attributes"`
SeriesID int `json:"SeriesID"`
TradeHold *string `json:"TradeHold"`
AddedTimestamp *int64 `json:"AddedTimestamp"`
UpdatedTimestamp *int64 `json:"UpdatedTimestamp"`
DeletedTimestamp *int64 `json:"DeletedTimestamp"`
}
// ChallengeProgress represents a player's progress towards a challenge.
type ChallengeProgress struct {
ID ChallengeID `json:"ID"`
CompleteCount int `json:"CompleteCount"`
IsHidden bool `json:"bIsHidden"`
NotifyCompleted bool `json:"bNotifyCompleted"`
NotifyAvailable bool `json:"bNotifyAvailable"`
NotifyNewInfo bool `json:"bNotifyNewInfo"`
RewardsAvailable bool `json:"bRewardsAvailable"`
IsComplete bool `json:"bComplete"`
RequirementProgress []RequirementProgress `json:"RequirementProgress"`
ProgressResetTime int64 `json:"ProgressResetTimeUTC"`
}
type RequirementProgress struct {
ProgressCount int `json:"ProgressCount"`
ProgressChange int `json:"ProgressChange"`
}
type GetActiveChallengesRequest struct {
Challenges []interface{} `json:"Challenges"`
Folders []interface{} `json:"Folders"`
}
type GetActiveChallengesResponse struct {
Challenges []Challenge `json:"Challenges"`
}
type PlayerProgressRequest struct {
PlayerID PlayerID `json:"PlayerID"`
ChallengeIDs []ChallengeID `json:"ChallengeIDs"`
}
type PlayerProgressResponse struct {
ProgressData []ChallengeProgress `json:"ProgressData"`
}
type CollectRewardRequest struct {
PlayerID PlayerID `json:"PlayerID"`
ChallengeID ChallengeID `json:"ID"`
}
type FTECheckpointCompleteRequest struct {
PlayerID PlayerID `json:"PlayerID"`
GroupName string `json:"GroupName"`
CheckpointName string `json:"CheckpointName"`
}
type FTEGroupCompleteRequest struct {
PlayerID PlayerID `json:"PlayerID"`
GroupName string `json:"GroupName"`
}
// GetActiveChallenges retrieves the list of currently active challenges.
func (p *PsyNetRPC) GetActiveChallenges(ctx context.Context) ([]Challenge, error) {
request := GetActiveChallengesRequest{
Challenges: []interface{}{},
Folders: []interface{}{},
}
var result GetActiveChallengesResponse
err := p.sendRequestSync(ctx, "Challenges/GetActiveChallenges v1", request, &result)
if err != nil {
return nil, err
}
return result.Challenges, nil
}
// GetChallengeProgress retrieves the authenticated player's progression on challenges.
func (p *PsyNetRPC) GetChallengeProgress(ctx context.Context, challengeIDs []ChallengeID) ([]ChallengeProgress, error) {
request := PlayerProgressRequest{
PlayerID: p.localPlayerID,
ChallengeIDs: challengeIDs,
}
var result PlayerProgressResponse
err := p.sendRequestSync(ctx, "Challenges/PlayerProgress v1", request, &result)
if err != nil {
return nil, err
}
return result.ProgressData, nil
}
// CollectChallengeReward collects rewards from a completed challenge.
func (p *PsyNetRPC) CollectChallengeReward(ctx context.Context, challengeID ChallengeID) error {
request := CollectRewardRequest{
PlayerID: p.localPlayerID,
ChallengeID: challengeID,
}
var result interface{}
err := p.sendRequestSync(ctx, "Challenges/CollectReward v1", request, &result)
if err != nil {
return err
}
return nil
}
// FTECheckpointComplete marks a First Time Experience (FTE) checkpoint as complete.
func (p *PsyNetRPC) FTECheckpointComplete(ctx context.Context, groupName string, checkpointName string) error {
request := FTECheckpointCompleteRequest{
PlayerID: p.localPlayerID,
GroupName: groupName,
CheckpointName: checkpointName,
}
var result interface{}
err := p.sendRequestSync(ctx, "Challenges/FTECheckpointComplete v1", request, &result)
if err != nil {
return err
}
return nil
}
// FTEGroupComplete marks a First Time Experience (FTE) group as complete.
func (p *PsyNetRPC) FTEGroupComplete(ctx context.Context, groupName string) error {
request := FTEGroupCompleteRequest{
PlayerID: p.localPlayerID,
GroupName: groupName,
}
var result interface{}
err := p.sendRequestSync(ctx, "Challenges/FTEGroupComplete v1", request, &result)
if err != nil {
return err
}
return nil
}