83 lines
2.0 KiB
Go
83 lines
2.0 KiB
Go
package room
|
||
|
||
import (
|
||
"fmt"
|
||
"samba/pkg/log"
|
||
"samba/pkg/xtime"
|
||
"samba/server/game/baseroom"
|
||
"samba/server/game/player"
|
||
"samba/server/truco/service"
|
||
"samba/stub"
|
||
"samba/util/config"
|
||
"samba/util/model"
|
||
"time"
|
||
)
|
||
|
||
type ClubMatchQueue struct{}
|
||
|
||
func (q ClubMatchQueue) Matching() {
|
||
if config.Cmd.IsClub <= 0 {
|
||
return
|
||
}
|
||
p := model.NewRobotScorePoolOp().Load()
|
||
if !xtime.IsTodayTimestamp(p.Time) {
|
||
// 非今天,重置分数池
|
||
model.NewRobotScorePoolOp().Reset()
|
||
*p = model.RobotScorePool{}
|
||
}
|
||
if p.Score <= -2000 {
|
||
// 总AI输了超过2000分,不配置AI
|
||
service.TrucoService.NewTimer(2*time.Second, q.Matching, false, "ClubMatchQueue.Matching")
|
||
return
|
||
}
|
||
|
||
waitRooms := baseroom.RoomMgr.FindWaitRooms()
|
||
now := time.Now()
|
||
clubRobotMap := map[int]bool{}
|
||
for _, ir := range waitRooms {
|
||
if ir.ClubId() <= 0 {
|
||
continue
|
||
}
|
||
|
||
room := ir.(*TrucoRoom)
|
||
|
||
hasRobot, ok := clubRobotMap[ir.ClubId()]
|
||
if !ok {
|
||
info, err := model.NewClubInfoOp().Load(ir.ClubId())
|
||
if err != nil {
|
||
log.Error(fmt.Sprintf("failed to load club info %s", err))
|
||
continue
|
||
}
|
||
hasRobot = info.HasRobot()
|
||
clubRobotMap[ir.ClubId()] = hasRobot
|
||
}
|
||
|
||
if t := room.LatestSeatedTime(); t.IsZero() || now.Sub(t) < 90*time.Second || !hasRobot {
|
||
// 尚未到超时时间,或俱乐部在机器人投放白名单外
|
||
continue
|
||
}
|
||
|
||
var playerNum, robotNum int
|
||
for _, seat := range room.Seats {
|
||
if seat.Player() != nil {
|
||
playerNum++
|
||
if seat.Player().IsRobot() {
|
||
robotNum++
|
||
}
|
||
}
|
||
}
|
||
|
||
// 匹配机器人
|
||
robotConfig := stub.FindClubRobotConfig(room.RoomCnf.Blind, room.RoomCnf.PlayType)
|
||
if playerNum < room.RoomCnf.MinPlayers && robotNum < robotConfig.RobotNum {
|
||
if user := player.ClubRobotMgr.Pop(robotConfig, room.ClubId()); user != nil {
|
||
room.OnEnterRoom(user)
|
||
} else {
|
||
log.Warn(fmt.Sprintf("clubId %d has not robot", room.ClubId()))
|
||
}
|
||
}
|
||
|
||
}
|
||
service.TrucoService.NewTimer(2*time.Second, q.Matching, false, "ClubMatchQueue.Matching")
|
||
}
|