67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package rpc
|
|
|
|
import (
|
|
"blazing/logic/service/common"
|
|
"blazing/logic/service/fight/info"
|
|
"blazing/modules/player/model"
|
|
"blazing/modules/player/service"
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/liwnn/zset"
|
|
csmap "github.com/mhmtszr/concurrent-swiss-map"
|
|
)
|
|
|
|
type RPCfight struct {
|
|
fightmap *csmap.CsMap[int, common.FightI]
|
|
zs *zset.ZSet[uint32, *model.PVP]
|
|
}
|
|
|
|
func (r *RPCfight) join(pvp info.RPCFightinfo) {
|
|
|
|
ret := service.NewPVPService(pvp.PlayerID).Get(pvp.PlayerID)
|
|
score := 800
|
|
if ret != nil {
|
|
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[len(ret.RankInfo)-1].Score > score })
|
|
|
|
diff := s - score
|
|
// 等待越久,允许区间越大
|
|
wait := time.Now().Sub(u.RankInfo[len(ret.RankInfo)-1].LastMatchTime.Time).Seconds()
|
|
maxAllow := 100 + int(wait)*10
|
|
if diff < maxAllow {
|
|
//找到上一个,如果区间分数少于一定,
|
|
//直接进行匹配
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
func (r *RPCfight) ADD(s string) {
|
|
println("收到sun:join", s)
|
|
var pvp info.RPCFightinfo
|
|
json.Unmarshal([]byte(s), &pvp)
|
|
if pvp.Type == 1 {
|
|
r.join(pvp)
|
|
} else { //==0 退出
|
|
r.cancel(pvp)
|
|
}
|
|
|
|
}
|
|
func (r *RPCfight) cancel(pvp info.RPCFightinfo) {
|
|
r.zs.Remove(pvp.PlayerID)
|
|
}
|
|
|
|
///定义map,存储用户对战斗容器的映射,便于外部传入时候进行直接操作
|
|
|
|
var fightmap = RPCfight{
|
|
fightmap: csmap.New[int, common.FightI](),
|
|
zs: zset.New[uint32, *model.PVP](func(a, b *model.PVP) bool {
|
|
return a.Less(b)
|
|
}),
|
|
}
|