You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.0 KiB
Go

package manager
import (
"git.noahlan.cn/northlan/ngs/session"
"git.noahlan.cn/northlan/ntools-go/uuid"
)
type GameStatus int32
const (
GameStarted GameStatus = iota + 1 // 游戏已经开始
GameEnded // 游戏已结束
)
type DataFilter func(session *session.Session, data *Data) bool
// Data is Session data
type Data struct {
liveRoomId int64 // Session 对应 直播间ID
battleId int64 // 战局ID
currentStatus GameStatus // 当前战局状态
}
func NewGameData(liveRoomId int64) *Data {
return &Data{
liveRoomId: liveRoomId,
currentStatus: GameEnded,
}
}
func (m *Data) LiveRoomId() int64 {
return m.liveRoomId
}
func (m *Data) BattleId() int64 {
return m.battleId
}
func (m *Data) CurrentStatus() GameStatus {
return m.currentStatus
}
func (m *Data) SetStatus(status GameStatus) GameStatus {
m.currentStatus = status
if status == GameStarted {
m.battleId = uuid.NextId()
} else if status == GameEnded {
m.battleId = 0
}
return m.currentStatus
}