112 lines
3.4 KiB
Go
112 lines
3.4 KiB
Go
package friend
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/pb"
|
|
|
|
"go.mongodb.org/mongo-driver/bson"
|
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|
)
|
|
|
|
//好友列表
|
|
|
|
func (this *apiComp) RefreshAssistHeroCheck(session comm.IUserSession, req *pb.FriendRefreshAssistHeroReq) (errdata *pb.ErrorData) {
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) RefreshAssistHero(session comm.IUserSession, req *pb.FriendRefreshAssistHeroReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
self *pb.DBFriend
|
|
err error
|
|
ahero []*pb.DBHero // 助战英雄列表
|
|
list *pb.DBAssistHero
|
|
strangerCount int32 // 陌生人的数量
|
|
friends []*pb.DBFriend
|
|
heros []*pb.DBHero
|
|
uids []string
|
|
names []string
|
|
//aherofr []*pb.DBHero // 好友的助战列表
|
|
)
|
|
list, err = this.module.modelAssist.getAssist(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
self, err = this.module.modelFriend.GetFriend(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendSelfNoData,
|
|
Title: pb.ErrorCode_FriendSelfNoData.ToString(),
|
|
}
|
|
return
|
|
}
|
|
if friends, err = this.module.modelFriend.GetFriends(self.FriendIds); err != nil {
|
|
for _, v := range friends {
|
|
if v.AssistHeroId != "" {
|
|
names = append(names, v.Info.Name)
|
|
uids = append(uids, v.Uid)
|
|
heros = append(heros, v.Hero)
|
|
}
|
|
}
|
|
}
|
|
|
|
if list.RefreshNum >= this.module.ModuleTools.GetGlobalConf().FriendHelpHeroRefreshNum {
|
|
return
|
|
}
|
|
list.RefreshNum++
|
|
strangerCount = comm.AssistHeroCount // 默认一个界面12条
|
|
if int32(len(uids)) > list.RefreshNum*comm.AssistHeroCount {
|
|
strangerCount = int32(len(uids)) - list.RefreshNum*comm.AssistHeroCount
|
|
if strangerCount > comm.AssistHeroCount {
|
|
strangerCount = comm.AssistHeroCount
|
|
}
|
|
heros = append(heros[list.RefreshNum*comm.AssistHeroCount : list.RefreshNum*comm.AssistHeroCount+strangerCount])
|
|
names = append(names[list.RefreshNum*comm.AssistHeroCount : list.RefreshNum*comm.AssistHeroCount+strangerCount])
|
|
uids = append(uids[list.RefreshNum*comm.AssistHeroCount : list.RefreshNum*comm.AssistHeroCount+strangerCount])
|
|
} else {
|
|
heros = []*pb.DBHero{}
|
|
names = []string{}
|
|
uids = []string{}
|
|
}
|
|
for pos, key := range uids {
|
|
list.Data[key] = names[pos]
|
|
ahero = append(ahero, heros[pos])
|
|
}
|
|
|
|
localNum, _ := this.module.modelFriend.DB.CountDocuments(core.SqlTable(this.module.modelFriend.TableName), bson.M{})
|
|
randomIndex := comm.GetRandNum(0, int32(localNum))
|
|
cur, err := this.module.modelFriend.DB.Find(core.SqlTable(this.module.modelFriend.TableName), bson.M{"assistHeroId": bson.M{"$ne": ""}}, options.Find().SetSkip(int64(randomIndex)).SetLimit(int64(strangerCount)))
|
|
for cur.Next(context.TODO()) {
|
|
tmp := &pb.DBFriend{}
|
|
if err = cur.Decode(tmp); err == nil {
|
|
ahero = append(ahero, tmp.Hero)
|
|
list.Data[tmp.Uid] = tmp.Info.Name
|
|
}
|
|
}
|
|
if err = this.module.modelAssist.Change(session.GetUserId(), map[string]interface{}{
|
|
"refreshNum": list.RefreshNum,
|
|
"data": list.Data,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), "refreshassisthero", &pb.FriendRefreshAssistHeroResp{
|
|
Data: list,
|
|
Hero: ahero,
|
|
})
|
|
|
|
return
|
|
}
|