| 440aa055  zhouhaihai
 
聊天 | 1
2
3
4
5 |   local ipairs = ipairs
  local table = table
  local math = math
  local redisproxy = redisproxy
  local MsgPack = MsgPack
 | 
| 4cf74232  zhouhaihai
 
pvp | 6
7 |   local httpc = require("http.httpc")
  local remoteUrl = skynet.getenv("codeurl")
 | 
| 440aa055  zhouhaihai
 
聊天 | 8
9
10 |   
  
  local _M = {}
 | 
| 4cf74232  zhouhaihai
 
pvp | 11 |   local _pvpBattleInfoCacheC = {}  --查询列表 缓存pvp战斗相关数据缓存
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 12
13
14
15
16
17
18
19
20
21 |   local _pvpBattleInfoCacheH = {}  --查询列表 缓存pvp战斗相关数据缓存
  local _pvpHeroInfoCacheH = {}  --查询列表 缓存pvp 英雄相关数据缓存
  local _pvpStartBattleCacheC = nil -- 当前战斗缓存
  local _pvpStartBattleCacheH = nil -- 当前战斗缓存
  
  local _pvpRecordInfoCacheC = {} -- 记录缓存
  local _pvpRecordInfoCacheH = {} -- 记录缓存
  local _pvpRecordBattleInfoCacheC = {} -- 记录战斗数据缓存
  local _pvpRecordBattleInfoCacheH = {} -- 记录战斗数据缓存
  local _pvpRecordHeroInfoCacheH = {}  --查询列表 缓存pvp 英雄相关数据缓存
 | 
| f317b790  zhouhaihai
 
pvp 遗留 | 22
23 |   local _revengeRecord = {} -- 复仇对单人1分钟间隔
  local RevengeWaitTime = 60
 | 
| 440aa055  zhouhaihai
 
聊天 | 24
25 |   
  function _M.formatCommonRpc(agent , data)
 | 
| 53227d9c  zhouhaihai
 
pvp 编队胜利推送 | 26 |   	if true then return end
 | 
| 440aa055  zhouhaihai
 
聊天 | 27 |   	local role = agent.role
 | 
| fa565e0c  zhouhaihai
 
优化结构 | 28 |   	local roleId = role:getProperty("id")
 | 
| 440aa055  zhouhaihai
 
聊天 | 29 |   	local msg = MsgPack.unpack(data)
 | 
| fa565e0c  zhouhaihai
 
优化结构 | 30 |   	local pvpTC = role:getProperty("pvpTC")
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 31 |   	for slot, heroId in pairs(msg.heros or {}) do
 | 
| 440aa055  zhouhaihai
 
聊天 | 32
33
34
35 |   		if not role.heros[heroId] then
  			return
  		end
  	end
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 36 |   	if not msg.heros or not next(msg.heros) then
 | 
| fa565e0c  zhouhaihai
 
优化结构 | 37 |   		return
 | 
| 440aa055  zhouhaihai
 
聊天 | 38 |   	end
 | 
| f603a60f  zhouhaihai
 
支援技实装 | 39
40
41
42
43
44
45 |   	local supports = {}
  	for slot, support in pairs(msg.supports) do
  		if slot ~= 1 and slot ~= 2 then return end
  		local level = role.dinerData:getProperty("dishTree"):getv(support, 0)
  		if level <= 0 then return end
  		supports[slot] = support
  	end
 | 
| 440aa055  zhouhaihai
 
聊天 | 46 |   
 | 
| fa565e0c  zhouhaihai
 
优化结构 | 47
48
49
50
51
52 |   	table.clear(pvpTC)
  	pvpTC.heros = {}
  	for slot, heroId in pairs(msg.heros) do
  		pvpTC.heros[slot] = heroId
  	end
  	pvpTC.leader = msg.leader
 | 
| f603a60f  zhouhaihai
 
支援技实装 | 53 |   	pvpTC.supports = supports
 | 
| f7f26c15  zhouhaihai
 
编队整理 增加 tactics战术 | 54
55
56 |   	if msg.tactics and globalCsv.tactics_skill_passive_cell[msg.tactics] then
  		pvpTC.tactics = msg.tactics
  	end
 | 
| fa565e0c  zhouhaihai
 
优化结构 | 57
58 |   	
  	role:savePvpCTeam(pvpTC)
 | 
| 440aa055  zhouhaihai
 
聊天 | 59
60
61
62 |   	SendPacket(actionCodes.Pvp_formatCommonRpc, '')
  	return true
  end
  
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 63
64
65
66 |   function _M.formatHighRpc(agent , data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
 | 
| 53227d9c  zhouhaihai
 
pvp 编队胜利推送 | 67
68 |   	
  	if not role:isCrossServerPvpPlayer() then return end
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 69
70
71
72
73
74
75
76
77
78 |   	local pvpTH = {}
  	local had = {} -- 上阵的角色
  	local supportHad = {}
  	for i = 1, 3 do
  		local team = msg.teams[i]
  		if not team then return end
  
  		if not team.heros or not next(team.heros) then
  			return
  		end
 | 
| 4cf74232  zhouhaihai
 
pvp | 79 |   
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 |   		for slot, heroId in pairs(team.heros or {}) do
  			if not role.heros[heroId] or had[heroId] then
  				return
  			end
  			had[heroId] = 1
  		end
  
  		local supports = {}
  		for slot, support in pairs(team.supports) do
  			if slot ~= 1 and slot ~= 2 then return end
  			local level = role.dinerData:getProperty("dishTree"):getv(support, 0)
  			if level <= 0 or supportHad[support] then return end
  			supports[slot] = support
  			supportHad[support] = 1
  		end
  
  		local curTeam = {}
  		curTeam.heros = team.heros
  		curTeam.leader = team.leader
  		curTeam.supports = supports
 | 
| f7f26c15  zhouhaihai
 
编队整理 增加 tactics战术 | 100
101
102 |   		if team.tactics and globalCsv.tactics_skill_passive_cell[team.tactics] then
  			curTeam.tactics = team.tactics
  		end
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 103
104
105
106
107 |   
  		table.insert(pvpTH, curTeam)
  	end
  	
  	role:savePvpHTeam(pvpTH)
 | 
| e3c5cc5e  zhouhaihai
 
跨服竞技场over | 108 |   	role:changeCrossServerPvpSelfInfo("format")
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 109
110
111
112
113 |   	SendPacket(actionCodes.Pvp_formatHighRpc, '')
  	return true
  end
  
  local function getMatchInfo(role, pvpList, battleCache, dbKey, infoFuncName, infoCache)
 | 
| 4cf74232  zhouhaihai
 
pvp | 114 |   	table.clear(battleCache)
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 115 |   	local dbKey = role:getPvpDBKey(dbKey)
 | 
| 4cf74232  zhouhaihai
 
pvp | 116
117
118 |   	local redret = redisproxy:pipelining(function(red)
  		for _, info in ipairs(pvpList) do
  			if info.t == 1 then
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 119 |   				red:zscore(dbKey, info.id)
 | 
| 4cf74232  zhouhaihai
 
pvp | 120
121
122
123
124
125
126
127
128
129 |   			end
  		end
  	end)
  
  	local matches = {}
  	local curIdx = 1
  	for idx, info in ipairs(pvpList) do
  		local curInfo = {idx = idx}
  		if info.t == 1 then --玩家
  			curInfo.roleId = info.id
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 130 |   			curInfo.score = role:unpackPvpScore(redret[curIdx] or 0)
 | 
| 4cf74232  zhouhaihai
 
pvp | 131
132 |   			curIdx = curIdx + 1
  			-- name, level, headId, battleV, heros
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 133 |   			local online, roleInfo = rpcRole(curInfo.roleId, infoFuncName)
 | 
| 4cf74232  zhouhaihai
 
pvp | 134
135
136
137 |   			for k , v in pairs(roleInfo) do
  				if k == "battleInfo" then
  					battleCache[curInfo.roleId] = v
  				else
 | 
| 821e2704  zhouhaihai
 
heros 增加 supports | 138 |   					if (k == "team" or k == "battleV") and infoCache then
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 139
140 |   						infoCache[curInfo.roleId] = infoCache[curInfo.roleId] or {}
  						infoCache[curInfo.roleId][k] = v
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 141 |   					end
 | 
| 4cf74232  zhouhaihai
 
pvp | 142
143
144
145
146
147
148
149
150
151
152
153
154 |   					curInfo[k] = v
  				end
  			end
  		elseif info.t == 2 then  	-- robot
  			curInfo.robot = info.id
  		end
  		table.insert(matches, curInfo)
  	end
  	return matches
  end
  
  -- 获取pvp信息
  function _M.infoRpc(agent, data)
 | 
| 440aa055  zhouhaihai
 
聊天 | 155 |   	local role = agent.role
 | 
| 4cf74232  zhouhaihai
 
pvp | 156 |   	local roleId = role:getProperty("id")
 | 
| 440aa055  zhouhaihai
 
聊天 | 157 |   	local msg = MsgPack.unpack(data)
 | 
| 4cf74232  zhouhaihai
 
pvp | 158 |   	local ptype = msg.ptype or 1
 | 
| d232676a  zhouhaihai
 
功能解锁  冒险返回 | 159
160 |   	
  	if not role:isFuncUnlock(FuncUnlock.Pvp) then return end
 | 
| 440aa055  zhouhaihai
 
聊天 | 161 |   
 | 
| 4cf74232  zhouhaihai
 
pvp | 162
163 |   	local response = {}
  	if ptype == 1 then -- 普通pvp
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 164 |   		local dbKey = role:getPvpDBKey(RANK_PVP_COMMON)
 | 
| 4cf74232  zhouhaihai
 
pvp | 165 |   		local redret = redisproxy:pipelining(function(red)
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 166
167 |   			red:zscore(dbKey, roleId)
  			red:zrevrank(dbKey, roleId)
 | 
| 4cf74232  zhouhaihai
 
pvp | 168 |   		end)
 | 
| aaf6a9e6  zhouhaihai
 
分数默认1000 | 169 |   		local score = role:unpackPvpScore(redret[1])
 | 
| 4cf74232  zhouhaihai
 
pvp | 170 |   		local rank = tonumber(redret[2] or -2) + 1  --排名 1 - ...  -1 未上榜 没打过pvp
 | 
| aaf6a9e6  zhouhaihai
 
分数默认1000 | 171 |   
 | 
| 4cf74232  zhouhaihai
 
pvp | 172
173 |   		local pvpMC = role:getProperty("pvpMC")
  		if not next(pvpMC) then --没有分配过对手
 | 
| 68a6dc62  zhouhaihai
 
匹配规则调整 | 174 |   			role:refreshPvpMatchC(score, -1)
 | 
| 4cf74232  zhouhaihai
 
pvp | 175
176
177
178 |   			pvpMC = role:getProperty("pvpMC")
  		end
  		if not next(pvpMC) then return end
  		
 | 
| 4cf74232  zhouhaihai
 
pvp | 179 |   		response.rank = rank
 | 
| b115474f  zhouhaihai
 
默认积分 1000 | 180 |   		response.score = score
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 181 |   		response.matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo")
 | 
| 4cf74232  zhouhaihai
 
pvp | 182 |   	elseif ptype == 2 then -- 高级pvp
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 183
184 |   		if not role:isTimeResetOpen(TimeReset.PvpHight) then return end
  		local dbKey = role:getPvpDBKey(RANK_PVP_HIGHT)
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 185 |   		local redret = redisproxy:pipelining(function(red)
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 186
187 |   			red:zscore(dbKey, roleId)
  			red:zrevrank(dbKey, roleId)
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 188
189
190
191
192
193 |   		end)
  		local score = role:unpackPvpScore(redret[1])
  		local rank = tonumber(redret[2] or -2) + 1  --排名 1 - ...  -1 未上榜 没打过pvp
  
  		local pvpMH = role:getProperty("pvpMH")
  		if not next(pvpMH) then --没有分配过对手
 | 
| 68a6dc62  zhouhaihai
 
匹配规则调整 | 194 |   			role:refreshPvpMatchH(score, -1)
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 195
196
197
198
199
200
201 |   			pvpMH = role:getProperty("pvpMH")
  		end
  		if not next(pvpMH) then return end
  		
  		response.rank = rank
  		response.score = score
  		response.matches = getMatchInfo(role, pvpMH, _pvpBattleInfoCacheH, RANK_PVP_HIGHT, "pvpHInfo", _pvpHeroInfoCacheH)
 | 
| 4cf74232  zhouhaihai
 
pvp | 202
203
204
205 |   	else
  		return
  	end
  	SendPacket(actionCodes.Pvp_infoRpc, MsgPack.pack(response))
 | 
| 440aa055  zhouhaihai
 
聊天 | 206
207
208 |   	return true
  end
  
 | 
| 4cf74232  zhouhaihai
 
pvp | 209 |   function _M.refreshMatchCRpc(agent, data)
 | 
| 440aa055  zhouhaihai
 
聊天 | 210
211 |   	local role = agent.role
  	local msg = MsgPack.unpack(data)
 | 
| 4cf74232  zhouhaihai
 
pvp | 212
213
214 |   	role:refreshPvpMatchC()
  
  	local pvpMC = role:getProperty("pvpMC")
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 215 |   	local matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo")
 | 
| 440aa055  zhouhaihai
 
聊天 | 216 |   
 | 
| 4cf74232  zhouhaihai
 
pvp | 217 |   	SendPacket(actionCodes.Pvp_refreshMatchCRpc, MsgPack.pack({matches = matches}))
 | 
| 440aa055  zhouhaihai
 
聊天 | 218
219
220 |   	return true
  end
  
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 221
222
223 |   function _M.refreshMatchHRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 224
225 |   	if not role:isTimeResetOpen(TimeReset.PvpHight) then return end
  
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 226
227
228
229
230
231
232
233
234 |   	role:refreshPvpMatchH()
  
  	local pvpMH = role:getProperty("pvpMH")
  	local matches = getMatchInfo(role, pvpMH, _pvpBattleInfoCacheH, RANK_PVP_HIGHT, "pvpHInfo", _pvpHeroInfoCacheH)
  
  	SendPacket(actionCodes.Pvp_refreshMatchHRpc, MsgPack.pack({matches = matches}))
  	return true
  end
  
 | 
| 440aa055  zhouhaihai
 
聊天 | 235
236
237 |   function _M.buyCountRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
 | 
| 4cf74232  zhouhaihai
 
pvp | 238 |   	local count = msg.count
 | 
| 440aa055  zhouhaihai
 
聊天 | 239 |   
 | 
| 4cf74232  zhouhaihai
 
pvp | 240
241
242
243 |   	if math.illegalNum(count, 1, math.huge) then
  		return 1
  	end
  
 | 
| 3d8050ef  测试
 
钻石3改成虹光玉8 | 244 |   	local cost = {[ItemId.Jade] = globalCsv.pvp_buy_cost * count}
 | 
| 4cf74232  zhouhaihai
 
pvp | 245 |   	if not role:checkItemEnough(cost) then return 2 end
 | 
| 058b4f09  zhangqijia
 
feat: 限制每天购买竞技场门票的张数 | 246
247
248
249
250
251 |   
  	--限制每天购买次数
  	local pvpBought = role.dailyData:getProperty("pvpBought")
  	if count + pvpBought > globalCsv["pvp_buy_max"] then return 3 end
  	role.dailyData:updateProperty({field = "pvpBought", value = count + pvpBought})
  
 | 
| 3133cb76  zhouhaihai
 
日志 | 252
253 |   	role:costItems(cost, {log = {desc = "buyPvpKey"}})
  	role:award({[ItemId.PvpKey] = count}, {log = {desc = "buyPvpKey"}})
 | 
| 440aa055  zhouhaihai
 
聊天 | 254
255
256
257
258
259 |   
  	SendPacket(actionCodes.Pvp_buyCountRpc, '')
  	return true
  end
  
  function _M.startBattleRpc(agent, data)
 | 
| 4cf74232  zhouhaihai
 
pvp | 260
261 |   	local role = agent.role
  	local msg = MsgPack.unpack(data)
 | 
| 440aa055  zhouhaihai
 
聊天 | 262 |   
 | 
| 4cf74232  zhouhaihai
 
pvp | 263
264
265 |   	local idx = msg.idx
  	local revenge = msg.revenge
  
 | 
| 819f6c60  zhouhaihai
 
战斗不判断防守阵容 | 266
267 |   	-- local pvpTC = role:getProperty("pvpTC")
  	-- if not pvpTC.heros or not next(pvpTC.heros) then return 1 end
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 268 |   
 | 
| 53227d9c  zhouhaihai
 
pvp 编队胜利推送 | 269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298 |   	local team = msg.team
  	if not team then return end
  
  	for slot, heroId in pairs(team.heros or {}) do
  		if not role.heros[heroId] then
  			return
  		end
  	end
  	if not team.heros or not next(team.heros) then
  		return
  	end
  	local supports = {}
  	for slot, support in pairs(team.supports) do
  		if slot ~= 1 and slot ~= 2 then return end
  		local level = role.dinerData:getProperty("dishTree"):getv(support, 0)
  		if level <= 0 then return end
  		supports[slot] = support
  	end
  
  	local pvpTC = {}
  	pvpTC.heros = {}
  	for slot, heroId in pairs(team.heros) do
  		pvpTC.heros[slot] = heroId
  	end
  	pvpTC.leader = team.leader
  	pvpTC.supports = supports
  	if team.tactics and globalCsv.tactics_skill_passive_cell[team.tactics] then
  		pvpTC.tactics = team.tactics
  	end
  
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 299 |   	local matchInfo, result, key, wait
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 300 |   
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 301 |   	local now = skynet.timex()
 | 
| 4cf74232  zhouhaihai
 
pvp | 302 |   	if revenge then  --复仇
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 303 |   		local temp = _pvpRecordInfoCacheC[idx]
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 304 |   		if not temp then return 2 end
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 305 |   
 | 
| f317b790  zhouhaihai
 
pvp 遗留 | 306 |   		if not _revengeRecord[temp.id] or now >= _revengeRecord[temp.id] then
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 307 |   			if temp.t == 1 then
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 308 |   				matchInfo = _pvpRecordBattleInfoCacheC[temp.id]
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 309
310
311
312
313 |   			elseif temp.t == 2 then
  				matchInfo = {robot = temp.id}
  			end
  		else
  			result = 1
 | 
| f317b790  zhouhaihai
 
pvp 遗留 | 314 |   			wait = _revengeRecord[temp.id] - now
 | 
| 4cf74232  zhouhaihai
 
pvp | 315
316
317 |   		end
  	else  --打正常
  		local pvpMC = role:getProperty("pvpMC")
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 318 |   		if not pvpMC[idx] then return 3 end
 | 
| 4cf74232  zhouhaihai
 
pvp | 319
320
321
322
323
324
325 |   		if pvpMC[idx].t == 1 then
  			matchInfo = _pvpBattleInfoCacheC[pvpMC[idx].id]
  		elseif pvpMC[idx].t == 2 then
  			matchInfo = {robot = pvpMC[idx].id}
  		end
  	end
  
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 326 |   	if not result and not matchInfo then return 4 end
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 327 |   
 | 
| 2c3a1b31  zhangqijia
 
fix: 修复复仇扣除3门票的BUG | 328 |   	if not revenge then
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 329
330
331
332 |   		-- 次数扣一波
  		local pvpFree = role.dailyData:getProperty("pvpFree")
  		if pvpFree >= globalCsv.pvp_battle_free_count then
  			local cost = {[ItemId.PvpKey] = 1}
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 333 |   			if not role:checkItemEnough(cost) then return 5 end
 | 
| 887c1843  zhouhaihai
 
日志新一批 | 334 |   			role:costItems(cost, {log = {desc = "startPvp", int1 = 1}})
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 335
336
337 |   		else
  			role.dailyData:updateProperty({field = "pvpFree", delta = 1})
  		end
 | 
| 2c3a1b31  zhangqijia
 
fix: 修复复仇扣除3门票的BUG | 338 |   	end
 | 
| 4cf74232  zhouhaihai
 
pvp | 339 |   
 | 
| 2c3a1b31  zhangqijia
 
fix: 修复复仇扣除3门票的BUG | 340 |   	if not result then
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 341 |   		key = tostring(math.random())
 | 
| 53227d9c  zhouhaihai
 
pvp 编队胜利推送 | 342 |   		_pvpStartBattleCacheC = {idx = idx, key = key, revenge = revenge, pvpTC = pvpTC}
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 343
344 |   
  		role:checkTaskEnter("PvpBattle")
 | 
| f22a33af  zhouhaihai
 
自己的日志 | 345
346
347 |   
  
  		role:mylog("pvp_action", {desc = "startBattle", short1 = 1, int1 = revenge and 1 or 0})
 | 
| 4cf74232  zhouhaihai
 
pvp | 348
349 |   	end
  
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 350 |   	SendPacket(actionCodes.Pvp_startBattleRpc, MsgPack.pack({matchInfo = matchInfo, key = key, result = result, wait = wait}))
 | 
| 4cf74232  zhouhaihai
 
pvp | 351 |   	return true
 | 
| 440aa055  zhouhaihai
 
聊天 | 352
353
354 |   end
  
  function _M.endBattleRpc(agent, data)
 | 
| 4cf74232  zhouhaihai
 
pvp | 355
356
357 |   	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
 | 
| 440aa055  zhouhaihai
 
聊天 | 358 |   
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 359 |   	if not msg.key or not _pvpStartBattleCacheC or msg.key ~= _pvpStartBattleCacheC.key then 
 | 
| d6a66c74  zhouhaihai
 
校验失败也返回 | 360
361 |   		SendPacket(actionCodes.Pvp_endBattleRpc, MsgPack.pack({errorCode = 1}))
  		return true
 | 
| 4cf74232  zhouhaihai
 
pvp | 362 |   	end
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 363 |   
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 364 |   	if not msg.idx or msg.idx ~= _pvpStartBattleCacheC.idx then
 | 
| 4cf74232  zhouhaihai
 
pvp | 365
366 |   		return 2
  	end
 | 
| 440aa055  zhouhaihai
 
聊天 | 367 |   
 | 
| 4cf74232  zhouhaihai
 
pvp | 368 |   	local isWin = msg.starNum and msg.starNum > 0
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 369 |   	local now = skynet.timex()
 | 
| 4cf74232  zhouhaihai
 
pvp | 370 |   
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 371 |   	local revenge = _pvpStartBattleCacheC.revenge
 | 
| 4cf74232  zhouhaihai
 
pvp | 372
373 |   	local match
  	if revenge then
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 374 |   		match = _pvpRecordInfoCacheC[msg.idx]
 | 
| f317b790  zhouhaihai
 
pvp 遗留 | 375 |   		_revengeRecord[match.id] = now + RevengeWaitTime  -- 1分钟内不能再打
 | 
| b3a55168  测试
 
复仇胜利需要扣除门票或次数 | 376
377
378
379
380
381
382
383
384
385
386
387 |   
          if isWin then
              -- 次数扣一波
              local pvpFree = role.dailyData:getProperty("pvpFree")
              if pvpFree >= globalCsv.pvp_battle_free_count then
                  local cost = {[ItemId.PvpKey] = 1}
                  if not role:checkItemEnough(cost) then return 5 end
                  role:costItems(cost, {log = {desc = "startPvp", int1 = 1}})
              else
                  role.dailyData:updateProperty({field = "pvpFree", delta = 1})
              end
          end
 | 
| 4cf74232  zhouhaihai
 
pvp | 388
389
390
391
392
393
394 |   	else
  		local pvpMC = role:getProperty("pvpMC")
  		match = pvpMC[msg.idx]
  	end
  	
  	if not match then return end
  
 | 
| edf2ee12  zhouhaihai
 
防作弊 | 395
396
397
398
399
400
401
402
403
404 |   	-- 防作弊
  	if not role:checkBattleCheat("pvpc", {
  		isWin = isWin,
  		info = msg.info,
  		format = _pvpStartBattleCacheC.pvpTC,
  	}) then
  		SendPacket(actionCodes.Pvp_endBattleRpc, MsgPack.pack({errorCode = 1}))
  		return true
  	end
  
 | 
| 4cf74232  zhouhaihai
 
pvp | 405 |   	local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpBonus, true)
 | 
| 7bb30dca  zhouhaihai
 
修改发奖 | 406 |   	local reward, change = role:award({[temp[1]] = temp[2]}, {log = {desc = "pvpBattleC"}})
 | 
| 53227d9c  zhouhaihai
 
pvp 编队胜利推送 | 407
408
409
410
411
412
413
414
415 |   	local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = 0, 0, 0, 0, -1, -1
  	-- 失败了没再排行榜 不计入
  	if isWin or (not isWin and role:isInPvpRank(RANK_PVP_COMMON)) then
  		myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank= role:changePvpScoreCommon(match.t == 1 and match.id or -1, isWin)
  	end
  	if isWin then
  		-- 记录编队
  		role:savePvpCTeam(_pvpStartBattleCacheC.pvpTC)
  	end
 | 
| 4cf74232  zhouhaihai
 
pvp | 416 |   
 | 
| 4cf74232  zhouhaihai
 
pvp | 417 |   	-- 请求上传录像
 | 
| 4cf74232  zhouhaihai
 
pvp | 418
419
420
421
422
423 |   	local params = {
  		["roleid"] = roleId,
  		["key"] = "zhaolugame20191016",
  		["time"] = now,
  	}
  	local status, body = httpc.get(remoteUrl, "/applyvideo?" .. httpGetFormatData(params), {}, {})
 | 
| 39e60fd1  zhouhaihai
 
支持上传 oss | 424 |   	local video, headers = nil, nil
 | 
| 4cf74232  zhouhaihai
 
pvp | 425
426
427 |   	if tonumber(status) == 200 then
  		local result = json.decode(body)
  		video = result.name
 | 
| 39e60fd1  zhouhaihai
 
支持上传 oss | 428 |   		headers = result.headers
 | 
| 4cf74232  zhouhaihai
 
pvp | 429 |   	else
 | 
| 77b54f12  zhouhaihai
 
中心服录像上传 | 430 |   		skynet.error("applyvideo", "error", status, body)
 | 
| 4cf74232  zhouhaihai
 
pvp | 431
432
433
434
435
436
437
438
439
440
441
442
443 |   	end
  
  	-- 加入战斗记录
  	redisproxy:pipelining(function(red)
  		local dbKey = string.format(RECORD_PVP_COMMON, roleId)
  		red:lpush(dbKey, MsgPack.pack({
  			id = match.id,
  			t = match.t,
  			win = isWin,
  			time = now,
  			video = video,
  			sdelta = myScore - oldmyScore,
  		}))
 | 
| 8c20d812  zhouhaihai
 
pvp bUg | 444 |   		red:ltrim(dbKey, 0, 9)
 | 
| 4cf74232  zhouhaihai
 
pvp | 445
446
447
448
449
450
451
452
453
454
455 |   		-- 对方加入战斗记录
  		if match.t == 1 then
  			dbKey = string.format(RECORD_PVP_COMMON, match.id)
  			red:lpush(dbKey, MsgPack.pack({
  				id = roleId,
  				t = 1,
  				win = not isWin,
  				time = now,
  				video = video,
  				sdelta = matchScore - oldMatchScore,
  			}))
 | 
| 8c20d812  zhouhaihai
 
pvp bUg | 456 |   			red:ltrim(dbKey, 0, 9)
 | 
| 9cede2e2  zhouhaihai
 
主推红点 和冒险次数 | 457
458 |   
  			rpcRole(match.id, "redPTag", RedPointTags.PvpCR, now)
 | 
| 4cf74232  zhouhaihai
 
pvp | 459
460 |   		end
  	end)
 | 
| 3dbbc9f3  zhouhaihai
 
加上新的任务 | 461
462
463
464 |   
  	if isWin then
  		role:checkTaskEnter("PvpWin", {score = myScore})
  	end
 | 
| d4e9b817  zhouhaihai
 
战斗 日志 | 465
466
467
468
469
470
471
472
473
474 |   
  	role:checkBattle("pvpc", {
  		isWin = isWin,
  		info = msg.info,
  		robotId = match.t == 2 and match.id or nil,
  		enemy = match.t == 1 and _pvpBattleInfoCacheC[match.id] or nil,
  		score = myScore,
  		reward = reward,
  		rank = myRank,
  	})
 | 
| e84a1beb  测试
 
gm后台查询日志,公告相关协议 | 475
476 |   	role:mylog("pvp_action", {desc = "battleEnd", short1 = 1, int1 = isWin and 1 or 0, int2 = revenge and 1 or 0, cint1 = oldMyRank, cint2 = myRank, 
      cint3 = match.id, long1 = 1, key1 = msg.key, key2 = role:getHerosLogStr(role:getProperty("pvpTC").heros)})
 | 
| 440aa055  zhouhaihai
 
聊天 | 477 |   	
 | 
| d4e9b817  zhouhaihai
 
战斗 日志 | 478
479
480
481
482 |   	_pvpBattleInfoCacheC = {}  --重新发阵容了 没毛病
  	_pvpRecordInfoCacheC = {} -- 记录刷新了
  	_pvpRecordBattleInfoCacheC = {} -- 取新纪录的时候搞
  	_pvpStartBattleCacheC = nil
  
 | 
| 4cf74232  zhouhaihai
 
pvp | 483
484 |   	SendPacket(actionCodes.Pvp_endBattleRpc, MsgPack.pack({
  		reward = reward,
 | 
| 7bb30dca  zhouhaihai
 
修改发奖 | 485 |   		change = change,
 | 
| 4cf74232  zhouhaihai
 
pvp | 486
487
488
489
490
491
492 |   		myScore = myScore,
  		matchScore = matchScore,
  		oldmyScore = oldmyScore,
  		oldMatchScore = oldMatchScore,
  		myRank = myRank,
  		oldMyRank = oldMyRank,
  		video = video,
 | 
| 39e60fd1  zhouhaihai
 
支持上传 oss | 493 |   		headers = headers,
 | 
| 4cf74232  zhouhaihai
 
pvp | 494
495
496
497 |   	}))
  	return true
  end
  
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 498
499
500
501
502
503
504 |   
  function _M.startBattleHRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
  
  	local idx = msg.idx
  	local revenge = msg.revenge
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 505 |   	if not role:isTimeResetOpen(TimeReset.PvpHight) then return end
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 506 |   
 | 
| 819f6c60  zhouhaihai
 
战斗不判断防守阵容 | 507
508 |   	-- local pvpTH = role:getProperty("pvpTH")
  	-- if not next(pvpTH) then return 1 end
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541 |   
  	-- 检查并记录玩家队伍
  	local pvpTH = {}
  	local had = {} -- 上阵的角色
  	local supportHad = {}
  	for i = 1, 3 do
  		local team = msg.teams[i]
  		if not team then return end
  
  		if not team.heros or not next(team.heros) then
  			return
  		end
  
  		for slot, heroId in pairs(team.heros or {}) do
  			if not role.heros[heroId] or had[heroId] then
  				return
  			end
  			had[heroId] = 1
  		end
  
  		local supports = {}
  		for slot, support in pairs(team.supports) do
  			if slot ~= 1 and slot ~= 2 then return end
  			local level = role.dinerData:getProperty("dishTree"):getv(support, 0)
  			if level <= 0 or supportHad[support] then return end
  			supports[slot] = support
  			supportHad[support] = 1
  		end
  
  		local curTeam = {}
  		curTeam.heros = team.heros
  		curTeam.leader = team.leader
  		curTeam.supports = supports
 | 
| f7f26c15  zhouhaihai
 
编队整理 增加 tactics战术 | 542
543
544
545 |   		if team.tactics and globalCsv.tactics_skill_passive_cell[team.tactics] then
  			curTeam.tactics = team.tactics
  		end
  
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571 |   		table.insert(pvpTH, curTeam)
  	end
  
  	local enemyTeamRecord, result, key, wait, enemyT, matchInfo
  
  	local now = skynet.timex()
  	if revenge then  --复仇
  		local temp = _pvpRecordInfoCacheH[idx]
  		if not temp then return 2 end
  
  		if not _revengeRecord[temp.id] or now >= _revengeRecord[temp.id] then
  			if temp.t == 1 then
  				enemyTeamRecord = _pvpRecordBattleInfoCacheH[temp.id]
  				enemyT = _pvpRecordHeroInfoCacheH[temp.id]
  			elseif temp.t == 2 then
  				enemyTeamRecord = {robot = temp.id}
  			end
  		else
  			result = 1
  			wait = _revengeRecord[temp.id] - now
  		end
  	else  --打正常
  		local pvpMH = role:getProperty("pvpMH")
  		if not pvpMH[idx] then return 3 end
  		if pvpMH[idx].t == 1 then
  			enemyTeamRecord = _pvpBattleInfoCacheH[pvpMH[idx].id]
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 572 |   			enemyT = _pvpHeroInfoCacheH[pvpMH[idx].id]
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 573
574
575
576
577
578
579 |   		elseif pvpMH[idx].t == 2 then
  			enemyTeamRecord = {robot = pvpMH[idx].id}
  		end
  	end
  
  	if not result and not enemyTeamRecord then return 4 end
  
 | 
| 2c3a1b31  zhangqijia
 
fix: 修复复仇扣除3门票的BUG | 580 |   	if not revenge then
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 581 |   		-- 次数扣一波
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 582
583
584
585 |   		local pvpFreeH = role.dailyData:getProperty("pvpFreeH")
  		if pvpFreeH >= globalCsv.pvp_battle_free_count_high then
  			local cost = {[ItemId.PvpKey] = globalCsv.pvp_battle_high_cost}
  			if not role:checkItemEnough(cost) then return 5 end
 | 
| 887c1843  zhouhaihai
 
日志新一批 | 586 |   			role:costItems(cost, {log = {desc = "startPvp", int1 = 2}})
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 587
588
589 |   		else
  			role.dailyData:updateProperty({field = "pvpFreeH", delta = 1})
  		end
 | 
| 2c3a1b31  zhangqijia
 
fix: 修复复仇扣除3门票的BUG | 590 |   	end
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 591 |   
 | 
| 2c3a1b31  zhangqijia
 
fix: 修复复仇扣除3门票的BUG | 592 |   	if not result then
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612 |   
  		-- 只发送指定的那个敌人
  		if enemyTeamRecord.robot then
  			matchInfo = enemyTeamRecord
  		else
  			matchInfo = enemyTeamRecord[1]
  		end
  
  		key = tostring(math.random())
  		_pvpStartBattleCacheH = {
  			idx = idx,  -- 数据索引
  			key = key, -- 战斗校验 key
  			revenge = revenge, -- 是否是复仇
  			result = {}, -- 战斗记录
  			pvpTH = pvpTH,  -- 我方队伍缓存
  			enemyTB = enemyTeamRecord,  --敌方战斗队伍缓存
  			enemyT = enemyT,
  		}
  
  		role:checkTaskEnter("PvpBattle")
 | 
| 3133cb76  zhouhaihai
 
日志 | 613 |   
 | 
| f22a33af  zhouhaihai
 
自己的日志 | 614
615 |   		role:mylog("pvp_action", {desc = "startBattle", short1 = 2, int1 = revenge and 1 or 0})
  
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633 |   	end
  	
  	SendPacket(actionCodes.Pvp_startBattleHRpc, MsgPack.pack({
  		matchInfo = matchInfo, --敌方队伍 信息
  		key = key, --战斗校验 key
  		round = 1, -- 战斗场数索引
  		result = result, -- 返回状态
  		wait = wait -- 等待复仇时间  
  	}))
  	return true
  end
  
  function _M.endBattleHRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  
  	if not msg.key or not _pvpStartBattleCacheH or msg.key ~= _pvpStartBattleCacheH.key then 
 | 
| d6a66c74  zhouhaihai
 
校验失败也返回 | 634
635 |   		SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({errorCode = 1}))
  		return true
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 636
637
638
639
640
641
642
643
644
645
646
647
648
649 |   	end
  
  	if not msg.idx or msg.idx ~= _pvpStartBattleCacheH.idx then
  		return 2
  	end
  
  	local isWin = msg.starNum and msg.starNum > 0
  	local now = skynet.timex()
  
  	local revenge = _pvpStartBattleCacheH.revenge
  	local match
  	if revenge then
  		match = _pvpRecordInfoCacheH[msg.idx]
  		_revengeRecord[match.id] = now + RevengeWaitTime  -- 1分钟内不能再打
 | 
| b3a55168  测试
 
复仇胜利需要扣除门票或次数 | 650 |   
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 651
652
653
654
655
656
657
658
659
660
661
662
663
664 |   	else
  		local pvpMH = role:getProperty("pvpMH")
  		match = pvpMH[msg.idx]
  	end
  	
  	if not match then return end
  
  	-- 请求上传录像
  	local params = {
  		["roleid"] = roleId,
  		["key"] = "zhaolugame20191016",
  		["time"] = now,
  	}
  	local status, body = httpc.get(remoteUrl, "/applyvideo?" .. httpGetFormatData(params), {}, {})
 | 
| 39e60fd1  zhouhaihai
 
支持上传 oss | 665 |   	local video, headers = nil, nil
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 666
667
668 |   	if tonumber(status) == 200 then
  		local result = json.decode(body)
  		video = result.name
 | 
| 39e60fd1  zhouhaihai
 
支持上传 oss | 669 |   		headers = result.headers
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 670 |   	else
 | 
| 77b54f12  zhouhaihai
 
中心服录像上传 | 671 |   		skynet.error("applyvideo", "error", status, body)
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 672
673
674
675
676
677
678 |   	end
  
  	table.insert(_pvpStartBattleCacheH.result, {
  		isWin = isWin,
  		video = video,
  	})
  
 | 
| e84a1beb  测试
 
gm后台查询日志,公告相关协议 | 679 |       local curStatus
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 680
681
682
683
684 |   	-- 检查是否结束战斗
  	local winCount, loseCount = 0, 0
  	for _, status in pairs(_pvpStartBattleCacheH.result) do
  		if status.isWin then
  			winCount = winCount + 1
 | 
| e84a1beb  测试
 
gm后台查询日志,公告相关协议 | 685 |               curStatus = true
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 686
687
688
689
690 |   		else
  			loseCount = loseCount + 1
  		end
  	end
  
 | 
| edf2ee12  zhouhaihai
 
防作弊 | 691
692
693
694
695
696
697
698
699
700 |   	-- 防作弊
  	if not role:checkBattleCheat("pvph", {
  		isWin = isWin,
  		info = msg.info,
  		format = _pvpStartBattleCacheH.pvpTH[#_pvpStartBattleCacheH.result]
  	}) then
  		SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({errorCode = 1}))
  		return true
  	end
  
 | 
| e84a1beb  测试
 
gm后台查询日志,公告相关协议 | 701
702 |       local curHTeam = _pvpStartBattleCacheH.pvpTH[#_pvpStartBattleCacheH.result] or {}
  
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 703
704
705
706
707
708 |   	if winCount >= 2 then
  		isWin = true
  	elseif loseCount >= 2 then
  		isWin = false
  	else -- 没结束
  		-- 返回继续战斗
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 709
710
711
712
713 |   		local key = tostring(math.random())
  		_pvpStartBattleCacheH.key = key
  		local round = #_pvpStartBattleCacheH.result + 1
  		local matchInfo = nil
  		if _pvpStartBattleCacheH.enemyTB.robot then
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 714 |   			matchInfo = _pvpStartBattleCacheH.enemyTB
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 715
716
717
718
719
720
721
722
723
724 |   		else
  			matchInfo = _pvpStartBattleCacheH.enemyTB[round]
  		end
  
  		-- 继续战斗
  		SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({
  			matchInfo = matchInfo, --敌方队伍 信息
  			key = key, --战斗校验 key
  			round = round, -- 战斗场数索引
  			video = video, -- 返回让客户端上传录像
 | 
| 39e60fd1  zhouhaihai
 
支持上传 oss | 725 |   			headers = headers,
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 726 |   		}))
 | 
| e84a1beb  测试
 
gm后台查询日志,公告相关协议 | 727
728 |           role:mylog("pvp_action", {desc = "battleEnd", short1 = 2, int1 = curStatus and 1 or 0, int2 = revenge and 1 or 0, cint1 = 0, cint2 = 0, 
          cint3 = match.id, long1 = #_pvpStartBattleCacheH.result, key1 = msg.key, key2 = role:getHerosLogStr(curHTeam.heros)})
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 729
730 |   		return true
  	end
 | 
| 2c3a1b31  zhangqijia
 
fix: 修复复仇扣除3门票的BUG | 731
732
733
734
735
736
737
738
739
740
741 |   	if revenge and isWin then
  		-- 次数扣一波
  		local pvpFreeH = role.dailyData:getProperty("pvpFreeH")
  		if pvpFreeH >= globalCsv.pvp_battle_free_count_high then
  			local cost = {[ItemId.PvpKey] = globalCsv.pvp_battle_high_cost}
  			if not role:checkItemEnough(cost) then return 5 end
  			role:costItems(cost, {log = {desc = "startPvp", int1 = 2}})
  		else
  			role.dailyData:updateProperty({field = "pvpFreeH", delta = 1})
  		end
  	end
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 742
743 |   
  	-- 战斗结束了发奖 
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 744 |   	local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpgroupBonus, true)
 | 
| 7bb30dca  zhouhaihai
 
修改发奖 | 745 |   	local reward, change = role:award({[temp[1]] = temp[2]}, {log = {desc = "pvpBattleH"}})
 | 
| 53227d9c  zhouhaihai
 
pvp 编队胜利推送 | 746
747
748
749
750
751
752
753
754
755
756
757 |   
  
  	local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = 0, 0, 0, 0, -1, -1
  	-- 失败了没再排行榜 不计入
  	if role:isTimeResetOpen(TimeReset.PvpHight) then
  		if isWin or (not isWin and role:isInPvpRank(RANK_PVP_HIGHT)) then
  			myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = role:changePvpScoreHigh(match.t == 1 and match.id or -1, isWin)
  		end
  		-- 记录编队
  		if isWin then
  			role:savePvpHTeam(_pvpStartBattleCacheH.pvpTH)
  		end
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 758 |   	end
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 759
760
761
762 |   
  	-- 加入战斗记录
  	local selfTeam = {}
  	local enemyTeam = {}
 | 
| e3c5cc5e  zhouhaihai
 
跨服竞技场over | 763 |   
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 764
765
766 |   	for _idx, info in ipairs(_pvpStartBattleCacheH.result) do
  		info.winId = info.isWin and roleId or match.id
  		info.isWin = nil
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 767 |   		selfTeam[_idx] = {
 | 
| 821e2704  zhouhaihai
 
heros 增加 supports | 768 |   			team = role:getTeamHerosInfo(_pvpStartBattleCacheH.pvpTH[_idx]),
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 769
770 |   			battleV = role:getTeamBattleValue(_pvpStartBattleCacheH.pvpTH[_idx].heros)
  		}
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 771 |   		if match.t == 1 and _pvpStartBattleCacheH.enemyT then
 | 
| e3c5cc5e  zhouhaihai
 
跨服竞技场over | 772 |   			enemyTeam[_idx] = {
 | 
| 821e2704  zhouhaihai
 
heros 增加 supports | 773 |   				team = _pvpStartBattleCacheH.enemyT["team"][_idx],
 | 
| e3c5cc5e  zhouhaihai
 
跨服竞技场over | 774
775 |   				battleV = _pvpStartBattleCacheH.enemyT["battleV"][_idx]
  			}
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808 |   		end
  	end
  	local recordBattle = {
  		result = _pvpStartBattleCacheH.result,
  		[roleId] = selfTeam,
  		[match.id] = enemyTeam
  	}
  
  	redisproxy:pipelining(function(red)
  		local dbKey = string.format(RECORD_PVP_HIGH, roleId)
  		red:lpush(dbKey, MsgPack.pack({
  			id = match.id,
  			t = match.t,
  			win = isWin,
  			time = now,
  			sdelta = myScore - oldmyScore,
  			-- 队伍信息
  			record = recordBattle,
  		}))
  		red:ltrim(dbKey, 0, 9)
  		-- 对方加入战斗记录
  		if match.t == 1 then
  			dbKey = string.format(RECORD_PVP_HIGH, match.id)
  			red:lpush(dbKey, MsgPack.pack({
  				id = roleId,
  				t = 1,
  				win = not isWin,
  				time = now,
  				sdelta = matchScore - oldMatchScore,
  				-- 队伍信息
  				record = recordBattle,
  			}))
  			red:ltrim(dbKey, 0, 9)
 | 
| 9cede2e2  zhouhaihai
 
主推红点 和冒险次数 | 809 |   			rpcRole(match.id, "redPTag", RedPointTags.PvpHR, now)
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 810
811
812 |   		end
  	end)
  
 | 
| d4e9b817  zhouhaihai
 
战斗 日志 | 813
814
815
816
817
818
819
820
821
822 |   	role:checkBattle("pvph", {
  		isWin = isWin,
  		info = msg.info,
  		robotId = match.t == 2 and match.id or nil,
  		enemy = match.t == 1 and (revenge and _pvpRecordBattleInfoCacheH[match.id] or _pvpBattleInfoCacheH[match.id]) or nil,
  		score = myScore,
  		reward = reward,
  		rank = myRank,
  	})
  
 | 
| e84a1beb  测试
 
gm后台查询日志,公告相关协议 | 823
824 |       role:mylog("pvp_action", {desc = "battleEnd", short1 = 2, int1 = curStatus and 1 or 0, int2 = revenge and 1 or 0, cint1 = oldMyRank, cint2 = myRank, 
      cint3 = match.id, long1 = #_pvpStartBattleCacheH.result, key1 = msg.key, key2 = role:getHerosLogStr(curHTeam.heros)})
 | 
| d4e9b817  zhouhaihai
 
战斗 日志 | 825 |   
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 826
827
828
829
830
831
832
833
834
835 |   	_pvpBattleInfoCacheH = {}  --重新发阵容了 没毛病
  	_pvpRecordInfoCacheH = {} -- 记录刷新了
  	_pvpRecordBattleInfoCacheH = {} -- 取新纪录的时候搞
  	_pvpStartBattleCacheH = nil
  	_pvpHeroInfoCacheH = {}
  	_pvpRecordHeroInfoCacheH = {}
  
  	if isWin then
  		role:checkTaskEnter("PvpWin", {score = myScore})
  	end
 | 
| e84a1beb  测试
 
gm后台查询日志,公告相关协议 | 836 |   
 | 
| f22a33af  zhouhaihai
 
自己的日志 | 837 |   	
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 838
839 |   	SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({
  		reward = reward,
 | 
| 7bb30dca  zhouhaihai
 
修改发奖 | 840 |   		change = change,
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 841
842
843
844
845
846
847 |   		myScore = myScore,
  		matchScore = matchScore,
  		oldmyScore = oldmyScore,
  		oldMatchScore = oldMatchScore,
  		myRank = myRank,
  		oldMyRank = oldMyRank,
  		video = video,
 | 
| c3b1fa38  zhouhaihai
 
缺个tou | 848 |   		headers = headers,
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 849
850
851
852
853
854 |   		isWin = isWin,
  	}))
  	return true
  end
  
  
 | 
| 4cf74232  zhouhaihai
 
pvp | 855
856
857 |   function _M.rankListRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
 | 
| f317b790  zhouhaihai
 
pvp 遗留 | 858 |   	local msg = MsgPack.unpack(data)
 | 
| 4cf74232  zhouhaihai
 
pvp | 859
860
861
862 |   	local ptype = msg.ptype or 1
  
  	local response = {}
  	if ptype == 1 then -- 普通pvp
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 863 |   		local dbKey = role:getPvpDBKey(RANK_PVP_COMMON)
 | 
| 4cf74232  zhouhaihai
 
pvp | 864 |   		local redret = redisproxy:pipelining(function(red)
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 865
866
867 |   			red:zscore(dbKey, roleId)
  			red:zrevrank(dbKey, roleId)
  			red:zrevrange(dbKey, 0, 99, "WITHSCORES")
 | 
| 4cf74232  zhouhaihai
 
pvp | 868 |   		end)
 | 
| aaf6a9e6  zhouhaihai
 
分数默认1000 | 869 |   		local score = role:unpackPvpScore(redret[1])
 | 
| 4cf74232  zhouhaihai
 
pvp | 870 |   		local rank = tonumber(redret[2] or -2) + 1  --排名 1 - ...  -1 未上榜 没打过pvp
 | 
| 4cf74232  zhouhaihai
 
pvp | 871
872 |   		local rankList = {}
  		for i = 1, #redret[3], 2 do
 | 
| f317b790  zhouhaihai
 
pvp 遗留 | 873
874 |   			local roleId = tonumber(redret[3][i])
  			local score = role:unpackPvpScore(redret[3][i + 1])
 | 
| 4cf74232  zhouhaihai
 
pvp | 875
876
877
878
879
880
881
882
883
884
885 |   			local online, curInfo = rpcRole(roleId, "friendSInfo")
  			curInfo.score = score
  			curInfo.roleId = roleId
  			table.insert(rankList, curInfo)
  		end
  		
  		response.score = score
  		response.rank = rank
  		response.rankList = rankList
  
  	elseif ptype == 2 then -- 高级pvp
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 886 |   		local dbKey = role:getPvpDBKey(RANK_PVP_HIGHT)
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 887 |   		local redret = redisproxy:pipelining(function(red)
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 888
889
890 |   			red:zscore(dbKey, roleId)
  			red:zrevrank(dbKey, roleId)
  			red:zrevrange(dbKey, 0, 99, "WITHSCORES")
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 891
892
893
894
895
896
897 |   		end)
  		local score = role:unpackPvpScore(redret[1])
  		local rank = tonumber(redret[2] or -2) + 1  --排名 1 - ...  -1 未上榜 没打过pvp
  		local rankList = {}
  		for i = 1, #redret[3], 2 do
  			local roleId = tonumber(redret[3][i])
  			local score = role:unpackPvpScore(redret[3][i + 1])
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 898 |   			local online, curInfo = rpcRole(roleId, "pvpHRankInfo")
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 899
900
901
902
903
904
905
906 |   			curInfo.score = score
  			curInfo.roleId = roleId
  			table.insert(rankList, curInfo)
  		end
  		
  		response.score = score
  		response.rank = rank
  		response.rankList = rankList
 | 
| 4cf74232  zhouhaihai
 
pvp | 907
908
909
910
911
912
913
914
915
916 |   	else
  		return
  	end
  	SendPacket(actionCodes.Pvp_rankListRpc, MsgPack.pack(response))
  	return true
  end
  
  function _M.recordListRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
 | 
| 8c20d812  zhouhaihai
 
pvp bUg | 917 |   	local msg = MsgPack.unpack(data)
 | 
| 4cf74232  zhouhaihai
 
pvp | 918
919
920
921
922
923
924
925
926 |   	local ptype = msg.ptype or 1
  
  	local recordList = {}
  	local now = skynet.timex()
  	if ptype == 1 then -- 普通pvp
  		local rlist = redisproxy:lrange(string.format(RECORD_PVP_COMMON, roleId), 0 , 9)
  		local tempList = {}
  		for _, temp in ipairs(rlist) do
  			local one = MsgPack.unpack(temp)
 | 
| 85083dba  zhouhaihai
 
拉黑从申请列表移除 | 927 |   			if now - one.time <= globalCsv.pvp_record_keep_time then -- 大于一天的弃之
 | 
| 4cf74232  zhouhaihai
 
pvp | 928
929
930 |   				table.insert(tempList, one)
  			end
  		end
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 931 |   		_pvpRecordInfoCacheC = tempList
 | 
| 4cf74232  zhouhaihai
 
pvp | 932 |   
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 933 |   		recordList = getMatchInfo(role, tempList, _pvpRecordBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo")
 | 
| 4cf74232  zhouhaihai
 
pvp | 934
935
936
937
938
939
940 |   		for idx, info in ipairs(recordList) do
  			local temp = tempList[idx]
  			info.win = temp.win
  			info.time = temp.time
  			info.video = temp.video
  			info.sdelta = temp.sdelta
  		end
 | 
| 9cede2e2  zhouhaihai
 
主推红点 和冒险次数 | 941 |   		role:clearRedPTag(RedPointTags.PvpCR)
 | 
| 4cf74232  zhouhaihai
 
pvp | 942 |   	elseif ptype == 2 then -- 高级pvp
 | 
| 4c5d72ab  zhouhaihai
 
高级pvp | 943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960 |   		local rlist = redisproxy:lrange(string.format(RECORD_PVP_HIGH, roleId), 0 , 9)
  		local tempList = {}
  		for _, temp in ipairs(rlist) do
  			local one = MsgPack.unpack(temp)
  			if now - one.time <= globalCsv.pvp_record_keep_time then -- 大于一天的弃之
  				table.insert(tempList, one)
  			end
  		end
  		_pvpRecordInfoCacheH = tempList
  
  		recordList = getMatchInfo(role, tempList, _pvpRecordBattleInfoCacheH, RANK_PVP_HIGHT, "pvpHInfo", _pvpRecordHeroInfoCacheH)
  		for idx, info in ipairs(recordList) do
  			local temp = tempList[idx]
  			info.win = temp.win
  			info.time = temp.time
  			info.sdelta = temp.sdelta
  			info.record = temp.record
  		end
 | 
| 9cede2e2  zhouhaihai
 
主推红点 和冒险次数 | 961
962 |   		role:clearRedPTag(RedPointTags.PvpHR)
  
 | 
| 4cf74232  zhouhaihai
 
pvp | 963
964
965
966
967 |   	else
  		return
  	end
  	SendPacket(actionCodes.Pvp_recordListRpc, MsgPack.pack({list = recordList}))
  	return true
 | 
| 440aa055  zhouhaihai
 
聊天 | 968
969 |   end
  
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 970
971
972
973 |   function _M.highDivisionGiftRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
 | 
| 75e7709e  zhouhaihai
 
领取bug | 974 |   	local pvpHGTime = role:getProperty("pvpHGTime")
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 975 |   	if pvpHGTime == 0 then return end
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 976 |   
 | 
| 42327de8  zhouhaihai
 
高级竞技场红点 | 977 |   	local newTime, newReward = role:calculatePvpHGift(role:getPvpHDivision())
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 978
979 |   	if not next(newReward) then return end
  
 | 
| 75e7709e  zhouhaihai
 
领取bug | 980 |   	role:updateProperties({
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 981
982
983
984 |   		pvpHGTime = newTime,
  		pvpHGift = {},
  	})
  
 | 
| 7bb30dca  zhouhaihai
 
修改发奖 | 985 |   	local reward, change = role:award(newReward, {log = {desc = "pvpDivisionH"}})
 | 
| f22a33af  zhouhaihai
 
自己的日志 | 986 |   	role:mylog("pvp_action", {desc = "pvpDivisionH"})
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 987 |   
 | 
| 7bb30dca  zhouhaihai
 
修改发奖 | 988 |   	SendPacket(actionCodes.Pvp_highDivisionGiftRpc, MsgPack.pack(role:packReward(reward, change)))
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009 |   	return true
  end
  
  function _M.shopBuyRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	local msg = MsgPack.unpack(data)
  	local id = msg.id
  	local count = msg.count or 1
  
  	local csvData = csvdb["shop_pvpCsv"][id]
  	if not csvData then return end
  
  	local pvpShop = role:getProperty("pvpShop")
  	if csvData.limit > 0 then
  		if math.illegalNum(count, 1, csvData.limit - (pvpShop[id] or 0)) then return end
  	end
  
  	if not role:checkItemEnough({[ItemId.PvpCoin] = csvData.cost * count}) then return end
  	
 | 
| 3133cb76  zhouhaihai
 
日志 | 1010 |   	role:costItems({[ItemId.PvpCoin] = csvData.cost * count}, {log = {desc = "pvpShop", int1 = id, int2 = count}})
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 1011
1012
1013
1014
1015
1016
1017
1018 |   	if csvData.limit > 0 then
  		role:changeUpdates({{type = "pvpShop", field = id, value = (pvpShop[id] or 0) + count}})
  	end
  
  	local gift = csvData.gift:toNumMap()
  	for id, c in pairs(gift) do
  		gift[id] = c * count
  	end
 | 
| 7bb30dca  zhouhaihai
 
修改发奖 | 1019 |   	local reward, change = role:award(gift, {log = {desc = "pvpShop", int1 = id, int2 = count}})
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 1020 |   
 | 
| f22a33af  zhouhaihai
 
自己的日志 | 1021
1022 |   	role:mylog("pvp_action", {desc = "pvpShop", int1 = id, int2 = count})
  
 | 
| 7bb30dca  zhouhaihai
 
修改发奖 | 1023 |   	SendPacket(actionCodes.Pvp_shopBuyRpc, MsgPack.pack(role:packReward(reward, change)))
 | 
| da898074  zhouhaihai
 
pvp 高级领奖 | 1024
1025
1026 |   	return true
  end
  
 | 
| e3c5cc5e  zhouhaihai
 
跨服竞技场over | 1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107 |   
  ----------------------------跨服竞技场----------------------------------
  
  function _M.crossInfoRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	if not role:isTimeResetOpen(TimeReset.PvpCross) then return end
  
  	local result = role:getCrossServerPvpMatchInfo()
  	if not result then return end
  
  	SendPacket(actionCodes.Pvp_crossInfoRpc, MsgPack.pack(result))
  	return true
  end
  
  function _M.crossRoleInfoRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	if not role:isTimeResetOpen(TimeReset.PvpCross) then return end
  
  	local result = role:getCrossServerPvpRoleInfo()
  	if not result then return end
  
  	SendPacket(actionCodes.Pvp_crossRoleInfoRpc, MsgPack.pack({roleInfo = result}))
  	return true
  end
  
  
  function _M.crossRoleInfoDetailRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	if not role:isTimeResetOpen(TimeReset.PvpCross) then return end
  	local msg = MsgPack.unpack(data)
  	if not msg.ids or not next(msg.ids) then return end
  
  	local result = role:getCrossServerPvpRoleInfoDeatil(msg.ids)
  	if not result then return end
  
  	SendPacket(actionCodes.Pvp_crossRoleInfoDetailRpc, MsgPack.pack(result))
  	return true
  end
  
  
  function _M.crossMatchRecordRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	if not role:isTimeResetOpen(TimeReset.PvpCross) then return 1 end
  	local msg = MsgPack.unpack(data)
  	if not msg.round then return 2 end
  	if not msg.matchIdx then return 3 end
  
  	local result = role:getCrossServerPvpMatchRecord(msg.round, msg.matchIdx)
  	if not result then return 4 end
  
  	SendPacket(actionCodes.Pvp_crossMatchRecordRpc, MsgPack.pack(result))
  	return true
  end
  
  function _M.crossBetInfoRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	if not role:isTimeResetOpen(TimeReset.PvpCross) then return end
  
  	local result = role:getCrossServerPvpBetInfo()
  	if not result then return end
  
  
  	SendPacket(actionCodes.Pvp_crossBetInfoRpc, MsgPack.pack(result))
  	return true
  end
  
  function _M.crossBetRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  
 | 
| c581c6e9  zhouhaihai
 
pvp 优化 | 1108
1109 |   	if not role:isTimeResetOpen(TimeReset.PvpCross) then return 1 end
  	if msg.idx ~= 1 and msg.idx ~= 2 then return 2 end
 | 
| e3c5cc5e  zhouhaihai
 
跨服竞技场over | 1110 |   
 | 
| c581c6e9  zhouhaihai
 
pvp 优化 | 1111
1112 |   	local result, code = role:setCrossServerPvpBet(msg.idx)
  	if not result then return 10 + code end
 | 
| 3133cb76  zhouhaihai
 
日志 | 1113 |   	
 | 
| f22a33af  zhouhaihai
 
自己的日志 | 1114 |   	role:mylog("pvp_action", {desc = "crossBet"})
 | 
| e3c5cc5e  zhouhaihai
 
跨服竞技场over | 1115
1116
1117
1118
1119
1120
1121 |   	SendPacket(actionCodes.Pvp_crossBetRpc, MsgPack.pack(result))
  	return true
  end
  
  
  
  
 | 
| 440aa055  zhouhaihai
 
聊天 | 1122 |   return _M
 |