Files
bl/common/rpc/user.go
xinian 10e1126cd7
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
fix: 修复宠物竞技奖励计算逻辑错误
2026-03-05 13:34:06 +08:00

88 lines
2.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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]
}
// // ExtractBetweenBrackets 提取字符串中第一个 [] 中间的文本
// // 返回值:中间文本、是否成功、错误信息
// func ExtractBetweenBrackets(s string) (string, bool, error) {
// // 1. 找到第一个 [ 的索引
// leftIdx := strings.Index(s, "[")
// if leftIdx == -1 {
// return "", false, errors.New("未找到左中括号 [")
// }
// // 2. 找到第一个 [ 之后的第一个 ] 的索引
// rightIdx := strings.Index(s[leftIdx+1:], "]")
// if rightIdx == -1 {
// return "", false, errors.New("找到左中括号 [ 但未找到对应的右中括号 ]")
// }
// // 3. 计算实际的右中括号索引(加上 leftIdx+1
// rightIdx += leftIdx + 1
// // 4. 提取中间文本(去除前后空格,可选)
// result := strings.TrimSpace(s[leftIdx+1 : rightIdx])
// // 5. 检查是否为空
// if result == "" {
// return "", true, errors.New("中括号中间无文本")
// }
// return result, true, nil
// }
func (r *RPCfight) ADD(s string) {
println("收到sun:join", s)
var pvp info.RPCFightinfo
json.Unmarshal([]byte(s), &pvp)
//t, _, _ := ExtractBetweenBrackets(s)
ret := service.NewPVPService(pvp.PlayerID).Get(pvp.PlayerID)
score := 1000
if ret != nil {
score = int(ret.RankInfo.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 })
diff := s - score
// 等待越久,允许区间越大
wait := time.Now().Sub(u.RankInfo.LastMatchTime.Time).Seconds()
maxAllow := 100 + int(wait)*10
if diff < maxAllow {
//找到上一个,如果区间分数少于一定,
//直接进行匹配
}
}
}
func (r *RPCfight) Cancel(s string) {
// r.zs.Remove()
}
///定义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)
}),
}