diff --git a/comm/const.go b/comm/const.go index 380a28d0c..2e0eaf3ec 100644 --- a/comm/const.go +++ b/comm/const.go @@ -341,6 +341,7 @@ const ( const ( PagodaType = 101 // 普通塔 + SeasonType = 2 // 赛季塔类型 ) const ( diff --git a/modules/gourmet/api_getlist.go b/modules/gourmet/api_getlist.go index 951c48651..239deb20d 100644 --- a/modules/gourmet/api_getlist.go +++ b/modules/gourmet/api_getlist.go @@ -32,9 +32,5 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.GourmetGetListRe // 计算订单信息 this.module.modelGourmet.CalculationGourmet(session.GetUserId(), _gourmet) session.SendMsg(string(this.module.GetType()), GourmetGetListResp, &pb.GourmetGetListResp{Data: _gourmet}) - - // this.GetRandUser(session, &pb.GourmetGetRandUserReq{ - // People: 10, - // }) return } diff --git a/modules/hero/hero_test.go b/modules/hero/hero_test.go index 663fbb5aa..3bd0fc7b4 100644 --- a/modules/hero/hero_test.go +++ b/modules/hero/hero_test.go @@ -60,6 +60,7 @@ func (this *TestService) InitSys() { } func Test_Main(t *testing.T) { + ids := utils.Numbers(0, 10, 5) for _, v := range ids { fmt.Printf("%d", v) diff --git a/modules/smithy/api_getlist.go b/modules/smithy/api_getlist.go index 6050fa1ff..c1f4e6a91 100644 --- a/modules/smithy/api_getlist.go +++ b/modules/smithy/api_getlist.go @@ -28,5 +28,6 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.SmithyGetListReq // 计算订单信息 this.module.modelSmithy.CalculationSmithy(session.GetUserId(), _gourmet) session.SendMsg(string(this.module.GetType()), SmithyGetListResp, &pb.SmithyGetListResp{Data: _gourmet}) + return } diff --git a/modules/smithy/api_getranduser.go b/modules/smithy/api_getranduser.go index 3f2ddb9f7..ed6b75b3d 100644 --- a/modules/smithy/api_getranduser.go +++ b/modules/smithy/api_getranduser.go @@ -1,10 +1,14 @@ package smithy import ( + "context" "go_dreamfactory/comm" + "go_dreamfactory/lego/core" "go_dreamfactory/pb" "go_dreamfactory/utils" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo/options" "google.golang.org/protobuf/proto" ) @@ -20,15 +24,16 @@ func (this *apiComp) GetRandUserCheck(session comm.IUserSession, req *pb.SmithyG /// 获取一些玩家数据 func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRandUserReq) (code pb.ErrorCode, data proto.Message) { var ( - szDbUser []*pb.DBUser - randOnlineUsers []string + szDbUser []*pb.DBUser + mapUser map[string]struct{} ) + mapUser = make(map[string]struct{}, req.People) code = this.GetRandUserCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } // 获取在线玩家信息 - onlineList, err := this.module.ModuleUser.UserOnlineList() + onlineList, err := this.module.ModuleUser.CrossUserOnlineList() if err != nil { code = pb.ErrorCode_DBError return @@ -36,27 +41,44 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRan var szUid []string for _, v := range onlineList { - if v.Uid == session.GetUserId() { // 过滤自己信息 + if v.Uid == session.GetUserId() || v.Uid == "" { // 过滤自己信息 continue } - + mapUser[v.Uid] = struct{}{} szUid = append(szUid, v.Uid) } // 随机在线玩家信息 - if len(onlineList) > int(req.People) { - randArr := utils.Numbers(0, len(onlineList), int(req.People)) + if len(szUid) > int(req.People) { + randArr := utils.Numbers(0, len(szUid), int(req.People)) for _, v := range randArr { if szUid[v] != "" { - randOnlineUsers = append(randOnlineUsers, szUid[v]) + mapUser[szUid[v]] = struct{}{} } } } else { // 数量不足 则有多少给多少 for _, v := range szUid { - randOnlineUsers = append(randOnlineUsers, v) + mapUser[v] = struct{}{} + } + left := int(req.People) - len(mapUser) + if left > 0 { // 一个人也没有 那就从db 中随机取 + if _data, err1 := this.module.modelSmithy.DB.Find(core.SqlTable(comm.TableUser), bson.M{}, options.Find().SetSort(bson.M{"lv": -1}).SetLimit(int64(req.People))); err1 == nil { + for _data.Next(context.TODO()) { + temp := &pb.DBUser{} + if err = _data.Decode(temp); err == nil { + if len(mapUser) >= int(req.People) { + break + } + if _, ok := mapUser[temp.Uid]; !ok { + mapUser[temp.Uid] = struct{}{} + } + } + } + } } } - for _, v := range randOnlineUsers { - szDbUser = append(szDbUser, this.module.ModuleUser.GetUser(v)) // 转成user对象 + for k := range mapUser { + user, _ := this.module.ModuleUser.GetCrossUser(k) + szDbUser = append(szDbUser, user) // 转成user对象 } session.SendMsg(string(this.module.GetType()), SmithyGetRandUserResp, &pb.SmithyGetRandUserResp{User: szDbUser}) return diff --git a/modules/timer/chat.go b/modules/timer/chat.go index a4753f69a..fcdcde899 100644 --- a/modules/timer/chat.go +++ b/modules/timer/chat.go @@ -14,7 +14,6 @@ import ( "go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/log" - "go.mongodb.org/mongo-driver/bson" "google.golang.org/protobuf/types/known/anypb" ) @@ -78,7 +77,6 @@ func (this *ChatComp) Start() (err error) { } } }) - this.module.chat.module.rank.DB.Find("heor", bson.M{}) return } diff --git a/modules/timer/season.go b/modules/timer/season.go index 5d2703aa5..782e6951a 100644 --- a/modules/timer/season.go +++ b/modules/timer/season.go @@ -50,7 +50,7 @@ func (this *SeasonPagoda) Start() (err error) { // _data := this.GetSeasonLoop(2) // this.module.Debugf("%v", _data) - // this.TimerSeasonOver() + this.TimerSeasonOver() return } func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData { @@ -70,9 +70,8 @@ func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData { // // 赛季塔结束 func (this *SeasonPagoda) TimerSeasonOver() { this.module.Debugf("TimerSeasonOver:%d", time.Now().Unix()) - // 修改 - conf := this.GetSeasonLoop(2) - rest, err := this.DB.Find(comm.TableServerData, bson.M{}) + conf := this.GetSeasonLoop(comm.SeasonType) // 获取赛季塔重置配置 + rest, err := this.DB.Find(comm.TableServerData, bson.M{}) // 查询服务器记录的赛季塔信息 if err != nil { serverData := &pb.DBServerData{} for rest.Next(context.TODO()) {