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分钟忽略差异
|
b115474f
zhouhaihai
默认积分 1000
|
9
|
local PVP_RANK_ROBOT_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)
|
fa565e0c
zhouhaihai
优化结构
|
25
26
27
|
local roleId = self:getProperty("id")
local isPlayer = matchId ~= -1
local redret = redisproxy:pipelining(function(red)
|
4c5d72ab
zhouhaihai
高级pvp
|
28
29
|
red:zscore(rankKey, roleId)
red:zrevrank(rankKey, roleId)
|
fa565e0c
zhouhaihai
优化结构
|
30
|
if isPlayer then
|
4c5d72ab
zhouhaihai
高级pvp
|
31
|
red:zscore(rankKey, matchId)
|
fa565e0c
zhouhaihai
优化结构
|
32
33
|
end
end)
|
3dbbc9f3
zhouhaihai
加上新的任务
|
34
|
local myScore = self:unpackPvpScore(redret[1])
|
4cf74232
zhouhaihai
pvp
|
35
|
local oldMyRank = tonumber(redret[2] or -2) + 1
|
fa565e0c
zhouhaihai
优化结构
|
36
37
|
local matchScore = PVP_RANK_ROBOT_SCORE
if isPlayer then
|
3dbbc9f3
zhouhaihai
加上新的任务
|
38
|
matchScore = self:unpackPvpScore(redret[3])
|
fa565e0c
zhouhaihai
优化结构
|
39
|
end
|
4cf74232
zhouhaihai
pvp
|
40
|
local oldmyScore, oldMatchScore = myScore, matchScore
|
fa565e0c
zhouhaihai
优化结构
|
41
|
|
4c5d72ab
zhouhaihai
高级pvp
|
42
|
myScore, matchScore = changeScoreCallback(myScore, matchScore)
|
fa565e0c
zhouhaihai
优化结构
|
43
44
45
46
|
myScore = math.max(myScore, 0)
matchScore = math.max(matchScore, 0)
local now = skynet.timex()
|
f5207098
zhouhaihai
bug
|
47
|
redret = redisproxy:pipelining(function(red)
|
4c5d72ab
zhouhaihai
高级pvp
|
48
|
red:zadd(rankKey, self:packPvpScore(myScore, now), roleId)
|
fa565e0c
zhouhaihai
优化结构
|
49
|
if isPlayer then
|
4c5d72ab
zhouhaihai
高级pvp
|
50
|
red:zadd(rankKey, self:packPvpScore(matchScore, now), matchId)
|
fa565e0c
zhouhaihai
优化结构
|
51
|
end
|
4c5d72ab
zhouhaihai
高级pvp
|
52
|
red:zrevrank(rankKey, roleId)
|
fa565e0c
zhouhaihai
优化结构
|
53
|
end)
|
4c5d72ab
zhouhaihai
高级pvp
|
54
|
|
4cf74232
zhouhaihai
pvp
|
55
56
57
58
59
60
|
local myRank
if isPlayer then
myRank = tonumber(redret[3] or -2) + 1
else
myRank = tonumber(redret[2] or -2) + 1
end
|
4c5d72ab
zhouhaihai
高级pvp
|
61
62
|
return {myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank}
|
fa565e0c
zhouhaihai
优化结构
|
63
64
|
end
|
4c5d72ab
zhouhaihai
高级pvp
|
65
66
67
68
69
70
71
72
73
74
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
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
matchScore = matchScore - scoreChange
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
function Role:changePvpScoreHigh(matchId, isWin)
local function changeScoreCallback(myScore, matchScore)
local myMinScore = 0
local matchMinScore = 0
for _, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
if myScore >= division.division then
myMinScore = division.division
end
if matchScore >= division.division then
matchMinScore = division.division
end
end
if isWin then
local scoreChange = math.ceil(50 / (1 + 10 ^ ((myScore - matchScore) / 1000)))
myScore = myScore + scoreChange
matchScore = matchScore - scoreChange
else
local scoreChange = math.ceil(50 / (1 + 10 ^ ((matchScore - myScore) / 1000)))
myScore = myScore - scoreChange
matchScore = matchScore + scoreChange
end
return math.max(myScore, myMinScore), math.max(matchScore, matchMinScore)
end
local result = self:changePvpScore(RANK_PVP_HIGHT, changeScoreCallback, matchId)
self:refreshPvpMatchH(result[1])
return table.unpack(result)
end
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]
|
fa565e0c
zhouhaihai
优化结构
|
126
|
local roleId = self:getProperty("id")
|
4c5d72ab
zhouhaihai
高级pvp
|
127
128
|
score = score or self:unpackPvpScore(redisproxy:zscore(rankKey, roleId))
|
fa565e0c
zhouhaihai
优化结构
|
129
130
131
132
|
local function getPlayers(levels)
local redret = redisproxy:pipelining(function(red)
for _, level in ipairs(levels) do
local low, high = table.unpack(level)
|
4c5d72ab
zhouhaihai
高级pvp
|
133
134
135
136
|
red:zadd(rankKey, low * PVP_RANK_TIME_SORT_PLACE, "std_temp1")
red:zadd(rankKey, high * PVP_RANK_TIME_SORT_PLACE + PVP_RANK_TIME_SORT_PLACE - 1, "std_temp2")
red:ZREVRANK(rankKey, "std_temp1")
red:ZREVRANK(rankKey, "std_temp2")
|
fa565e0c
zhouhaihai
优化结构
|
137
|
end
|
4c5d72ab
zhouhaihai
高级pvp
|
138
|
red:zrem(rankKey, "std_temp1", "std_temp2")
|
fa565e0c
zhouhaihai
优化结构
|
139
140
141
142
143
144
145
146
147
148
149
|
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
|
4c5d72ab
zhouhaihai
高级pvp
|
150
|
red:ZREVRANGE(rankKey, rank2, rank1)
|
fa565e0c
zhouhaihai
优化结构
|
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
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
|
187
|
local match = self:getProperty(mField)
|
fa565e0c
zhouhaihai
优化结构
|
188
189
|
local hadPlayer = {[roleId] = 1}
local hadRobot = {}
|
4c5d72ab
zhouhaihai
高级pvp
|
190
|
for _, one in pairs(match) do
|
fa565e0c
zhouhaihai
优化结构
|
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
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
|
224
|
local tempMatch = {}
|
fa565e0c
zhouhaihai
优化结构
|
225
226
227
228
|
local curCount = 0
for i = 1, 3 do
local objId = getPlayer(i)
if objId then
|
4c5d72ab
zhouhaihai
高级pvp
|
229
|
tempMatch[i] = {t = 1, id = objId}
|
fa565e0c
zhouhaihai
优化结构
|
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
|
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
|
257
|
tempMatch[i] = {t = 1, id = objId}
|
fa565e0c
zhouhaihai
优化结构
|
258
259
260
261
262
263
264
265
266
267
268
269
270
|
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
|
271
|
local id = math.randomInt(1, #csvdb[robotCsv])
|
fa565e0c
zhouhaihai
优化结构
|
272
273
|
if not hadRobot[id] then
hadRobot[id] = 1
|
4c5d72ab
zhouhaihai
高级pvp
|
274
|
tempMatch[i] = {t = 2, id = id}
|
fa565e0c
zhouhaihai
优化结构
|
275
276
277
278
279
|
break
end
end
end
end
|
4c5d72ab
zhouhaihai
高级pvp
|
280
281
|
self:setProperty(mField, tempMatch)
end
|
fa565e0c
zhouhaihai
优化结构
|
282
|
|
4c5d72ab
zhouhaihai
高级pvp
|
283
284
|
function Role:refreshPvpMatchC(score)
self:refreshPvpMatch(score, RANK_PVP_COMMON)
|
fa565e0c
zhouhaihai
优化结构
|
285
286
|
end
|
4c5d72ab
zhouhaihai
高级pvp
|
287
288
289
|
function Role:refreshPvpMatchH(score)
self:refreshPvpMatch(score, RANK_PVP_HIGHT)
end
|
fa565e0c
zhouhaihai
优化结构
|
290
291
292
293
294
|
end
return RolePvp
|