68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package room
|
|
|
|
import (
|
|
"samba/proto"
|
|
"samba/server/game/baseroom"
|
|
"samba/server/game/player"
|
|
"samba/stub"
|
|
"samba/util/util"
|
|
"time"
|
|
)
|
|
|
|
var _ player.IRobot = (*RobotHosting)(nil)
|
|
|
|
type RobotHosting struct {
|
|
*BaseRobot
|
|
}
|
|
|
|
func NewRobotHosting(room *TrucoRoom, seat *TrucoSeat) *RobotHosting {
|
|
return &RobotHosting{
|
|
BaseRobot: NewBaseRobot(stub.RteHosting, seat.Player().UserInfo, seat, room),
|
|
}
|
|
}
|
|
|
|
func (r *RobotHosting) OnMessage(msgId string, msg interface{}) {
|
|
switch msgId {
|
|
|
|
case proto.NtfDecidingGameId:
|
|
if TeamColor(msg.(*proto.NtfDecidingGame).TeamColor) == r.room.teamColor(r.seat.No()) {
|
|
r.deferDo(baseroom.TtDecidingGame, r.room.AutoDecidingAct)
|
|
}
|
|
|
|
case proto.NtfPlayerActId:
|
|
if msg.(*proto.NtfPlayerAct).Seat == r.seat.No() {
|
|
r.deferDo(baseroom.TtPlayerAct, func() {
|
|
r.room.AutoPlayerOutPoker()
|
|
})
|
|
}
|
|
|
|
case proto.NtfPlayerRspRaiseId:
|
|
if TeamColor(msg.(*proto.NtfPlayerRspRaise).TeamColor) == r.room.teamColor(r.seat.No()) {
|
|
r.deferDo(baseroom.TtPlayerRspRaise, func() {
|
|
r.room.AutoPlayerRspRaise(TeamColor(msg.(*proto.NtfPlayerRspRaise).TeamColor))
|
|
})
|
|
}
|
|
case proto.NtfUserDisbandRoomId:
|
|
ntf := msg.(*proto.NtfUserDisbandRoom)
|
|
if ntf.Type == 1 || len(ntf.Agree) == r.room.SeatPlayerNum() {
|
|
// ntf.Type==1 管理员强制解散
|
|
r.GameClean()
|
|
}
|
|
case proto.NtfGameSettleId, proto.NtfMaintainId:
|
|
r.GameClean()
|
|
}
|
|
}
|
|
|
|
func (r *RobotHosting) Cnf() stub.RobotTemper {
|
|
return stub.RteHosting
|
|
}
|
|
|
|
func (r *RobotHosting) deferDo(typ baseroom.TimerType, f func()) {
|
|
// 随机延时2-4秒
|
|
sec := util.RandSecond(2, 4)
|
|
if r.getRound() == 0 {
|
|
sec += 2 * time.Second
|
|
}
|
|
r.NewTimer(typ, sec, f)
|
|
}
|