From 4536d5173802cf441f209ae65493e5cebd598372 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Thu, 27 Oct 2022 17:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=AB=9E=E6=8A=80=E5=9C=BA?= =?UTF-8?q?=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/arena/modelarena.go | 10 ++++++++-- pb/arena_db.pb.go | 36 +++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/modules/arena/modelarena.go b/modules/arena/modelarena.go index 38feb6cab..d273af707 100644 --- a/modules/arena/modelarena.go +++ b/modules/arena/modelarena.go @@ -34,7 +34,12 @@ func (this *modelArena) Init(service core.IService, module core.IModule, comp co this.module = module.(*Arena) //创建uid索引 this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ - Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + Keys: bson.A{ + bsonx.Doc{ + {Key: "uid", Value: bsonx.Int32(1)}, + }, + bson.M{"loc": "2d"}, + }, }) return } @@ -119,6 +124,7 @@ 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)}, }) return } @@ -237,7 +243,7 @@ func (this *modelArena) matchePlayer(uid string, dan, num int32) (results []*pb. cursor *mongo.Cursor ) results = make([]*pb.ArenaPlayer, 0) - if cursor, err = this.DBModel.DB.Find(comm.TableArena, bson.M{"uid": bson.M{"$ne": uid}, "dan": dan}, options.Find().SetSkip(0).SetLimit(int64(num))); err != nil { + if cursor, err = this.DBModel.DB.Find(comm.TableArena, bson.M{"uid": bson.M{"$ne": uid}, "dan": dan, "loc": bson.M{"$near": []int32{dan * 1000, rand.Int31n(100)}, "$maxDistance": 100}}, options.Find().SetSkip(0).SetLimit(int64(num))); err != nil { this.module.Errorln(err) return } else { diff --git a/pb/arena_db.pb.go b/pb/arena_db.pb.go index 964e11050..d735b3b61 100644 --- a/pb/arena_db.pb.go +++ b/pb/arena_db.pb.go @@ -485,6 +485,7 @@ 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"` //地图索引 匹配系统使用 } func (x *DBArenaUser) Reset() { @@ -659,6 +660,13 @@ func (x *DBArenaUser) GetDefendtotaluum() int32 { return 0 } +func (x *DBArenaUser) GetLoc() []int32 { + if x != nil { + return x.Loc + } + return nil +} + var File_arena_arena_db_proto protoreflect.FileDescriptor var file_arena_arena_db_proto_rawDesc = []byte{ @@ -712,7 +720,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, 0xf1, 0x04, 0x0a, 0x0b, 0x44, 0x42, + 0x74, 0x65, 0x52, 0x05, 0x53, 0x74, 0x61, 0x74, 0x65, 0x22, 0x83, 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, @@ -751,18 +759,20 @@ var file_arena_arena_db_proto_rawDesc = []byte{ 0x6d, 0x18, 0x13, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x64, 0x65, 0x66, 0x65, 0x6e, 0x64, 0x77, 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, 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, + 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, } var (