decode.go
4.98 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
package confcardholder
import (
"apigame/util/util-lx/lxalilog"
"apigame/util/zslice"
"encoding/json"
"errors"
"fmt"
)
// Decode 解析配置原始数据
func (c *ActivityConfig) Decode(gameId string, rawData any) {
raw := rawData.(*ActivityConfigRaw)
c.GameId = gameId
c.Raw = raw
c.Id = raw.Id
c.OpenLevel = raw.OpenLevel
c.PreviewTime = raw.PreviewTime
c.StartTime = raw.StartTime
c.EndTime = raw.EndTime
c.Round = raw.Round
c.IconPath = raw.IconPath
c.Awards = make(map[string]string)
c.AlbumConfig = make(map[int]AlbumConfig)
c.CardConfig = make(map[int]CardConfig)
c.CardholderConfig = make(map[int]OpenCardholderConfig)
c.NormalCardStarConfig = make(map[string]NormalCardStarConfig)
c.CardSequenceConfig = make(map[string]CardSequenceConfig)
c.StarShopConfig = make(map[int]StarShopConfig)
// 解析奖励
{
err := json.Unmarshal([]byte(raw.Awards), &c.Awards)
if err != nil {
lxalilog.Errors(err, raw.Awards, gameId, raw.Id)
return
}
}
// 卡组配置
{
configs := make([]AlbumConfig, 0)
err := json.Unmarshal([]byte(raw.AlbumConfig), &configs)
if err != nil {
lxalilog.Errors(err, raw.AlbumConfig, gameId, raw.Id)
return
}
for _, i2 := range configs {
c.AlbumConfig[i2.SetId] = i2
}
}
// 卡牌配置
{
configs := make([]CardConfig, 0)
err := json.Unmarshal([]byte(raw.CardConfig), &configs)
if err != nil {
lxalilog.Errors(err, raw.CardConfig, gameId, raw.Id)
return
}
for _, i2 := range configs {
c.CardConfig[i2.Id] = i2
}
}
// 卡包开卡规则
{
configs := make([]OpenCardholderConfig, 0)
err := json.Unmarshal([]byte(raw.CardHolderConfig), &configs)
if err != nil {
lxalilog.Errors(err, raw.CardHolderConfig, gameId, raw.Id)
return
}
for _, i2 := range configs {
c.CardholderConfig[i2.Id] = i2
}
}
// 卡片星级配置
{
configs := make([]NormalCardStarConfig, 0)
err := json.Unmarshal([]byte(raw.NormalCardStarSequence), &configs)
if err != nil {
lxalilog.Errors(err, raw.NormalCardStarSequence, gameId, raw.Id)
return
}
for _, i2 := range configs {
combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort)
c.NormalCardStarConfig[combineId] = i2
if !zslice.Contains(c.ListSequenceId, i2.SequenceId) {
c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId)
}
}
}
// 卡片星级对应卡牌配置
{
configs := make([]CardSequenceConfig, 0)
err := json.Unmarshal([]byte(raw.CardSequenceConfig), &configs)
if err != nil {
lxalilog.Errors(err, raw.CardSequenceConfig, gameId, raw.Id)
return
}
for _, i2 := range configs {
combineId := CombineIdSequenceIdCohort(i2.Id, i2.SequenceId, i2.Cohort)
c.CardSequenceConfig[combineId] = i2
if !zslice.Contains(c.ListSequenceId, i2.SequenceId) {
c.ListSequenceId = append(c.ListSequenceId, i2.SequenceId)
}
}
}
// 星星商店配置
{
configs := make([]StarShopConfig, 0)
err := json.Unmarshal([]byte(raw.StarShopConfig), &configs)
if err != nil {
lxalilog.Errors(err, raw.StarShopConfig, gameId, raw.Id)
return
}
for _, i2 := range configs {
c.StarShopConfig[i2.Id] = i2
}
}
c.GenerateConfigClient()
}
// GenerateConfigClient 生成给客户端的配置
func (c *ActivityConfig) GenerateConfigClient() {
configClient := &ActivityConfigClient{
Id: c.Id,
Round: c.Round,
IconPath: c.IconPath,
RoundAwards: c.Awards,
Albums: make([]AlbumConfig, 0),
Cards: make([]CardConfig, 0),
Holders: make([]OpenCardholderConfig, 0),
StarShop: make([]StarShopConfig, 0),
}
for _, i2 := range c.AlbumConfig {
configClient.Albums = append(configClient.Albums, i2)
}
for _, i2 := range c.CardConfig {
configClient.Cards = append(configClient.Cards, i2)
}
for _, i2 := range c.CardholderConfig {
configClient.Holders = append(configClient.Holders, i2)
}
for _, i2 := range c.StarShopConfig {
configClient.StarShop = append(configClient.StarShop, i2)
}
c.Client = configClient
}
// CombineIdSequenceIdCohort 组合ID k=ID_用户序列_用户分组
func CombineIdSequenceIdCohort(id, sequenceId, cohort int) string {
return fmt.Sprintf("%d_%d_%d", id, sequenceId, cohort)
}
// FindNormalCardStarConfig 查找配置 非保底卡星级ID
func (c *ActivityConfig) FindNormalCardStarConfig(id, sequenceId, cohort int) (conf NormalCardStarConfig, has bool) {
combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort)
conf, has = c.NormalCardStarConfig[combineId]
if !has {
lxalilog.Errors(errors.New("ht_cardholder NormalCardStarConfig error"), id, sequenceId, cohort)
}
return
}
// FindCardSequenceConfig 查找配置 星级ID对应的卡片
func (c *ActivityConfig) FindCardSequenceConfig(id, sequenceId, cohort int) (conf CardSequenceConfig, has bool) {
combineId := CombineIdSequenceIdCohort(id, sequenceId, cohort)
conf, has = c.CardSequenceConfig[combineId]
if !has {
lxalilog.Errors(errors.New("ht_cardholder CardSequenceConfig error"), id, sequenceId, cohort)
fmt.Println(id)
fmt.Println(sequenceId)
fmt.Println(cohort)
}
return
}