diff --git a/common/rpc/func.go b/common/rpc/func.go index c4bbaf614..3fc6d4804 100644 --- a/common/rpc/func.go +++ b/common/rpc/func.go @@ -82,8 +82,7 @@ func ListenFunc(ctx g.Ctx) { continue } cool.Logger.Info(ctx, "成功订阅 Redis 主题", "topic", subscribeTopic) - _, err = conn.Do(ctx, "subscribe", "sun:join") //加入队列 - _, err = conn.Do(ctx, "subscribe", "sun:cancel") //退出队列 + _, err = conn.Do(ctx, "subscribe", "sun:join") //加入队列 // 4. 循环接收消息 connError := false diff --git a/common/rpc/user.go b/common/rpc/user.go index 0de324174..db541cbb6 100644 --- a/common/rpc/user.go +++ b/common/rpc/user.go @@ -17,42 +17,10 @@ type RPCfight struct { 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("未找到左中括号 [") -// } +func (r *RPCfight) join(pvp info.RPCFightinfo) { -// // 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 + score := 800 if ret != nil { score = int(ret.RankInfo.Score) } @@ -73,8 +41,19 @@ func (r *RPCfight) ADD(s string) { } } -func (r *RPCfight) Cancel(s string) { - // r.zs.Remove() +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,存储用户对战斗容器的映射,便于外部传入时候进行直接操作 diff --git a/logic/service/fight/info/info.go b/logic/service/fight/info/info.go index 9361137f8..20d93f957 100644 --- a/logic/service/fight/info/info.go +++ b/logic/service/fight/info/info.go @@ -52,6 +52,7 @@ type Fightinfo struct { FightType uint32 } type RPCFightinfo struct { + Type int PlayerID uint32 // 战斗模式 1 = 1v1 2 = 6v6 3大乱斗 0 什么都不做 Mode uint32 @@ -60,6 +61,15 @@ type RPCFightinfo struct { Status uint32 // FightType uint32 } +type RPCFightStartinfo struct { + Servierid int // 非0表示rpc跨服 + PlayerID uint32 + // 战斗模式 1 = 1v1 2 = 6v6 3大乱斗 0 什么都不做 + Mode uint32 + //Type uint32 //战斗类型 + + Status uint32 +} // FightPetInfo 战斗精灵信息结构体,FightPetInfo类 type FightPetInfo struct { diff --git a/logic/service/player/player.go b/logic/service/player/player.go index 3e3b8cb3b..9dfe6d49d 100644 --- a/logic/service/player/player.go +++ b/logic/service/player/player.go @@ -93,6 +93,7 @@ type Player struct { MainConn gnet.Conn baseplayer IsLogin bool //是否登录 + IsJoin bool //是否加入RPC对局 用重连函数写临时缓存join,重连后统一join Done MapNPC *time.Timer