playroom好友优化,随机拜访好友去重

This commit is contained in:
hahwu 2026-04-08 18:06:13 +08:00
parent 6def839472
commit cf9dd92090
4 changed files with 39 additions and 0 deletions

View File

@ -35,6 +35,9 @@ func (p *Player) GetVisitorPlayer() int {
if GoUtil.InArray(k, todayVisitedUsers) {
continue
}
if GoUtil.InArray(k, PlayroomMod.RandVisitor) {
continue
}
if v.Time < now-86400 {
continue
}
@ -66,6 +69,9 @@ func (p *Player) GetVisitorPlayer() int {
if GoUtil.InArray(uid, todayVisitedUsers) {
continue
}
if GoUtil.InArray(uid, PlayroomMod.RandVisitor) {
continue
}
ps := G_GameLogicPtr.GetSimplePlayerByUid(uid)
if ps == nil {
continue

View File

@ -62,6 +62,7 @@ type PlayroomMod struct {
TodayVisitedUsers []int // 今日已拜访过的用户
ADItem map[int]*ItemInfo
WeeklyDiscount map[int]int // 每周折扣
RandVisitor []int // 随机访客
}
type DressInfo struct {
@ -604,6 +605,7 @@ func (p *PlayroomMod) ResetGame() {
p.GameReward = make(map[int]*item.Item)
p.InteractNum = 0
p.RevengeUid = 0
p.RandVisitor = nil
}
func (p *PlayroomMod) GetGameId() int {
return p.GameId
@ -1104,3 +1106,15 @@ func (p *PlayroomMod) AdWatch(Id int) error {
func (p *PlayroomMod) ResetWeeklyDiscount() {
p.WeeklyDiscount = make(map[int]int)
}
func (p *PlayroomMod) AddRandVisitor(id int) {
p.RandVisitor = append(p.RandVisitor, id)
}
func (p *PlayroomMod) GetRandVisitor() []int {
return p.RandVisitor
}
func (p *PlayroomMod) ResetRandVisitor() {
p.RandVisitor = make([]int, 0)
}

View File

@ -3101,6 +3101,12 @@ func ReqPlayroomInfo(player *Player, req *msg.ReqPlayroomInfo) error {
}
if req.Uid == -1 {
target = player.GetVisitorPlayer()
if target == 0 {
PlayroomMod.ResetRandVisitor()
target = player.GetVisitorPlayer()
} else {
PlayroomMod.AddRandVisitor(target)
}
}
if target == 0 {
player.PlayroomVisit(target)

View File

@ -0,0 +1,13 @@
package unit
import (
"server/game"
"testing"
)
func TestPlayroomVisit(t *testing.T) {
player := new(game.Player)
player.M_DwUin = 100101056
player.InitPlayerOnly()
player.GetVisitorPlayer()
}