From b4b68cbf852b6624801e3de6166c12920b5b1294 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 18 Dec 2023 14:37:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=89=E6=B6=88=E6=8A=95=E9=99=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/api_surrender.go | 29 +++++++++++++++++++++++--- modules/entertainment/room.go | 29 +++++--------------------- pb/entertain_msg.pb.go | 17 ++++++++++++--- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/modules/entertainment/api_surrender.go b/modules/entertainment/api_surrender.go index 36ae850d0..26802cb10 100644 --- a/modules/entertainment/api_surrender.go +++ b/modules/entertainment/api_surrender.go @@ -17,10 +17,33 @@ func (this *apiComp) SurrenderCheck(session comm.IUserSession, req *pb.Entertain } func (this *apiComp) Surrender(session comm.IUserSession, req *pb.EntertainSurrenderReq) (errdata *pb.ErrorData) { - + var ( + list *pb.DBXXLData + err error + ) + if list, err = this.module.model.getEntertainmList(session.GetUserId()); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + // 操作消息返回 + if list.Touxiang <= 0 { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_EntertainMaxTouxiangCount, + Title: pb.ErrorCode_EntertainMaxTouxiangCount.ToString(), + } + } if errdata = this.module.gameMgr.RoomDistribute(req.Roomid, session, "surrender", req); errdata == nil { - // 操作消息返回 - session.SendMsg(string(this.module.GetType()), "surrender", &pb.EntertainSurrenderResp{}) + list.Touxiang -= 1 + this.module.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{ + "touxiang": list.Touxiang, + }) + session.SendMsg(string(this.module.GetType()), "surrender", &pb.EntertainSurrenderResp{ + Leftcount: list.Touxiang, + }) } return diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index f63a87f0c..741664508 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -506,32 +506,13 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } return } - if list, err := this.module.model.getEntertainmList(session.GetUserId()); err == nil { - if list.Touxiang <= 0 { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_EntertainMaxTouxiangCount, - Title: pb.ErrorCode_EntertainMaxTouxiangCount.ToString(), - } - } - list.Touxiang -= 1 - this.module.model.modifyEntertainmList(session.GetUserId(), map[string]interface{}{ - "touxiang": list.Touxiang, - }) - var winner *pb.PlayerData - if this.player1.Userinfo.Uid == session.GetUserId() { - winner = this.player2 - } else { - winner = this.player1 - } - this.GameOver(winner) + var winner *pb.PlayerData + if this.player1.Userinfo.Uid == session.GetUserId() { + winner = this.player2 } else { - errdata = &pb.ErrorData{ - Code: pb.ErrorCode_DBError, - Title: pb.ErrorCode_DBError.ToString(), - Message: err.Error(), - } - return + winner = this.player1 } + this.GameOver(winner) } return } diff --git a/pb/entertain_msg.pb.go b/pb/entertain_msg.pb.go index debcc0790..803b53da0 100644 --- a/pb/entertain_msg.pb.go +++ b/pb/entertain_msg.pb.go @@ -2208,6 +2208,8 @@ type EntertainSurrenderResp struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + + Leftcount int32 `protobuf:"varint,1,opt,name=leftcount,proto3" json:"leftcount"` // 投降剩余次数 } func (x *EntertainSurrenderResp) Reset() { @@ -2242,6 +2244,13 @@ func (*EntertainSurrenderResp) Descriptor() ([]byte, []int) { return file_entertain_entertain_msg_proto_rawDescGZIP(), []int{39} } +func (x *EntertainSurrenderResp) GetLeftcount() int32 { + if x != nil { + return x.Leftcount + } + return 0 +} + var File_entertain_entertain_msg_proto protoreflect.FileDescriptor var file_entertain_entertain_msg_proto_rawDesc = []byte{ @@ -2459,9 +2468,11 @@ var file_entertain_entertain_msg_proto_rawDesc = []byte{ 0x0a, 0x15, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x53, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x6f, 0x6f, 0x6d, 0x69, 0x64, 0x22, - 0x18, 0x0a, 0x16, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x53, 0x75, 0x72, 0x72, - 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, - 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x36, 0x0a, 0x16, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x53, 0x75, 0x72, 0x72, + 0x65, 0x6e, 0x64, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x65, 0x66, + 0x74, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x6c, 0x65, + 0x66, 0x74, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var (