-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifestActivities.go
161 lines (138 loc) · 4.06 KB
/
manifestActivities.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
package goBungieNet
import (
"encoding/json"
"errors"
"fmt"
"time"
)
type DestinyActivityReward struct {
Text string `json:rewardText`
Items []DestinyItemQuantity `json:rewardItems`
}
type DestinyActivityModifier struct {
ActivityModifierHash uint32
}
type DestinyActivityChallenges struct {
ObjectiveHash uint32
}
type DestinyActivityUnlockString struct {
DisplayString string
}
type DestinyActivityPlaylistItem struct {
ActivityHash uint32
DirectActivityModeHash uint32
DirectActivityModeType DestinyActivityMode
ActivityModeHashes []uint32
ActivityModeTypes []DestinyActivityMode
}
type DestinyActivityMatchmaking struct {
IsMatchmade bool
MinParty int32
MaxParty int32
MaxPlayers int32
RequiresGuardianOath bool
}
type DestinyActivityGuided struct {
MaxLobbySize int32 `json:"guidedMaxLobbySize"`
MinLobbySize int32 `json:"guidedMinLobbySize"`
DisbandCount int32 `json:"guidedDisbandCount"`
}
type DestinyActivity struct {
ActivityLevel int32
ActivityLightLevel int32
ActivityTypeHash uint32
ActivityModeHashes []uint32
ActivityModeTypes []DestinyActivityMode
Challenges []DestinyActivityChallenges
DisplayProperties DestinyDisplayProperties
DestinationHash uint32
DirectActivityModeHash uint32
DirectActivityModeType DestinyActivityMode
GuidedGame DestinyActivityGuided
Matchmaking DestinyActivityMatchmaking
Modifiers []DestinyActivityModifier
OptionalUnlockStrings []DestinyActivityUnlockString
PCGRImage string
PlaceHash uint32
IsPlaylist bool
IsPVP bool
PlaylistItems []DestinyActivityPlaylistItem
ReleaseIcon string
ReleaseTimeEpoch int32 `json:"releaseTime"`
ReleaseTime time.Time `json:"-"`
Rewards []DestinyActivityReward
Redacted bool
Tier int32
}
func manifestActivityDefinition(languageCode string, activityHash uint32) (*DestinyActivity, error) {
dataFile := fmt.Sprintf("%s-%s", manifestWorld, languageCode)
db, err := manifestOpenData(dataFile)
if err != nil {
return nil, err
}
rows, err := db.Query("SELECT json FROM DestinyActivityDefinition WHERE id = $1", int32(activityHash))
if err != nil {
return nil, err
}
defer rows.Close()
if !rows.Next() {
return nil, errors.New("No Results!")
}
var jsonData string
err = rows.Scan(&jsonData)
if err != nil {
return nil, err
}
result := DestinyActivity{}
err = json.Unmarshal([]byte(jsonData), &result)
if err != nil {
return nil, err
}
result.ReleaseTime = time.Unix(int64(result.ReleaseTimeEpoch), 0)
return &result, nil
}
func (base *DestinyMilestoneActivity) Definition(languageCode string) (*DestinyActivity, error) {
return manifestActivityDefinition(languageCode, base.ActivityHash)
}
func (base *CharacterActivities) ActivityDefinition(languageCode string) (*DestinyActivity, error) {
return manifestActivityDefinition(languageCode, base.CurrentActivityHash)
}
func ActivityDefinitions(languageCode string, hashes []uint32) (*[]DestinyActivity, error) {
dataFile := fmt.Sprintf("%s-%s", manifestWorld, languageCode)
db, err := manifestOpenData(dataFile)
if err != nil {
return nil, err
}
params := make([]interface{}, len(hashes))
queryStr := "SELECT json FROM DestinyActivityDefinition WHERE id IN ("
for index, hash := range hashes {
params[index] = int32(hash)
if index+1 < len(hashes) {
queryStr += "?,"
} else {
queryStr += "?"
}
}
queryStr += ")"
rows, err := db.Query(queryStr, params...)
if err != nil {
return nil, err
}
defer rows.Close()
var defns []DestinyActivity
for rows.Next() {
var jsonData string
err = rows.Scan(&jsonData)
if err != nil {
return &defns, err
}
result := DestinyActivity{}
err = json.Unmarshal([]byte(jsonData), &result)
if err != nil {
return &defns, err
}
result.ReleaseTime = time.Unix(int64(result.ReleaseTimeEpoch), 0)
defns = append(defns, result)
}
return &defns, nil
}