xy пре 1 недеља
родитељ
комит
e725326bb6

+ 1 - 0
bin/client_msg/common.proto

@@ -65,6 +65,7 @@ message RoomInfo {
   int32 id = 9;
   int32 room_level = 10; //房间的每个等级都对应着不同的奖励和消耗
   roomStatus room_status = 11;
+  NotifyPlayerOpt cur_color_opt_data = 12;
 }
 
 message RoleData {

+ 46 - 0
src/server/game/ludo/battle.go

@@ -1,13 +1,16 @@
 package ludo
 
 import (
+	"fmt"
 	"server/game"
 	"server/msg"
+	"server/tools"
 	"time"
 )
 
 type RoomInfoWrapper struct {
 	*msg.RoomInfo
+	TimerManager *tools.TimerManager
 }
 
 func init() {
@@ -132,6 +135,8 @@ func (room_info *RoomInfoWrapper) notify_player_move(list []*msg.RoleData) {
 		CanMoveRoles: list,
 	}
 	room_info.NotifyToAllPlayer(message)
+	room_info.setCurColorOpt(message)
+	room_info.StartCountdownPlayerOpt()
 }
 
 // 通知玩家状态
@@ -152,6 +157,47 @@ func (room_info *RoomInfoWrapper) notify_player_sz() {
 		Opt:   msg.OptType_ZHI_SHAI_ZI,
 	}
 	room_info.NotifyToAllPlayer(message)
+	room_info.setCurColorOpt(message)
+	room_info.StartCountdownPlayerOpt()
+}
+
+// 托管操作一次
+func (room_info *RoomInfoWrapper) tuoGuanOpt() {
+	curColorOpt := room_info.CurColorOptData.Opt
+	curColor := room_info.CurRoundColor
+	if curColorOpt == msg.OptType_SELECT_ROLE {
+		role_id := room_info.CurColorOptData.CanMoveRoles[0].MId
+		room_info.send_role_move(curColor, role_id)
+	} else if curColorOpt == msg.OptType_ZHI_SHAI_ZI {
+		room_info.send_sz(curColor)
+	}
+}
+
+// 超过10秒玩家没有操作,将他的timeout 累计加1,然后给他托管一次
+func (room_info *RoomInfoWrapper) TimeOutTuoGuan() {
+	cur_color := room_info.CurRoundColor
+	color_data := room_info.getColorDataByColor(cur_color)
+	color_data.TimeOutNum = color_data.TimeOutNum + 1
+	if color_data.TimeOutNum > 5 { //如果玩家累计5次托管行为,将玩家踢出房间
+
+	} else {
+		room_info.tuoGuanOpt()
+	}
+}
+
+// 开始计时玩家操作
+func (room_info *RoomInfoWrapper) StartCountdownPlayerOpt() {
+	room_info.TimerManager.AddEvent(room_info.GetRoomTimeOutKey(), 10*time.Second, room_info.TimeOutTuoGuan)
+}
+
+// 取消玩家计时
+func (room_info *RoomInfoWrapper) CancelCountdownPlayerOpt() {
+	room_info.TimerManager.RemoveEvent(room_info.GetRoomTimeOutKey())
+}
+
+// 获取房间倒计时的key
+func (room_info *RoomInfoWrapper) GetRoomTimeOutKey() string {
+	return fmt.Sprintf("%d_TimeOut", room_info.Id)
 }
 
 // 获取房间ID

+ 2 - 21
src/server/game/ludo/color_recv.go

@@ -19,8 +19,8 @@ func RecvPlayerRoleMove(args []interface{}) {
 		fmt.Printf("I房间不存在 %d\n", room_id)
 	} else {
 		room_info := GetBattleRoomById(room_id)
-
 		if room_info != nil {
+			room_info.CancelCountdownPlayerOpt()
 			room_info.send_role_move(m.Color, m.RoleId)
 		} else {
 			fmt.Printf("IV房间不存在 %d\n", room_id)
@@ -50,26 +50,7 @@ func RecvPlayerSzNumber(args []interface{}) {
 		room_info := GetBattleRoomById(room_id)
 
 		if room_info != nil {
-
-			room_info.notify_player_status(color, msg.PlayerStatus_SZ_ANIMATION, nil)
-
-			sz_number := randomSz()
-
-			round_data := &msg.Round{
-				MColor:   color,
-				SzNumber: sz_number,
-				Opt:      msg.OptType_ZHI_SHAI_ZI,
-			}
-
-			room_info.addRound(round_data)
-
-			msg_body := &msg.NotifyPlayerSzNumber{
-				Color:    color,
-				SzNumber: sz_number,
-			}
-
-			room_info.NotifyToAllPlayer(msg_body)
-			room_info.delayActionSz(1000, msg_body)
+			room_info.send_sz(color)
 		}
 
 	}

+ 25 - 0
src/server/game/ludo/color_send.go

@@ -72,3 +72,28 @@ func (room_info *RoomInfoWrapper) send_role_move(color msg.RoleType, role_id str
 
 	room_info.delayActionNextRound(delay_time, color, szNumber, isAddRound, isFinish)
 }
+
+// 发送掷骰子消息
+func (room_info *RoomInfoWrapper) send_sz(color msg.RoleType) {
+	room_info.CancelCountdownPlayerOpt()
+
+	room_info.notify_player_status(color, msg.PlayerStatus_SZ_ANIMATION, nil)
+
+	sz_number := randomSz()
+
+	round_data := &msg.Round{
+		MColor:   color,
+		SzNumber: sz_number,
+		Opt:      msg.OptType_ZHI_SHAI_ZI,
+	}
+
+	room_info.addRound(round_data)
+
+	msg_body := &msg.NotifyPlayerSzNumber{
+		Color:    color,
+		SzNumber: sz_number,
+	}
+
+	room_info.NotifyToAllPlayer(msg_body)
+	room_info.delayActionSz(1000, msg_body)
+}

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

@@ -80,8 +80,6 @@ var (
 	}
 )
 
-var TimerManager = tools.NewTimerManager()
-
 func InitGame() {
 	gameConfig = &Config{
 		RoomMap:    make(map[int32]*msg.RoomInfo),
@@ -97,7 +95,7 @@ func startGame(room_info *msg.RoomInfo) *RoomInfoWrapper {
 	//设置第一个操作的阵营
 	setFirstColor(room_info)
 	// player_count := getPlayerCount(room_info)
-	room := &RoomInfoWrapper{room_info}
+	room := &RoomInfoWrapper{room_info, tools.NewTimerManager()}
 	runBattle(room)
 	return room
 }

+ 5 - 0
src/server/game/ludo/ludo_room_data.go

@@ -271,3 +271,8 @@ func (room_info *RoomInfoWrapper) getCanMoveRoles(roles []*msg.RoleData, szNumbe
 	}
 	return temp
 }
+
+// 设置当前玩家操作类型
+func (room_info *RoomInfoWrapper) setCurColorOpt(opt *msg.NotifyPlayerOpt) {
+	room_info.CurColorOptData = opt
+}

+ 59 - 49
src/server/msg/common.pb.go

@@ -439,20 +439,21 @@ func (x *Round) GetSzNumber() int32 {
 }
 
 type RoomInfo struct {
-	state         protoimpl.MessageState `protogen:"open.v1"`
-	Roles         []*RoleData            `protobuf:"bytes,1,rep,name=roles,proto3" json:"roles,omitempty"`
-	Colors        []*ColorData           `protobuf:"bytes,2,rep,name=colors,proto3" json:"colors,omitempty"`
-	RoomType      RoomType               `protobuf:"varint,3,opt,name=room_type,json=roomType,proto3,enum=RoomType" json:"room_type,omitempty"`
-	RoomMode      RoomMode               `protobuf:"varint,4,opt,name=room_mode,json=roomMode,proto3,enum=RoomMode" json:"room_mode,omitempty"`
-	CurRoundColor RoleType               `protobuf:"varint,5,opt,name=cur_round_color,json=curRoundColor,proto3,enum=RoleType" json:"cur_round_color,omitempty"`
-	Rounds        []*Round               `protobuf:"bytes,6,rep,name=rounds,proto3" json:"rounds,omitempty"`
-	FinishColors  []*ColorData           `protobuf:"bytes,7,rep,name=finish_colors,json=finishColors,proto3" json:"finish_colors,omitempty"`
-	KictColors    []*ColorData           `protobuf:"bytes,8,rep,name=kict_colors,json=kictColors,proto3" json:"kict_colors,omitempty"`
-	Id            int32                  `protobuf:"varint,9,opt,name=id,proto3" json:"id,omitempty"`
-	RoomLevel     int32                  `protobuf:"varint,10,opt,name=room_level,json=roomLevel,proto3" json:"room_level,omitempty"` //房间的每个等级都对应着不同的奖励和消耗
-	RoomStatus    RoomStatus             `protobuf:"varint,11,opt,name=room_status,json=roomStatus,proto3,enum=RoomStatus" json:"room_status,omitempty"`
-	unknownFields protoimpl.UnknownFields
-	sizeCache     protoimpl.SizeCache
+	state           protoimpl.MessageState `protogen:"open.v1"`
+	Roles           []*RoleData            `protobuf:"bytes,1,rep,name=roles,proto3" json:"roles,omitempty"`
+	Colors          []*ColorData           `protobuf:"bytes,2,rep,name=colors,proto3" json:"colors,omitempty"`
+	RoomType        RoomType               `protobuf:"varint,3,opt,name=room_type,json=roomType,proto3,enum=RoomType" json:"room_type,omitempty"`
+	RoomMode        RoomMode               `protobuf:"varint,4,opt,name=room_mode,json=roomMode,proto3,enum=RoomMode" json:"room_mode,omitempty"`
+	CurRoundColor   RoleType               `protobuf:"varint,5,opt,name=cur_round_color,json=curRoundColor,proto3,enum=RoleType" json:"cur_round_color,omitempty"`
+	Rounds          []*Round               `protobuf:"bytes,6,rep,name=rounds,proto3" json:"rounds,omitempty"`
+	FinishColors    []*ColorData           `protobuf:"bytes,7,rep,name=finish_colors,json=finishColors,proto3" json:"finish_colors,omitempty"`
+	KictColors      []*ColorData           `protobuf:"bytes,8,rep,name=kict_colors,json=kictColors,proto3" json:"kict_colors,omitempty"`
+	Id              int32                  `protobuf:"varint,9,opt,name=id,proto3" json:"id,omitempty"`
+	RoomLevel       int32                  `protobuf:"varint,10,opt,name=room_level,json=roomLevel,proto3" json:"room_level,omitempty"` //房间的每个等级都对应着不同的奖励和消耗
+	RoomStatus      RoomStatus             `protobuf:"varint,11,opt,name=room_status,json=roomStatus,proto3,enum=RoomStatus" json:"room_status,omitempty"`
+	CurColorOptData *NotifyPlayerOpt       `protobuf:"bytes,12,opt,name=cur_color_opt_data,json=curColorOptData,proto3" json:"cur_color_opt_data,omitempty"`
+	unknownFields   protoimpl.UnknownFields
+	sizeCache       protoimpl.SizeCache
 }
 
 func (x *RoomInfo) Reset() {
@@ -562,6 +563,13 @@ func (x *RoomInfo) GetRoomStatus() RoomStatus {
 	return RoomStatus_AWAIT
 }
 
+func (x *RoomInfo) GetCurColorOptData() *NotifyPlayerOpt {
+	if x != nil {
+		return x.CurColorOptData
+	}
+	return nil
+}
+
 type RoleData struct {
 	state         protoimpl.MessageState `protogen:"open.v1"`
 	MColor        RoleType               `protobuf:"varint,1,opt,name=m_color,json=mColor,proto3,enum=RoleType" json:"m_color,omitempty"`
@@ -1990,7 +1998,7 @@ const file_common_proto_rawDesc = "" +
 	"\am_color\x18\x01 \x01(\x0e2\t.roleTypeR\x06mColor\x12\x15\n" +
 	"\x06m_road\x18\x02 \x01(\tR\x05mRoad\x12\x1a\n" +
 	"\x03opt\x18\x03 \x01(\x0e2\b.OptTypeR\x03opt\x12\x1a\n" +
-	"\bszNumber\x18\x04 \x01(\x05R\bszNumber\"\xad\x03\n" +
+	"\bszNumber\x18\x04 \x01(\x05R\bszNumber\"\xec\x03\n" +
 	"\bRoomInfo\x12\x1f\n" +
 	"\x05roles\x18\x01 \x03(\v2\t.RoleDataR\x05roles\x12\"\n" +
 	"\x06colors\x18\x02 \x03(\v2\n" +
@@ -2009,7 +2017,8 @@ const file_common_proto_rawDesc = "" +
 	"room_level\x18\n" +
 	" \x01(\x05R\troomLevel\x12,\n" +
 	"\vroom_status\x18\v \x01(\x0e2\v.roomStatusR\n" +
-	"roomStatus\"\xb0\x01\n" +
+	"roomStatus\x12=\n" +
+	"\x12cur_color_opt_data\x18\f \x01(\v2\x10.NotifyPlayerOptR\x0fcurColorOptData\"\xb0\x01\n" +
 	"\bRoleData\x12\"\n" +
 	"\am_color\x18\x01 \x01(\x0e2\t.roleTypeR\x06mColor\x12\x15\n" +
 	"\x06m_seat\x18\x02 \x01(\x05R\x05mSeat\x12\x11\n" +
@@ -2205,39 +2214,40 @@ var file_common_proto_depIdxs = []int32{
 	10, // 8: RoomInfo.finish_colors:type_name -> ColorData
 	10, // 9: RoomInfo.kict_colors:type_name -> ColorData
 	6,  // 10: RoomInfo.room_status:type_name -> roomStatus
-	0,  // 11: RoleData.m_color:type_name -> roleType
-	4,  // 12: RoleData.m_cur_road:type_name -> roadType
-	0,  // 13: ColorData.m_color:type_name -> roleType
-	0,  // 14: SendColorSz.color:type_name -> roleType
-	0,  // 15: SendRoleMove.color:type_name -> roleType
-	0,  // 16: NotifyPlayerSzNumber.color:type_name -> roleType
-	30, // 17: NotifyPlayerSzNumber.err_msg:type_name -> MsgError
-	0,  // 18: NotifyPlayerMove.color:type_name -> roleType
-	11, // 19: NotifyPlayerMove.step:type_name -> MoveStepData
-	9,  // 20: NotifyPlayerMove.kick:type_name -> RoleData
-	0,  // 21: NotifyPlayerOpt.color:type_name -> roleType
-	1,  // 22: NotifyPlayerOpt.opt:type_name -> OptType
-	9,  // 23: NotifyPlayerOpt.canMoveRoles:type_name -> RoleData
-	0,  // 24: NotifyPlayerStatus.color:type_name -> roleType
-	5,  // 25: NotifyPlayerStatus.status:type_name -> playerStatus
-	10, // 26: NotifyPlayerStatus.colors:type_name -> ColorData
-	0,  // 27: NotifySettlement.color:type_name -> roleType
-	10, // 28: NotifySettlement.finish_colors:type_name -> ColorData
-	8,  // 29: NotifyUpdateRoomInfo.room_info:type_name -> RoomInfo
-	20, // 30: ResLogin.userInfo:type_name -> UserInfo
-	30, // 31: ResLogin.err_msg:type_name -> MsgError
-	30, // 32: ResRegister.err_msg:type_name -> MsgError
-	30, // 33: ResEnterHall.err_msg:type_name -> MsgError
-	8,  // 34: ResEnterHall.reconnect_room_info:type_name -> RoomInfo
-	2,  // 35: MatchLudo.select_room_type:type_name -> roomType
-	0,  // 36: MatchLudo.select_color:type_name -> roleType
-	30, // 37: ResMatchLudo.err_msg:type_name -> MsgError
-	8,  // 38: ResMatchLudo.room:type_name -> RoomInfo
-	39, // [39:39] is the sub-list for method output_type
-	39, // [39:39] is the sub-list for method input_type
-	39, // [39:39] is the sub-list for extension type_name
-	39, // [39:39] is the sub-list for extension extendee
-	0,  // [0:39] is the sub-list for field type_name
+	16, // 11: RoomInfo.cur_color_opt_data:type_name -> NotifyPlayerOpt
+	0,  // 12: RoleData.m_color:type_name -> roleType
+	4,  // 13: RoleData.m_cur_road:type_name -> roadType
+	0,  // 14: ColorData.m_color:type_name -> roleType
+	0,  // 15: SendColorSz.color:type_name -> roleType
+	0,  // 16: SendRoleMove.color:type_name -> roleType
+	0,  // 17: NotifyPlayerSzNumber.color:type_name -> roleType
+	30, // 18: NotifyPlayerSzNumber.err_msg:type_name -> MsgError
+	0,  // 19: NotifyPlayerMove.color:type_name -> roleType
+	11, // 20: NotifyPlayerMove.step:type_name -> MoveStepData
+	9,  // 21: NotifyPlayerMove.kick:type_name -> RoleData
+	0,  // 22: NotifyPlayerOpt.color:type_name -> roleType
+	1,  // 23: NotifyPlayerOpt.opt:type_name -> OptType
+	9,  // 24: NotifyPlayerOpt.canMoveRoles:type_name -> RoleData
+	0,  // 25: NotifyPlayerStatus.color:type_name -> roleType
+	5,  // 26: NotifyPlayerStatus.status:type_name -> playerStatus
+	10, // 27: NotifyPlayerStatus.colors:type_name -> ColorData
+	0,  // 28: NotifySettlement.color:type_name -> roleType
+	10, // 29: NotifySettlement.finish_colors:type_name -> ColorData
+	8,  // 30: NotifyUpdateRoomInfo.room_info:type_name -> RoomInfo
+	20, // 31: ResLogin.userInfo:type_name -> UserInfo
+	30, // 32: ResLogin.err_msg:type_name -> MsgError
+	30, // 33: ResRegister.err_msg:type_name -> MsgError
+	30, // 34: ResEnterHall.err_msg:type_name -> MsgError
+	8,  // 35: ResEnterHall.reconnect_room_info:type_name -> RoomInfo
+	2,  // 36: MatchLudo.select_room_type:type_name -> roomType
+	0,  // 37: MatchLudo.select_color:type_name -> roleType
+	30, // 38: ResMatchLudo.err_msg:type_name -> MsgError
+	8,  // 39: ResMatchLudo.room:type_name -> RoomInfo
+	40, // [40:40] is the sub-list for method output_type
+	40, // [40:40] is the sub-list for method input_type
+	40, // [40:40] is the sub-list for extension type_name
+	40, // [40:40] is the sub-list for extension extendee
+	0,  // [0:40] is the sub-list for field type_name
 }
 
 func init() { file_common_proto_init() }