From 745e047159aa2d63b04dcbfc4b6d692926dfbfde Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 27 Oct 2022 19:56:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8C=B9=E9=85=8D=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/arena/api_challenge.go | 1 + modules/arena/api_challengereward.go | 6 +- modules/arena/api_info.go | 1 + modules/arena/api_setdattformt.go | 3 +- modules/arena/api_setdefformt.go | 1 + modules/arena/modelarena.go | 16 ++++-- pb/arena_db.pb.go | 41 +++++++------ pb/arena_msg.pb.go | 86 ++++++++++++++++++++++------ sys/db/init_test.go | 20 +++++-- 9 files changed, 130 insertions(+), 45 deletions(-) diff --git a/modules/arena/api_challenge.go b/modules/arena/api_challenge.go index f6a770d85..3ea71e096 100644 --- a/modules/arena/api_challenge.go +++ b/modules/arena/api_challenge.go @@ -81,6 +81,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.ArenaChallenge Leadpos: req.Battle.Leadpos, Formt: heros, } + red.Isdef = true if err = this.module.modelArena.updateArenaUserInfo(red); err != nil { code = pb.ErrorCode_DBError return diff --git a/modules/arena/api_challengereward.go b/modules/arena/api_challengereward.go index e1a51fbe6..2908a80af 100644 --- a/modules/arena/api_challengereward.go +++ b/modules/arena/api_challengereward.go @@ -135,12 +135,12 @@ func (this *apiComp) ChallengeReward(session comm.IUserSession, req *pb.ArenaCha Isdefend: false, Rivalid: bule.Uid, Rivalname: bule.Name, - Leadpos: rival.Attack.Leadpos, - Formt: make([]*pb.DBHeroBase, len(rival.Attack.Formt)), + Leadpos: rival.Defend.Leadpos, + Formt: make([]*pb.DBHeroBase, len(rival.Defend.Formt)), Addintegral: red.Changeintegral, State: redstate, } - for i, v := range rival.Attack.Formt { + for i, v := range rival.Defend.Formt { if v != nil { redrecord.Formt[i] = &pb.DBHeroBase{ Oid: v.Id, diff --git a/modules/arena/api_info.go b/modules/arena/api_info.go index 5c6b6f411..7d2f736cd 100644 --- a/modules/arena/api_info.go +++ b/modules/arena/api_info.go @@ -53,6 +53,7 @@ func (this *apiComp) Info(session comm.IUserSession, req *pb.ArenaInfoReq) (code Ticket: 10, Record: make([]*pb.DBArenaBattleRecord, 0), Lastrtickettime: 0, + Isdef: false, } if info.Dan, err = this.module.modelArena.computedan(info.Integral); err != nil { code = pb.ErrorCode_ConfigNoFound diff --git a/modules/arena/api_setdattformt.go b/modules/arena/api_setdattformt.go index 392edf2f2..e39f315e7 100644 --- a/modules/arena/api_setdattformt.go +++ b/modules/arena/api_setdattformt.go @@ -31,10 +31,11 @@ func (this *apiComp) SetAttFormt(session comm.IUserSession, req *pb.ArenaSetAttF code = pb.ErrorCode_DBError return } - info.Defend = &pb.DBPlayerBattleFormt{ + info.Attack = &pb.DBPlayerBattleFormt{ Leadpos: req.Leadpos, Formt: heros, } + if err = this.module.modelArena.updateArenaUserInfo(info); err != nil { code = pb.ErrorCode_DBError return diff --git a/modules/arena/api_setdefformt.go b/modules/arena/api_setdefformt.go index 3f9251ec1..32af8559e 100644 --- a/modules/arena/api_setdefformt.go +++ b/modules/arena/api_setdefformt.go @@ -36,6 +36,7 @@ func (this *apiComp) SetDefFormt(session comm.IUserSession, req *pb.ArenaSetDefF Leadpos: req.Leadpos, Formt: heros, } + info.Isdef = true if err = this.module.modelArena.updateArenaUserInfo(info); err != nil { code = pb.ErrorCode_DBError return diff --git a/modules/arena/modelarena.go b/modules/arena/modelarena.go index 26217e000..f3ad95317 100644 --- a/modules/arena/modelarena.go +++ b/modules/arena/modelarena.go @@ -124,7 +124,8 @@ func (this *modelArena) updateArenaUserInfo(info *pb.DBArenaUser) (err error) { "attacktotaluum": info.Attacktotaluum, "defendwinuum": info.Defendwinuum, "defendtotaluum": info.Defendtotaluum, - "loc": []int32{dan * 1000, rand.Int31n(100)}, + "loc": []float64{float64(dan), float64(rand.Int31n(100)) / 1000.0}, + "isdef": info.Isdef, }) return } @@ -243,10 +244,17 @@ func (this *modelArena) matchePlayer(uid string, dan, num int32) (results []*pb. cursor *mongo.Cursor ) results = make([]*pb.ArenaPlayer, 0) + port := []float64{float64(dan), float64(rand.Int31n(100)) / 1000.0} if cursor, err = this.DBModel.DB.Find(comm.TableArena, bson.M{ - "uid": bson.M{"$ne": uid}, - "dan": dan, - "loc": bson.M{"$geoWithin": bson.M{"$center": bson.A{[]int32{dan * 1000, rand.Int31n(100)}, 100}}}, + "isdef": true, + "uid": bson.M{"$ne": uid}, + "dan": dan, + "loc": bson.M{ + "$near": bson.M{ + "$geometry": bson.M{"type": "Point", "coordinates": port}, + "$maxDistance": 100000, + }, + }, }, options.Find().SetSkip(0).SetLimit(int64(num))); err != nil { this.module.Errorln(err) return diff --git a/pb/arena_db.pb.go b/pb/arena_db.pb.go index d735b3b61..f5cc46365 100644 --- a/pb/arena_db.pb.go +++ b/pb/arena_db.pb.go @@ -485,7 +485,8 @@ type DBArenaUser struct { Attacktotaluum int32 `protobuf:"varint,18,opt,name=attacktotaluum,proto3" json:"attacktotaluum"` //进攻总次数 Defendwinuum int32 `protobuf:"varint,19,opt,name=defendwinuum,proto3" json:"defendwinuum"` //防守胜利 Defendtotaluum int32 `protobuf:"varint,20,opt,name=defendtotaluum,proto3" json:"defendtotaluum"` //防守总 - Loc []int32 `protobuf:"varint,21,rep,packed,name=loc,proto3" json:"loc"` //地图索引 匹配系统使用 + Loc []float64 `protobuf:"fixed64,21,rep,packed,name=loc,proto3" json:"loc"` //地图索引 匹配系统使用 + Isdef bool `protobuf:"varint,22,opt,name=isdef,proto3" json:"isdef"` //是否设置防守 } func (x *DBArenaUser) Reset() { @@ -660,13 +661,20 @@ func (x *DBArenaUser) GetDefendtotaluum() int32 { return 0 } -func (x *DBArenaUser) GetLoc() []int32 { +func (x *DBArenaUser) GetLoc() []float64 { if x != nil { return x.Loc } return nil } +func (x *DBArenaUser) GetIsdef() bool { + if x != nil { + return x.Isdef + } + return false +} + var File_arena_arena_db_proto protoreflect.FileDescriptor var file_arena_arena_db_proto_rawDesc = []byte{ @@ -720,7 +728,7 @@ var file_arena_arena_db_proto_rawDesc = []byte{ 0x28, 0x05, 0x52, 0x0b, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x74, 0x65, 0x67, 0x72, 0x61, 0x6c, 0x12, 0x28, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x53, 0x74, 0x61, - 0x74, 0x65, 0x52, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x22, 0x83, 0x05, 0x0a, 0x0b, 0x44, 0x42, + 0x74, 0x65, 0x52, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x22, 0x99, 0x05, 0x0a, 0x0b, 0x44, 0x42, 0x41, 0x72, 0x65, 0x6e, 0x61, 0x55, 0x73, 0x65, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, @@ -760,19 +768,20 @@ var file_arena_arena_db_proto_rawDesc = []byte{ 0x69, 0x6e, 0x75, 0x75, 0x6d, 0x12, 0x26, 0x0a, 0x0e, 0x64, 0x65, 0x66, 0x65, 0x6e, 0x64, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x75, 0x75, 0x6d, 0x18, 0x14, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x64, 0x65, 0x66, 0x65, 0x6e, 0x64, 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x75, 0x75, 0x6d, 0x12, 0x10, 0x0a, - 0x03, 0x6c, 0x6f, 0x63, 0x18, 0x15, 0x20, 0x03, 0x28, 0x05, 0x52, 0x03, 0x6c, 0x6f, 0x63, 0x2a, - 0x9f, 0x01, 0x0a, 0x11, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, - 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0d, 0x0a, 0x09, 0x41, 0x74, 0x74, 0x61, 0x63, 0x6b, 0x57, - 0x69, 0x6e, 0x10, 0x00, 0x12, 0x0e, 0x0a, 0x0a, 0x41, 0x74, 0x74, 0x61, 0x63, 0x6b, 0x4c, 0x6f, - 0x73, 0x74, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x44, 0x65, 0x66, 0x65, 0x6e, 0x64, 0x6b, 0x57, - 0x69, 0x6e, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x44, 0x65, 0x66, 0x65, 0x6e, 0x64, 0x4c, 0x6f, - 0x73, 0x74, 0x10, 0x03, 0x12, 0x12, 0x0a, 0x0e, 0x57, 0x61, 0x69, 0x74, 0x69, 0x6e, 0x67, 0x52, - 0x65, 0x76, 0x65, 0x6e, 0x67, 0x65, 0x10, 0x04, 0x12, 0x11, 0x0a, 0x0d, 0x52, 0x65, 0x76, 0x65, - 0x6e, 0x67, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0x05, 0x12, 0x14, 0x0a, 0x10, 0x52, - 0x65, 0x76, 0x65, 0x6e, 0x67, 0x65, 0x53, 0x75, 0x63, 0x63, 0x65, 0x65, 0x64, 0x65, 0x64, 0x10, - 0x06, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x65, 0x76, 0x65, 0x6e, 0x67, 0x65, 0x45, 0x6e, 0x64, 0x10, - 0x07, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x03, 0x6c, 0x6f, 0x63, 0x18, 0x15, 0x20, 0x03, 0x28, 0x01, 0x52, 0x03, 0x6c, 0x6f, 0x63, 0x12, + 0x14, 0x0a, 0x05, 0x69, 0x73, 0x64, 0x65, 0x66, 0x18, 0x16, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, + 0x69, 0x73, 0x64, 0x65, 0x66, 0x2a, 0x9f, 0x01, 0x0a, 0x11, 0x42, 0x61, 0x74, 0x74, 0x6c, 0x65, + 0x52, 0x65, 0x63, 0x6f, 0x72, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0d, 0x0a, 0x09, 0x41, + 0x74, 0x74, 0x61, 0x63, 0x6b, 0x57, 0x69, 0x6e, 0x10, 0x00, 0x12, 0x0e, 0x0a, 0x0a, 0x41, 0x74, + 0x74, 0x61, 0x63, 0x6b, 0x4c, 0x6f, 0x73, 0x74, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x44, 0x65, + 0x66, 0x65, 0x6e, 0x64, 0x6b, 0x57, 0x69, 0x6e, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x44, 0x65, + 0x66, 0x65, 0x6e, 0x64, 0x4c, 0x6f, 0x73, 0x74, 0x10, 0x03, 0x12, 0x12, 0x0a, 0x0e, 0x57, 0x61, + 0x69, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x76, 0x65, 0x6e, 0x67, 0x65, 0x10, 0x04, 0x12, 0x11, + 0x0a, 0x0d, 0x52, 0x65, 0x76, 0x65, 0x6e, 0x67, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, + 0x05, 0x12, 0x14, 0x0a, 0x10, 0x52, 0x65, 0x76, 0x65, 0x6e, 0x67, 0x65, 0x53, 0x75, 0x63, 0x63, + 0x65, 0x65, 0x64, 0x65, 0x64, 0x10, 0x06, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x65, 0x76, 0x65, 0x6e, + 0x67, 0x65, 0x45, 0x6e, 0x64, 0x10, 0x07, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/arena_msg.pb.go b/pb/arena_msg.pb.go index a084c22bb..aa432f95f 100644 --- a/pb/arena_msg.pb.go +++ b/pb/arena_msg.pb.go @@ -1054,6 +1054,44 @@ func (x *ArenaDelRewardResp) GetBid() string { return "" } +type ArenaPlotReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *ArenaPlotReq) Reset() { + *x = ArenaPlotReq{} + if protoimpl.UnsafeEnabled { + mi := &file_arena_arena_msg_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ArenaPlotReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ArenaPlotReq) ProtoMessage() {} + +func (x *ArenaPlotReq) ProtoReflect() protoreflect.Message { + mi := &file_arena_arena_msg_proto_msgTypes[20] + 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 ArenaPlotReq.ProtoReflect.Descriptor instead. +func (*ArenaPlotReq) Descriptor() ([]byte, []int) { + return file_arena_arena_msg_proto_rawDescGZIP(), []int{20} +} + var File_arena_arena_msg_proto protoreflect.FileDescriptor var file_arena_arena_msg_proto_rawDesc = []byte{ @@ -1139,7 +1177,8 @@ var file_arena_arena_msg_proto_rawDesc = []byte{ 0x3e, 0x0a, 0x12, 0x41, 0x72, 0x65, 0x6e, 0x61, 0x44, 0x65, 0x6c, 0x52, 0x65, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63, 0x63, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63, 0x63, 0x12, 0x10, 0x0a, - 0x03, 0x62, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, 0x69, 0x64, 0x42, + 0x03, 0x62, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, 0x69, 0x64, 0x22, + 0x0e, 0x0a, 0x0c, 0x41, 0x72, 0x65, 0x6e, 0x61, 0x50, 0x6c, 0x6f, 0x74, 0x52, 0x65, 0x71, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } @@ -1155,7 +1194,7 @@ func file_arena_arena_msg_proto_rawDescGZIP() []byte { return file_arena_arena_msg_proto_rawDescData } -var file_arena_arena_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 20) +var file_arena_arena_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 21) var file_arena_arena_msg_proto_goTypes = []interface{}{ (*ArenaInfoReq)(nil), // 0: ArenaInfoReq (*ArenaInfoResp)(nil), // 1: ArenaInfoResp @@ -1177,22 +1216,23 @@ var file_arena_arena_msg_proto_goTypes = []interface{}{ (*ArenaBuyResp)(nil), // 17: ArenaBuyResp (*ArenaDelRewardReq)(nil), // 18: ArenaDelRewardReq (*ArenaDelRewardResp)(nil), // 19: ArenaDelRewardResp - (*DBArenaUser)(nil), // 20: DBArenaUser - (*ArenaPlayer)(nil), // 21: ArenaPlayer - (*BattleFormation)(nil), // 22: BattleFormation - (ErrorCode)(0), // 23: ErrorCode - (*BattleInfo)(nil), // 24: BattleInfo - (*BattleReport)(nil), // 25: BattleReport + (*ArenaPlotReq)(nil), // 20: ArenaPlotReq + (*DBArenaUser)(nil), // 21: DBArenaUser + (*ArenaPlayer)(nil), // 22: ArenaPlayer + (*BattleFormation)(nil), // 23: BattleFormation + (ErrorCode)(0), // 24: ErrorCode + (*BattleInfo)(nil), // 25: BattleInfo + (*BattleReport)(nil), // 26: BattleReport } var file_arena_arena_msg_proto_depIdxs = []int32{ - 20, // 0: ArenaInfoResp.info:type_name -> DBArenaUser - 20, // 1: ArenaOtherInfoResp.info:type_name -> DBArenaUser - 21, // 2: ArenaMatcheResp.players:type_name -> ArenaPlayer - 22, // 3: ArenaChallengeReq.battle:type_name -> BattleFormation - 23, // 4: ArenaChallengeResp.code:type_name -> ErrorCode - 24, // 5: ArenaChallengeResp.info:type_name -> BattleInfo - 25, // 6: ArenaChallengeRewardReq.report:type_name -> BattleReport - 21, // 7: ArenaRankResp.players:type_name -> ArenaPlayer + 21, // 0: ArenaInfoResp.info:type_name -> DBArenaUser + 21, // 1: ArenaOtherInfoResp.info:type_name -> DBArenaUser + 22, // 2: ArenaMatcheResp.players:type_name -> ArenaPlayer + 23, // 3: ArenaChallengeReq.battle:type_name -> BattleFormation + 24, // 4: ArenaChallengeResp.code:type_name -> ErrorCode + 25, // 5: ArenaChallengeResp.info:type_name -> BattleInfo + 26, // 6: ArenaChallengeRewardReq.report:type_name -> BattleReport + 22, // 7: ArenaRankResp.players:type_name -> ArenaPlayer 8, // [8:8] is the sub-list for method output_type 8, // [8:8] is the sub-list for method input_type 8, // [8:8] is the sub-list for extension type_name @@ -1449,6 +1489,18 @@ func file_arena_arena_msg_proto_init() { return nil } } + file_arena_arena_msg_proto_msgTypes[20].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ArenaPlotReq); 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{ @@ -1456,7 +1508,7 @@ func file_arena_arena_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_arena_arena_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 20, + NumMessages: 21, NumExtensions: 0, NumServices: 0, }, diff --git a/sys/db/init_test.go b/sys/db/init_test.go index babe29ee4..1ccc3f1b1 100644 --- a/sys/db/init_test.go +++ b/sys/db/init_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "go_dreamfactory/comm" + "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/mgo" "go_dreamfactory/pb" "math/rand" @@ -12,6 +13,7 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) @@ -38,13 +40,23 @@ func Test_2D(t *testing.T) { fmt.Printf("err:%v", err) return } else { - port := []int32{2 * 1000, rand.Int31n(100)} + //创建uid索引 + _index, err := sys.CreateIndex(core.SqlTable(comm.TableArena), mongo.IndexModel{ + Keys: bson.M{"loc": "2dsphere"}, + }) + fmt.Printf("_index:%v err:%v \n", _index, err) + port := []float64{2, float64(rand.Int31n(100)) / 1000.0} fmt.Printf("port:%v \n", port) if cursor, err := sys.Find(comm.TableArena, bson.M{ - "dan": 2, + // "dan": 2, + // "loc": bson.M{ + // "$geoWithin": bson.M{ + // "$center": bson.A{port, 100}, + // }, "loc": bson.M{ - "$geoWithin": bson.M{ - "$center": bson.A{port, 30}, + "$near": bson.M{ + "$geometry": bson.M{"type": "Point", "coordinates": port}, + "$maxDistance": 100000, }, }, // bson.A{[]int32{2 * 1000, rand.Int31n(100)}, 100}