Blame view

src/actions/PvpAction.lua 27 KB
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
26
  
  function _M.formatCommonRpc(agent , data)
  	local role = agent.role
fa565e0c   zhouhaihai   优化结构
27
  	local roleId = role:getProperty("id")
440aa055   zhouhaihai   聊天
28
  	local msg = MsgPack.unpack(data)
fa565e0c   zhouhaihai   优化结构
29
  	local pvpTC = role:getProperty("pvpTC")
3dbbc9f3   zhouhaihai   加上新的任务
30
  	for slot, heroId in pairs(msg.heros or {}) do
440aa055   zhouhaihai   聊天
31
32
33
34
  		if not role.heros[heroId] then
  			return
  		end
  	end
3dbbc9f3   zhouhaihai   加上新的任务
35
  	if not msg.heros or not next(msg.heros) then
fa565e0c   zhouhaihai   优化结构
36
  		return
440aa055   zhouhaihai   聊天
37
  	end
f603a60f   zhouhaihai   支援技实装
38
39
40
41
42
43
44
  	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   聊天
45
  
fa565e0c   zhouhaihai   优化结构
46
47
48
49
50
51
  	table.clear(pvpTC)
  	pvpTC.heros = {}
  	for slot, heroId in pairs(msg.heros) do
  		pvpTC.heros[slot] = heroId
  	end
  	pvpTC.leader = msg.leader
f603a60f   zhouhaihai   支援技实装
52
  	pvpTC.supports = supports
fa565e0c   zhouhaihai   优化结构
53
54
  	
  	role:savePvpCTeam(pvpTC)
440aa055   zhouhaihai   聊天
55
56
57
58
  	SendPacket(actionCodes.Pvp_formatCommonRpc, '')
  	return true
  end
  
4c5d72ab   zhouhaihai   高级pvp
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  function _M.formatHighRpc(agent , data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
  
  	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
74
  
4c5d72ab   zhouhaihai   高级pvp
75
76
77
78
79
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
  
  		table.insert(pvpTH, curTeam)
  	end
  	
  	role:savePvpHTeam(pvpTH)
e3c5cc5e   zhouhaihai   跨服竞技场over
100
  	role:changeCrossServerPvpSelfInfo("format")
4c5d72ab   zhouhaihai   高级pvp
101
102
103
104
105
  	SendPacket(actionCodes.Pvp_formatHighRpc, '')
  	return true
  end
  
  local function getMatchInfo(role, pvpList, battleCache, dbKey, infoFuncName, infoCache)
4cf74232   zhouhaihai   pvp
106
  	table.clear(battleCache)
da898074   zhouhaihai   pvp 高级领奖
107
  	local dbKey = role:getPvpDBKey(dbKey)
4cf74232   zhouhaihai   pvp
108
109
110
  	local redret = redisproxy:pipelining(function(red)
  		for _, info in ipairs(pvpList) do
  			if info.t == 1 then
4c5d72ab   zhouhaihai   高级pvp
111
  				red:zscore(dbKey, info.id)
4cf74232   zhouhaihai   pvp
112
113
114
115
116
117
118
119
120
121
  			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   加上新的任务
122
  			curInfo.score = role:unpackPvpScore(redret[curIdx] or 0)
4cf74232   zhouhaihai   pvp
123
124
  			curIdx = curIdx + 1
  			-- name, level, headId, battleV, heros
4c5d72ab   zhouhaihai   高级pvp
125
  			local online, roleInfo = rpcRole(curInfo.roleId, infoFuncName)
4cf74232   zhouhaihai   pvp
126
127
128
129
  			for k , v in pairs(roleInfo) do
  				if k == "battleInfo" then
  					battleCache[curInfo.roleId] = v
  				else
da898074   zhouhaihai   pvp 高级领奖
130
131
132
  					if (k == "heros" or k == "battleV") and infoCache then
  						infoCache[curInfo.roleId] = infoCache[curInfo.roleId] or {}
  						infoCache[curInfo.roleId][k] = v
4c5d72ab   zhouhaihai   高级pvp
133
  					end
4cf74232   zhouhaihai   pvp
134
135
136
137
138
139
140
141
142
143
144
145
146
  					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   聊天
147
  	local role = agent.role
4cf74232   zhouhaihai   pvp
148
  	local roleId = role:getProperty("id")
440aa055   zhouhaihai   聊天
149
  	local msg = MsgPack.unpack(data)
4cf74232   zhouhaihai   pvp
150
  	local ptype = msg.ptype or 1
d232676a   zhouhaihai   功能解锁 冒险返回
151
152
  	
  	if not role:isFuncUnlock(FuncUnlock.Pvp) then return end
440aa055   zhouhaihai   聊天
153
  
4cf74232   zhouhaihai   pvp
154
155
  	local response = {}
  	if ptype == 1 then -- 普通pvp
da898074   zhouhaihai   pvp 高级领奖
156
  		local dbKey = role:getPvpDBKey(RANK_PVP_COMMON)
4cf74232   zhouhaihai   pvp
157
  		local redret = redisproxy:pipelining(function(red)
da898074   zhouhaihai   pvp 高级领奖
158
159
  			red:zscore(dbKey, roleId)
  			red:zrevrank(dbKey, roleId)
4cf74232   zhouhaihai   pvp
160
  		end)
aaf6a9e6   zhouhaihai   分数默认1000
161
  		local score = role:unpackPvpScore(redret[1])
4cf74232   zhouhaihai   pvp
162
  		local rank = tonumber(redret[2] or -2) + 1  --排名 1 - ...  -1 未上榜 没打过pvp
aaf6a9e6   zhouhaihai   分数默认1000
163
  
4cf74232   zhouhaihai   pvp
164
165
166
167
168
169
170
  		local pvpMC = role:getProperty("pvpMC")
  		if not next(pvpMC) then --没有分配过对手
  			role:refreshPvpMatchC(score)
  			pvpMC = role:getProperty("pvpMC")
  		end
  		if not next(pvpMC) then return end
  		
4cf74232   zhouhaihai   pvp
171
  		response.rank = rank
b115474f   zhouhaihai   默认积分 1000
172
  		response.score = score
4c5d72ab   zhouhaihai   高级pvp
173
  		response.matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo")
4cf74232   zhouhaihai   pvp
174
  	elseif ptype == 2 then -- 高级pvp
da898074   zhouhaihai   pvp 高级领奖
175
176
  		if not role:isTimeResetOpen(TimeReset.PvpHight) then return end
  		local dbKey = role:getPvpDBKey(RANK_PVP_HIGHT)
4c5d72ab   zhouhaihai   高级pvp
177
  		local redret = redisproxy:pipelining(function(red)
da898074   zhouhaihai   pvp 高级领奖
178
179
  			red:zscore(dbKey, roleId)
  			red:zrevrank(dbKey, roleId)
4c5d72ab   zhouhaihai   高级pvp
180
181
182
183
184
185
186
187
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 --没有分配过对手
  			role:refreshPvpMatchH(score)
  			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
194
195
196
197
  	else
  		return
  	end
  	SendPacket(actionCodes.Pvp_infoRpc, MsgPack.pack(response))
440aa055   zhouhaihai   聊天
198
199
200
  	return true
  end
  
4cf74232   zhouhaihai   pvp
201
  function _M.refreshMatchCRpc(agent, data)
440aa055   zhouhaihai   聊天
202
203
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
4cf74232   zhouhaihai   pvp
204
205
206
  	role:refreshPvpMatchC()
  
  	local pvpMC = role:getProperty("pvpMC")
4c5d72ab   zhouhaihai   高级pvp
207
  	local matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo")
440aa055   zhouhaihai   聊天
208
  
4cf74232   zhouhaihai   pvp
209
  	SendPacket(actionCodes.Pvp_refreshMatchCRpc, MsgPack.pack({matches = matches}))
440aa055   zhouhaihai   聊天
210
211
212
  	return true
  end
  
4c5d72ab   zhouhaihai   高级pvp
213
214
215
  function _M.refreshMatchHRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
da898074   zhouhaihai   pvp 高级领奖
216
217
  	if not role:isTimeResetOpen(TimeReset.PvpHight) then return end
  
4c5d72ab   zhouhaihai   高级pvp
218
219
220
221
222
223
224
225
226
  	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   聊天
227
228
229
  function _M.buyCountRpc(agent, data)
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
4cf74232   zhouhaihai   pvp
230
  	local count = msg.count
440aa055   zhouhaihai   聊天
231
  
4cf74232   zhouhaihai   pvp
232
233
234
235
236
237
  	if math.illegalNum(count, 1, math.huge) then
  		return 1
  	end
  
  	local cost = {[ItemId.Diamond] = globalCsv.pvp_buy_cost * count}
  	if not role:checkItemEnough(cost) then return 2 end
3133cb76   zhouhaihai   日志
238
239
  	role:costItems(cost, {log = {desc = "buyPvpKey"}})
  	role:award({[ItemId.PvpKey] = count}, {log = {desc = "buyPvpKey"}})
440aa055   zhouhaihai   聊天
240
241
242
243
244
245
  
  	SendPacket(actionCodes.Pvp_buyCountRpc, '')
  	return true
  end
  
  function _M.startBattleRpc(agent, data)
4cf74232   zhouhaihai   pvp
246
247
  	local role = agent.role
  	local msg = MsgPack.unpack(data)
440aa055   zhouhaihai   聊天
248
  
4cf74232   zhouhaihai   pvp
249
250
251
  	local idx = msg.idx
  	local revenge = msg.revenge
  
3dbbc9f3   zhouhaihai   加上新的任务
252
253
254
  	local pvpTC = role:getProperty("pvpTC")
  	if not pvpTC.heros or not next(pvpTC.heros) then return 1 end
  
85083dba   zhouhaihai   拉黑从申请列表移除
255
  	local matchInfo, result, key, wait
3dbbc9f3   zhouhaihai   加上新的任务
256
  
85083dba   zhouhaihai   拉黑从申请列表移除
257
  	local now = skynet.timex()
4cf74232   zhouhaihai   pvp
258
  	if revenge then  --复仇
4c5d72ab   zhouhaihai   高级pvp
259
  		local temp = _pvpRecordInfoCacheC[idx]
3dbbc9f3   zhouhaihai   加上新的任务
260
  		if not temp then return 2 end
85083dba   zhouhaihai   拉黑从申请列表移除
261
  
f317b790   zhouhaihai   pvp 遗留
262
  		if not _revengeRecord[temp.id] or now >= _revengeRecord[temp.id] then
85083dba   zhouhaihai   拉黑从申请列表移除
263
  			if temp.t == 1 then
4c5d72ab   zhouhaihai   高级pvp
264
  				matchInfo = _pvpRecordBattleInfoCacheC[temp.id]
85083dba   zhouhaihai   拉黑从申请列表移除
265
266
267
268
269
  			elseif temp.t == 2 then
  				matchInfo = {robot = temp.id}
  			end
  		else
  			result = 1
f317b790   zhouhaihai   pvp 遗留
270
  			wait = _revengeRecord[temp.id] - now
4cf74232   zhouhaihai   pvp
271
272
273
  		end
  	else  --打正常
  		local pvpMC = role:getProperty("pvpMC")
3dbbc9f3   zhouhaihai   加上新的任务
274
  		if not pvpMC[idx] then return 3 end
4cf74232   zhouhaihai   pvp
275
276
277
278
279
280
281
  		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   加上新的任务
282
  	if not result and not matchInfo then return 4 end
85083dba   zhouhaihai   拉黑从申请列表移除
283
284
285
286
287
288
  
  	if not result then
  		-- 次数扣一波
  		local pvpFree = role.dailyData:getProperty("pvpFree")
  		if pvpFree >= globalCsv.pvp_battle_free_count then
  			local cost = {[ItemId.PvpKey] = 1}
3dbbc9f3   zhouhaihai   加上新的任务
289
  			if not role:checkItemEnough(cost) then return 5 end
3133cb76   zhouhaihai   日志
290
  			role:costItems(cost, {log = {desc = "startPvp", short1 = 1}})
85083dba   zhouhaihai   拉黑从申请列表移除
291
292
293
  		else
  			role.dailyData:updateProperty({field = "pvpFree", delta = 1})
  		end
4cf74232   zhouhaihai   pvp
294
  
85083dba   zhouhaihai   拉黑从申请列表移除
295
  		key = tostring(math.random())
4c5d72ab   zhouhaihai   高级pvp
296
  		_pvpStartBattleCacheC = {idx = idx, key = key, revenge = revenge}
3dbbc9f3   zhouhaihai   加上新的任务
297
298
  
  		role:checkTaskEnter("PvpBattle")
3133cb76   zhouhaihai   日志
299
300
301
  
  
  		role:log("pvp_action", {desc = "startBattle", short1 = 1, int1 = revenge and 1 or 0})
4cf74232   zhouhaihai   pvp
302
303
  	end
  
85083dba   zhouhaihai   拉黑从申请列表移除
304
  	SendPacket(actionCodes.Pvp_startBattleRpc, MsgPack.pack({matchInfo = matchInfo, key = key, result = result, wait = wait}))
4cf74232   zhouhaihai   pvp
305
  	return true
440aa055   zhouhaihai   聊天
306
307
308
  end
  
  function _M.endBattleRpc(agent, data)
4cf74232   zhouhaihai   pvp
309
310
311
  	local role = agent.role
  	local roleId = role:getProperty("id")
  	local msg = MsgPack.unpack(data)
440aa055   zhouhaihai   聊天
312
  
4c5d72ab   zhouhaihai   高级pvp
313
  	if not msg.key or not _pvpStartBattleCacheC or msg.key ~= _pvpStartBattleCacheC.key then 
4cf74232   zhouhaihai   pvp
314
315
  		return 1
  	end
3dbbc9f3   zhouhaihai   加上新的任务
316
  
4c5d72ab   zhouhaihai   高级pvp
317
  	if not msg.idx or msg.idx ~= _pvpStartBattleCacheC.idx then
4cf74232   zhouhaihai   pvp
318
319
  		return 2
  	end
440aa055   zhouhaihai   聊天
320
  
4cf74232   zhouhaihai   pvp
321
  	local isWin = msg.starNum and msg.starNum > 0
85083dba   zhouhaihai   拉黑从申请列表移除
322
  	local now = skynet.timex()
4cf74232   zhouhaihai   pvp
323
  
4c5d72ab   zhouhaihai   高级pvp
324
  	local revenge = _pvpStartBattleCacheC.revenge
4cf74232   zhouhaihai   pvp
325
326
  	local match
  	if revenge then
4c5d72ab   zhouhaihai   高级pvp
327
  		match = _pvpRecordInfoCacheC[msg.idx]
f317b790   zhouhaihai   pvp 遗留
328
  		_revengeRecord[match.id] = now + RevengeWaitTime  -- 1分钟内不能再打
4cf74232   zhouhaihai   pvp
329
330
331
332
333
334
335
336
  	else
  		local pvpMC = role:getProperty("pvpMC")
  		match = pvpMC[msg.idx]
  	end
  	
  	if not match then return end
  
  	local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpBonus, true)
3133cb76   zhouhaihai   日志
337
  	local reward = role:award({[temp[1]] = temp[2]}, {log = {desc = "pvpBattleC"}})
4cf74232   zhouhaihai   pvp
338
339
340
  	local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = role:changePvpScoreCommon(match.t == 1 and match.id or -1, isWin)
  
  	_pvpBattleInfoCacheC = {}  --重新发阵容了 没毛病
4c5d72ab   zhouhaihai   高级pvp
341
342
343
  	_pvpRecordInfoCacheC = {} -- 记录刷新了
  	_pvpRecordBattleInfoCacheC = {} -- 取新纪录的时候搞
  	_pvpStartBattleCacheC = nil
4cf74232   zhouhaihai   pvp
344
345
  
  	-- 请求上传录像
4cf74232   zhouhaihai   pvp
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
  	local params = {
  		["roleid"] = roleId,
  		["key"] = "zhaolugame20191016",
  		["time"] = now,
  	}
  	local status, body = httpc.get(remoteUrl, "/applyvideo?" .. httpGetFormatData(params), {}, {})
  	local video = nil
  	if tonumber(status) == 200 then
  		local result = json.decode(body)
  		video = result.name
  	else
  		skynet.error("applyvideo", "error", status, body, content)
  	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
371
  		red:ltrim(dbKey, 0, 9)
4cf74232   zhouhaihai   pvp
372
373
374
375
376
377
378
379
380
381
382
  		-- 对方加入战斗记录
  		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
383
  			red:ltrim(dbKey, 0, 9)
4cf74232   zhouhaihai   pvp
384
385
  		end
  	end)
3dbbc9f3   zhouhaihai   加上新的任务
386
387
388
389
  
  	if isWin then
  		role:checkTaskEnter("PvpWin", {score = myScore})
  	end
3133cb76   zhouhaihai   日志
390
391
  
  	role:log("pvp_action", {desc = "battleEnd", short1 = 1, int1 = isWin and 1 or 0, int2 = revenge and 1 or 0})
440aa055   zhouhaihai   聊天
392
  	
4cf74232   zhouhaihai   pvp
393
394
395
396
397
398
399
400
401
402
403
404
405
  	SendPacket(actionCodes.Pvp_endBattleRpc, MsgPack.pack({
  		reward = reward,
  		myScore = myScore,
  		matchScore = matchScore,
  		oldmyScore = oldmyScore,
  		oldMatchScore = oldMatchScore,
  		myRank = myRank,
  		oldMyRank = oldMyRank,
  		video = video,
  	}))
  	return true
  end
  
4c5d72ab   zhouhaihai   高级pvp
406
407
408
409
410
411
412
  
  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 高级领奖
413
  	if not role:isTimeResetOpen(TimeReset.PvpHight) then return end
4c5d72ab   zhouhaihai   高级pvp
414
415
  
  	local pvpTH = role:getProperty("pvpTH")
da898074   zhouhaihai   pvp 高级领奖
416
  	if not next(pvpTH) then return 1 end
4c5d72ab   zhouhaihai   高级pvp
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
  
  	-- 检查并记录玩家队伍
  	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
  
  		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 高级领奖
477
  			enemyT = _pvpHeroInfoCacheH[pvpMH[idx].id]
4c5d72ab   zhouhaihai   高级pvp
478
479
480
481
482
483
484
485
486
487
488
489
490
  		elseif pvpMH[idx].t == 2 then
  			enemyTeamRecord = {robot = pvpMH[idx].id}
  		end
  	end
  
  	if not result and not enemyTeamRecord then return 4 end
  
  	if not result 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
3133cb76   zhouhaihai   日志
491
  			role:costItems(cost, {log = {desc = "startPvp", short1 = 2}})
4c5d72ab   zhouhaihai   高级pvp
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
  		else
  			role.dailyData:updateProperty({field = "pvpFreeH", delta = 1})
  		end
  
  
  		-- 只发送指定的那个敌人
  		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   日志
516
517
518
  
  		role:log("pvp_action", {desc = "startBattle", short1 = 2, int1 = revenge and 1 or 0})
  
4c5d72ab   zhouhaihai   高级pvp
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
  	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 
  		return 1
  	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分钟内不能再打
  	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), {}, {})
  	local video = nil
  	if tonumber(status) == 200 then
  		local result = json.decode(body)
  		video = result.name
  	else
  		skynet.error("applyvideo", "error", status, body, content)
  	end
  
  	table.insert(_pvpStartBattleCacheH.result, {
  		isWin = isWin,
  		video = video,
  	})
  
  	-- 检查是否结束战斗
  	local winCount, loseCount = 0, 0
  	for _, status in pairs(_pvpStartBattleCacheH.result) do
  		if status.isWin then
  			winCount = winCount + 1
  		else
  			loseCount = loseCount + 1
  		end
  	end
  
  	if winCount >= 2 then
  		isWin = true
  	elseif loseCount >= 2 then
  		isWin = false
  	else -- 没结束
  		-- 返回继续战斗
  
  		local key = tostring(math.random())
  		_pvpStartBattleCacheH.key = key
  		local round = #_pvpStartBattleCacheH.result + 1
  		local matchInfo = nil
  		if _pvpStartBattleCacheH.enemyTB.robot then
da898074   zhouhaihai   pvp 高级领奖
601
  			matchInfo = _pvpStartBattleCacheH.enemyTB
4c5d72ab   zhouhaihai   高级pvp
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
  		else
  			matchInfo = _pvpStartBattleCacheH.enemyTB[round]
  		end
  
  		-- 继续战斗
  		SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({
  			matchInfo = matchInfo, --敌方队伍 信息
  			key = key, --战斗校验 key
  			round = round, -- 战斗场数索引
  			video = video, -- 返回让客户端上传录像
  		}))
  		return true
  	end
  
  	-- 战斗结束了发奖 
da898074   zhouhaihai   pvp 高级领奖
617
  	local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpgroupBonus, true)
3133cb76   zhouhaihai   日志
618
  	local reward = role:award({[temp[1]] = temp[2]}, {log = {desc = "pvpBattleH"}})
da898074   zhouhaihai   pvp 高级领奖
619
620
621
622
  	local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = 0, 0, 0, 0, 0, 0
  	if role:isTimeResetOpen(TimeReset.PvpHight) then 
  		myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = role:changePvpScoreHigh(match.t == 1 and match.id or -1, isWin)
  	end
4c5d72ab   zhouhaihai   高级pvp
623
624
625
626
  
  	-- 加入战斗记录
  	local selfTeam = {}
  	local enemyTeam = {}
e3c5cc5e   zhouhaihai   跨服竞技场over
627
  
4c5d72ab   zhouhaihai   高级pvp
628
629
630
  	for _idx, info in ipairs(_pvpStartBattleCacheH.result) do
  		info.winId = info.isWin and roleId or match.id
  		info.isWin = nil
da898074   zhouhaihai   pvp 高级领奖
631
632
633
634
  		selfTeam[_idx] = {
  			heros = role:getTeamHerosInfo(_pvpStartBattleCacheH.pvpTH[_idx].heros),
  			battleV = role:getTeamBattleValue(_pvpStartBattleCacheH.pvpTH[_idx].heros)
  		}
4c5d72ab   zhouhaihai   高级pvp
635
  		if match.t == 1 and _pvpStartBattleCacheH.enemyT then
e3c5cc5e   zhouhaihai   跨服竞技场over
636
637
638
639
  			enemyTeam[_idx] = {
  				heros = _pvpStartBattleCacheH.enemyT["heros"][_idx],
  				battleV = _pvpStartBattleCacheH.enemyT["battleV"][_idx]
  			}
4c5d72ab   zhouhaihai   高级pvp
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
  		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)
  		end
  	end)
  
  	_pvpBattleInfoCacheH = {}  --重新发阵容了 没毛病
  	_pvpRecordInfoCacheH = {} -- 记录刷新了
  	_pvpRecordBattleInfoCacheH = {} -- 取新纪录的时候搞
  	_pvpStartBattleCacheH = nil
  	_pvpHeroInfoCacheH = {}
  	_pvpRecordHeroInfoCacheH = {}
  
  	if isWin then
  		role:checkTaskEnter("PvpWin", {score = myScore})
  	end
3133cb76   zhouhaihai   日志
686
  	role:log("pvp_action", {desc = "battleEnd", short1 = 2, int1 = isWin and 1 or 0, int2 = revenge and 1 or 0})
4c5d72ab   zhouhaihai   高级pvp
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
  	
  	SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({
  		reward = reward,
  		myScore = myScore,
  		matchScore = matchScore,
  		oldmyScore = oldmyScore,
  		oldMatchScore = oldMatchScore,
  		myRank = myRank,
  		oldMyRank = oldMyRank,
  		video = video,
  		isWin = isWin,
  	}))
  	return true
  end
  
  
4cf74232   zhouhaihai   pvp
703
704
705
  function _M.rankListRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
f317b790   zhouhaihai   pvp 遗留
706
  	local msg = MsgPack.unpack(data)
4cf74232   zhouhaihai   pvp
707
708
709
710
  	local ptype = msg.ptype or 1
  
  	local response = {}
  	if ptype == 1 then -- 普通pvp
da898074   zhouhaihai   pvp 高级领奖
711
  		local dbKey = role:getPvpDBKey(RANK_PVP_COMMON)
4cf74232   zhouhaihai   pvp
712
  		local redret = redisproxy:pipelining(function(red)
da898074   zhouhaihai   pvp 高级领奖
713
714
715
  			red:zscore(dbKey, roleId)
  			red:zrevrank(dbKey, roleId)
  			red:zrevrange(dbKey, 0, 99, "WITHSCORES")
4cf74232   zhouhaihai   pvp
716
  		end)
aaf6a9e6   zhouhaihai   分数默认1000
717
  		local score = role:unpackPvpScore(redret[1])
4cf74232   zhouhaihai   pvp
718
  		local rank = tonumber(redret[2] or -2) + 1  --排名 1 - ...  -1 未上榜 没打过pvp
4cf74232   zhouhaihai   pvp
719
720
  		local rankList = {}
  		for i = 1, #redret[3], 2 do
f317b790   zhouhaihai   pvp 遗留
721
722
  			local roleId = tonumber(redret[3][i])
  			local score = role:unpackPvpScore(redret[3][i + 1])
4cf74232   zhouhaihai   pvp
723
724
725
726
727
728
729
730
731
732
733
  			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 高级领奖
734
  		local dbKey = role:getPvpDBKey(RANK_PVP_HIGHT)
4c5d72ab   zhouhaihai   高级pvp
735
  		local redret = redisproxy:pipelining(function(red)
da898074   zhouhaihai   pvp 高级领奖
736
737
738
  			red:zscore(dbKey, roleId)
  			red:zrevrank(dbKey, roleId)
  			red:zrevrange(dbKey, 0, 99, "WITHSCORES")
4c5d72ab   zhouhaihai   高级pvp
739
740
741
742
743
744
745
  		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 高级领奖
746
  			local online, curInfo = rpcRole(roleId, "pvpHRankInfo")
4c5d72ab   zhouhaihai   高级pvp
747
748
749
750
751
752
753
754
  			curInfo.score = score
  			curInfo.roleId = roleId
  			table.insert(rankList, curInfo)
  		end
  		
  		response.score = score
  		response.rank = rank
  		response.rankList = rankList
4cf74232   zhouhaihai   pvp
755
756
757
758
759
760
761
762
763
764
  	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
765
  	local msg = MsgPack.unpack(data)
4cf74232   zhouhaihai   pvp
766
767
768
769
770
771
772
773
774
  	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   拉黑从申请列表移除
775
  			if now - one.time <= globalCsv.pvp_record_keep_time then -- 大于一天的弃之
4cf74232   zhouhaihai   pvp
776
777
778
  				table.insert(tempList, one)
  			end
  		end
4c5d72ab   zhouhaihai   高级pvp
779
  		_pvpRecordInfoCacheC = tempList
4cf74232   zhouhaihai   pvp
780
  
4c5d72ab   zhouhaihai   高级pvp
781
  		recordList = getMatchInfo(role, tempList, _pvpRecordBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo")
4cf74232   zhouhaihai   pvp
782
783
784
785
786
787
788
789
790
  		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
  		
  	elseif ptype == 2 then -- 高级pvp
4c5d72ab   zhouhaihai   高级pvp
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
  		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
4cf74232   zhouhaihai   pvp
809
810
811
812
813
  	else
  		return
  	end
  	SendPacket(actionCodes.Pvp_recordListRpc, MsgPack.pack({list = recordList}))
  	return true
440aa055   zhouhaihai   聊天
814
815
  end
  
da898074   zhouhaihai   pvp 高级领奖
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
  function _M.highDivisionGiftRpc(agent, data)
  	local role = agent.role
  	local roleId = role:getProperty("id")
  
  	local pvpHGTime = self:getProperty("pvpHGTime")
  	if pvpHGTime == 0 then return end
  	local score = role:unpackPvpScore(redisproxy:zscore(role:getPvpDBKey(RANK_PVP_HIGHT), roleId))
  
  	local divisionId = nil
  	for _id, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
  		if score >= division.division then
  			divisionId = _id
  		else
  			break
  		end
  	end
  
  	local newTime, newReward = role:calculatePvpHGift(divisionId)
  	if not next(newReward) then return end
  
  	self:updateProperties({
  		pvpHGTime = newTime,
  		pvpHGift = {},
  	})
  
3133cb76   zhouhaihai   日志
841
842
  	local reward = role:award(newReward, {log = {desc = "pvpDivisionH"}})
  	role:log("pvp_action", {desc = "pvpDivisionH"})
da898074   zhouhaihai   pvp 高级领奖
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
  
  	SendPacket(actionCodes.Pvp_highDivisionGiftRpc, MsgPack.pack({reward = reward}))
  	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   日志
866
  	role:costItems({[ItemId.PvpCoin] = csvData.cost * count}, {log = {desc = "pvpShop", int1 = id, int2 = count}})
da898074   zhouhaihai   pvp 高级领奖
867
868
869
870
871
872
873
874
  	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
3133cb76   zhouhaihai   日志
875
  	local reward = role:award(gift, {log = {desc = "pvpShop", int1 = id, int2 = count}})
da898074   zhouhaihai   pvp 高级领奖
876
  
3133cb76   zhouhaihai   日志
877
  	role:log("pvp_action", {desc = "pvpShop", int1 = id, int2 = count})
da898074   zhouhaihai   pvp 高级领奖
878
879
880
881
882
  
  	SendPacket(actionCodes.Pvp_shopBuyRpc, MsgPack.pack({reward = reward}))
  	return true
  end
  
e3c5cc5e   zhouhaihai   跨服竞技场over
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
  
  ----------------------------跨服竞技场----------------------------------
  
  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 优化
964
965
  	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
966
  
c581c6e9   zhouhaihai   pvp 优化
967
968
  	local result, code = role:setCrossServerPvpBet(msg.idx)
  	if not result then return 10 + code end
3133cb76   zhouhaihai   日志
969
970
  	
  	role:log("pvp_action", {desc = "crossBet"})
e3c5cc5e   zhouhaihai   跨服竞技场over
971
972
973
974
975
976
977
  	SendPacket(actionCodes.Pvp_crossBetRpc, MsgPack.pack(result))
  	return true
  end
  
  
  
  
440aa055   zhouhaihai   聊天
978
  return _M