Gogs há 4 meses atrás
pai
commit
e7eac13920

+ 1 - 0
bin/client_msg/common.proto

@@ -108,6 +108,7 @@ enum PlayerOptType {
     OPT_BIND         = 4;  // 绑定
     OPT_SELECT      = 5;  // 选择操作
     OPT_SHOW         = 6;  // 亮牌
+    OPT_ANTE         = 7;  // 底注
 }
 
 message PlayerOpt {

+ 3 - 1
src/server/game/room/room.go

@@ -21,6 +21,7 @@ const (
 	RoomStatusWaiting = 0 // 等待开局
 	RoomStatusDealing = 1 // 发牌中
 	RoomStatusPlaying = 2 // 游戏进行中
+	RoomStatusEnd     = 3 // 游戏结束
 )
 
 type Room struct {
@@ -205,7 +206,7 @@ func (r *Room) SetNextRound() {
 		}
 	}
 	r.RoundSitPos = int(r.Players[nextIndex].SitPos)
-	log.Debug("下一个操作的玩家座位:%d", r.RoundSitPos)
+	log.Debug("SetNextRound:下一个操作的玩家座位:%d", r.RoundSitPos)
 }
 
 // 获取没有弃牌的玩家是否只有一个,并返回没有弃牌的座位号
@@ -225,6 +226,7 @@ func (r *Room) IsOnlyOneNotPacked() (bool, int32) {
 func (r *Room) PlayerWin(sitPos int32) {
 	player := r.GetPlayerBySitPos(sitPos)
 	player.IsWin = true
+	r.Status = RoomStatusEnd
 }
 
 // 增加押注

+ 27 - 5
src/server/game/teen/opt.go

@@ -15,7 +15,13 @@ func seen(room *room.Room, sitPos int32) {
 	log.Debug("看牌的位置: %d", room.RoundSitPos)
 	player := room.GetPlayerBySitPos(sitPos)
 	player.IsSeen = true
-	seenCards := *room.GetPlayerBySitPos(sitPos).HandCards
+	var seenCards []msg.ReqCard
+	//如果是机器人返回空的看牌
+	if player.IsRobot {
+		seenCards = make([]msg.ReqCard, 0)
+	} else {
+		seenCards = *room.GetPlayerBySitPos(sitPos).HandCards
+	}
 	SendRoundMsgToAll(room, &msg.ReqRound{
 		Round:       int32(room.Round),
 		RoundSitPos: int32(sitPos),
@@ -31,6 +37,7 @@ func packed(room *room.Room, sitPos int32) {
 	if isOnlyOne, sp := room.IsOnlyOneNotPacked(); isOnlyOne {
 		// 如果所有玩家都弃牌,判定当前座位玩家获胜
 		room.PlayerWin(sp)
+		sendResult(room, sp)
 	}
 	room.SetNextRound()
 	log.Debug("弃牌的位置: %d", room.RoundSitPos)
@@ -59,6 +66,17 @@ func chaal(room *room.Room, sitPos int32, betAmount int32) {
 	})
 }
 
+// 底注
+func ante(room *room.Room, sitPos int32, betAmount int32) {
+	room.AddBet(betAmount)
+	SendRoundMsgToAll(room, &msg.ReqRound{
+		Round:       int32(room.Round),
+		RoundSitPos: int32(sitPos),
+		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_ANTE},
+		UserId:      room.GetPlayerBySitPos(sitPos).GetUserId(),
+	})
+}
+
 // 亮牌
 func show(room *room.Room, sitPos int32) {
 	room.SetNextRound()
@@ -78,8 +96,12 @@ func cancelOptTimeout(player *room.Player, sitPos int32) {
 
 // 房间状态检测
 func checkRoomStatus(r *room.Room) {
-	log.Debug("下一个操作的玩家座位:%d", r.RoundSitPos)
-	game.Module.Skeleton.AfterFunc(time.Second*1, func() {
-		notifyPlayerAction(r, int32(r.RoundSitPos), msg.PlayerOptType_OPT_SELECT)
-	})
+	if r.Status == room.RoomStatusEnd {
+	} else {
+		log.Debug("checkRoomStatus:下一个操作的玩家座位:%d", r.RoundSitPos)
+		game.Module.Skeleton.AfterFunc(time.Second*1, func() {
+			notifyPlayerAction(r, int32(r.RoundSitPos), msg.PlayerOptType_OPT_SELECT)
+		})
+	}
+
 }

+ 24 - 5
src/server/game/teen/robot.go

@@ -7,6 +7,7 @@ import (
 	"server/game"
 	"server/game/room"
 	"server/msg"
+	"sync"
 	"time"
 
 	"github.com/name5566/leaf/log"
@@ -52,7 +53,7 @@ func randomIndianHeadImage() string {
 // 人机操作
 func robotOpt(r *room.Room, sitPos int32, optType msg.PlayerOptType) {
 	if optType == msg.PlayerOptType_OPT_SELECT {
-		robotSelect(r, sitPos)
+		go robotSelect(r, sitPos)
 	}
 	// switch optType {
 	// case msg.PlayerOptType_OPT_SELECT:
@@ -68,10 +69,24 @@ func robotOpt(r *room.Room, sitPos int32, optType msg.PlayerOptType) {
 
 func robotSelect(r *room.Room, sitPos int32) {
 	log.Debug("robotSelect, sitPos: %d", sitPos)
-	game.Module.Skeleton.AfterFunc(time.Second*1, func() {
-		robotChaal(r, sitPos)
-	})
-
+	wg := sync.WaitGroup{}
+	wg.Add(1)
+	go func() {
+		time.Sleep(time.Second * 1)
+		randTime := rand.Intn(2) + 1
+		if randTime == 1 {
+			isSeen := r.GetPlayerBySitPos(sitPos).IsSeen
+			log.Debug("isSeen: %v", isSeen)
+			if !isSeen {
+				robotSeen(r, sitPos)
+			}
+		}
+		wg.Done()
+	}()
+
+	wg.Wait()
+	log.Debug("robotChaal, sitPos: %d", sitPos)
+	robotChaal(r, sitPos)
 }
 
 func robotPack(r *room.Room, sitPos int32) {
@@ -94,3 +109,7 @@ func robotShow(r *room.Room, sitPos int32) {
 func robotPacked(r *room.Room, sitPos int32) {
 
 }
+
+func robotSeen(r *room.Room, sitPos int32) {
+	recvPlayerOptAction(r, sitPos, &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_SEEN})
+}

+ 11 - 4
src/server/game/teen/round.go

@@ -28,7 +28,7 @@ func startDealCard(r *room.Room) {
 		for _, player := range players {
 			delay := time.Duration(300 * time.Millisecond)
 			game.Module.Skeleton.AfterFunc(delay, func() {
-				chaal(r, player.SitPos, 100)
+				ante(r, player.SitPos, 100)
 			})
 		}
 
@@ -123,9 +123,6 @@ func recvPlayerOptAction(room *room.Room, sitPos int32, opt *msg.PlayerOpt) {
 			packed(room, sitPos)
 		} else if optType == msg.PlayerOptType_OPT_CHAAL { // 跟注
 			chaal(room, sitPos, opt.BetAmount)
-			game.Module.Skeleton.AfterFunc(time.Second*1, func() {
-				sendRoomBet(room)
-			})
 		} else if optType == msg.PlayerOptType_OPT_SHOW { // 亮牌
 			show(room, sitPos)
 		}
@@ -165,3 +162,13 @@ func sendRoomBet(room *room.Room) {
 		}
 	}
 }
+
+// 发送结果
+func sendResult(r *room.Room, sitPos int32) {
+	log.Debug("发送结果: %d", r.GameRound.TotalBet)
+	for _, player := range r.Players {
+		if player.Agent != nil {
+			player.Agent.WriteMsg(&msg.ReqResult{RoundSitPos: sitPos, Result: r.GameRound.TotalBet})
+		}
+	}
+}

+ 14 - 10
src/server/msg/common.pb.go

@@ -31,6 +31,7 @@ const (
 	PlayerOptType_OPT_BIND   PlayerOptType = 4 // 绑定
 	PlayerOptType_OPT_SELECT PlayerOptType = 5 // 选择操作
 	PlayerOptType_OPT_SHOW   PlayerOptType = 6 // 亮牌
+	PlayerOptType_OPT_ANTE   PlayerOptType = 7 // 底注
 )
 
 // Enum value maps for PlayerOptType.
@@ -43,6 +44,7 @@ var (
 		4: "OPT_BIND",
 		5: "OPT_SELECT",
 		6: "OPT_SHOW",
+		7: "OPT_ANTE",
 	}
 	PlayerOptType_value = map[string]int32{
 		"OPT_NONE":   0,
@@ -52,6 +54,7 @@ var (
 		"OPT_BIND":   4,
 		"OPT_SELECT": 5,
 		"OPT_SHOW":   6,
+		"OPT_ANTE":   7,
 	}
 )
 
@@ -1853,16 +1856,17 @@ var file_common_proto_rawDesc = []byte{
 	0x43, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x5f, 0x6d, 0x73,
 	0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x4d, 0x73,
 	0x67, 0x22, 0x1b, 0x0a, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61,
-	0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x2a, 0x76,
-	0x0a, 0x0d, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4f, 0x70, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12,
-	0x0c, 0x0a, 0x08, 0x4f, 0x50, 0x54, 0x5f, 0x4e, 0x4f, 0x4e, 0x45, 0x10, 0x00, 0x12, 0x0c, 0x0a,
-	0x08, 0x4f, 0x50, 0x54, 0x5f, 0x53, 0x45, 0x45, 0x4e, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x4f,
-	0x50, 0x54, 0x5f, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x44, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x4f,
-	0x50, 0x54, 0x5f, 0x43, 0x48, 0x41, 0x41, 0x4c, 0x10, 0x03, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x50,
-	0x54, 0x5f, 0x42, 0x49, 0x4e, 0x44, 0x10, 0x04, 0x12, 0x0e, 0x0a, 0x0a, 0x4f, 0x50, 0x54, 0x5f,
-	0x53, 0x45, 0x4c, 0x45, 0x43, 0x54, 0x10, 0x05, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x50, 0x54, 0x5f,
-	0x53, 0x48, 0x4f, 0x57, 0x10, 0x06, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x2f, 0x6d, 0x73, 0x67, 0x62,
-	0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x2a, 0x84,
+	0x01, 0x0a, 0x0d, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x4f, 0x70, 0x74, 0x54, 0x79, 0x70, 0x65,
+	0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x50, 0x54, 0x5f, 0x4e, 0x4f, 0x4e, 0x45, 0x10, 0x00, 0x12, 0x0c,
+	0x0a, 0x08, 0x4f, 0x50, 0x54, 0x5f, 0x53, 0x45, 0x45, 0x4e, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a,
+	0x4f, 0x50, 0x54, 0x5f, 0x50, 0x41, 0x43, 0x4b, 0x45, 0x44, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09,
+	0x4f, 0x50, 0x54, 0x5f, 0x43, 0x48, 0x41, 0x41, 0x4c, 0x10, 0x03, 0x12, 0x0c, 0x0a, 0x08, 0x4f,
+	0x50, 0x54, 0x5f, 0x42, 0x49, 0x4e, 0x44, 0x10, 0x04, 0x12, 0x0e, 0x0a, 0x0a, 0x4f, 0x50, 0x54,
+	0x5f, 0x53, 0x45, 0x4c, 0x45, 0x43, 0x54, 0x10, 0x05, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x50, 0x54,
+	0x5f, 0x53, 0x48, 0x4f, 0x57, 0x10, 0x06, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x50, 0x54, 0x5f, 0x41,
+	0x4e, 0x54, 0x45, 0x10, 0x07, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x2f, 0x6d, 0x73, 0x67, 0x62, 0x06,
+	0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (