81 lines
1.5 KiB
Go
81 lines
1.5 KiB
Go
![]() |
package room
|
||
|
|
||
|
import (
|
||
|
. "samba/server/game/player"
|
||
|
"samba/stub"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type MatchPlayer struct {
|
||
|
*Player
|
||
|
Weight int // 玩家权重,用于座位排序
|
||
|
}
|
||
|
|
||
|
type MatchRoom struct {
|
||
|
id int
|
||
|
cnf *stub.Room
|
||
|
player []*MatchPlayer
|
||
|
tm time.Time
|
||
|
playerWeight int // 玩家初始权重
|
||
|
robotWeight int // 机器人初始权重
|
||
|
|
||
|
onlyMatchRobot bool // 是否只匹配机器人
|
||
|
}
|
||
|
|
||
|
func NewMatchRoom(no int, cnf *stub.Room) *MatchRoom {
|
||
|
return &MatchRoom{id: no, cnf: cnf, player: nil, tm: time.Now(), playerWeight: 100, robotWeight: 1000}
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) SetOnlyMatchRobot() {
|
||
|
m.onlyMatchRobot = true
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) OnlyMatchRobot() bool {
|
||
|
return m.onlyMatchRobot
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) Cnf() *stub.Room {
|
||
|
return m.cnf
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) Type() int {
|
||
|
return m.cnf.Id
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) Id() int {
|
||
|
return m.id
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) RealPlayers() []*MatchPlayer {
|
||
|
var players []*MatchPlayer
|
||
|
for _, player := range m.player {
|
||
|
if !player.IsRobot() {
|
||
|
players = append(players, player)
|
||
|
}
|
||
|
}
|
||
|
return players
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) Players() []*MatchPlayer {
|
||
|
return m.player
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) AddPlayer(user *Player) []*MatchPlayer {
|
||
|
m.player = append(m.player, &MatchPlayer{Player: user})
|
||
|
return m.player
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) RemovePlayer(uid int64) []*MatchPlayer {
|
||
|
for i, p := range m.player {
|
||
|
if p.UID == uid {
|
||
|
m.player = append(m.player[:i], m.player[i+1:]...)
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
return m.player
|
||
|
}
|
||
|
|
||
|
func (m *MatchRoom) Is2V2() bool {
|
||
|
return m.cnf.MinPlayers == 4
|
||
|
}
|