66 lines
1.2 KiB
Go
66 lines
1.2 KiB
Go
![]() |
package player
|
||
|
|
||
|
import (
|
||
|
"samba/stub"
|
||
|
"samba/util/eternal"
|
||
|
"samba/util/model"
|
||
|
)
|
||
|
|
||
|
type Player struct {
|
||
|
*model.UserInfo
|
||
|
LuckyPoint *model.UserLuckyPoint
|
||
|
Continue GameContinue // 继续
|
||
|
Robot IRobot
|
||
|
// 子游戏 游戏次数
|
||
|
gameCounts map[string]int64
|
||
|
}
|
||
|
|
||
|
func (p *Player) IsRobot() bool {
|
||
|
return p.UType == eternal.RobotType
|
||
|
}
|
||
|
|
||
|
func (p *Player) IsHosting() bool {
|
||
|
if p.Robot != nil && p.Robot.Cnf() == stub.RteHosting {
|
||
|
return true
|
||
|
}
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
func (p *Player) CleanRobot() {
|
||
|
if p.Robot != nil {
|
||
|
p.Robot.Clean()
|
||
|
}
|
||
|
p.Robot = nil
|
||
|
}
|
||
|
|
||
|
func (p *Player) Load() error {
|
||
|
userInfo, err := model.NewUserInfoOp().LoadFromRedis(p.UID)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
p.UserInfo = userInfo
|
||
|
lucky, err := model.NewUserLuckyPointOp().Load(p.UID)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
p.LuckyPoint = lucky
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
// GetPlayCount 获取玩家总共游戏次数,name为子游戏名称
|
||
|
func (p *Player) GetPlayCount(name string) (int64, error) {
|
||
|
if p.gameCounts == nil {
|
||
|
p.gameCounts = make(map[string]int64)
|
||
|
}
|
||
|
if count, ok := p.gameCounts[name]; ok {
|
||
|
return count, nil
|
||
|
}
|
||
|
count, err := model.NewUserMstatOp().GetUserGameCount(p.UID, name)
|
||
|
if err != nil {
|
||
|
return count, err
|
||
|
}
|
||
|
p.gameCounts[name] = count
|
||
|
return count, nil
|
||
|
|
||
|
}
|