优化
This commit is contained in:
parent
759f716eeb
commit
02f8b18c1b
@ -339,6 +339,7 @@ const (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
PagodaType = 101 // 普通塔
|
PagodaType = 101 // 普通塔
|
||||||
|
SeasonType = 2 // 赛季塔类型
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -32,9 +32,5 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.GourmetGetListRe
|
|||||||
// 计算订单信息
|
// 计算订单信息
|
||||||
this.module.modelGourmet.CalculationGourmet(session.GetUserId(), _gourmet)
|
this.module.modelGourmet.CalculationGourmet(session.GetUserId(), _gourmet)
|
||||||
session.SendMsg(string(this.module.GetType()), GourmetGetListResp, &pb.GourmetGetListResp{Data: _gourmet})
|
session.SendMsg(string(this.module.GetType()), GourmetGetListResp, &pb.GourmetGetListResp{Data: _gourmet})
|
||||||
|
|
||||||
// this.GetRandUser(session, &pb.GourmetGetRandUserReq{
|
|
||||||
// People: 10,
|
|
||||||
// })
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ func (this *TestService) InitSys() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_Main(t *testing.T) {
|
func Test_Main(t *testing.T) {
|
||||||
|
|
||||||
ids := utils.Numbers(0, 10, 5)
|
ids := utils.Numbers(0, 10, 5)
|
||||||
for _, v := range ids {
|
for _, v := range ids {
|
||||||
fmt.Printf("%d", v)
|
fmt.Printf("%d", v)
|
||||||
|
@ -28,5 +28,6 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.SmithyGetListReq
|
|||||||
// 计算订单信息
|
// 计算订单信息
|
||||||
this.module.modelSmithy.CalculationSmithy(session.GetUserId(), _gourmet)
|
this.module.modelSmithy.CalculationSmithy(session.GetUserId(), _gourmet)
|
||||||
session.SendMsg(string(this.module.GetType()), SmithyGetListResp, &pb.SmithyGetListResp{Data: _gourmet})
|
session.SendMsg(string(this.module.GetType()), SmithyGetListResp, &pb.SmithyGetListResp{Data: _gourmet})
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
package smithy
|
package smithy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/utils"
|
"go_dreamfactory/utils"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,14 +25,15 @@ 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) {
|
func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRandUserReq) (code pb.ErrorCode, data proto.Message) {
|
||||||
var (
|
var (
|
||||||
szDbUser []*pb.DBUser
|
szDbUser []*pb.DBUser
|
||||||
randOnlineUsers []string
|
mapUser map[string]struct{}
|
||||||
)
|
)
|
||||||
|
mapUser = make(map[string]struct{}, req.People)
|
||||||
code = this.GetRandUserCheck(session, req)
|
code = this.GetRandUserCheck(session, req)
|
||||||
if code != pb.ErrorCode_Success {
|
if code != pb.ErrorCode_Success {
|
||||||
return // 参数校验失败直接返回
|
return // 参数校验失败直接返回
|
||||||
}
|
}
|
||||||
// 获取在线玩家信息
|
// 获取在线玩家信息
|
||||||
onlineList, err := this.module.ModuleUser.UserOnlineList()
|
onlineList, err := this.module.ModuleUser.CrossUserOnlineList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
code = pb.ErrorCode_DBError
|
code = pb.ErrorCode_DBError
|
||||||
return
|
return
|
||||||
@ -36,27 +41,44 @@ func (this *apiComp) GetRandUser(session comm.IUserSession, req *pb.SmithyGetRan
|
|||||||
|
|
||||||
var szUid []string
|
var szUid []string
|
||||||
for _, v := range onlineList {
|
for _, v := range onlineList {
|
||||||
if v.Uid == session.GetUserId() { // 过滤自己信息
|
if v.Uid == session.GetUserId() || v.Uid == "" { // 过滤自己信息
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
mapUser[v.Uid] = struct{}{}
|
||||||
szUid = append(szUid, v.Uid)
|
szUid = append(szUid, v.Uid)
|
||||||
}
|
}
|
||||||
// 随机在线玩家信息
|
// 随机在线玩家信息
|
||||||
if len(onlineList) > int(req.People) {
|
if len(szUid) > int(req.People) {
|
||||||
randArr := utils.Numbers(0, len(onlineList), int(req.People))
|
randArr := utils.Numbers(0, len(szUid), int(req.People))
|
||||||
for _, v := range randArr {
|
for _, v := range randArr {
|
||||||
if szUid[v] != "" {
|
if szUid[v] != "" {
|
||||||
randOnlineUsers = append(randOnlineUsers, szUid[v])
|
mapUser[szUid[v]] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // 数量不足 则有多少给多少
|
} else { // 数量不足 则有多少给多少
|
||||||
for _, v := range szUid {
|
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})
|
session.SendMsg(string(this.module.GetType()), SmithyGetRandUserResp, &pb.SmithyGetRandUserResp{User: szDbUser})
|
||||||
return
|
return
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/cron"
|
"go_dreamfactory/lego/sys/cron"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func (this *SeasonPagoda) Start() (err error) {
|
|||||||
// _data := this.GetSeasonLoop(2)
|
// _data := this.GetSeasonLoop(2)
|
||||||
// this.module.Debugf("%v", _data)
|
// this.module.Debugf("%v", _data)
|
||||||
|
|
||||||
// this.TimerSeasonOver()
|
this.TimerSeasonOver()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData {
|
func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData {
|
||||||
@ -70,9 +70,8 @@ func (this *SeasonPagoda) GetSeasonLoop(id int32) *cfg.GameSeasonLoopData {
|
|||||||
// // 赛季塔结束
|
// // 赛季塔结束
|
||||||
func (this *SeasonPagoda) TimerSeasonOver() {
|
func (this *SeasonPagoda) TimerSeasonOver() {
|
||||||
this.module.Debugf("TimerSeasonOver:%d", time.Now().Unix())
|
this.module.Debugf("TimerSeasonOver:%d", time.Now().Unix())
|
||||||
// 修改
|
conf := this.GetSeasonLoop(comm.SeasonType) // 获取赛季塔重置配置
|
||||||
conf := this.GetSeasonLoop(2)
|
rest, err := this.DB.Find(comm.TableServerData, bson.M{}) // 查询服务器记录的赛季塔信息
|
||||||
rest, err := this.DB.Find(comm.TableServerData, bson.M{})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
serverData := &pb.DBServerData{}
|
serverData := &pb.DBServerData{}
|
||||||
for rest.Next(context.TODO()) {
|
for rest.Next(context.TODO()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user