-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproducts.go
More file actions
133 lines (112 loc) · 3.8 KB
/
products.go
File metadata and controls
133 lines (112 loc) · 3.8 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
package rlapi
import (
"context"
"strconv"
)
type ContainerDrop struct {
ProductID int `json:"ProductID"`
SeriesID int `json:"SeriesID"`
Drops []Product `json:"Drops"`
}
// UnlockResult represents the result of unlocking a container
type UnlockResult struct {
UnlockedItems []Product `json:"UnlockedItems"`
UsedKeys []string `json:"UsedKeys"`
RemainingKeys []Product `json:"RemainingKeys"`
}
// TradeInResult represents the result of trading in items
type TradeInResult struct {
ReceivedItems []Product `json:"ReceivedItems"`
TradedItems []string `json:"TradedItems"`
}
// CrossEntitlementStatus represents cross-platform entitlement status
type CrossEntitlementStatus struct {
CrossEntitledProductIDs []int `json:"CrossEntitledProductIDs"`
LockedProductIDs []int `json:"LockedProductIDs"`
}
type GetPlayerProductsRequest struct {
PlayerID PlayerID `json:"PlayerID"`
UpdatedTimestamp string `json:"UpdatedTimestamp"`
}
type GetPlayerProductsResponse struct {
ProductData []Product `json:"ProductData"`
}
type GetContainerDropTableResponse struct {
ContainerDrops []ContainerDrop `json:"ContainerDrops"`
}
type UnlockContainerRequest struct {
PlayerID PlayerID `json:"PlayerID"`
InstanceIDs []string `json:"InstanceIDs"`
KeyInstanceIDs []string `json:"KeyInstanceIDs"`
}
type UnlockContainerResponse struct {
Drops []Product `json:"Drops"`
}
type TradeInRequest struct {
PlayerID PlayerID `json:"PlayerID"`
ProductInstances []string `json:"ProductInstances"`
}
type TradeInResponse struct {
Drops []Product `json:"Drops"`
}
type GetProductStatusResponse struct {
CrossEntitledProductIDs []int `json:"CrossEntitledProductIDs"`
LockedProductIDs []interface{} `json:"LockedProductIDs"`
}
// GetPlayerProducts retrieves all products/items owned by the authenticated player.
func (p *PsyNetRPC) GetPlayerProducts(ctx context.Context, updatedTimestamp int) ([]Product, error) {
request := GetPlayerProductsRequest{
PlayerID: p.localPlayerID,
UpdatedTimestamp: strconv.Itoa(updatedTimestamp),
}
var result GetPlayerProductsResponse
err := p.sendRequestSync(ctx, "Products/GetPlayerProducts v2", request, &result)
if err != nil {
return nil, err
}
return result.ProductData, nil
}
// GetContainerDropTable retrieves the drop table for containers.
func (p *PsyNetRPC) GetContainerDropTable(ctx context.Context) ([]ContainerDrop, error) {
var result GetContainerDropTableResponse
err := p.sendRequestSync(ctx, "Products/GetContainerDropTable v2", emptyRequest{}, &result)
if err != nil {
return nil, err
}
return result.ContainerDrops, nil
}
// UnlockContainer unlocks containers returns the dropped items.
func (p *PsyNetRPC) UnlockContainer(ctx context.Context, instanceIDs []string) ([]Product, error) {
request := UnlockContainerRequest{
PlayerID: p.localPlayerID,
InstanceIDs: instanceIDs,
KeyInstanceIDs: []string{},
}
var result UnlockContainerResponse
err := p.sendRequestSync(ctx, "Products/UnlockContainer v2", request, &result)
if err != nil {
return nil, err
}
return result.Drops, nil
}
// TradeIn trades in multiple items for new items.
func (p *PsyNetRPC) TradeIn(ctx context.Context, productInstances []string) ([]Product, error) {
request := TradeInRequest{
PlayerID: p.localPlayerID,
ProductInstances: productInstances,
}
var result TradeInResponse
err := p.sendRequestSync(ctx, "Products/TradeIn v2", request, &result)
if err != nil {
return nil, err
}
return result.Drops, nil
}
func (p *PsyNetRPC) GetCrossEntitlementProductStatus(ctx context.Context) (*GetProductStatusResponse, error) {
var result GetProductStatusResponse
err := p.sendRequestSync(ctx, "Products/CrossEntitlement/GetProductStatus v1", emptyRequest{}, &result)
if err != nil {
return nil, err
}
return &result, nil
}