package room import ( "math/rand" "samba/pkg/log" "samba/proto" "samba/server/game/baseroom" "samba/server/truco/poker" "samba/stub" "samba/util/model" "samba/util/util" "time" ) type RobotNormal struct { *BaseRobot } func NewRobotNormal(cnf stub.RobotTemper, userInfo *model.UserInfo, seat *TrucoSeat, room *TrucoRoom) *RobotNormal { return &RobotNormal{ BaseRobot: NewBaseRobot(cnf, userInfo, seat, room), } } func (r *RobotNormal) OnMessage(msgId string, iMsg interface{}) { switch msgId { case proto.RspEnterRoomId: r.NewTimer(baseroom.TtEnterRoom, time.Second*time.Duration(RobotOnMsgTime), func() { r.sendReady(r.room) }) case proto.NtfDealPokersId: r.sortPokers() msg := iMsg.(*proto.NtfDealPokers) if util.RandHappened(50) { break } r.NewSecretEmoteTimer(time.Second*time.Duration(rand.Int()%2+RobotOnMsgTime+3), func() { r.sendSecretEmote(r.room, msg) }) case proto.NtfDecidingGameId: msg := iMsg.(*proto.NtfDecidingGame) if TeamColor(msg.TeamColor) == r.room.teamColor(r.seat.No()) { r.NewTimer(baseroom.TtDecidingGame, time.Second*time.Duration(rand.Int()%RobotOnMsgRandTime+RobotOnMsgTime), func() { r.onDecidingAct(r.room, msg) }) } case proto.NtfPlayerActId: msg := iMsg.(*proto.NtfPlayerAct) if msg.Seat == r.seat.No() { r.NewTimer(baseroom.TtPlayerAct, time.Second*time.Duration(rand.Int()%RobotOnMsgRandTime+RobotOnMsgTime), func() { r.onPlayerAct(r.room, msg) }) } case proto.NtfPlayerRspRaiseId: msg := iMsg.(*proto.NtfPlayerRspRaise) if TeamColor(msg.TeamColor) != r.room.teamColor(r.seat.No()) { return } r.NewTimer(baseroom.TtPlayerRspRaise, time.Second*time.Duration(rand.Int()%RobotOnMsgRandTime+RobotOnMsgTime), func() { r.onRspRaise(r.room, msg) }) case proto.NtfEmoteId: r.onEmote(iMsg.(*proto.NtfEmote)) case proto.NtfUserDisbandRoomId: msg := iMsg.(*proto.NtfUserDisbandRoom) if len(msg.Agree) == r.room.SeatPlayerNum() { r.GameClean() } //case proto.NtfRoundSettleId: case proto.NtfGameSettleId, proto.NtfMaintainId: r.GameClean() } } func (r *RobotNormal) outPokerRound(room *TrucoRoom, _ interface{}) { var outPoker *poker.Poker pos := r.positionInOutPoker(room) if pos == 0 { outPoker = r.outMaxPoker(room) } else { if bigger, _ := r.teammateBigger(room); bigger { outPoker = r.outMinPoker(room) } else { if r.canBigger(room) { outPoker = r.outMaxPoker(room) } else { outPoker = r.outMinPoker(room) } } } if outPoker != nil { req := &proto.ReqPlayerOutPoker{Poker: outPoker.ToInt()} msg := util.MakeMessage(proto.ReqPlayerOutPokerId, req, r.UID, room.Id()) room.OnMessage(proto.ReqPlayerOutPokerId, msg) } else { log.Error(r.room.SeatLog(r.seat, "ai error")) } } func (r *RobotNormal) outPokerRound3(room *TrucoRoom, _ interface{}) { if len(r.seat.Pokers) > 0 { req := &proto.ReqPlayerOutPoker{Poker: r.seat.Pokers[0].ToInt()} msg := util.MakeMessage(proto.ReqPlayerOutPokerId, req, r.UID, room.Id()) room.OnMessage(proto.ReqPlayerOutPokerId, msg) } else { log.Error(r.room.SeatLog(r.seat, "ai error")) } } func (r *RobotNormal) outPoker(room *TrucoRoom, msg interface{}) { if r.getRound() < 2 { r.outPokerRound(room, msg) } else { r.outPokerRound3(room, msg) } } func (r *RobotNormal) onPlayerAct(room *TrucoRoom, msg *proto.NtfPlayerAct) { colorNum := 0 if r.canRaise(msg) { for _, pk := range r.seat.Pokers { colorNum += util.Tie(room.isBigPoker(pk), 1, 0) } } if r.canRaise(msg) && colorNum >= stub.GGlobalAI.TrucoNormalRaise { r.sendRaise(room, IntToActType(msg.CanCall), true) } else { r.outPoker(room, msg) } } func (r *RobotNormal) onRspRaise(room *TrucoRoom, _ *proto.NtfPlayerRspRaise) { colorNum := 0 for _, pk := range r.seat.Pokers { colorNum += util.Tie(room.isBigPoker(pk), 1, 0) } if colorNum >= stub.GGlobalAI.TrucoNormalRaise { r.sendRaise(room, AtAgree, false) } else { r.sendRaise(room, AtGiveUp, false) } } // 发牌时发暗号 func (r *RobotNormal) onEmoji(room *TrucoRoom, _ interface{}) { if !room.IsMVM() { return } } func (r *RobotNormal) onDecidingAct(room *TrucoRoom, _ *proto.NtfDecidingGame) { colorNum := r.bigPokerNumForTeam(room, 4) if colorNum >= stub.GGlobalAI.TrucoAplombRaise1 { r.sendRaise(room, AtAgree, true) } else { r.sendRaise(room, AtGiveUp, true) } }