Gogs před 4 měsíci
rodič
revize
a8655d11c6

+ 4 - 7
bin/client_msg/common.proto

@@ -101,13 +101,10 @@ message ResPlayerOptAction {
 // PlayerOptType 玩家操作类型
 enum PlayerOptType {
     OPT_NONE        = 0;  // 无操作
-    OPT_LOOK_CARD   = 1;  // 看牌
-    OPT_DISCARD     = 2;  // 弃牌
-    OPT_CALL        = 3;  // 跟注
-    OPT_RAISE       = 4;  // 加注
-    OPT_DOUBLE      = 5;  // 加倍
-    OPT_FOLD        = 6;  // 放弃
-    OPT_SELECT      = 7;  // 选择操作
+    OPT_SEEN   = 1;  // 看牌
+    OPT_PACKED     = 2;  // 弃牌
+    OPT_CHAAL        = 3;  // 跟注
+    OPT_SELECT      = 4;  // 选择操作
 }
 
 message PlayerOpt {

+ 15 - 14
src/server/game/room/room.go

@@ -2,6 +2,7 @@ package room
 
 import (
 	"github.com/name5566/leaf/gate"
+	"github.com/name5566/leaf/log"
 )
 
 type Round struct {
@@ -68,7 +69,7 @@ type Player struct {
 	//手牌
 	HandCards []Card
 	// 座位
-	SitPos int
+	SitPos int32
 	// 等待发牌
 	WaitCard bool
 	// 是否已看牌
@@ -79,8 +80,6 @@ type Player struct {
 	IsOpenCard bool
 	// 是否已结算
 	IsSettle bool
-	// 是否已离开
-	IsLeave bool
 	// 是否已准备
 	IsReady bool
 	// 是否是庄家
@@ -106,11 +105,13 @@ func (r *Room) RemovePlayer(p *Player) {
 }
 
 func (r *Room) RemoveAllRobot() {
-	for i, player := range r.Players {
-		if player.IsRobot {
-			r.Players = append(r.Players[:i], r.Players[i+1:]...)
+	newPlayers := make([]*Player, 0)
+	for _, player := range r.Players {
+		if !player.IsRobot {
+			newPlayers = append(newPlayers, player)
 		}
 	}
+	r.Players = newPlayers
 }
 
 func (r *Room) GetPlayer(id string) *Player {
@@ -153,14 +154,14 @@ func (r *Room) GetWaitCardPlayers() []*Player {
 
 // sitPos 是当前玩家的座位号,GetWaitCardPlayers  从sitPos开始 顺时针方向把所有玩家返回
 // 从指定座位号开始顺时针获取所有玩家
-func (room *Room) GetPlayersBySitPos(startSitPos int) []*Player {
+func (room *Room) GetPlayersBySitPos(startSitPos int32) []*Player {
 	players := make([]*Player, 0)
-	maxSitPos := 5 // 假设最大6个座位
-
+	maxSitPos := int32(5) //
+	log.Debug("startSitPos:%v", room.Players)
 	// 先添加大于等于 startSitPos 的座位
-	for sitPos := startSitPos; sitPos < maxSitPos; sitPos++ {
+	for sitPos := startSitPos; sitPos <= maxSitPos; sitPos++ {
 		for _, player := range room.Players {
-			if player.SitPos == sitPos && !player.IsLeave {
+			if player.SitPos == sitPos {
 				players = append(players, player)
 				break
 			}
@@ -168,9 +169,9 @@ func (room *Room) GetPlayersBySitPos(startSitPos int) []*Player {
 	}
 
 	// 再添加小于 startSitPos 的座位
-	for sitPos := 0; sitPos < startSitPos; sitPos++ {
+	for sitPos := int32(0); sitPos < startSitPos; sitPos++ {
 		for _, player := range room.Players {
-			if player.SitPos == sitPos && !player.IsLeave {
+			if player.SitPos == sitPos {
 				players = append(players, player)
 				break
 			}
@@ -181,7 +182,7 @@ func (room *Room) GetPlayersBySitPos(startSitPos int) []*Player {
 }
 
 // 根据座位号获取玩家
-func (r *Room) GetPlayerBySitPos(sitPos int) *Player {
+func (r *Room) GetPlayerBySitPos(sitPos int32) *Player {
 	for _, player := range r.Players {
 		if player.SitPos == sitPos {
 			return player

+ 3 - 3
src/server/game/teen/event.go

@@ -26,7 +26,7 @@ func handleEvents() {
 				userData.Teen_Patti_Room = &room.Room{
 					Id:      "teen_patti",
 					Players: make([]*room.Player, 0),
-					Status:  1,
+					Status:  room.RoomStatusWaiting,
 				}
 			}
 			userData.Teen_Patti_Room.Players = append(userData.Teen_Patti_Room.Players, &room.Player{
@@ -34,7 +34,7 @@ func handleEvents() {
 				Agent:    event.Agent,
 				IsRobot:  false,
 				UserData: userData,
-				SitPos:   0,
+				SitPos:   SelfSitPos,
 			})
 			userData.Teen_Patti_Room.GameRound = &room.GameRound{
 				Rounds: make([]room.Round, 0),
@@ -45,7 +45,7 @@ func handleEvents() {
 			m := event.Data.(*msg.ResPlayerOptAction)
 			userData := event.Agent.UserData().(*user.UserData)
 			if userData.Teen_Patti_Room != nil {
-				recvPlayerOptAction(userData.Teen_Patti_Room, int(m.SitPos), m.PlayerOpt.OptType)
+				recvPlayerOptAction(userData.Teen_Patti_Room, m.SitPos, m.PlayerOpt.OptType)
 			} else {
 				log.Error("userData.Teen_Patti_Room is nil")
 			}

+ 7 - 37
src/server/game/teen/opt.go

@@ -7,67 +7,37 @@ import (
 )
 
 // 看牌
-func lookCard(room *room.Room, sitPos int) {
+func lookCard(room *room.Room, sitPos int32) {
 	SendRoundMsgToAll(room, &msg.ReqRound{
 		Round:       int32(room.Round),
 		RoundSitPos: int32(sitPos),
-		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_LOOK_CARD},
+		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_SEEN},
 		UserId:      room.GetPlayerBySitPos(sitPos).GetUserId(),
 	})
 }
 
 // 弃牌
-func discardCard(room *room.Room, sitPos int) {
+func discardCard(room *room.Room, sitPos int32) {
 	SendRoundMsgToAll(room, &msg.ReqRound{
 		Round:       int32(room.Round),
 		RoundSitPos: int32(sitPos),
-		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_FOLD},
+		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_PACKED},
 		UserId:      room.GetPlayerBySitPos(sitPos).GetUserId(),
 	})
 }
 
 // 跟注
-func call(room *room.Room, sitPos int) {
+func call(room *room.Room, sitPos int32) {
 	SendRoundMsgToAll(room, &msg.ReqRound{
 		Round:       int32(room.Round),
 		RoundSitPos: int32(sitPos),
-		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_CALL},
-		UserId:      room.GetPlayerBySitPos(sitPos).GetUserId(),
-	})
-}
-
-// 加注
-func raise(room *room.Room, sitPos int) {
-	SendRoundMsgToAll(room, &msg.ReqRound{
-		Round:       int32(room.Round),
-		RoundSitPos: int32(sitPos),
-		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_RAISE},
-		UserId:      room.GetPlayerBySitPos(sitPos).GetUserId(),
-	})
-}
-
-// 加倍
-func double(room *room.Room, sitPos int) {
-	SendRoundMsgToAll(room, &msg.ReqRound{
-		Round:       int32(room.Round),
-		RoundSitPos: int32(sitPos),
-		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_DOUBLE},
-		UserId:      room.GetPlayerBySitPos(sitPos).GetUserId(),
-	})
-}
-
-// 放弃
-func fold(room *room.Room, sitPos int) {
-	SendRoundMsgToAll(room, &msg.ReqRound{
-		Round:       int32(room.Round),
-		RoundSitPos: int32(sitPos),
-		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_FOLD},
+		PlayerOpt:   &msg.PlayerOpt{OptType: msg.PlayerOptType_OPT_CHAAL},
 		UserId:      room.GetPlayerBySitPos(sitPos).GetUserId(),
 	})
 }
 
 // 取消操作超时
-func cancelOptTimeout(player *room.Player, sitPos int) {
+func cancelOptTimeout(player *room.Player, sitPos int32) {
 	eventID := fmt.Sprintf("player_%s_opt_%s", player.Id, sitPos)
 	timerMgr.RemoveEvent(eventID)
 }

+ 1 - 1
src/server/game/teen/robot.go

@@ -48,6 +48,6 @@ func randomIndianHeadImage() string {
 }
 
 // 人机操作
-func robotOpt(r *room.Room, sitPos int, optType msg.PlayerOptType) {
+func robotOpt(r *room.Room, sitPos int32, optType msg.PlayerOptType) {
 
 }

+ 20 - 19
src/server/game/teen/round.go

@@ -19,15 +19,16 @@ func startDealCard(r *room.Room) {
 		r.Status = room.RoomStatusDealing
 		dealer := r.GetDealerPlayer()
 		// 找到庄家下家依次发牌
-		for _, player := range r.GetPlayersBySitPos(dealer.SitPos) {
+		for i, player := range r.GetPlayersBySitPos(dealer.SitPos) {
 			player.HandCards = getThreeCards(r)
 			player.WaitCard = false
-			game.Module.Skeleton.AfterFunc(time.Second*1, func() {
-				notifyPlayerDealCard(r, player.SitPos)
+			game.Module.Skeleton.AfterFunc(time.Second*1*time.Duration(i), func() {
+
 				// 如果等待的人数小于等于0,则开始通知庄家操作
 				// if len(r.GetWaitCardPlayers()) <= 0 {
 
 				// }
+				notifyPlayerDealCard(r, player.SitPos)
 				if player.SitPos == dealer.SitPos {
 					game.Module.Skeleton.Go(func() {
 						notifyPlayerAction(r, dealer.SitPos, msg.PlayerOptType_OPT_SELECT)
@@ -51,7 +52,7 @@ func getThreeCards(room *room.Room) []room.Card {
 }
 
 // 通知玩家发牌
-func notifyPlayerDealCard(room *room.Room, sitPos int) {
+func notifyPlayerDealCard(room *room.Room, sitPos int32) {
 	//遍历所有玩家
 	for _, player := range room.Players {
 		if player.Agent != nil {
@@ -61,16 +62,22 @@ func notifyPlayerDealCard(room *room.Room, sitPos int) {
 }
 
 // 通知玩家操作
-func notifyPlayerAction(room *room.Room, sitPos int, optType msg.PlayerOptType) {
+func notifyPlayerAction(room *room.Room, sitPos int32, optType msg.PlayerOptType) {
 	player := room.GetPlayerBySitPos(sitPos)
-	if player.Agent != nil {
-		player.Agent.WriteMsg(&msg.ReqPlayerAction{SitPos: int32(sitPos), PlayerOpt: &msg.PlayerOpt{OptType: optType}})
-		//玩家超过思考时间,则算起牌,否则算操作
-		addPlayerOptTimeout(room, player, time.Second*time.Duration(GameConfig.ThinkTime))
+	if !player.IsRobot {
+
 	} else {
 		//人机直接操作
 		robotOpt(room, sitPos, optType)
 	}
+
+	players := room.GetPlayersBySitPos(sitPos)
+	for _, p := range players {
+		if p.Agent != nil {
+			p.Agent.WriteMsg(&msg.ReqPlayerAction{SitPos: int32(sitPos), PlayerOpt: &msg.PlayerOpt{OptType: optType}})
+			addPlayerOptTimeout(room, player, time.Second*time.Duration(GameConfig.ThinkTime))
+		}
+	}
 	// game.Module.Skeleton.AfterFunc(time.Second*time.Duration(GameConfig.ThinkTime), func() {
 
 	// })
@@ -86,22 +93,16 @@ func addPlayerOptTimeout(room *room.Room, player *room.Player, timeout time.Dura
 }
 
 // 收到玩家操作
-func recvPlayerOptAction(room *room.Room, sitPos int, optType msg.PlayerOptType) {
+func recvPlayerOptAction(room *room.Room, sitPos int32, optType msg.PlayerOptType) {
 	player := room.GetPlayerBySitPos(sitPos)
 	if player.Agent != nil {
 		cancelOptTimeout(player, sitPos)
-		if optType == msg.PlayerOptType_OPT_LOOK_CARD { // 看牌
+		if optType == msg.PlayerOptType_OPT_SEEN { // 看牌
 			lookCard(room, sitPos)
-		} else if optType == msg.PlayerOptType_OPT_DISCARD { // 弃牌
+		} else if optType == msg.PlayerOptType_OPT_PACKED { // 弃牌
 			discardCard(room, sitPos)
-		} else if optType == msg.PlayerOptType_OPT_CALL { // 跟注
+		} else if optType == msg.PlayerOptType_OPT_CHAAL { // 跟注
 			call(room, sitPos)
-		} else if optType == msg.PlayerOptType_OPT_RAISE { // 加注
-			raise(room, sitPos)
-		} else if optType == msg.PlayerOptType_OPT_DOUBLE { // 加倍
-			double(room, sitPos)
-		} else if optType == msg.PlayerOptType_OPT_FOLD { // 放弃
-			fold(room, sitPos)
 		}
 	}
 }

+ 17 - 5
src/server/game/teen/sit.go

@@ -5,16 +5,28 @@ import (
 	"server/game/room"
 )
 
-// 随机选一个一个玩家当庄家
+// 随机选一个一个玩家当庄家md
 func randomDealer(room *room.Room) {
-	room.SetDealerPlayer(room.Players[rand.Intn(len(room.Players))])
+	// room.SetDealerPlayer(room.Players[rand.Intn(len(room.Players))])
+	room.SetDealerPlayer(room.GetPlayerBySitPos(SelfSitPos))
 }
 
 // 一共4个座位,指定需要的座位数量,且不重复的随即返回
 func randomSitPos(room *room.Room, num int) []int {
-	sitPos := make([]int, 0)
-	for i := 0; i < num; i++ {
-		sitPos = append(sitPos, rand.Intn(4))
+	availablePos := make([]int, 4)
+	for i := range availablePos {
+		availablePos[i] = i
+	}
+
+	// 随机选择不重复的座位号
+	sitPos := make([]int, 0, num)
+	for i := 0; i < num && len(availablePos) > 0; i++ {
+		// 随机选择一个索引
+		index := rand.Intn(len(availablePos))
+		// 将选中的座位号添加到结果中
+		sitPos = append(sitPos, availablePos[index])
+		// 从可用座位中移除已选择的座位
+		availablePos = append(availablePos[:index], availablePos[index+1:]...)
 	}
 	return sitPos
 }

+ 7 - 4
src/server/game/teen/teen.go

@@ -3,7 +3,6 @@ package teen
 import (
 	"encoding/json"
 	"fmt"
-	"log"
 	"math/rand"
 	"os"
 	"server/game"
@@ -13,6 +12,7 @@ import (
 	"time"
 
 	"github.com/name5566/leaf/gate"
+	"github.com/name5566/leaf/log"
 )
 
 type TeenPattiRoom struct {
@@ -40,6 +40,8 @@ var GameConfig struct {
 // 	Status:  1,
 // }
 
+var SelfSitPos int32 = 4
+
 func InitGame() {
 
 }
@@ -62,14 +64,15 @@ func createRoom(userId string, roomId string, agent gate.Agent) {
 	random := rand.Intn(3) + 1
 	//先移除掉除自己之外的机器人
 	userData.Teen_Patti_Room.RemoveAllRobot()
-	sitPos := randomSitPos(userData.Teen_Patti_Room, random)
+	sitPosList := randomSitPos(userData.Teen_Patti_Room, random)
+	log.Debug("sitPosList: %v, random: %d", sitPosList, random)
 	for i := 0; i < random; i++ {
 		userData.Teen_Patti_Room.Players = append(userData.Teen_Patti_Room.Players, &room.Player{
 			Id:       fmt.Sprintf("%d", i),
 			Agent:    nil,
 			IsRobot:  true,
 			UserData: createRobotUserData(),
-			SitPos:   sitPos[i],
+			SitPos:   int32(sitPosList[i]),
 		})
 	}
 	randomDealer(userData.Teen_Patti_Room)
@@ -94,7 +97,7 @@ func startGame(userId string, roomId string, agent gate.Agent, teenPattiRoom *ro
 		RoomId:   roomId,
 		GameId:   "teen_patti",
 		RoomInfo: buildRoom(teenPattiRoom),
-		SitPos:   int32(teenPattiRoom.GetPlayer(userId).SitPos),
+		SitPos:   SelfSitPos,
 	})
 	game.Module.Skeleton.AfterFunc(time.Second*2, func() {
 		startDealCard(teenPattiRoom)

+ 21 - 33
src/server/msg/common.pb.go

@@ -24,37 +24,28 @@ const (
 type PlayerOptType int32
 
 const (
-	PlayerOptType_OPT_NONE      PlayerOptType = 0 // 无操作
-	PlayerOptType_OPT_LOOK_CARD PlayerOptType = 1 // 看牌
-	PlayerOptType_OPT_DISCARD   PlayerOptType = 2 // 弃牌
-	PlayerOptType_OPT_CALL      PlayerOptType = 3 // 跟注
-	PlayerOptType_OPT_RAISE     PlayerOptType = 4 // 加注
-	PlayerOptType_OPT_DOUBLE    PlayerOptType = 5 // 加倍
-	PlayerOptType_OPT_FOLD      PlayerOptType = 6 // 放弃
-	PlayerOptType_OPT_SELECT    PlayerOptType = 7 // 选择操作
+	PlayerOptType_OPT_NONE   PlayerOptType = 0 // 无操作
+	PlayerOptType_OPT_SEEN   PlayerOptType = 1 // 看牌
+	PlayerOptType_OPT_PACKED PlayerOptType = 2 // 弃牌
+	PlayerOptType_OPT_CHAAL  PlayerOptType = 3 // 跟注
+	PlayerOptType_OPT_SELECT PlayerOptType = 4 // 选择操作
 )
 
 // Enum value maps for PlayerOptType.
 var (
 	PlayerOptType_name = map[int32]string{
 		0: "OPT_NONE",
-		1: "OPT_LOOK_CARD",
-		2: "OPT_DISCARD",
-		3: "OPT_CALL",
-		4: "OPT_RAISE",
-		5: "OPT_DOUBLE",
-		6: "OPT_FOLD",
-		7: "OPT_SELECT",
+		1: "OPT_SEEN",
+		2: "OPT_PACKED",
+		3: "OPT_CHAAL",
+		4: "OPT_SELECT",
 	}
 	PlayerOptType_value = map[string]int32{
-		"OPT_NONE":      0,
-		"OPT_LOOK_CARD": 1,
-		"OPT_DISCARD":   2,
-		"OPT_CALL":      3,
-		"OPT_RAISE":     4,
-		"OPT_DOUBLE":    5,
-		"OPT_FOLD":      6,
-		"OPT_SELECT":    7,
+		"OPT_NONE":   0,
+		"OPT_SEEN":   1,
+		"OPT_PACKED": 2,
+		"OPT_CHAAL":  3,
+		"OPT_SELECT": 4,
 	}
 )
 
@@ -1640,16 +1631,13 @@ var file_common_proto_rawDesc = []byte{
 	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, 0x8c, 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, 0x11, 0x0a, 0x0d, 0x4f, 0x50, 0x54, 0x5f, 0x4c, 0x4f, 0x4f, 0x4b, 0x5f, 0x43, 0x41, 0x52,
-	0x44, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, 0x4f, 0x50, 0x54, 0x5f, 0x44, 0x49, 0x53, 0x43, 0x41,
-	0x52, 0x44, 0x10, 0x02, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x50, 0x54, 0x5f, 0x43, 0x41, 0x4c, 0x4c,
-	0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x4f, 0x50, 0x54, 0x5f, 0x52, 0x41, 0x49, 0x53, 0x45, 0x10,
-	0x04, 0x12, 0x0e, 0x0a, 0x0a, 0x4f, 0x50, 0x54, 0x5f, 0x44, 0x4f, 0x55, 0x42, 0x4c, 0x45, 0x10,
-	0x05, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x50, 0x54, 0x5f, 0x46, 0x4f, 0x4c, 0x44, 0x10, 0x06, 0x12,
-	0x0e, 0x0a, 0x0a, 0x4f, 0x50, 0x54, 0x5f, 0x53, 0x45, 0x4c, 0x45, 0x43, 0x54, 0x10, 0x07, 0x42,
-	0x07, 0x5a, 0x05, 0x2e, 0x2f, 0x6d, 0x73, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x2a, 0x5a, 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, 0x0e, 0x0a, 0x0a,
+	0x4f, 0x50, 0x54, 0x5f, 0x53, 0x45, 0x4c, 0x45, 0x43, 0x54, 0x10, 0x04, 0x42, 0x07, 0x5a, 0x05,
+	0x2e, 0x2f, 0x6d, 0x73, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (