修改房间推荐算法每次推荐不同房间

This commit is contained in:
sk 2024-11-05 17:06:02 +08:00
parent 0176f59e76
commit 8444db2e85
1 changed files with 45 additions and 0 deletions

View File

@ -26,6 +26,7 @@ var SceneMgrSingleton = &SceneMgr{
coinSceneAutoId: common.CoinSceneStartId,
hundredSceneAutoId: common.HundredSceneStartId,
password: make(map[string]struct{}),
pushList: make(map[int]struct{}),
}
// SceneMgr 房间管理器
@ -38,6 +39,8 @@ type SceneMgr struct {
coinSceneAutoId int // 金币场房间号
hundredSceneAutoId int // 百人场房间号
password map[string]struct{} // 密码
pushList map[int]struct{} // 已经推荐过的房间列表
lastPushSceneId int // 最后推荐的房间id
}
// AllocReplayCode 获取回访码
@ -422,7 +425,49 @@ func (m *SceneMgr) FindCustomInviteRoom(p *Player) *Scene {
return ret[i].createTime.Unix() < ret[j].createTime.Unix()
})
// 删除没有的房间
var list []*Scene
var pushList = map[int]struct{}{}
for k := range m.pushList {
var has bool
for _, v := range ret {
if v.sceneId == k {
has = true
break
}
}
if has {
pushList[k] = struct{}{}
}
}
m.pushList = pushList
// 删除推荐过的房间
for _, v := range ret {
if _, ok := m.pushList[v.sceneId]; !ok {
list = append(list, v)
}
}
if len(list) > 0 {
m.pushList[list[0].sceneId] = struct{}{}
return list[0]
}
if len(ret) > 0 {
// 全都推荐过了,循环推荐房间
var b bool
for _, v := range ret {
if b {
m.lastPushSceneId = v.sceneId
return v
}
if v.sceneId == m.lastPushSceneId {
b = true
}
}
// 没找到,从头开始
m.lastPushSceneId = ret[0].sceneId
return ret[0]
}