fix: 修复PVP赛季数据结构及相关逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-03-13 12:04:35 +08:00
committed by cnb
parent b9985bff3b
commit 0d44de2ea7
7 changed files with 35 additions and 28 deletions

View File

@@ -22,16 +22,16 @@ func (r *RPCfight) join(pvp info.RPCFightinfo) {
ret := service.NewPVPService(pvp.PlayerID).Get(pvp.PlayerID)
score := 800
if ret != nil {
score = int(ret.RankInfo.Score)
score = int(ret.RankInfo[len(ret.RankInfo)-1].Score)
}
r.zs.Add(pvp.PlayerID,
ret)
if r.zs.Length() > 2 {
u, s := r.zs.FindPrev(func(i *model.PVP) bool { return i.RankInfo.Score > score })
u, s := r.zs.FindPrev(func(i *model.PVP) bool { return i.RankInfo[len(ret.RankInfo)-1].Score > score })
diff := s - score
// 等待越久,允许区间越大
wait := time.Now().Sub(u.RankInfo.LastMatchTime.Time).Seconds()
wait := time.Now().Sub(u.RankInfo[len(ret.RankInfo)-1].LastMatchTime.Time).Seconds()
maxAllow := 100 + int(wait)*10
if diff < maxAllow {
//找到上一个,如果区间分数少于一定,

View File

@@ -6,10 +6,26 @@ import (
"math/rand/v2"
"time"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
"github.com/gogf/gf/v2/util/grand"
)
// IsToday 判断给定时间是否是今天
func IsToday(t1 *gtime.Time) bool {
if t1 == nil {
return false
}
t := t1.Time
// 获取当前时间
now := time.Now()
// 比较年、月、日是否相同
return t.Year() == now.Year() &&
t.Month() == now.Month() &&
t.Day() == now.Day()
}
func FindWithIndex[T any](slice []T, predicate func(item T) bool) (int, *T, bool) {
for i := range slice {
if predicate(slice[i]) {