Gogs hai 4 meses
pai
achega
7adc5db586

+ 1 - 0
bin/client_msg/common.proto

@@ -105,6 +105,7 @@ enum PlayerOptType {
     OPT_RAISE       = 4;  // 加注
     OPT_DOUBLE      = 5;  // 加倍
     OPT_FOLD        = 6;  // 放弃
+    OPT_SELECT      = 7;  // 选择操作
 }
 
 message PlayerOpt {

+ 6 - 0
src/server/game/internal/chanrpc.go

@@ -2,6 +2,7 @@ package internal
 
 import (
 	"server/msg"
+	"server/user"
 	"time"
 
 	"github.com/name5566/leaf/gate"
@@ -63,6 +64,11 @@ func handleAuth(args []interface{}) {
 			delete(authedUsers, m.UserId)
 		}
 
+		a.SetUserData(&user.UserData{
+			Id:              m.UserId,
+			Nickname:        m.NikeName,
+			Teen_Patti_Room: nil,
+		})
 		// 发送登录成功响应
 		a.WriteMsg(&msg.ReqLogin{
 			NikeName:   m.NikeName,

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

@@ -47,7 +47,7 @@ type Room struct {
 	// 当前回合的座位
 	RoundSitPos int
 	// 每局游戏
-	GameRound GameRound
+	GameRound *GameRound
 	// 牌堆
 	CardDeck []Card
 }

+ 4 - 1
src/server/game/teen/buildRoom.go

@@ -3,6 +3,8 @@ package teen
 import (
 	"server/game/room"
 	"server/msg"
+
+	"github.com/name5566/leaf/log"
 )
 
 func buildRoom(teenPattiRoom *room.Room) *msg.ReqRoom {
@@ -39,7 +41,8 @@ func convertToMsgCardList(cards []room.Card) []*msg.ReqCard {
 	return msgCards
 }
 
-func convertToMsgGameRound(gameRound room.GameRound) *msg.ReqGameRound {
+func convertToMsgGameRound(gameRound *room.GameRound) *msg.ReqGameRound {
+	log.Debug("convertToMsgGameRound: %v", gameRound)
 	return &msg.ReqGameRound{
 		Rounds: convertToMsgRoundList(gameRound.Rounds),
 	}

+ 4 - 0
src/server/game/teen/event.go

@@ -19,6 +19,7 @@ func handleEvents() {
 			})
 
 		case events.EventJoinTeenPattiRoom:
+			log.Debug("EventJoinTeenPattiRoom")
 			m := event.Data.(*msg.ResJoinRoom)
 			userData := event.Agent.UserData().(*user.UserData)
 			if userData.Teen_Patti_Room == nil {
@@ -35,6 +36,9 @@ func handleEvents() {
 				UserData: userData,
 				SitPos:   0,
 			})
+			userData.Teen_Patti_Room.GameRound = &room.GameRound{
+				Rounds: make([]room.Round, 0),
+			}
 			go startGame(m.UserId, m.RoomId, event.Agent, userData.Teen_Patti_Room)
 		case events.EventTeenPattiPlayerOptAction:
 			// m := event.Data.(*msg.ResPlayerOptAction)

+ 9 - 2
src/server/game/teen/robot.go

@@ -4,6 +4,8 @@ import (
 	"encoding/json"
 	"math/rand"
 	"os"
+	"server/game/room"
+	"server/msg"
 
 	"github.com/name5566/leaf/log"
 )
@@ -14,7 +16,7 @@ type RobotNames struct {
 
 // 随即印度人名字
 func randomIndianName() string {
-	data, err := os.ReadFile("../../../bin/gamedata/robot_name.json")
+	data, err := os.ReadFile("/home/zjh/teen_patti/bin/gamedata/robot_name.json")
 	if err != nil {
 		log.Fatal("%v", err)
 	}
@@ -32,7 +34,7 @@ type RobotHeadImages struct {
 
 // 随即印度人头像
 func randomIndianHeadImage() string {
-	data, err := os.ReadFile("../../../bin/gamedata/robot_head_image.json")
+	data, err := os.ReadFile("/home/zjh/teen_patti/bin/gamedata/robot_head_image.json")
 	if err != nil {
 		log.Fatal("%v", err)
 	}
@@ -44,3 +46,8 @@ func randomIndianHeadImage() string {
 	}
 	return images.HeadImages[rand.Intn(len(images.HeadImages))]
 }
+
+// 人机操作
+func robotOpt(r *room.Room, sitPos int, optType msg.PlayerOptType) {
+
+}

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

@@ -27,7 +27,7 @@ func startDealCard(r *room.Room) {
 				// 如果等待的人数小于等于0,则开始通知庄家操作
 				if len(r.GetWaitCardPlayers()) <= 0 {
 					game.Module.Skeleton.Go(func() {
-						notifyPlayerAction(r, dealer.SitPos)
+						notifyPlayerAction(r, dealer.SitPos, msg.PlayerOptType_OPT_SELECT)
 					}, func() {
 						r.Status = room.RoomStatusPlaying
 					})
@@ -59,13 +59,16 @@ func notifyPlayerDealCard(room *room.Room, sitPos int) {
 }
 
 // 通知玩家操作
-func notifyPlayerAction(room *room.Room, sitPos int) {
+func notifyPlayerAction(room *room.Room, sitPos int, optType msg.PlayerOptType) {
 	player := room.GetPlayerBySitPos(sitPos)
 	if player.Agent != nil {
 		player.Agent.WriteMsg(&msg.ReqPlayerAction{SitPos: int32(sitPos)})
+		//玩家超过思考时间,则算起牌,否则算操作
+		addPlayerOptTimeout(room, player, time.Second*time.Duration(GameConfig.ThinkTime))
+	} else {
+		//人机直接操作
+		robotOpt(room, sitPos, optType)
 	}
-	//玩家超过思考时间,则算起牌,否则算操作
-	addPlayerOptTimeout(room, player, time.Second*time.Duration(GameConfig.ThinkTime))
 	// game.Module.Skeleton.AfterFunc(time.Second*time.Duration(GameConfig.ThinkTime), func() {
 
 	// })

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

@@ -6,9 +6,11 @@ import (
 	"log"
 	"math/rand"
 	"os"
+	"server/game"
 	"server/game/room"
 	"server/msg"
 	"server/user"
+	"time"
 
 	"github.com/name5566/leaf/gate"
 )
@@ -93,7 +95,9 @@ func startGame(userId string, roomId string, agent gate.Agent, teenPattiRoom *ro
 		GameId:   "teen_patti",
 		RoomInfo: buildRoom(teenPattiRoom),
 	})
-
+	game.Module.Skeleton.AfterFunc(time.Second*2, func() {
+		startDealCard(teenPattiRoom)
+	})
 }
 
 /* 完整的52张牌映射:

+ 1 - 0
src/server/gate/router.go

@@ -11,4 +11,5 @@ func init() {
 	msg.Processor.SetRouter(&msg.Hello{}, game.ChanRPC)
 	msg.Processor.SetRouter(&msg.ResLogin{}, login.ChanRPC)
 	msg.Processor.SetRouter(&msg.ResGameInfo{}, hall.ChanRPC)
+	msg.Processor.SetRouter(&msg.ResJoinRoom{}, hall.ChanRPC)
 }

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

@@ -31,6 +31,7 @@ const (
 	PlayerOptType_OPT_RAISE     PlayerOptType = 4 // 加注
 	PlayerOptType_OPT_DOUBLE    PlayerOptType = 5 // 加倍
 	PlayerOptType_OPT_FOLD      PlayerOptType = 6 // 放弃
+	PlayerOptType_OPT_SELECT    PlayerOptType = 7 // 选择操作
 )
 
 // Enum value maps for PlayerOptType.
@@ -43,6 +44,7 @@ var (
 		4: "OPT_RAISE",
 		5: "OPT_DOUBLE",
 		6: "OPT_FOLD",
+		7: "OPT_SELECT",
 	}
 	PlayerOptType_value = map[string]int32{
 		"OPT_NONE":      0,
@@ -52,6 +54,7 @@ var (
 		"OPT_RAISE":     4,
 		"OPT_DOUBLE":    5,
 		"OPT_FOLD":      6,
+		"OPT_SELECT":    7,
 	}
 )
 
@@ -1616,16 +1619,17 @@ var file_common_proto_rawDesc = []byte{
 	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, 0x7c, 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, 0x42, 0x07, 0x5a, 0x05, 0x2e, 0x2f, 0x6d,
-	0x73, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	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,
 }
 
 var (