dto-player.go
2.44 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
package cardholder
import (
"apigame/service-common/svconst"
"apigame/service-common/svmysql"
"apigame/util/util-lx/lxalilog"
"apigame/util/util-lx/lxtime"
"encoding/json"
"fmt"
)
// Player 卡牌活动持久数据
type Player struct {
Uid int64 `gorm:"column:uid;primaryKey;comment:玩家唯一ID"`
ActivityId int64 `gorm:"comment:活动ID"`
Details *PlayerDetails `gorm:"-"` // 详情
DetailsText string `gorm:"comment:详情封装"`
CreateTime int64 `gorm:"comment:创建时间戳"`
UpdateTime int64 `gorm:"comment:修改时间戳"`
}
func (d *Player) MysqlInfo(suffix string) *svmysql.MysqlInfo {
tableName := svconst.MYSQL_TABLE_S_CARDHOLDER_DATA
return &svmysql.MysqlInfo{
DbMysql: svconst.DbCommon,
TableName: fmt.Sprintf("%s_%s", tableName, suffix),
}
}
func NewPlayer(uid int64) *Player {
d := &Player{
Uid: uid,
Details: NewPlayerDetails(),
}
d.Encode()
return d
}
// PlayerDetails 详情
type PlayerDetails struct {
Cards map[int]int // 每张卡集了多少张 k=卡牌ID v=数量
Album map[int]int // 卡组奖励领取 k=卡组ID v=数量
StarSequenceScales map[string]int // 星级序列刻度 k=ID_用户序列_用户分组 v=刻度
CardSequenceScales map[string]int // 卡牌序列刻度 k=ID_用户序列_用户分组 v=刻度
Round int // 卡册当前轮次
StarCount int // 星星点数
LastStarCount int // 上期活动剩余星星点数
AutoExchangeHolder []int // 活动切换时自动兑换的卡包
SequenceId int // 用户序列组ID
}
func NewPlayerDetails() *PlayerDetails {
return &PlayerDetails{
Cards: make(map[int]int),
Album: make(map[int]int),
StarSequenceScales: make(map[string]int),
CardSequenceScales: make(map[string]int),
Round: 1,
StarCount: 0,
AutoExchangeHolder: make([]int, 0),
}
}
func (d *Player) Init(uid int64) {
d.Uid = uid
d.CreateTime = lxtime.NowUninx()
}
// Encode 打包数据
func (d *Player) Encode() {
details, err := json.Marshal(d.Details)
if err != nil {
lxalilog.Errors(err, "Player Encode Error", d.Uid, d.ActivityId)
return
}
d.DetailsText = string(details)
}
// Decode 分包数据
func (d *Player) Decode() {
err := json.Unmarshal([]byte(d.DetailsText), d.Details)
if err != nil {
lxalilog.Errors(err, "Player Decode Error", d.Uid, d.ActivityId)
return
}
}