package manager import "git.noahlan.cn/northlan/ntools-go/uuid" func newRoomData() *RoomData { return &RoomData{ BattleId: 0, CurrentStatus: GameInit, UserMap: make(map[int32]map[int64]User), } } func (m *RoomData) SetStatus(status GameStatus) { if status == GameStarted { m.startGame() } else if status == GameEnded { m.endGame() } m.CurrentStatus = status } func (m *RoomData) UserJoin(user User) { tm, ok := m.UserMap[user.Team] if !ok { tm = make(map[int64]User) m.UserMap[user.Team] = tm } tm[user.ID] = user } func (m *RoomData) UserLeave(userId int64) { for _, tm := range m.UserMap { if _, ok := tm[userId]; ok { delete(tm, userId) } } } func (m *RoomData) GetUser(userId int64) (*User, bool) { for _, tm := range m.UserMap { if u, ok := tm[userId]; ok { return &u, true } } return nil, false } func (m *RoomData) startGame() { m.BattleId = uuid.NextId() m.UserMap = make(map[int32]map[int64]User) } func (m *RoomData) endGame() { m.BattleId = 0 m.UserMap = make(map[int32]map[int64]User) }