diff --git a/modules/entertainment/gamemgr.go b/modules/entertainment/gamemgr.go index 84bfcfc9a..6975e8a09 100644 --- a/modules/entertainment/gamemgr.go +++ b/modules/entertainment/gamemgr.go @@ -62,11 +62,13 @@ func (this *gameMgrComp) CreateMasterRoom(p *pb.PlayerData) (room *Room, err err return } -// 匹配加入房间 -func (this *gameMgrComp) MatchJoinRoom(p1 *pb.PlayerData, p2 *pb.PlayerData) (room *Room) { +// 创建一个玩法类型的房间(itype :-1 表示随机玩法) +func (this *gameMgrComp) CreateRoomByType(p1 *pb.PlayerData, p2 *pb.PlayerData, itype int32) (room *Room, err error) { room = new(Room) //初始化房间 - room = room.InitRoom(this.module, p1, p2) - + room, err = room.InitRoom(this.module, p1, p2, itype) + if err != nil { + return + } this.lock.Lock() this.rooms[room.Id] = room this.lock.Unlock() diff --git a/modules/entertainment/match.go b/modules/entertainment/match.go index bd3fc6eb2..9f940fa0e 100644 --- a/modules/entertainment/match.go +++ b/modules/entertainment/match.go @@ -108,7 +108,7 @@ func (this *matchComp) MatchNotic(players map[string]interface{}) (err error) { } } go func() { - this.module.gameMgr.MatchJoinRoom(p1, p2) + this.module.gameMgr.CreateRoomByType(p1, p2, -1) }() return diff --git a/modules/entertainment/module.go b/modules/entertainment/module.go index 7f6a5a0d9..b86e27f26 100644 --- a/modules/entertainment/module.go +++ b/modules/entertainment/module.go @@ -2,10 +2,12 @@ package entertainment import ( "context" + "encoding/json" "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/event" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" ) @@ -164,6 +166,69 @@ func (this *Entertainment) useroffline(ctx context.Context, req *pb.RPCGeneralRe } func (this *Entertainment) CreateRoom(sessions []comm.IUserSession, rulesStr string) (roomid string, err error) { + var ( + rules *pb.DBXxlRules = &pb.DBXxlRules{} + red *pb.DBUser + blue *pb.DBUser + p1 *pb.PlayerData + p2 *pb.PlayerData + room *Room + ) + + if err = json.Unmarshal([]byte(rulesStr), rules); err != nil { + this.Error("解析规则json", log.Field{Key: "err", Value: err.Error()}) + return + } + // 参数校验 + if rules.Card1 == "" || rules.Card2 == "" { + this.Error("未找到卡片信息", + log.Field{Key: "uid", Value: sessions[0].GetUserId()}, + log.Field{Key: "card1", Value: rules.Card1}, + log.Field{Key: "uid", Value: sessions[1].GetUserId()}, + log.Field{Key: "card2", Value: rules.Card2}) + return + } + //发起者 red + red, err = this.ModuleUser.GetUser(sessions[0].GetUserId()) + if err != nil { + this.Error("未找到红方信息", log.Field{Key: "uid", Value: sessions[0].GetUserId()}) + return + } + blue, err = this.ModuleUser.GetUser(sessions[1].GetUserId()) + if err != nil { + this.Error("未找到蓝方信息", log.Field{Key: "uid", Value: sessions[1].GetUserId()}) + return + } + p1 = &pb.PlayerData{ + Userinfo: &pb.BaseUserInfo{ + Uid: red.Uid, + Sid: red.Sid, + Name: red.Name, + Gender: red.Gender, + Skin: red.CurSkin, + Aframe: red.Curaframe, + Title: red.Curtitle, + Lv: red.Lv, + }, + Cardid: rules.Card1, + } + p2 = &pb.PlayerData{ + Userinfo: &pb.BaseUserInfo{ + Uid: blue.Uid, + Sid: blue.Sid, + Name: blue.Name, + Gender: blue.Gender, + Skin: blue.CurSkin, + Aframe: blue.Curaframe, + Title: blue.Curtitle, + Lv: blue.Lv, + }, + Cardid: rules.Card2, + } + + if room, err = this.gameMgr.CreateRoomByType(p1, p2, rules.RoomType); err != nil { + roomid = room.Id + } return } diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index f21107215..595c56f8f 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -61,11 +61,22 @@ func (this *Room) RandomPlayType() (itype int32) { return } -func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room { - var room *Room +func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.PlayerData, itype int32) (room *Room, err error) { this.module = module this.chessboard = new(MapData) - this.Playtype = this.RandomPlayType() + if itype == -1 { + this.Playtype = this.RandomPlayType() + } else { + if itype == 0 { + itype = 1 // 测试数据 后面删 + } + this.Playtype = itype + // 校验类型 + if _, err = this.module.configure.GetGameConsumeIntegralByKey(this.Playtype); err != nil { + return + } + } + this.chessboard.InitMap(module, this.Playtype) // 初始化棋盘 if s1, ok := this.module.GetUserSession(p1.Userinfo.Uid); !ok { this.module.PutUserSession(s1) @@ -97,7 +108,7 @@ func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.Play RoomType: this.RoomType, } - if err := this.module.SendMsgSyncToSession(string(this.module.GetType()), "enterroom", &pb.EntertainEnterRoomPush{ + if err = this.module.SendMsgSyncToSession(string(this.module.GetType()), "enterroom", &pb.EntertainEnterRoomPush{ Rooid: room.Id, Servepath: fmt.Sprintf("%s/%s", this.module.service.GetType(), this.module.service.GetId()), User1: room.player1, @@ -105,7 +116,7 @@ func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.Play }, this.szSession...); err != nil { this.module.Errorln(err) } - return room + return } // AI 操作了 diff --git a/modules/gameinvite/api_accept.go b/modules/gameinvite/api_accept.go index d4e4079b0..8c589905f 100644 --- a/modules/gameinvite/api_accept.go +++ b/modules/gameinvite/api_accept.go @@ -151,6 +151,16 @@ func (this *apiComp) Accept(session comm.IUserSession, req *pb.GameInviteAcceptR return } break + case 5: // 三消类型 + if roomid, err = this.module.catchBugs.CreateRoom(sessions, req.Rules); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.ToString(), + Message: err.Error(), + } + return + } + break } redRecord.Status = 1 redRecord.Roomid = roomid diff --git a/pb/entertain_db.pb.go b/pb/entertain_db.pb.go index 7676c65fe..f396776e5 100644 --- a/pb/entertain_db.pb.go +++ b/pb/entertain_db.pb.go @@ -498,6 +498,70 @@ func (x *DBXXLData) GetEtime() int64 { return 0 } +// 三消游戏规则 +type DBXxlRules struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + RoomType int32 `protobuf:"varint,1,opt,name=RoomType,proto3" json:"RoomType"` // 房间类型 + Card1 string `protobuf:"bytes,2,opt,name=card1,proto3" json:"card1"` // player1 卡 + Card2 string `protobuf:"bytes,3,opt,name=card2,proto3" json:"card2"` // player2 卡 +} + +func (x *DBXxlRules) Reset() { + *x = DBXxlRules{} + if protoimpl.UnsafeEnabled { + mi := &file_entertain_entertain_db_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DBXxlRules) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DBXxlRules) ProtoMessage() {} + +func (x *DBXxlRules) ProtoReflect() protoreflect.Message { + mi := &file_entertain_entertain_db_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DBXxlRules.ProtoReflect.Descriptor instead. +func (*DBXxlRules) Descriptor() ([]byte, []int) { + return file_entertain_entertain_db_proto_rawDescGZIP(), []int{6} +} + +func (x *DBXxlRules) GetRoomType() int32 { + if x != nil { + return x.RoomType + } + return 0 +} + +func (x *DBXxlRules) GetCard1() string { + if x != nil { + return x.Card1 + } + return "" +} + +func (x *DBXxlRules) GetCard2() string { + if x != nil { + return x.Card2 + } + return "" +} + var File_entertain_entertain_db_proto protoreflect.FileDescriptor var file_entertain_entertain_db_proto_rawDesc = []byte{ @@ -567,8 +631,13 @@ var file_entertain_entertain_db_proto_rawDesc = []byte{ 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, - 0x01, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x01, 0x22, 0x54, 0x0a, 0x0a, 0x44, 0x42, 0x58, 0x78, 0x6c, 0x52, 0x75, 0x6c, 0x65, 0x73, 0x12, + 0x1a, 0x0a, 0x08, 0x52, 0x6f, 0x6f, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x08, 0x52, 0x6f, 0x6f, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63, + 0x61, 0x72, 0x64, 0x31, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x63, 0x61, 0x72, 0x64, + 0x31, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x61, 0x72, 0x64, 0x32, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x63, 0x61, 0x72, 0x64, 0x32, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -583,7 +652,7 @@ func file_entertain_entertain_db_proto_rawDescGZIP() []byte { return file_entertain_entertain_db_proto_rawDescData } -var file_entertain_entertain_db_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_entertain_entertain_db_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_entertain_entertain_db_proto_goTypes = []interface{}{ (*MapData)(nil), // 0: MapData (*GirdeData)(nil), // 1: GirdeData @@ -591,16 +660,17 @@ var file_entertain_entertain_db_proto_goTypes = []interface{}{ (*DBXXLMatch)(nil), // 3: DBXXLMatch (*BoxData)(nil), // 4: BoxData (*DBXXLData)(nil), // 5: DBXXLData - nil, // 6: DBXXLData.RewardEntry - nil, // 7: DBXXLData.CardEntry - (*BaseUserInfo)(nil), // 8: BaseUserInfo + (*DBXxlRules)(nil), // 6: DBXxlRules + nil, // 7: DBXXLData.RewardEntry + nil, // 8: DBXXLData.CardEntry + (*BaseUserInfo)(nil), // 9: BaseUserInfo } var file_entertain_entertain_db_proto_depIdxs = []int32{ 1, // 0: MapData.data:type_name -> GirdeData - 8, // 1: PlayerData.userinfo:type_name -> BaseUserInfo - 8, // 2: DBXXLMatch.userinfo:type_name -> BaseUserInfo - 6, // 3: DBXXLData.reward:type_name -> DBXXLData.RewardEntry - 7, // 4: DBXXLData.card:type_name -> DBXXLData.CardEntry + 9, // 1: PlayerData.userinfo:type_name -> BaseUserInfo + 9, // 2: DBXXLMatch.userinfo:type_name -> BaseUserInfo + 7, // 3: DBXXLData.reward:type_name -> DBXXLData.RewardEntry + 8, // 4: DBXXLData.card:type_name -> DBXXLData.CardEntry 4, // 5: DBXXLData.box:type_name -> BoxData 6, // [6:6] is the sub-list for method output_type 6, // [6:6] is the sub-list for method input_type @@ -688,6 +758,18 @@ func file_entertain_entertain_db_proto_init() { return nil } } + file_entertain_entertain_db_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DBXxlRules); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -695,7 +777,7 @@ func file_entertain_entertain_db_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_entertain_entertain_db_proto_rawDesc, NumEnums: 0, - NumMessages: 8, + NumMessages: 9, NumExtensions: 0, NumServices: 0, },