2026-03-04 23:38:21 +08:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-20 04:58:23 +08:00
|
|
|
"blazing/common/data/share"
|
|
|
|
|
"blazing/cool"
|
2026-03-04 23:38:21 +08:00
|
|
|
"blazing/logic/service/common"
|
2026-03-05 11:21:38 +08:00
|
|
|
"blazing/logic/service/fight/info"
|
|
|
|
|
"blazing/modules/player/model"
|
2026-03-04 23:38:21 +08:00
|
|
|
"blazing/modules/player/service"
|
2026-03-20 04:58:23 +08:00
|
|
|
"context"
|
2026-03-05 11:21:38 +08:00
|
|
|
"encoding/json"
|
2026-03-04 23:38:21 +08:00
|
|
|
"time"
|
|
|
|
|
|
2026-03-20 04:58:23 +08:00
|
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
2026-03-04 23:38:21 +08:00
|
|
|
"github.com/liwnn/zset"
|
|
|
|
|
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type RPCfight struct {
|
|
|
|
|
fightmap *csmap.CsMap[int, common.FightI]
|
2026-03-05 11:21:38 +08:00
|
|
|
zs *zset.ZSet[uint32, *model.PVP]
|
2026-03-04 23:38:21 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-12 14:35:27 +08:00
|
|
|
func (r *RPCfight) join(pvp info.RPCFightinfo) {
|
2026-03-04 23:38:21 +08:00
|
|
|
|
2026-03-05 13:21:58 +08:00
|
|
|
ret := service.NewPVPService(pvp.PlayerID).Get(pvp.PlayerID)
|
2026-03-20 04:58:23 +08:00
|
|
|
ret.RankInfo.LastMatchTime = gtime.Now()
|
|
|
|
|
|
|
|
|
|
r.zs.Add(pvp.PlayerID, ret)
|
|
|
|
|
if r.zs.Length() > 1 {
|
|
|
|
|
u, _ := r.zs.FindNext(func(i *model.PVP) bool { return i.RankInfo.Score >= ret.RankInfo.Score })
|
2026-03-04 23:38:21 +08:00
|
|
|
|
2026-03-20 04:58:23 +08:00
|
|
|
diff := u.RankInfo.Score - ret.RankInfo.Score
|
2026-03-05 11:21:38 +08:00
|
|
|
// 等待越久,允许区间越大
|
2026-03-20 04:58:23 +08:00
|
|
|
wait := time.Now().Sub(u.RankInfo.LastMatchTime.Time).Seconds()
|
2026-03-05 11:21:38 +08:00
|
|
|
maxAllow := 100 + int(wait)*10
|
|
|
|
|
if diff < maxAllow {
|
|
|
|
|
//找到上一个,如果区间分数少于一定,
|
|
|
|
|
//直接进行匹配
|
2026-03-20 04:58:23 +08:00
|
|
|
useid1, _ := share.ShareManager.GetUserOnline(u.PlayerID)
|
|
|
|
|
cool.RedisDo(context.TODO(), "sun:start:"+gconv.String(useid1), info.RPCFightStartinfo{
|
|
|
|
|
Serverid: int(useid1),
|
|
|
|
|
PlayerID: u.PlayerID,
|
|
|
|
|
Mode: pvp.Mode,
|
|
|
|
|
Status: pvp.Status,
|
|
|
|
|
})
|
2026-03-05 11:21:38 +08:00
|
|
|
}
|
2026-03-04 23:38:21 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 14:35:27 +08:00
|
|
|
func (r *RPCfight) ADD(s string) {
|
|
|
|
|
println("收到sun:join", s)
|
2026-03-20 04:58:23 +08:00
|
|
|
var pvp []info.RPCFightinfo
|
|
|
|
|
|
2026-03-12 14:35:27 +08:00
|
|
|
json.Unmarshal([]byte(s), &pvp)
|
2026-03-20 04:58:23 +08:00
|
|
|
if pvp[0].Type == 1 {
|
|
|
|
|
r.join(pvp[0])
|
2026-03-12 14:35:27 +08:00
|
|
|
} else { //==0 退出
|
2026-03-20 04:58:23 +08:00
|
|
|
r.cancel(pvp[0])
|
2026-03-12 14:35:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
func (r *RPCfight) cancel(pvp info.RPCFightinfo) {
|
|
|
|
|
r.zs.Remove(pvp.PlayerID)
|
2026-03-05 13:21:58 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-04 23:38:21 +08:00
|
|
|
///定义map,存储用户对战斗容器的映射,便于外部传入时候进行直接操作
|
|
|
|
|
|
|
|
|
|
var fightmap = RPCfight{
|
|
|
|
|
fightmap: csmap.New[int, common.FightI](),
|
2026-03-05 11:21:38 +08:00
|
|
|
zs: zset.New[uint32, *model.PVP](func(a, b *model.PVP) bool {
|
2026-03-04 23:38:21 +08:00
|
|
|
return a.Less(b)
|
|
|
|
|
}),
|
|
|
|
|
}
|