From f7431e126ffc852d43f18620370735990205e9ad Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 25 Oct 2023 16:07:22 +0800 Subject: [PATCH] =?UTF-8?q?xxl=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/entertainment/api_match.go | 52 +++++------ modules/entertainment/gamemgr.go | 8 +- modules/entertainment/match.go | 7 +- modules/entertainment/module.go | 5 +- modules/entertainment/room.go | 60 +++++++++---- modules/entertainment/xxlPlat.go | 28 +++--- modules/entertainment/xxl_test.go | 12 +-- pb/entertain_msg.pb.go | 138 ++++++++++++++++++++++++----- 8 files changed, 213 insertions(+), 97 deletions(-) diff --git a/modules/entertainment/api_match.go b/modules/entertainment/api_match.go index eeb8d4e32..696549ba6 100644 --- a/modules/entertainment/api_match.go +++ b/modules/entertainment/api_match.go @@ -18,41 +18,31 @@ func (this *apiComp) MatchCheck(session comm.IUserSession, req *pb.EntertainMatc } func (this *apiComp) Match(session comm.IUserSession, req *pb.EntertainMatchReq) (errdata *pb.ErrorData) { - var ( - //bMatch bool - s2 comm.IUserSession - p1 *pb.PlayerData // 玩家1 - p2 *pb.PlayerData // 玩家2 - roomid string + user *pb.DBUser + err error ) - // 暂时只做机器人 - if robots, err := this.module.ModuleTools.RandRobotConfig(1); err == nil { - if len(robots) > 0 { - p2 = &pb.PlayerData{ - Uid: "999", // AI uid 暂定 - Name: robots[0].Name, - Score: 0, - Ps: 0, - Cardid: "27000001", // 机器人临时数据 - } - } - } - if u, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { - p1 = &pb.PlayerData{ - Uid: session.GetUserId(), // AI uid 暂定 - Name: u.Name, - Score: 0, - Ps: 0, - Cardid: "27000001", // 机器人临时数据 - } - } + user, err = this.module.ModuleUser.GetUser(session.GetUserId()) + if err != nil { - roomid = this.module.gameMgr.CreateRoom(session, s2, p1, p2) + } + this.module.match.MatchReq(&pb.DBXXLMatch{ + Userinfo: &pb.BaseUserInfo{ + Uid: user.Uid, + Sid: user.Sid, + Name: user.Name, + Gender: 0, + Skin: user.CurSkin, + Aframe: "", + Title: user.Curtitle, + Lv: user.Lv, + }, + Cardid: req.Idcard, + }) + + //room := this.module.gameMgr.CreateRoom(p1, p2) session.SendMsg(string(this.module.GetType()), "match", &pb.EntertainMatchResp{ - Maych: true, - Player: p2, - Roomid: roomid, + Maych: true, }) return } diff --git a/modules/entertainment/gamemgr.go b/modules/entertainment/gamemgr.go index 2548324ec..0709632cc 100644 --- a/modules/entertainment/gamemgr.go +++ b/modules/entertainment/gamemgr.go @@ -28,14 +28,14 @@ func (this *gameMgrComp) Init(service core.IService, module core.IModule, comp c return } -func (this *gameMgrComp) CreateRoom(s1 comm.IUserSession, s2 comm.IUserSession, p1 *pb.PlayerData, p2 *pb.PlayerData) (roomid string) { - room := new(Room) //初始化房间 - room = room.InitRoom(this.module, s1, s2, p1, p2) +func (this *gameMgrComp) CreateRoom(p1 *pb.PlayerData, p2 *pb.PlayerData) (room *Room) { + room = new(Room) //初始化房间 + room = room.InitRoom(this.module, p1, p2) this.lock.Lock() this.rooms[room.Id] = room this.lock.Unlock() - return room.Id + return room } func (this *gameMgrComp) CloseRoom(id string) { diff --git a/modules/entertainment/match.go b/modules/entertainment/match.go index ae9f3f679..ac51aee08 100644 --- a/modules/entertainment/match.go +++ b/modules/entertainment/match.go @@ -36,7 +36,6 @@ func (this *matchComp) Start() (err error) { func (this *matchComp) MatchReq(v *pb.DBXXLMatch) (err error) { data, _ := anypb.New(v) - this.module.service.Destroy() err = this.module.service.RpcCall( context.Background(), comm.Service_Mainte, @@ -46,7 +45,7 @@ func (this *matchComp) MatchReq(v *pb.DBXXLMatch) (err error) { Uid: v.Userinfo.Uid, Data: data, Matchnum: 2, // 匹配数量2 - Timeout: 10, + Timeout: 5, }, &pb.JoinMatchPoolResp{}) if err != nil { @@ -101,7 +100,9 @@ func (this *matchComp) MatchNotic(players map[string]interface{}) (err error) { } } } - //roomid := this.module.gameMgr.CreateRoom(p1, p2) + go func() { + this.module.gameMgr.CreateRoom(p1, p2) + }() return } diff --git a/modules/entertainment/module.go b/modules/entertainment/module.go index 104519d67..223075ff1 100644 --- a/modules/entertainment/module.go +++ b/modules/entertainment/module.go @@ -2,7 +2,6 @@ package entertainment import ( "go_dreamfactory/comm" - "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/pb" @@ -15,7 +14,7 @@ func NewModule() core.IModule { type Entertainment struct { modules.ModuleBase - service base.IRPCXService + service comm.IService api *apiComp configure *configureComp model *modelComp @@ -34,7 +33,7 @@ func (this *Entertainment) Init(service core.IService, module core.IModule, opti if err = this.ModuleBase.Init(service, module, options); err != nil { return } - this.service = service.(base.IRPCXService) + this.service = service.(comm.IService) return } diff --git a/modules/entertainment/room.go b/modules/entertainment/room.go index 8d34868de..a665e2ebb 100644 --- a/modules/entertainment/room.go +++ b/modules/entertainment/room.go @@ -1,6 +1,7 @@ package entertainment import ( + "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/sys/timewheel" "go_dreamfactory/modules" @@ -84,17 +85,27 @@ func (this *Room) operateTimeOut(task *timewheel.Task, args ...interface{}) { } } -func (this *Room) InitRoom(module *Entertainment, s1 comm.IUserSession, s2 comm.IUserSession, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room { - +func (this *Room) InitRoom(module *Entertainment, p1 *pb.PlayerData, p2 *pb.PlayerData) *Room { + var room *Room + this.module = module this.chessboard = new(MapData) this.chessboard.InitMap(module) // 初始化棋盘 + if s1, ok := this.module.GetUserSession(p1.Uid); !ok { + this.module.PutUserSession(s1) + } else { + this.szSession = append(this.szSession, s1.Clone()) + } - this.szSession = append(this.szSession, s1.Clone()) if p2.Uid != "999" { // 是否是机器人 - this.szSession = append(this.szSession, s2.Clone()) + if s2, ok := this.module.GetUserSession(p2.Uid); !ok { + this.module.PutUserSession(s2) + } else { + this.szSession = append(this.szSession, s2.Clone()) + } } this.MaxRound = module.ModuleTools.GetGlobalConf().ConsumeRounds - return &Room{ + + room = &Room{ ModuleBase: modules.ModuleBase{}, Id: primitive.NewObjectID().Hex(), szSession: this.szSession, @@ -105,6 +116,16 @@ func (this *Room) InitRoom(module *Entertainment, s1 comm.IUserSession, s2 comm. round: 1, MaxRound: this.MaxRound, } + + 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: this.player1, + User2: this.player2, + }, this.szSession...); err != nil { + this.Errorln(err) + } + return room } // AI 操作了 @@ -129,10 +150,10 @@ func (this *Room) AiOperator() { if this.NexPower != this.curPower { this.round++ } - - if len(szMap) > 0 { - this.player2.Energy += szMap[len(szMap)-1].CurEnergy - this.player2.Score += szMap[len(szMap)-1].CurSocre + for _, v := range szMap { // + if v.CurEnergy > 0 { + this.player2.Energy += v.CurEnergy + } } if bAddPs { @@ -283,8 +304,8 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr return } - if score, m, b := this.chessboard.CheckMap(color); score > 0 { - curScore += score + if m, b := this.chessboard.CheckMap(color, true); len(m) > 0 { + // curScore += score szMap = append(szMap, m...) bAddPs = b } else { // 不能消除 @@ -317,15 +338,20 @@ func (this *Room) ReceiveMessage(session comm.IUserSession, stype string, msg pr } this.player1.Ps = MaxPs } - if len(szMap) > 0 { + for _, v := range szMap { // if color == 1 { - this.player1.Energy += szMap[len(szMap)-1].CurEnergy - this.player1.Score += szMap[len(szMap)-1].CurSocre - } else { - this.player2.Energy += szMap[len(szMap)-1].CurEnergy - this.player2.Score += szMap[len(szMap)-1].CurSocre + this.player1.Score += v.CurSocre + if v.CurEnergy > 0 { + this.player1.Energy += v.CurEnergy + } else { + this.player2.Score += v.CurSocre + if v.CurEnergy > 0 { + this.player2.Energy += v.CurEnergy + } + } } } + if this.player1.Ps <= 0 { // 权限给下一个人 this.NexPower = this.player2.Uid if len(this.szSession) == 1 { // 校验2号玩家是不是AI diff --git a/modules/entertainment/xxlPlat.go b/modules/entertainment/xxlPlat.go index 8015d93b8..e3892c472 100644 --- a/modules/entertainment/xxlPlat.go +++ b/modules/entertainment/xxlPlat.go @@ -440,34 +440,34 @@ func (this *MapData) Check3X(color int32) (bEliminate bool, score int32, count i // 校验地图可消除的 判断各组上面2个和右边两个是否三个相等 // xc 判断用来是否加体力 -func (this *MapData) CheckMap(color int32) (score int32, szMap []*pb.MapData, xc bool) { +func (this *MapData) CheckMap(color int32, bSkill bool) (szMap []*pb.MapData, xc bool) { var curScore int32 var energy int32 for { curScore = 0 + energy = 0 if bRet, s, c := this.Check5X(color); bRet { - //fmt.Printf("=====检测消除5x===========\n") curScore += s energy += c xc = true // 只要有 4x 5x 就标记ture } if bRet, s, c := this.Check4X(color); bRet { - //fmt.Printf("=====检测消除4x===========\n") curScore += s energy += c xc = true } if bRet, s, c := this.Check3X(color); bRet { - //fmt.Printf("=====检测消除3x===========\n") curScore += s energy += c } - score += curScore // 总分 if this.DropGirde() { + if bSkill { + energy = 0 + } szMap = append(szMap, &pb.MapData{ Data: this.GetPalatData(), - CurSocre: score, + CurSocre: curScore, CurEnergy: energy, }) } @@ -531,13 +531,13 @@ func (this *MapData) AiSwapGirde() (score int32, szMap []*pb.MapData, oid1 int32 if b := this.SwapGirde(int32(pos), int32(pos+1)); b { oid1 = this.Plat[pos+1].Oid oid2 = this.Plat[pos].Oid - if s, m, b := this.CheckMap(2); s == 0 { + if m, b := this.CheckMap(2, true); len(m) > 0 { this.SwapGirde(int32(pos+1), int32(pos)) this.operElem = []int32{} oid1 = 0 oid2 = 0 } else { - score += s + szMap = append(szMap, m...) bAddPs = b break @@ -548,20 +548,22 @@ func (this *MapData) AiSwapGirde() (score int32, szMap []*pb.MapData, oid1 int32 if b := this.SwapGirde(int32(pos), int32(pos+Width)); b { oid1 = this.Plat[pos+Width].Oid oid2 = this.Plat[pos].Oid - if s, m, b := this.CheckMap(2); s == 0 { + if m, b := this.CheckMap(2, true); len(m) > 0 { this.SwapGirde(int32(pos+Width), int32(pos)) this.operElem = []int32{} oid1 = 0 oid2 = 0 } else { szMap = append(szMap, m...) - score += s bAddPs = b break } } } } + for _, v := range szMap { + score += v.CurSocre + } return } @@ -573,9 +575,11 @@ func (this *MapData) SkillUp(skillid int32, value int32) (score int32, szMap []* this.Plat[id] = &pb.GirdeData{} } if this.DropGirde() { - score, szMap, _ = this.CheckMap(1) + szMap, _ = this.CheckMap(1, false) + } + for _, v := range szMap { + score += v.CurSocre } - } return } diff --git a/modules/entertainment/xxl_test.go b/modules/entertainment/xxl_test.go index 2c45bf19c..23f891156 100644 --- a/modules/entertainment/xxl_test.go +++ b/modules/entertainment/xxl_test.go @@ -86,24 +86,24 @@ func Test_Main(t *testing.T) { m.InitMap(nil) m.SetMap() - var szMap []*pb.MapData + //var szMap []*pb.MapData // if bSwap, m := m.AiSwapGirde(); bSwap { // szMap = append(szMap, m...) // } m.SkillUp(1, 7) m.SwapGirde(1, 8) - m.CheckMap(1) + //m.CheckMap(1) m.DropGirde() - if score, m, _ := m.CheckMap(1); score > 0 { + // if m, _ := m.CheckMap(1, true); score > 0 { - szMap = append(szMap, m...) - } + // szMap = append(szMap, m...) + // } m.SwapGirde(1, 11) m.DropGirde() - m.CheckMap(1) + //m.CheckMap(1) time.Sleep(time.Second * 2000) diff --git a/pb/entertain_msg.pb.go b/pb/entertain_msg.pb.go index d9b2f7554..f1215c9c4 100644 --- a/pb/entertain_msg.pb.go +++ b/pb/entertain_msg.pb.go @@ -635,6 +635,77 @@ func (x *EntertainGameOverPush) GetRound() int32 { return 0 } +type EntertainEnterRoomPush struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Rooid string `protobuf:"bytes,1,opt,name=rooid,proto3" json:"rooid"` + Servepath string `protobuf:"bytes,2,opt,name=servepath,proto3" json:"servepath"` + User1 *PlayerData `protobuf:"bytes,3,opt,name=user1,proto3" json:"user1"` + User2 *PlayerData `protobuf:"bytes,4,opt,name=user2,proto3" json:"user2"` +} + +func (x *EntertainEnterRoomPush) Reset() { + *x = EntertainEnterRoomPush{} + if protoimpl.UnsafeEnabled { + mi := &file_entertain_entertain_msg_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *EntertainEnterRoomPush) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EntertainEnterRoomPush) ProtoMessage() {} + +func (x *EntertainEnterRoomPush) ProtoReflect() protoreflect.Message { + mi := &file_entertain_entertain_msg_proto_msgTypes[9] + 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 EntertainEnterRoomPush.ProtoReflect.Descriptor instead. +func (*EntertainEnterRoomPush) Descriptor() ([]byte, []int) { + return file_entertain_entertain_msg_proto_rawDescGZIP(), []int{9} +} + +func (x *EntertainEnterRoomPush) GetRooid() string { + if x != nil { + return x.Rooid + } + return "" +} + +func (x *EntertainEnterRoomPush) GetServepath() string { + if x != nil { + return x.Servepath + } + return "" +} + +func (x *EntertainEnterRoomPush) GetUser1() *PlayerData { + if x != nil { + return x.User1 + } + return nil +} + +func (x *EntertainEnterRoomPush) GetUser2() *PlayerData { + if x != nil { + return x.User2 + } + return nil +} + var File_entertain_entertain_msg_proto protoreflect.FileDescriptor var file_entertain_entertain_msg_proto_rawDesc = []byte{ @@ -709,8 +780,18 @@ var file_entertain_entertain_msg_proto_rawDesc = []byte{ 0x2e, 0x4d, 0x61, 0x70, 0x44, 0x61, 0x74, 0x61, 0x52, 0x07, 0x6d, 0x70, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x70, 0x6f, 0x77, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x72, 0x6f, 0x75, 0x6e, 0x64, 0x22, 0x92, 0x01, + 0x0a, 0x16, 0x45, 0x6e, 0x74, 0x65, 0x72, 0x74, 0x61, 0x69, 0x6e, 0x45, 0x6e, 0x74, 0x65, 0x72, + 0x52, 0x6f, 0x6f, 0x6d, 0x50, 0x75, 0x73, 0x68, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x6f, 0x6f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x72, 0x6f, 0x6f, 0x69, 0x64, 0x12, 0x1c, + 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x70, 0x61, 0x74, 0x68, 0x12, 0x21, 0x0a, 0x05, + 0x75, 0x73, 0x65, 0x72, 0x31, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x50, 0x6c, + 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, 0x72, 0x31, 0x12, + 0x21, 0x0a, 0x05, 0x75, 0x73, 0x65, 0x72, 0x32, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, + 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x75, 0x73, 0x65, + 0x72, 0x32, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -725,7 +806,7 @@ func file_entertain_entertain_msg_proto_rawDescGZIP() []byte { return file_entertain_entertain_msg_proto_rawDescData } -var file_entertain_entertain_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_entertain_entertain_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 10) var file_entertain_entertain_msg_proto_goTypes = []interface{}{ (*EntertainMatchReq)(nil), // 0: EntertainMatchReq (*EntertainMatchResp)(nil), // 1: EntertainMatchResp @@ -736,25 +817,28 @@ var file_entertain_entertain_msg_proto_goTypes = []interface{}{ (*EntertainOperatorResp)(nil), // 6: EntertainOperatorResp (*EntertainOperatorRstPush)(nil), // 7: EntertainOperatorRstPush (*EntertainGameOverPush)(nil), // 8: EntertainGameOverPush - (*PlayerData)(nil), // 9: PlayerData - (*MapData)(nil), // 10: MapData + (*EntertainEnterRoomPush)(nil), // 9: EntertainEnterRoomPush + (*PlayerData)(nil), // 10: PlayerData + (*MapData)(nil), // 11: MapData } var file_entertain_entertain_msg_proto_depIdxs = []int32{ - 9, // 0: EntertainMatchResp.player:type_name -> PlayerData - 9, // 1: EntertainStartGamePush.user1:type_name -> PlayerData - 9, // 2: EntertainStartGamePush.user2:type_name -> PlayerData - 10, // 3: EntertainStartGamePush.mpadata:type_name -> MapData - 10, // 4: EntertainOperatorRstPush.mpadata:type_name -> MapData - 9, // 5: EntertainOperatorRstPush.user1:type_name -> PlayerData - 9, // 6: EntertainOperatorRstPush.user2:type_name -> PlayerData - 9, // 7: EntertainGameOverPush.user1:type_name -> PlayerData - 9, // 8: EntertainGameOverPush.user2:type_name -> PlayerData - 10, // 9: EntertainGameOverPush.mpadata:type_name -> MapData - 10, // [10:10] is the sub-list for method output_type - 10, // [10:10] is the sub-list for method input_type - 10, // [10:10] is the sub-list for extension type_name - 10, // [10:10] is the sub-list for extension extendee - 0, // [0:10] is the sub-list for field type_name + 10, // 0: EntertainMatchResp.player:type_name -> PlayerData + 10, // 1: EntertainStartGamePush.user1:type_name -> PlayerData + 10, // 2: EntertainStartGamePush.user2:type_name -> PlayerData + 11, // 3: EntertainStartGamePush.mpadata:type_name -> MapData + 11, // 4: EntertainOperatorRstPush.mpadata:type_name -> MapData + 10, // 5: EntertainOperatorRstPush.user1:type_name -> PlayerData + 10, // 6: EntertainOperatorRstPush.user2:type_name -> PlayerData + 10, // 7: EntertainGameOverPush.user1:type_name -> PlayerData + 10, // 8: EntertainGameOverPush.user2:type_name -> PlayerData + 11, // 9: EntertainGameOverPush.mpadata:type_name -> MapData + 10, // 10: EntertainEnterRoomPush.user1:type_name -> PlayerData + 10, // 11: EntertainEnterRoomPush.user2:type_name -> PlayerData + 12, // [12:12] is the sub-list for method output_type + 12, // [12:12] is the sub-list for method input_type + 12, // [12:12] is the sub-list for extension type_name + 12, // [12:12] is the sub-list for extension extendee + 0, // [0:12] is the sub-list for field type_name } func init() { file_entertain_entertain_msg_proto_init() } @@ -872,6 +956,18 @@ func file_entertain_entertain_msg_proto_init() { return nil } } + file_entertain_entertain_msg_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*EntertainEnterRoomPush); 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{ @@ -879,7 +975,7 @@ func file_entertain_entertain_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_entertain_entertain_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 9, + NumMessages: 10, NumExtensions: 0, NumServices: 0, },