Blame view

src/models/RolePvp.lua 18.3 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分钟忽略差异
68a6dc62   zhouhaihai   匹配规则调整
9
10
11
12
13
14
  local PVP_RANK_BASE_SCORE = globalCsv.pvp_base_score -- 初始积分
  
  -- 匹配规则改为以排名来匹配
  local PVP_GET_ROBOT_SCORE = 2400 -- 2400分以下低档位匹配机器人
  local PRE_RANGE_COUNT = 20 -- 每个档位人数
  local NEED_MATCH = 3 --匹配到多少人
fa565e0c   zhouhaihai   优化结构
15
  
3dbbc9f3   zhouhaihai   加上新的任务
16
17
  
  function Role:unpackPvpScore(score)
aaf6a9e6   zhouhaihai   分数默认1000
18
19
  	if not score then return globalCsv.pvp_base_score end
  	score = tonumber(score)
fa565e0c   zhouhaihai   优化结构
20
21
22
  	return math.floor(score / PVP_RANK_TIME_SORT_PLACE)
  end
  
3dbbc9f3   zhouhaihai   加上新的任务
23
  function Role:packPvpScore(score, now)
fa565e0c   zhouhaihai   优化结构
24
25
26
27
  	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
28
29
  
  function Role:changePvpScore(rankKey, changeScoreCallback, matchId)
da898074   zhouhaihai   pvp 高级领奖
30
  	local dbKey = self:getPvpDBKey(rankKey)
fa565e0c   zhouhaihai   优化结构
31
32
33
  	local roleId = self:getProperty("id")
  	local isPlayer = matchId ~= -1
  	local redret = redisproxy:pipelining(function(red)
da898074   zhouhaihai   pvp 高级领奖
34
35
  		red:zscore(dbKey, roleId)
  		red:zrevrank(dbKey, roleId)
fa565e0c   zhouhaihai   优化结构
36
  		if isPlayer then
da898074   zhouhaihai   pvp 高级领奖
37
  			red:zscore(dbKey, matchId)
fa565e0c   zhouhaihai   优化结构
38
39
  		end
  	end)
3dbbc9f3   zhouhaihai   加上新的任务
40
  	local myScore = self:unpackPvpScore(redret[1])
4cf74232   zhouhaihai   pvp
41
  	local oldMyRank = tonumber(redret[2] or -2) + 1
53227d9c   zhouhaihai   pvp 编队胜利推送
42
  	local matchScore = PVP_RANK_BASE_SCORE
fa565e0c   zhouhaihai   优化结构
43
  	if isPlayer then
3dbbc9f3   zhouhaihai   加上新的任务
44
  		matchScore = self:unpackPvpScore(redret[3])
fa565e0c   zhouhaihai   优化结构
45
  	end
4cf74232   zhouhaihai   pvp
46
  	local oldmyScore, oldMatchScore = myScore, matchScore
fa565e0c   zhouhaihai   优化结构
47
  
4c5d72ab   zhouhaihai   高级pvp
48
  	myScore, matchScore = changeScoreCallback(myScore, matchScore)
fa565e0c   zhouhaihai   优化结构
49
50
51
52
  	myScore = math.max(myScore, 0)
  	matchScore = math.max(matchScore, 0)
  
  	local now = skynet.timex()
f5207098   zhouhaihai   bug
53
  	redret = redisproxy:pipelining(function(red)
da898074   zhouhaihai   pvp 高级领奖
54
  		red:zadd(dbKey, self:packPvpScore(myScore, now), roleId)
fa565e0c   zhouhaihai   优化结构
55
  		if isPlayer then
da898074   zhouhaihai   pvp 高级领奖
56
  			red:zadd(dbKey, self:packPvpScore(matchScore, now), matchId)
fa565e0c   zhouhaihai   优化结构
57
  		end
da898074   zhouhaihai   pvp 高级领奖
58
  		red:zrevrank(dbKey, roleId)
fa565e0c   zhouhaihai   优化结构
59
  	end)
4c5d72ab   zhouhaihai   高级pvp
60
  
4cf74232   zhouhaihai   pvp
61
62
63
64
65
66
  	local myRank
  	if isPlayer then
  		myRank = tonumber(redret[3] or -2) + 1
  	else
  		myRank = tonumber(redret[2] or -2) + 1
  	end
4c5d72ab   zhouhaihai   高级pvp
67
68
  
  	return {myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank}
fa565e0c   zhouhaihai   优化结构
69
70
  end
  
4c5d72ab   zhouhaihai   高级pvp
71
72
73
74
75
  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 编队胜利推送
76
  			matchScore = matchScore - math.ceil(scoreChange / 3) -- 防守方失败时,扣分减为原来的1/3
4c5d72ab   zhouhaihai   高级pvp
77
78
79
80
81
82
83
84
85
  		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)
68a6dc62   zhouhaihai   匹配规则调整
86
  	self:refreshPvpMatchC(result[1], result[5])
4c5d72ab   zhouhaihai   高级pvp
87
88
89
  	return table.unpack(result)
  end
  
42327de8   zhouhaihai   高级竞技场红点
90
91
92
93
94
95
96
97
98
99
100
101
102
  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 高级领奖
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  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
119
  			newReward[itemId] = math.min((newReward[itemId] or 0) + count * times, divisionData.limit)
da898074   zhouhaihai   pvp 高级领奖
120
121
122
123
124
  		end
  	end
  	return newTime, newReward
  end
  
4c5d72ab   zhouhaihai   高级pvp
125
  function Role:changePvpScoreHigh(matchId, isWin)
da898074   zhouhaihai   pvp 高级领奖
126
  	local oldMyDivision
4c5d72ab   zhouhaihai   高级pvp
127
  	local function changeScoreCallback(myScore, matchScore)
da898074   zhouhaihai   pvp 高级领奖
128
129
130
  		local myMinId = 0
  		local matchMinId = 0
  		for _id, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
4c5d72ab   zhouhaihai   高级pvp
131
  			if myScore >= division.division then
da898074   zhouhaihai   pvp 高级领奖
132
  				myMinId = _id
4c5d72ab   zhouhaihai   高级pvp
133
134
  			end
  			if matchScore >= division.division then
da898074   zhouhaihai   pvp 高级领奖
135
  				matchMinId = _id 
4c5d72ab   zhouhaihai   高级pvp
136
137
  			end
  		end
da898074   zhouhaihai   pvp 高级领奖
138
  		oldMyDivision = myMinId
4c5d72ab   zhouhaihai   高级pvp
139
140
141
  		if isWin then
  			local scoreChange = math.ceil(50 / (1 + 10 ^ ((myScore - matchScore) / 1000)))
  			myScore = myScore + scoreChange
53227d9c   zhouhaihai   pvp 编队胜利推送
142
  			matchScore = matchScore - math.ceil(scoreChange / 3) -- 防守方失败时,扣分减为原来的1/3
4c5d72ab   zhouhaihai   高级pvp
143
144
145
146
147
  		else
  			local scoreChange = math.ceil(50 / (1 + 10 ^ ((matchScore - myScore) / 1000)))
  			myScore = myScore - scoreChange
  			matchScore = matchScore + scoreChange
  		end
da898074   zhouhaihai   pvp 高级领奖
148
  		return math.max(myScore, csvdb["pvp_group_divisionCsv"][myMinId].division), math.max(matchScore, csvdb["pvp_group_divisionCsv"][matchMinId].division)
4c5d72ab   zhouhaihai   高级pvp
149
150
151
  	end
  
  	local result = self:changePvpScore(RANK_PVP_HIGHT, changeScoreCallback, matchId)
da898074   zhouhaihai   pvp 高级领奖
152
153
154
155
156
157
158
159
160
  	--{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
161
  	if newDivision ~= oldMyDivision or self:getProperty("pvpHGTime") == 0 then
da898074   zhouhaihai   pvp 高级领奖
162
163
164
165
166
167
168
169
  		--刷新段位奖励
  		local newTime, newReward = self:calculatePvpHGift(oldMyDivision)
  		self:updateProperties({
  			pvpHGTime = newTime,
  			pvpHGift = newReward,
  		})
  	end
  
68a6dc62   zhouhaihai   匹配规则调整
170
  	self:refreshPvpMatchH(result[1], result[5])
4c5d72ab   zhouhaihai   高级pvp
171
172
173
  	return table.unpack(result)
  end
  
53227d9c   zhouhaihai   pvp 编队胜利推送
174
175
176
177
178
179
180
181
182
183
184
185
186
  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
  
68a6dc62   zhouhaihai   匹配规则调整
187
188
  -- 新的匹配规则
  function Role:refreshPvpMatch(score, rank, rankKey)
4c5d72ab   zhouhaihai   高级pvp
189
190
191
192
193
194
  	local Fields = {
  		[RANK_PVP_COMMON] = "pvpMC",
  		[RANK_PVP_HIGHT] = "pvpMH",
  	}
  	local RobotCsvs = {
  		[RANK_PVP_COMMON] = "pvp_robotCsv",
68a6dc62   zhouhaihai   匹配规则调整
195
  		[RANK_PVP_HIGHT] = "pvp_robot_groupCsv",
4c5d72ab   zhouhaihai   高级pvp
196
  	}
68a6dc62   zhouhaihai   匹配规则调整
197
  
4c5d72ab   zhouhaihai   高级pvp
198
199
  	local mField = Fields[rankKey]
  	local robotCsv = RobotCsvs[rankKey]
4c5d72ab   zhouhaihai   高级pvp
200
  
68a6dc62   zhouhaihai   匹配规则调整
201
  	local dbKey = self:getPvpDBKey(rankKey)
fa565e0c   zhouhaihai   优化结构
202
  	local roleId = self:getProperty("id")
68a6dc62   zhouhaihai   匹配规则调整
203
  	if not score and not rank then
fa565e0c   zhouhaihai   优化结构
204
  		local redret = redisproxy:pipelining(function(red)
68a6dc62   zhouhaihai   匹配规则调整
205
206
  			red:zscore(dbKey, roleId)
  			red:zrevrank(dbKey, roleId)
fa565e0c   zhouhaihai   优化结构
207
  		end)
68a6dc62   zhouhaihai   匹配规则调整
208
209
  		score = self:unpackPvpScore(redret[1])
  		rank = tonumber(redret[2] or -2) + 1
fa565e0c   zhouhaihai   优化结构
210
  	end
68a6dc62   zhouhaihai   匹配规则调整
211
212
213
  	score =  score or self:unpackPvpScore(redisproxy:zscore(dbKey, roleId))
  	rank = rank or tonumber(redisproxy:zrevrank(dbKey, roleId) or -2) + 1
  	
4c5d72ab   zhouhaihai   高级pvp
214
  	local match = self:getProperty(mField)
fa565e0c   zhouhaihai   优化结构
215
216
  	local hadPlayer = {[roleId] = 1}
  	local hadRobot = {}
4c5d72ab   zhouhaihai   高级pvp
217
  	for _, one in pairs(match) do
fa565e0c   zhouhaihai   优化结构
218
219
220
221
222
223
224
  		if one.t == 1 then
  			hadPlayer[one.id] = 1
  		elseif one.t == 2 then
  			hadRobot[one.id] = 1
  		end
  	end
  
68a6dc62   zhouhaihai   匹配规则调整
225
226
227
228
229
230
231
232
233
234
  	local tempMatch = {}
  	local needRobot = 0
  	-- -1 没有上榜
  	if rank == -1 then
  		needRobot = NEED_MATCH
  	else
  		local need = PRE_RANGE_COUNT * NEED_MATCH
  		local low, heigh = math.floor(rank - need / 2 - 1), math.floor(rank + need / 2 - 1)
  		if low < 0 then
  			low = 0
fa565e0c   zhouhaihai   优化结构
235
  		end
68a6dc62   zhouhaihai   匹配规则调整
236
237
238
239
240
241
  		local rangeIds = redisproxy:ZREVRANGE(dbKey, low, heigh)
  		local lastRangeIds = {}
  		for idx, one in ipairs(rangeIds) do
  			local cid = tonumber(one)
  			if not hadPlayer[cid] then
  				lastRangeIds[#lastRangeIds + 1] = cid
fa565e0c   zhouhaihai   优化结构
242
243
  			end
  		end
68a6dc62   zhouhaihai   匹配规则调整
244
245
  		if score < PVP_GET_ROBOT_SCORE then
  			needRobot = 1
fa565e0c   zhouhaihai   优化结构
246
  		end
68a6dc62   zhouhaihai   匹配规则调整
247
248
249
  		local len = #lastRangeIds
  		if len < NEED_MATCH then
  			needRobot = NEED_MATCH - len
fa565e0c   zhouhaihai   优化结构
250
  		end
68a6dc62   zhouhaihai   匹配规则调整
251
252
253
254
255
256
  		local needPlayer = NEED_MATCH - needRobot
  		if needPlayer > 0 then
  			local pre = math.floor(len / needPlayer)
  			for i = 1, needPlayer do
  				local idx = math.randomInt((i - 1) * pre + 1, i * pre)
  				tempMatch[#tempMatch + 1] = {t = 1, id = lastRangeIds[idx]}
fa565e0c   zhouhaihai   优化结构
257
  			end
68a6dc62   zhouhaihai   匹配规则调整
258
  		end
fa565e0c   zhouhaihai   优化结构
259
  
68a6dc62   zhouhaihai   匹配规则调整
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
  	end
  	if needRobot > 0 then
  		local RobotPoolCount = 20
  		local max = #csvdb[robotCsv]
  		local min = 1
  		local mid
  		while min <= max do
  			mid = math.floor((min + max) / 2)
  			local tempPt = csvdb[robotCsv][mid].pt
  			if score == tempPt then
  				break
  			elseif score > tempPt then
  				min = mid + 1
  			elseif score < tempPt then
  				max = mid - 1
fa565e0c   zhouhaihai   优化结构
275
276
  			end
  		end
68a6dc62   zhouhaihai   匹配规则调整
277
278
279
280
281
282
283
284
285
286
287
288
289
290
  		assert(mid, "pvp no robot " .. robotCsv)
  		local low = mid - RobotPoolCount / 2
  		local heigh = mid + RobotPoolCount / 2
  		if low < 1 then
  			heigh = heigh + (1 - low)
  			low = 1
  		end
  		if heigh > #csvdb[robotCsv] then
  			heigh = #csvdb[robotCsv]
  		end
  		local pools = {}
  		for i = low, heigh do
  			if not hadRobot[i] then
  				pools[#pools + 1] = i
fa565e0c   zhouhaihai   优化结构
291
292
  			end
  		end
68a6dc62   zhouhaihai   匹配规则调整
293
294
295
296
297
  		local pre = math.floor(#pools / needRobot)
  		for i = 1, needRobot do
  			local idx = math.randomInt((i - 1) * pre + 1, i * pre)
  			tempMatch[#tempMatch + 1] = {t = 2, id = pools[idx]}
  		end
fa565e0c   zhouhaihai   优化结构
298
  	end
4c5d72ab   zhouhaihai   高级pvp
299
300
  	self:setProperty(mField, tempMatch)
  end
fa565e0c   zhouhaihai   优化结构
301
  
68a6dc62   zhouhaihai   匹配规则调整
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
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
371
372
373
374
375
376
377
378
379
380
381
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
  -- function Role:refreshPvpMatch(score, rank, 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]
  -- 	local dbKey = self:getPvpDBKey(rankKey)
  
  -- 	local roleId = self:getProperty("id")
  -- 	score =  score or self:unpackPvpScore(redisproxy:zscore(dbKey, roleId))
  
  -- 	local function getPlayers(levels)
  -- 		local redret = redisproxy:pipelining(function(red)
  -- 			for _, level in ipairs(levels) do
  -- 				local low, high = table.unpack(level)
  -- 				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")
  -- 			end
  -- 			red:zrem(dbKey, "std_temp1", "std_temp2")
  -- 		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
  -- 				red:ZREVRANGE(dbKey, rank2, rank1)
  -- 			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)
  -- 	local match = self:getProperty(mField)
  -- 	local hadPlayer = {[roleId] = 1}
  -- 	local hadRobot = {}
  -- 	for _, one in pairs(match) do
  -- 		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
  
  -- 	local tempMatch = {}
  -- 	local curCount = 0
  -- 	for i = 1, 3 do
  -- 		local objId = getPlayer(i)
  -- 		if objId then
  -- 			tempMatch[i] = {t = 1, id = objId}
  -- 			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)
  -- 					tempMatch[i] = {t = 1, id = objId}
  -- 					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
  -- 				local id = math.randomInt(1, #csvdb[robotCsv])
  -- 				if not hadRobot[id] then
  -- 					hadRobot[id] = 1
  -- 					tempMatch[i] = {t = 2, id = id}
  -- 					break
  -- 				end
  -- 			end
  -- 		end
  -- 	end
  -- 	self:setProperty(mField, tempMatch)
  -- end
  
  function Role:refreshPvpMatchC(score, rank)
  	self:refreshPvpMatch(score, rank, RANK_PVP_COMMON)
fa565e0c   zhouhaihai   优化结构
475
476
  end
  
68a6dc62   zhouhaihai   匹配规则调整
477
478
  function Role:refreshPvpMatchH(score, rank)
  	self:refreshPvpMatch(score, rank, RANK_PVP_HIGHT)
4c5d72ab   zhouhaihai   高级pvp
479
  end
fa565e0c   zhouhaihai   优化结构
480
  
da898074   zhouhaihai   pvp 高级领奖
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
  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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
  
  
  --------------------   跨服竞技场相关  -----------------------
  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
  		-- 是否过了时间
69a45034   zhouhaihai   跨服竞技场
524
  		local crossTime = skynet.timex() - self:getTimeResetStartTime(TimeReset.PvpCross) + RESET_TIME * 3600
e3c5cc5e   zhouhaihai   跨服竞技场over
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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
  		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   日志
616
  function Role:setCrossServerPvpBet(idx)
c581c6e9   zhouhaihai   pvp 优化
617
  	if not self:isTimeResetOpen(TimeReset.PvpCross) then return false , 1 end
69a45034   zhouhaihai   跨服竞技场
618
  	local crossTime = skynet.timex() - self:getTimeResetStartTime(TimeReset.PvpCross) +  RESET_TIME * 3600
e3c5cc5e   zhouhaihai   跨服竞技场over
619
620
621
622
623
  	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 优化
624
  		return false , 2
e3c5cc5e   zhouhaihai   跨服竞技场over
625
626
  	end
  	local pvpBet = self:getProperty("pvpBet")
c581c6e9   zhouhaihai   pvp 优化
627
  	if pvpBet[day] then return false , 3 end
e3c5cc5e   zhouhaihai   跨服竞技场over
628
  
c581c6e9   zhouhaihai   pvp 优化
629
630
631
  	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
632
  
c581c6e9   zhouhaihai   pvp 优化
633
  	local ok, result = pcall(skynet.call, pvpd, "lua", "setBet", idx, self:getProperty("id"), costNum)
e3c5cc5e   zhouhaihai   跨服竞技场over
634
635
  	if ok then
  		if result then
887c1843   zhouhaihai   日志新一批
636
  			self:costItems(cost, {log = {desc = "crossPvpBet", int1 = day}})
e3c5cc5e   zhouhaihai   跨服竞技场over
637
638
639
  			pvpBet[day] = {idx, cost[ItemId.Gold]}
  			self:setProperty("pvpBet", pvpBet)
  		end
c581c6e9   zhouhaihai   pvp 优化
640
  		return result, 5
e3c5cc5e   zhouhaihai   跨服竞技场over
641
642
  	else
  		print(result)
c581c6e9   zhouhaihai   pvp 优化
643
  		return false , 6
e3c5cc5e   zhouhaihai   跨服竞技场over
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
  	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   优化结构
664
665
666
667
  end
  
  
  return RolePvp