Blame view

src/models/RolePvp.lua 14.7 KB
fa565e0c   zhouhaihai   优化结构
1
2
3
4
5
6
7
8
  
  local RolePvp = {}
  
  RolePvp.bind = function (Role)
  
  local PVP_RANK_TIME_SORT_STD = 1924876800 -- 2030-12-31 00:00:00
  local PVP_RANK_TIME_SORT_PLACE = 1000000 -- 时间戳占据 6位数
  local PVP_RANK_TIME_SORT_PRECISION = 360 -- 时间精度 每6分钟忽略差异
53227d9c   zhouhaihai   pvp 编队胜利推送
9
  local PVP_RANK_BASE_SCORE = globalCsv.pvp_base_score -- 机器人积分
fa565e0c   zhouhaihai   优化结构
10
  
3dbbc9f3   zhouhaihai   加上新的任务
11
12
  
  function Role:unpackPvpScore(score)
aaf6a9e6   zhouhaihai   分数默认1000
13
14
  	if not score then return globalCsv.pvp_base_score end
  	score = tonumber(score)
fa565e0c   zhouhaihai   优化结构
15
16
17
  	return math.floor(score / PVP_RANK_TIME_SORT_PLACE)
  end
  
3dbbc9f3   zhouhaihai   加上新的任务
18
  function Role:packPvpScore(score, now)
fa565e0c   zhouhaihai   优化结构
19
20
21
22
  	now = now or skynet.timex()
  	return math.floor(score * PVP_RANK_TIME_SORT_PLACE + (PVP_RANK_TIME_SORT_STD - now) / PVP_RANK_TIME_SORT_PRECISION)
  end
  
4c5d72ab   zhouhaihai   高级pvp
23
24
  
  function Role:changePvpScore(rankKey, changeScoreCallback, matchId)
da898074   zhouhaihai   pvp 高级领奖
25
  	local dbKey = self:getPvpDBKey(rankKey)
fa565e0c   zhouhaihai   优化结构
26
27
28
  	local roleId = self:getProperty("id")
  	local isPlayer = matchId ~= -1
  	local redret = redisproxy:pipelining(function(red)
da898074   zhouhaihai   pvp 高级领奖
29
30
  		red:zscore(dbKey, roleId)
  		red:zrevrank(dbKey, roleId)
fa565e0c   zhouhaihai   优化结构
31
  		if isPlayer then
da898074   zhouhaihai   pvp 高级领奖
32
  			red:zscore(dbKey, matchId)
fa565e0c   zhouhaihai   优化结构
33
34
  		end
  	end)
3dbbc9f3   zhouhaihai   加上新的任务
35
  	local myScore = self:unpackPvpScore(redret[1])
4cf74232   zhouhaihai   pvp
36
  	local oldMyRank = tonumber(redret[2] or -2) + 1
53227d9c   zhouhaihai   pvp 编队胜利推送
37
  	local matchScore = PVP_RANK_BASE_SCORE
fa565e0c   zhouhaihai   优化结构
38
  	if isPlayer then
3dbbc9f3   zhouhaihai   加上新的任务
39
  		matchScore = self:unpackPvpScore(redret[3])
fa565e0c   zhouhaihai   优化结构
40
  	end
4cf74232   zhouhaihai   pvp
41
  	local oldmyScore, oldMatchScore = myScore, matchScore
fa565e0c   zhouhaihai   优化结构
42
  
4c5d72ab   zhouhaihai   高级pvp
43
  	myScore, matchScore = changeScoreCallback(myScore, matchScore)
fa565e0c   zhouhaihai   优化结构
44
45
46
47
  	myScore = math.max(myScore, 0)
  	matchScore = math.max(matchScore, 0)
  
  	local now = skynet.timex()
f5207098   zhouhaihai   bug
48
  	redret = redisproxy:pipelining(function(red)
da898074   zhouhaihai   pvp 高级领奖
49
  		red:zadd(dbKey, self:packPvpScore(myScore, now), roleId)
fa565e0c   zhouhaihai   优化结构
50
  		if isPlayer then
da898074   zhouhaihai   pvp 高级领奖
51
  			red:zadd(dbKey, self:packPvpScore(matchScore, now), matchId)
fa565e0c   zhouhaihai   优化结构
52
  		end
da898074   zhouhaihai   pvp 高级领奖
53
  		red:zrevrank(dbKey, roleId)
fa565e0c   zhouhaihai   优化结构
54
  	end)
4c5d72ab   zhouhaihai   高级pvp
55
  
4cf74232   zhouhaihai   pvp
56
57
58
59
60
61
  	local myRank
  	if isPlayer then
  		myRank = tonumber(redret[3] or -2) + 1
  	else
  		myRank = tonumber(redret[2] or -2) + 1
  	end
4c5d72ab   zhouhaihai   高级pvp
62
63
  
  	return {myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank}
fa565e0c   zhouhaihai   优化结构
64
65
  end
  
4c5d72ab   zhouhaihai   高级pvp
66
67
68
69
70
  function Role:changePvpScoreCommon(matchId, isWin)
  	local function changeScoreCallback(myScore, matchScore)
  		if isWin then
  			local scoreChange = math.ceil(60 / (1 + 10 ^ ((myScore - matchScore) / 400)))
  			myScore = myScore + scoreChange
53227d9c   zhouhaihai   pvp 编队胜利推送
71
  			matchScore = matchScore - math.ceil(scoreChange / 3) -- 防守方失败时,扣分减为原来的1/3
4c5d72ab   zhouhaihai   高级pvp
72
73
74
75
76
77
78
79
80
81
82
83
84
  		else
  			local scoreChange = math.ceil(60 / (1 + 10 ^ ((matchScore - myScore) / 400)))
  			myScore = myScore - scoreChange
  			matchScore = matchScore + scoreChange
  		end
  		return myScore, matchScore
  	end
  
  	local result = self:changePvpScore(RANK_PVP_COMMON, changeScoreCallback, matchId)
  	self:refreshPvpMatchC(result[1])
  	return table.unpack(result)
  end
  
42327de8   zhouhaihai   高级竞技场红点
85
86
87
88
89
90
91
92
93
94
95
96
97
  function Role:getPvpHDivision(score)
  	local score = score or self:unpackPvpScore(redisproxy:zscore(self:getPvpDBKey(RANK_PVP_HIGHT), self:getProperty("id")))
  	local divisionId = nil
  	for _id, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
  		if score >= division.division then
  			divisionId = _id
  		else
  			break
  		end
  	end
  	return divisionId
  end
  
da898074   zhouhaihai   pvp 高级领奖
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  function Role:calculatePvpHGift(division)
  	local now = skynet.timex()
  	local oldTime = self:getProperty("pvpHGTime")
  	local oldReward = self:getProperty("pvpHGift")
  
  	local newTime = oldTime
  	local newReward = clone(oldReward)
  
  	local divisionData = csvdb["pvp_group_divisionCsv"][division]
  	if oldTime == 0 then
  		newTime = now
  	else
  		local times = math.floor((now - oldTime) / globalCsv.pvp_high_reward_add_pre)
  		newTime = oldTime + times * globalCsv.pvp_high_reward_add_pre
  
  		for itemId, count in pairs(divisionData.reward:toNumMap()) do
2cc20bbe   zhouhaihai   times bug
114
  			newReward[itemId] = math.min((newReward[itemId] or 0) + count * times, divisionData.limit)
da898074   zhouhaihai   pvp 高级领奖
115
116
117
118
119
  		end
  	end
  	return newTime, newReward
  end
  
4c5d72ab   zhouhaihai   高级pvp
120
  function Role:changePvpScoreHigh(matchId, isWin)
da898074   zhouhaihai   pvp 高级领奖
121
  	local oldMyDivision
4c5d72ab   zhouhaihai   高级pvp
122
  	local function changeScoreCallback(myScore, matchScore)
da898074   zhouhaihai   pvp 高级领奖
123
124
125
  		local myMinId = 0
  		local matchMinId = 0
  		for _id, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
4c5d72ab   zhouhaihai   高级pvp
126
  			if myScore >= division.division then
da898074   zhouhaihai   pvp 高级领奖
127
  				myMinId = _id
4c5d72ab   zhouhaihai   高级pvp
128
129
  			end
  			if matchScore >= division.division then
da898074   zhouhaihai   pvp 高级领奖
130
  				matchMinId = _id 
4c5d72ab   zhouhaihai   高级pvp
131
132
  			end
  		end
da898074   zhouhaihai   pvp 高级领奖
133
  		oldMyDivision = myMinId
4c5d72ab   zhouhaihai   高级pvp
134
135
136
  		if isWin then
  			local scoreChange = math.ceil(50 / (1 + 10 ^ ((myScore - matchScore) / 1000)))
  			myScore = myScore + scoreChange
53227d9c   zhouhaihai   pvp 编队胜利推送
137
  			matchScore = matchScore - math.ceil(scoreChange / 3) -- 防守方失败时,扣分减为原来的1/3
4c5d72ab   zhouhaihai   高级pvp
138
139
140
141
142
  		else
  			local scoreChange = math.ceil(50 / (1 + 10 ^ ((matchScore - myScore) / 1000)))
  			myScore = myScore - scoreChange
  			matchScore = matchScore + scoreChange
  		end
da898074   zhouhaihai   pvp 高级领奖
143
  		return math.max(myScore, csvdb["pvp_group_divisionCsv"][myMinId].division), math.max(matchScore, csvdb["pvp_group_divisionCsv"][matchMinId].division)
4c5d72ab   zhouhaihai   高级pvp
144
145
146
  	end
  
  	local result = self:changePvpScore(RANK_PVP_HIGHT, changeScoreCallback, matchId)
da898074   zhouhaihai   pvp 高级领奖
147
148
149
150
151
152
153
154
155
  	--{myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank}
  	local newDivision = nil
  	for _id, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
  		if result[1] >= division.division then
  			newDivision = _id
  		else
  			break
  		end
  	end
a6308d6a   zhouhaihai   hgtime
156
  	if newDivision ~= oldMyDivision or self:getProperty("pvpHGTime") == 0 then
da898074   zhouhaihai   pvp 高级领奖
157
158
159
160
161
162
163
164
  		--刷新段位奖励
  		local newTime, newReward = self:calculatePvpHGift(oldMyDivision)
  		self:updateProperties({
  			pvpHGTime = newTime,
  			pvpHGift = newReward,
  		})
  	end
  
4c5d72ab   zhouhaihai   高级pvp
165
166
167
168
  	self:refreshPvpMatchH(result[1])
  	return table.unpack(result)
  end
  
53227d9c   zhouhaihai   pvp 编队胜利推送
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  function Role:isInPvpRank(rankKey)
  	local Fields = {
  		[RANK_PVP_COMMON] = "pvpMC",
  		[RANK_PVP_HIGHT] = "pvpMH",
  	}
  	local dbKey = self:getPvpDBKey(rankKey)
  	local roleId = self:getProperty("id")
  	if redisproxy:zscore(dbKey, roleId) then
  		return true
  	end
  	return false
  end
  
  
4c5d72ab   zhouhaihai   高级pvp
183
184
185
186
187
188
189
190
191
192
193
194
  function Role:refreshPvpMatch(score, rankKey)
  
  	local Fields = {
  		[RANK_PVP_COMMON] = "pvpMC",
  		[RANK_PVP_HIGHT] = "pvpMH",
  	}
  	local RobotCsvs = {
  		[RANK_PVP_COMMON] = "pvp_robotCsv",
  		[RANK_PVP_HIGHT] = "pvp_robotCsv",
  	}
  	local mField = Fields[rankKey]
  	local robotCsv = RobotCsvs[rankKey]
da898074   zhouhaihai   pvp 高级领奖
195
  	local dbKey = self:getPvpDBKey(rankKey)
4c5d72ab   zhouhaihai   高级pvp
196
  
fa565e0c   zhouhaihai   优化结构
197
  	local roleId = self:getProperty("id")
da898074   zhouhaihai   pvp 高级领奖
198
  	score =  score or self:unpackPvpScore(redisproxy:zscore(dbKey, roleId))
4c5d72ab   zhouhaihai   高级pvp
199
  
fa565e0c   zhouhaihai   优化结构
200
201
202
203
  	local function getPlayers(levels)
  		local redret = redisproxy:pipelining(function(red)
  			for _, level in ipairs(levels) do
  				local low, high = table.unpack(level)
da898074   zhouhaihai   pvp 高级领奖
204
205
206
207
  				red:zadd(dbKey, low * PVP_RANK_TIME_SORT_PLACE, "std_temp1")
  				red:zadd(dbKey, high * PVP_RANK_TIME_SORT_PLACE + PVP_RANK_TIME_SORT_PLACE - 1, "std_temp2")
  				red:ZREVRANK(dbKey, "std_temp1")
  				red:ZREVRANK(dbKey, "std_temp2")
fa565e0c   zhouhaihai   优化结构
208
  			end
da898074   zhouhaihai   pvp 高级领奖
209
  			red:zrem(dbKey, "std_temp1", "std_temp2")
fa565e0c   zhouhaihai   优化结构
210
211
212
213
214
215
216
217
218
219
220
  		end)
  
  		local PreGetCount = 7 
  		local redret = redisproxy:pipelining(function(red)
  			for idx, level in ipairs(levels) do
  				local rank1 = tonumber(redret[(idx - 1) * 4 + 3])
  				local rank2 = tonumber(redret[(idx - 1) * 4 + 4])
  				if rank1 - rank2 > PreGetCount then
  					rank2 = math.randomInt(rank2, rank1 - PreGetCount + 1)
  					rank1 = rank2 + PreGetCount - 1
  				end
da898074   zhouhaihai   pvp 高级领奖
221
  				red:ZREVRANGE(dbKey, rank2, rank1)
fa565e0c   zhouhaihai   优化结构
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
  			end
  		end)
  		return redret
  	end
  
  	local findIdx = #globalCsv.pvp_division
  	for idx, limit in ipairs(globalCsv.pvp_division) do
  		if score < limit then
  			findIdx = idx - 1
  			break
  		end
  	end
  	local levels = {
  		{}, {}, {}
  	}
  	if globalCsv.pvp_division[findIdx + 1] then
  		levels[1] = {globalCsv.pvp_division[findIdx + 1], (globalCsv.pvp_division[findIdx + 2] or 100000000) - 1}
  	end
  	levels[2] =  {globalCsv.pvp_division[findIdx], (globalCsv.pvp_division[findIdx + 1] or 100000000) - 1}
  	if globalCsv.pvp_division[findIdx - 1] then
  		levels[3] =  {globalCsv.pvp_division[findIdx - 1], globalCsv.pvp_division[findIdx] - 1}
  	end
  	local redirect = {}
  	for i = #levels , 1, -1 do
  		if not next(levels[i]) then
  			table.remove(levels, i)
  			redirect[i] = -1
  			for _, v in pairs(redirect) do
  				redirect[_] = v - 1
  			end
  		else
  			redirect[i] = i
  		end
  	end
  
  	local result = getPlayers(levels)
4c5d72ab   zhouhaihai   高级pvp
258
  	local match = self:getProperty(mField)
fa565e0c   zhouhaihai   优化结构
259
260
  	local hadPlayer = {[roleId] = 1}
  	local hadRobot = {}
4c5d72ab   zhouhaihai   高级pvp
261
  	for _, one in pairs(match) do
fa565e0c   zhouhaihai   优化结构
262
263
264
265
266
267
268
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
  		if one.t == 1 then
  			hadPlayer[one.id] = 1
  		elseif one.t == 2 then
  			hadRobot[one.id] = 1
  		end
  	end
  
  	for _, temp in pairs(result) do
  		for i = #temp, 1, -1 do
  			local id = tonumber(temp[i])
  			if hadPlayer[id] then
  				table.remove(temp, i)
  			else
  				temp[i] = id
  				hadPlayer[id] = 1
  			end
  		end
  	end
  	-- 增加第几个
  	local function getPlayer(idx)
  		for i = idx, 3 do
  			if redirect[i] ~= -1 then
  				local curR = result[redirect[i]] or {}
  				if next(curR) then
  					local curIdx = math.randomInt(1, #curR)
  					local objId = curR[curIdx]
  					table.remove(curR, curIdx)
  					return objId
  				end
  			end
  		end
  	end
  
4c5d72ab   zhouhaihai   高级pvp
295
  	local tempMatch = {}
fa565e0c   zhouhaihai   优化结构
296
297
298
299
  	local curCount = 0
  	for i = 1, 3 do
  		local objId = getPlayer(i)
  		if objId then
4c5d72ab   zhouhaihai   高级pvp
300
  			tempMatch[i] = {t = 1, id = objId}
fa565e0c   zhouhaihai   优化结构
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
  			curCount = curCount + 1
  		end
  	end
  	
  	-- 正常的玩家不够了 低一档继续
  	if curCount < 3 then
  		local level = nil
  		if globalCsv.pvp_division[findIdx - 2] then
  			level =  {globalCsv.pvp_division[findIdx - 2], globalCsv.pvp_division[findIdx - 1] - 1}
  		end
  		if level then
  			local result = getPlayers({level})[1] or {}
  			for i = #result, 1, -1 do
  				local id = tonumber(result[i])
  				if hadPlayer[id] then
  					table.remove(result, i)
  				else
  					result[i] = id
  					hadPlayer[id] = 1
  				end
  			end
  
  			if next(result) then
  				for i = curCount + 1, 3 do
  					local curIdx = math.randomInt(1, #result)
  					local objId = result[curIdx]
  					table.remove(result, curIdx)
4c5d72ab   zhouhaihai   高级pvp
328
  					tempMatch[i] = {t = 1, id = objId}
fa565e0c   zhouhaihai   优化结构
329
330
331
332
333
334
335
336
337
338
339
340
341
  					curCount = curCount + 1
  					if not next(result) then
  						break
  					end
  				end
  			end
  		end
  	end
  
  	-- 增加机器人
  	if curCount < 3 then
  		for i = curCount + 1, 3 do
  			while true do
4c5d72ab   zhouhaihai   高级pvp
342
  				local id = math.randomInt(1, #csvdb[robotCsv])
fa565e0c   zhouhaihai   优化结构
343
344
  				if not hadRobot[id] then
  					hadRobot[id] = 1
4c5d72ab   zhouhaihai   高级pvp
345
  					tempMatch[i] = {t = 2, id = id}
fa565e0c   zhouhaihai   优化结构
346
347
348
349
350
  					break
  				end
  			end
  		end
  	end
4c5d72ab   zhouhaihai   高级pvp
351
352
  	self:setProperty(mField, tempMatch)
  end
fa565e0c   zhouhaihai   优化结构
353
  
4c5d72ab   zhouhaihai   高级pvp
354
355
  function Role:refreshPvpMatchC(score)
  	self:refreshPvpMatch(score, RANK_PVP_COMMON)
fa565e0c   zhouhaihai   优化结构
356
357
  end
  
4c5d72ab   zhouhaihai   高级pvp
358
359
360
  function Role:refreshPvpMatchH(score)
  	self:refreshPvpMatch(score, RANK_PVP_HIGHT)
  end
fa565e0c   zhouhaihai   优化结构
361
  
da898074   zhouhaihai   pvp 高级领奖
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
  function Role:getPvpDBKey(ptype)
  	local dbList
  	local round
  	if ptype == RANK_PVP_COMMON then
  		dbList = RANK_PVP_COMMON_KEY
  		round = self:getTimeResetRound(TimeReset.PvpRank)
  	elseif ptype == RANK_PVP_HIGHT then
  		dbList = RANK_PVP_HIGHT_KEY
  		round = self:getTimeResetRound(TimeReset.PvpHight)
  	end
  	local idx = 1
  	if round % 2 == 1 then
  		idx = 2 
  	end
  	return dbList[idx]
  end
  
  
  
  
e3c5cc5e   zhouhaihai   跨服竞技场over
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
  
  
  --------------------   跨服竞技场相关  -----------------------
  local serverId = tonumber(skynet.getenv("servId"))
  -- 自己是否参赛  -- 更换头像 名字 队伍 需要上传
  function Role:isCrossServerPvpPlayer()
  	if not self:isTimeResetOpen(TimeReset.PvpCross) then 
  		self._isCrossServerPvpPlayer = nil
  		return false
  	end
  	if self._isCrossServerPvpPlayer == nil then
  		self:getCrossServerPvpMatchInfo()
  	end
  	return self._isCrossServerPvpPlayer
  end
  
  function Role:changeCrossServerPvpSelfInfo(cType)
  	if not self:isCrossServerPvpPlayer() then return end
  	local change = {id = self:packPvpCrossRoleId(serverId, self:getProperty("id"))}
  	if cType == "name" or cType == "level" or cType == "headId" then	
  		change[cType] = self:getProperty(cType)
  	elseif cType == "format" then
  		-- 是否过了时间
  		local crossTime = skynet.timex() - self:getTimeResetStartTime(TimeReset.PvpCross)
  		local aday = 3600 * 24
  		local day = math.ceil(crossTime / aday) -- 当前是第几个比赛日
  		local ctime = crossTime % aday -- 当前在本天 经过多少时间
  
  		if day > globalCsv.pvp_cross_server_day or ctime >= globalCsv.pvp_cross_server_stop_format then
  			return 
  		end
  		change.battleV = self:getProperty("pvpTBVH")
  		change.heros = self:getProperty("pvpTSH")
  		change.battleInfo = self:getProperty("pvpTBH")
  	end
  
  	pcall(skynet.call, pvpd, "lua", "updateRoleInfo", change)
  end
  
  -- 获取当前阵容信息
  function Role:getCrossServerPvpMatchInfo()
  	if not self:isTimeResetOpen(TimeReset.PvpCross) then return end
  	local ok, result = pcall(skynet.call, pvpd, "lua", "getMatchInfo")
  	if ok then
  		local cur = result.roleInfo and result.roleInfo[self:packPvpCrossRoleId(serverId, self:getProperty("id"))]
  		self._isCrossServerPvpPlayer = cur and true or false
  		return result
  	else
  		print(result)
  	end
  end
  
  -- 获取角色信息 简略 
  function Role:getCrossServerPvpRoleInfo()
  	if not self:isTimeResetOpen(TimeReset.PvpCross) then return end
  
  	local ok, result = pcall(skynet.call, pvpd, "lua", "getRoleInfo")
  	if ok then
  		return result
  	else
  		print(result)
  	end
  end
  
  function Role:getCrossServerPvpRoleInfoDeatil(pIds)
  	if not self:isTimeResetOpen(TimeReset.PvpCross) then return end
  
  	local ok, result = pcall(skynet.call, pvpd, "lua", "getRoleDetail", pIds)
  	if ok then
  		return result
  	else
  		print(result)
  	end
  end
  
  function Role:getCrossServerPvpMatchRecord(round, matchIdx)
  	if not self:isTimeResetOpen(TimeReset.PvpCross) then return end
  
  	local ok, result = pcall(skynet.call, pvpd, "lua", "getMatchRecord", round, matchIdx)
  	if ok then
  		return result
  	else
  		print(result)
  	end
  end
  
  function Role:getCrossServerPvpBetInfo()
  	if not self:isTimeResetOpen(TimeReset.PvpCross) then return end
  	local pvpBet = self:getProperty("pvpBet")
  	local back = {}
  
  	local ok, result = pcall(skynet.call, pvpd, "lua", "getBetInfo")
  
  	if ok then
  		if result.betInfo then
  			local maxRound = 0
  			for round, matchIdx in pairs(result.betInfo) do
  				if round > maxRound then
  					maxRound = round
  				end
  				back[round] = {
  					matchIdx = matchIdx,
  					bet = pvpBet[round]
  				}
  			end
  			if maxRound ~= 0 then
  				back[maxRound].betNum = result.betNum
  			end
  		end
  		return back
  	else
  		print(result)
  	end
  end
  
3133cb76   zhouhaihai   日志
497
  function Role:setCrossServerPvpBet(idx)
c581c6e9   zhouhaihai   pvp 优化
498
  	if not self:isTimeResetOpen(TimeReset.PvpCross) then return false , 1 end
e3c5cc5e   zhouhaihai   跨服竞技场over
499
500
501
502
503
504
  	local crossTime = skynet.timex() - self:getTimeResetStartTime(TimeReset.PvpCross)
  	local aday = 3600 * 24
  	local day = math.ceil(crossTime / aday) -- 当前是第几个比赛日
  	local ctime = crossTime % aday -- 当前在本天 经过多少时间
  
  	if day > globalCsv.pvp_cross_server_day or ctime >= globalCsv.pvp_cross_server_stop_stake then
c581c6e9   zhouhaihai   pvp 优化
505
  		return false , 2
e3c5cc5e   zhouhaihai   跨服竞技场over
506
507
  	end
  	local pvpBet = self:getProperty("pvpBet")
c581c6e9   zhouhaihai   pvp 优化
508
  	if pvpBet[day] then return false , 3 end
e3c5cc5e   zhouhaihai   跨服竞技场over
509
  
c581c6e9   zhouhaihai   pvp 优化
510
511
512
  	local costNum = self:getProperty("level") * globalCsv.pvp_cross_bet_pre_level
  	local cost = {[ItemId.Gold] = costNum}
  	if not self:checkItemEnough(cost) then return false , 4 end
e3c5cc5e   zhouhaihai   跨服竞技场over
513
  
c581c6e9   zhouhaihai   pvp 优化
514
  	local ok, result = pcall(skynet.call, pvpd, "lua", "setBet", idx, self:getProperty("id"), costNum)
e3c5cc5e   zhouhaihai   跨服竞技场over
515
516
  	if ok then
  		if result then
887c1843   zhouhaihai   日志新一批
517
  			self:costItems(cost, {log = {desc = "crossPvpBet", int1 = day}})
e3c5cc5e   zhouhaihai   跨服竞技场over
518
519
520
  			pvpBet[day] = {idx, cost[ItemId.Gold]}
  			self:setProperty("pvpBet", pvpBet)
  		end
c581c6e9   zhouhaihai   pvp 优化
521
  		return result, 5
e3c5cc5e   zhouhaihai   跨服竞技场over
522
523
  	else
  		print(result)
c581c6e9   zhouhaihai   pvp 优化
524
  		return false , 6
e3c5cc5e   zhouhaihai   跨服竞技场over
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
  	end
  end
  
  
  
  function Role:packPvpCrossRoleId(servId, roleId)
  	return roleId * 1000 + servId
  end
  
  function Role:unpackPvpCrossRoleId(tempId)
  	local servId = tempId % 1000
  	local roleId = math.floor(tempId / 1000)
  	return servId, roleId
  end
  
  -- -- 获取参赛玩家详情
  -- function Role:
  
  
  
fa565e0c   zhouhaihai   优化结构
545
546
547
548
  end
  
  
  return RolePvp