This commit is contained in:
殷勇 2023-11-06 12:06:37 +08:00
parent 4a3955fd5b
commit b2b6ec729a
2 changed files with 18 additions and 18 deletions

View File

@ -8,7 +8,6 @@ import (
"math/rand" "math/rand"
"mt" "mt"
"q5" "q5"
"sort"
"time" "time"
) )
@ -890,22 +889,6 @@ func (gm *GuildMgr) SearchGuild(sinceId int64, name string, cb func(errCode int3
}) })
} }
func (gm *GuildMgr) GetTopGuildsByTotalStars(rankNum int) []*Guild {
allGuilds := make([]*Guild, 0, len(gm.guilds))
for _, guild := range gm.guilds {
allGuilds = append(allGuilds, guild)
}
sort.Slice(allGuilds, func(i, j int) bool {
return allGuilds[i].TotalStars > allGuilds[j].TotalStars
})
if len(allGuilds) <= rankNum {
return allGuilds
}
return allGuilds[:rankNum]
}
// RandomGuilds 随机10个公会 // RandomGuilds 随机10个公会
func (gm *GuildMgr) RandomGuilds() []*Guild { func (gm *GuildMgr) RandomGuilds() []*Guild {
if len(gm.guilds) <= RandomGuildCount { if len(gm.guilds) <= RandomGuildCount {

View File

@ -5,6 +5,7 @@ import (
"f5" "f5"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"q5" "q5"
"sort"
) )
type Player struct { type Player struct {
@ -350,7 +351,23 @@ func (p *Player) CMRecommendGuildList(hdr *f5.MsgHdr, msg *cs.CMRecommendGuildLi
func (p *Player) CMGetTopGuildsByTotalStars(hdr *f5.MsgHdr, msg *cs.CMGetTopGuildsByTotalStars) { func (p *Player) CMGetTopGuildsByTotalStars(hdr *f5.MsgHdr, msg *cs.CMGetTopGuildsByTotalStars) {
rspMsg := new(cs.SMGetTopGuildsByTotalStars) rspMsg := new(cs.SMGetTopGuildsByTotalStars)
guildsNum := int(msg.GetGuildsNum()) guildsNum := int(msg.GetGuildsNum())
rspMsg.Guilds = p.FillMFGuilds(guildMgr.GetTopGuildsByTotalStars(guildsNum))
var allMFGuilds []*cs.MFGuild
for _, g := range guildMgr.guilds {
guild := p.FillMFGuild(g)
allMFGuilds = append(allMFGuilds, guild)
}
sort.Slice(allMFGuilds, func(i, j int) bool {
return allMFGuilds[i].GetTotalStars() > allMFGuilds[j].GetTotalStars()
})
if guildsNum > len(allMFGuilds) {
guildsNum = len(allMFGuilds)
}
allMFGuilds = allMFGuilds[:guildsNum]
rspMsg.Guilds = allMFGuilds
p.SendMsg(rspMsg) p.SendMsg(rspMsg)
} }