Commit da89807497f99247dab8949528a61278a7e374dd

Authored by zhouhaihai
1 parent cfd68b3a

pvp 高级领奖

src/GlobalVar.lua
1 1 XXTEA_KEY = "699D448D6D24f7F941E9F6E99F823E18"
2 2 RESET_TIME = 4
3   -RESET_RANK_TIME = 8
  3 +
  4 +START_RESET_TIME_BASE = 1584921600 -- 0时区
  5 +TIME_ZONE = math.floor(os.difftime(START_RESET_TIME_BASE, os.time(os.date("!*t", START_RESET_TIME_BASE))) / 3600) -- 本地时区
  6 +
  7 +START_RESET_TIME = START_RESET_TIME_BASE - TIME_ZONE * 3600
  8 +
  9 +
4 10 MAX_ROLE_NUM = 1000000
5 11 -- 属性枚举
6 12 AttsEnum = {
... ... @@ -98,17 +104,31 @@ ItemId = {
98 104 BreakCost = 10, -- 突破材料
99 105 EquipUp = 11, -- 装备升级材料
100 106 DinerCoin = 12, --后勤物资
101   - LoveUp = 14, --好感度提升道具
  107 + PvpCoin = 14, --挑战货币
102 108 OldCoin = 15, --古代金币
103 109 AdvPoint = 16, -- 探险点
104 110 DinerSpTask = 20, -- 餐厅任务采购券
105 111 LoveBreak = 21, --好感度突破道具
106 112 PvpKey = 22, -- pvp钥匙
107 113 LunchFragment = 23,
108   - HeroFC = {700, 701, 702, 703}, -- 通用角色碎片
  114 + HeroFC = {700, 701, 702, 703}, --通用角色碎片
109 115 AdvKey = 80, -- 冒险钥匙
110 116 BoxKey = 60, -- 拆解工具
111 117 }
  118 +
  119 +TimeReset = {
  120 + CrossDay = 1, --通用跨天
  121 + CrossWeek = 2, --通用跨周
  122 + DinerRank = 1, -- 餐厅排行榜
  123 + PvpRank = 2, -- pvp排行榜
  124 + PvpHight = 11, --高级竞技场
  125 + PvpCross = 12, -- 跨服竞技场
  126 + PvpShop = 13, -- 竞技场商城
  127 + DailyBattle1 = 14, -- 特殊-每日副本(贴纸)
  128 + DailyBattle2 = 15, -- 特殊-每日副本(装备)
  129 + DailyBattle2 = 16, -- 特殊-每日副本(时钟箱)
  130 +}
  131 +
112 132 --客户端不需要知道这个
113 133 AdvSpecialStage = {
114 134 [1]= "In",
... ...
src/ProtocolCode.lua
... ... @@ -160,6 +160,8 @@ actionCodes = {
160 160 Pvp_refreshMatchHRpc = 509,
161 161 Pvp_startBattleHRpc = 510,
162 162 Pvp_endBattleHRpc = 511,
  163 + Pvp_highDivisionGiftRpc = 512,
  164 + Pvp_shopBuyRpc = 513,
163 165  
164 166  
165 167 Store_rechargeRpc = 550,
... ...
src/RedisKeys.lua
... ... @@ -24,8 +24,10 @@ RANK_DINER = {"rank:diner1", "rank:diner2"} -- é¤åŽ…æŽ’è¡Œæ¦œ 两个æ¯å¤©äº’æ
24 24 RANK_DINER_INFO = "rank:diner:info"
25 25  
26 26 RANK_PVP_COMMON = "rank:pvpc"
  27 +RANK_PVP_COMMON_KEY = {"rank:pvpc1", "rank:pvpc2"}
27 28 RECORD_PVP_COMMON = "record:pvpc:%d"
28 29 RANK_PVP_HIGHT = "rank:pvph"
  30 +RANK_PVP_HIGHT_KEY = {"rank:pvph1", "rank:pvph2"}
29 31 RECORD_PVP_HIGH = "record:pvph:%d"
30 32  
31 33  
... ...
src/actions/HeroAction.lua
... ... @@ -245,7 +245,7 @@ function _M.commentHeroRpc(agent, data)
245 245 result.status = 1
246 246 else
247 247 local commentKey = getCommentKey(heroType)
248   - local SERV = string.format("NAMED%d", math.random(1, 5))
  248 + local SERV = string.format(".NAMED%d", math.random(1, 5))
249 249 local legal, mod = skynet.call(SERV, "lua", "check", content)
250 250 if not legal then
251 251 content = mod or ""
... ...
src/actions/HttpAction.lua
... ... @@ -43,7 +43,7 @@ function _M.reload_csvdata(query, body)
43 43 return "code error"
44 44 end
45 45  
46   - local ok, status = pcall(skynet.call, 'CSVDATA', "lua", "reload", body)
  46 + local ok, status = pcall(skynet.call, '.CSVDATA', "lua", "reload", body)
47 47 if status == "ok" then
48 48 skynet.error(string.format("reload_csvdata time: %s, code: %s", skynet.timex(), body))
49 49 return 'success'
... ... @@ -69,7 +69,7 @@ function _M.hotfix_csvdata(query, body)
69 69 if not ok or type(result) ~= 'table' then
70 70 return "decode error"
71 71 end
72   - local ok, status = pcall(skynet.call, 'CSVDATA', "lua", "hotfix", result)
  72 + local ok, status = pcall(skynet.call, '.CSVDATA', "lua", "hotfix", result)
73 73  
74 74 if status == "ok" then
75 75 skynet.error(string.format("hotfix_csvdata time: %s, code: %s", skynet.timex(), body))
... ... @@ -150,7 +150,7 @@ function _M.hotfix_code(query, body)
150 150  
151 151 skynet.error(string.format("hotfix_code time: %s, code: %s", skynet.timex(), body))
152 152  
153   - pcall(skynet.call, 'WATCHDOG', "lua", "hotfix", body)
  153 + pcall(skynet.call, '.WATCHDOG', "lua", "hotfix", body)
154 154 return 'success'
155 155 end
156 156  
... ...
src/actions/PvpAction.lua
... ... @@ -103,6 +103,7 @@ end
103 103  
104 104 local function getMatchInfo(role, pvpList, battleCache, dbKey, infoFuncName, infoCache)
105 105 table.clear(battleCache)
  106 + local dbKey = role:getPvpDBKey(dbKey)
106 107 local redret = redisproxy:pipelining(function(red)
107 108 for _, info in ipairs(pvpList) do
108 109 if info.t == 1 then
... ... @@ -125,8 +126,9 @@ local function getMatchInfo(role, pvpList, battleCache, dbKey, infoFuncName, inf
125 126 if k == "battleInfo" then
126 127 battleCache[curInfo.roleId] = v
127 128 else
128   - if k == "heros" and infoCache then
129   - infoCache[curInfo.roleId] = v
  129 + if (k == "heros" or k == "battleV") and infoCache then
  130 + infoCache[curInfo.roleId] = infoCache[curInfo.roleId] or {}
  131 + infoCache[curInfo.roleId][k] = v
130 132 end
131 133 curInfo[k] = v
132 134 end
... ... @@ -150,9 +152,10 @@ function _M.infoRpc(agent, data)
150 152  
151 153 local response = {}
152 154 if ptype == 1 then -- 普通pvp
  155 + local dbKey = role:getPvpDBKey(RANK_PVP_COMMON)
153 156 local redret = redisproxy:pipelining(function(red)
154   - red:zscore(RANK_PVP_COMMON, roleId)
155   - red:zrevrank(RANK_PVP_COMMON, roleId)
  157 + red:zscore(dbKey, roleId)
  158 + red:zrevrank(dbKey, roleId)
156 159 end)
157 160 local score = role:unpackPvpScore(redret[1])
158 161 local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp
... ... @@ -168,9 +171,11 @@ function _M.infoRpc(agent, data)
168 171 response.score = score
169 172 response.matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo")
170 173 elseif ptype == 2 then -- 高级pvp
  174 + if not role:isTimeResetOpen(TimeReset.PvpHight) then return end
  175 + local dbKey = role:getPvpDBKey(RANK_PVP_HIGHT)
171 176 local redret = redisproxy:pipelining(function(red)
172   - red:zscore(RANK_PVP_HIGHT, roleId)
173   - red:zrevrank(RANK_PVP_HIGHT, roleId)
  177 + red:zscore(dbKey, roleId)
  178 + red:zrevrank(dbKey, roleId)
174 179 end)
175 180 local score = role:unpackPvpScore(redret[1])
176 181 local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp
... ... @@ -207,6 +212,8 @@ end
207 212 function _M.refreshMatchHRpc(agent, data)
208 213 local role = agent.role
209 214 local msg = MsgPack.unpack(data)
  215 + if not role:isTimeResetOpen(TimeReset.PvpHight) then return end
  216 +
210 217 role:refreshPvpMatchH()
211 218  
212 219 local pvpMH = role:getProperty("pvpMH")
... ... @@ -397,9 +404,10 @@ function _M.startBattleHRpc(agent, data)
397 404  
398 405 local idx = msg.idx
399 406 local revenge = msg.revenge
  407 + if not role:isTimeResetOpen(TimeReset.PvpHight) then return end
400 408  
401 409 local pvpTH = role:getProperty("pvpTH")
402   - if not pvpTH.heros or not next(pvpTH.heros) then return 1 end
  410 + if not next(pvpTH) then return 1 end
403 411  
404 412 -- 检查并记录玩家队伍
405 413 local pvpTH = {}
... ... @@ -460,7 +468,7 @@ function _M.startBattleHRpc(agent, data)
460 468 if not pvpMH[idx] then return 3 end
461 469 if pvpMH[idx].t == 1 then
462 470 enemyTeamRecord = _pvpBattleInfoCacheH[pvpMH[idx].id]
463   - enemyT = _pvpHeroInfoCacheH[temp.id]
  471 + enemyT = _pvpHeroInfoCacheH[pvpMH[idx].id]
464 472 elseif pvpMH[idx].t == 2 then
465 473 enemyTeamRecord = {robot = pvpMH[idx].id}
466 474 end
... ... @@ -581,7 +589,7 @@ function _M.endBattleHRpc(agent, data)
581 589 local round = #_pvpStartBattleCacheH.result + 1
582 590 local matchInfo = nil
583 591 if _pvpStartBattleCacheH.enemyTB.robot then
584   - matchInfo = _pvpStartBattleCacheH.enemyTB.robot
  592 + matchInfo = _pvpStartBattleCacheH.enemyTB
585 593 else
586 594 matchInfo = _pvpStartBattleCacheH.enemyTB[round]
587 595 end
... ... @@ -597,10 +605,12 @@ function _M.endBattleHRpc(agent, data)
597 605 end
598 606  
599 607 -- 战斗结束了发奖
600   - local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpBonus, true)
  608 + local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpgroupBonus, true)
601 609 local reward = role:award({[temp[1]] = temp[2]})
602   - local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = role:changePvpScoreHigh(match.t == 1 and match.id or -1, isWin)
603   -
  610 + local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = 0, 0, 0, 0, 0, 0
  611 + if role:isTimeResetOpen(TimeReset.PvpHight) then
  612 + myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = role:changePvpScoreHigh(match.t == 1 and match.id or -1, isWin)
  613 + end
604 614  
605 615 -- 加入战斗记录
606 616 local selfTeam = {}
... ... @@ -608,7 +618,10 @@ function _M.endBattleHRpc(agent, data)
608 618 for _idx, info in ipairs(_pvpStartBattleCacheH.result) do
609 619 info.winId = info.isWin and roleId or match.id
610 620 info.isWin = nil
611   - selfTeam[_idx] = role:getTeamHerosInfo(_pvpStartBattleCacheH.pvpTH[_idx].heros)
  621 + selfTeam[_idx] = {
  622 + heros = role:getTeamHerosInfo(_pvpStartBattleCacheH.pvpTH[_idx].heros),
  623 + battleV = role:getTeamBattleValue(_pvpStartBattleCacheH.pvpTH[_idx].heros)
  624 + }
612 625 if match.t == 1 and _pvpStartBattleCacheH.enemyT then
613 626 enemyTeam[_idx] = _pvpStartBattleCacheH.enemyT[_idx]
614 627 end
... ... @@ -681,10 +694,11 @@ function _M.rankListRpc(agent, data)
681 694  
682 695 local response = {}
683 696 if ptype == 1 then -- 普通pvp
  697 + local dbKey = role:getPvpDBKey(RANK_PVP_COMMON)
684 698 local redret = redisproxy:pipelining(function(red)
685   - red:zscore(RANK_PVP_COMMON, roleId)
686   - red:zrevrank(RANK_PVP_COMMON, roleId)
687   - red:zrevrange(RANK_PVP_COMMON, 0, 99, "WITHSCORES")
  699 + red:zscore(dbKey, roleId)
  700 + red:zrevrank(dbKey, roleId)
  701 + red:zrevrange(dbKey, 0, 99, "WITHSCORES")
688 702 end)
689 703 local score = role:unpackPvpScore(redret[1])
690 704 local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp
... ... @@ -703,10 +717,11 @@ function _M.rankListRpc(agent, data)
703 717 response.rankList = rankList
704 718  
705 719 elseif ptype == 2 then -- 高级pvp
  720 + local dbKey = role:getPvpDBKey(RANK_PVP_HIGHT)
706 721 local redret = redisproxy:pipelining(function(red)
707   - red:zscore(RANK_PVP_HIGHT, roleId)
708   - red:zrevrank(RANK_PVP_HIGHT, roleId)
709   - red:zrevrange(RANK_PVP_HIGHT, 0, 99, "WITHSCORES")
  722 + red:zscore(dbKey, roleId)
  723 + red:zrevrank(dbKey, roleId)
  724 + red:zrevrange(dbKey, 0, 99, "WITHSCORES")
710 725 end)
711 726 local score = role:unpackPvpScore(redret[1])
712 727 local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp
... ... @@ -714,7 +729,7 @@ function _M.rankListRpc(agent, data)
714 729 for i = 1, #redret[3], 2 do
715 730 local roleId = tonumber(redret[3][i])
716 731 local score = role:unpackPvpScore(redret[3][i + 1])
717   - local online, curInfo = rpcRole(roleId, "friendSInfo")
  732 + local online, curInfo = rpcRole(roleId, "pvpHRankInfo")
718 733 curInfo.score = score
719 734 curInfo.roleId = roleId
720 735 table.insert(rankList, curInfo)
... ... @@ -784,4 +799,69 @@ function _M.recordListRpc(agent, data)
784 799 return true
785 800 end
786 801  
  802 +function _M.highDivisionGiftRpc(agent, data)
  803 + local role = agent.role
  804 + local roleId = role:getProperty("id")
  805 +
  806 + local pvpHGTime = self:getProperty("pvpHGTime")
  807 + if pvpHGTime == 0 then return end
  808 + local score = role:unpackPvpScore(redisproxy:zscore(role:getPvpDBKey(RANK_PVP_HIGHT), roleId))
  809 +
  810 + local divisionId = nil
  811 + for _id, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
  812 + if score >= division.division then
  813 + divisionId = _id
  814 + else
  815 + break
  816 + end
  817 + end
  818 +
  819 + local newTime, newReward = role:calculatePvpHGift(divisionId)
  820 + if not next(newReward) then return end
  821 +
  822 + self:updateProperties({
  823 + pvpHGTime = newTime,
  824 + pvpHGift = {},
  825 + })
  826 +
  827 + local reward = role:award(newReward)
  828 +
  829 + SendPacket(actionCodes.Pvp_highDivisionGiftRpc, MsgPack.pack({reward = reward}))
  830 + return true
  831 +end
  832 +
  833 +function _M.shopBuyRpc(agent, data)
  834 + local role = agent.role
  835 + local roleId = role:getProperty("id")
  836 +
  837 + local msg = MsgPack.unpack(data)
  838 + local id = msg.id
  839 + local count = msg.count or 1
  840 +
  841 + local csvData = csvdb["shop_pvpCsv"][id]
  842 + if not csvData then return end
  843 +
  844 + local pvpShop = role:getProperty("pvpShop")
  845 + if csvData.limit > 0 then
  846 + if math.illegalNum(count, 1, csvData.limit - (pvpShop[id] or 0)) then return end
  847 + end
  848 +
  849 + if not role:checkItemEnough({[ItemId.PvpCoin] = csvData.cost * count}) then return end
  850 +
  851 + role:costItems({[ItemId.PvpCoin] = csvData.cost * count})
  852 + if csvData.limit > 0 then
  853 + role:changeUpdates({{type = "pvpShop", field = id, value = (pvpShop[id] or 0) + count}})
  854 + end
  855 +
  856 + local gift = csvData.gift:toNumMap()
  857 + for id, c in pairs(gift) do
  858 + gift[id] = c * count
  859 + end
  860 + local reward = role:award(gift)
  861 +
  862 +
  863 + SendPacket(actionCodes.Pvp_shopBuyRpc, MsgPack.pack({reward = reward}))
  864 + return true
  865 +end
  866 +
787 867 return _M
788 868 \ No newline at end of file
... ...
src/actions/RoleAction.lua
... ... @@ -22,7 +22,7 @@ local function validName(name)
22 22 local exist = redisproxy:exists(string_format("user:%s", name))
23 23 if exist then return "existed" end
24 24  
25   - local SERV = string_format("NAMED%d", math.random(1, 5))
  25 + local SERV = string_format(".NAMED%d", math.random(1, 5))
26 26 local legal = skynet.call(SERV, "lua", "check", name)
27 27 return legal and "ok" or "illegal"
28 28 end
... ... @@ -119,8 +119,7 @@ function _M.loginRpc( agent, data )
119 119 role:advEndlessSeasonCheck(true) -- 冒险赛季更新检查
120 120  
121 121 -- 跨天登陆事件
122   - role:onCrossDay(now)
123   - role:onResetRank(now)
  122 + role:updateTimeReset(now)
124 123 role:setProperty("ltime", now)
125 124 redisproxy:zadd(FRIEND_RECOMMEND, now, roleId)
126 125  
... ... @@ -217,7 +216,7 @@ function _M.loginRpc( agent, data )
217 216  
218 217 -- 发下缓存的世界消息
219 218 local worldChatResponse = {worldChats = {}}
220   - local ok, msgs = pcall(skynet.call, 'GLOBALD', "lua", "getWorldMsg", role._channelIdx)
  219 + local ok, msgs = pcall(skynet.call, '.GLOBALD', "lua", "getWorldMsg", role._channelIdx)
221 220 if not ok then
222 221 msgs = {}
223 222 end
... ... @@ -246,7 +245,7 @@ function _M.loginRpc( agent, data )
246 245 role:saveHangTeam()
247 246 role:savePvpCTeam()
248 247  
249   - role:log("login", {ip = agent.ip})
  248 + role:log("login", {key1 = agent.ip:toArray(false, ":")[1]})
250 249  
251 250 return true
252 251 end
... ... @@ -297,7 +296,7 @@ function _M.createRpc(agent, data)
297 296 -- 欢迎邮件
298 297 redisproxy:insertEmail({roleId = roleId, emailId = 1})
299 298  
300   - newRole:log("create", { ip = agent.ip})
  299 + newRole:log("create", {key1 = agent.ip:toArray(false, ":")[1]})
301 300  
302 301 SendPacket(actionCodes.Role_createRpc, MsgPack.pack(response))
303 302 return true
... ... @@ -357,7 +356,7 @@ function _M.changeIntroRpc(agent, data)
357 356 local content = msg.content
358 357 if not content or type(content) ~= "string" then return end
359 358  
360   - local SERV = string_format("CHATED%d", math.random(1, 5))
  359 + local SERV = string_format(".CHATED%d", math.random(1, 5))
361 360 local legal, mod = skynet.call(SERV, "lua", "check", content)
362 361 if not legal then
363 362 content = mod or ""
... ... @@ -472,9 +471,8 @@ function _M.openTimeBoxRpc(agent, data)
472 471 local boxId = boxL[slot].id
473 472 local itemData = csvdb["itemCsv"][boxId]
474 473 local randomData = csvdb["item_randomCsv"][itemData.id]
475   - reward = randomData.gift:toNumMap() -- 固定奖励
476 474 -- 随机奖励
477   - local reward = {}
  475 + reward = {}
478 476 for i = 1, 10 do
479 477 local num = randomData["num" .. i]
480 478 local gift = randomData["gift" .. i]
... ... @@ -743,7 +741,7 @@ function _M.chatRpc(agent, data)
743 741 -- 判断禁言
744 742 local result = nil
745 743  
746   - local SERV = string_format("CHATED%d", math.random(1, 5))
  744 + local SERV = string_format(".CHATED%d", math.random(1, 5))
747 745 local legal, mod = skynet.call(SERV, "lua", "check", content)
748 746 if not legal then
749 747 content = mod or ""
... ... @@ -798,7 +796,7 @@ function _M.chatRpc(agent, data)
798 796 end
799 797 end
800 798 mcast_util.pub_world(actionCodes.Role_chat, MsgPack.pack(response))
801   - pcall(skynet.send, 'GLOBALD', "lua", "sendWorldMsg", role._channelIdx, response)
  799 + pcall(skynet.send, '.GLOBALD', "lua", "sendWorldMsg", role._channelIdx, response)
802 800 end,
803 801 -- 私聊
804 802 [2] = function ()
... ...
src/agent.lua
... ... @@ -5,7 +5,6 @@ require "GlobalVar"
5 5 require "RedisKeys"
6 6 require "skynet.manager"
7 7  
8   -local harbor = require "skynet.harbor"
9 8 local queue = require "skynet.queue"
10 9 local netpack = require "skynet.netpack"
11 10 local socket = require "skynet.socket"
... ... @@ -115,7 +114,11 @@ function rpcRole(roleId, funcName, ...)
115 114 end
116 115 else
117 116 local roleCross = require("models.RoleCross")
118   - return false, roleCross.handle(funcName, roleId, ...)
  117 + if funcName == "getProperties" then
  118 + return false, roleCross.handle(funcName, roleId, fields)
  119 + else
  120 + return false, roleCross.handle(funcName, roleId, ...)
  121 + end
119 122 end
120 123 end
121 124  
... ... @@ -236,13 +239,12 @@ function CMD.close()
236 239 mcast_util.usub_union()
237 240 local role = agentInfo.role
238 241 if not role then return end
239   - role:log("logout", {online = skynet.timex()-role:getProperty("ltime")})
  242 + role:log("logout", {int1 = skynet.timex()-role:getProperty("ltime")})
240 243 role:onOfflineEvent()
241 244 end
242 245  
243 246 function CMD.exit()
244 247 if agentInfo.role then
245   - -- role:log("logout", {online = skynet.timex()-role:getProperty("ltime")})
246 248 datacenter.set("agent", agentInfo.role:getProperty("id"), nil)
247 249 end
248 250 skynet.exit()
... ... @@ -298,9 +300,9 @@ skynet.start(function()
298 300 end
299 301 end)
300 302  
301   - redisd = harbor.queryname("REDIS")
  303 + redisd = skynet.localname(".REDIS")
302 304 if tonumber(skynet.getenv "logd") == 1 then
303   - logd = harbor.queryname("LOGD")
  305 + logd = skynet.localname(".LOGD")
304 306 end
305 307  
306 308 cs = queue()
... ...
src/models/RolePvp.lua
... ... @@ -22,13 +22,14 @@ end
22 22  
23 23  
24 24 function Role:changePvpScore(rankKey, changeScoreCallback, matchId)
  25 + local dbKey = self:getPvpDBKey(rankKey)
25 26 local roleId = self:getProperty("id")
26 27 local isPlayer = matchId ~= -1
27 28 local redret = redisproxy:pipelining(function(red)
28   - red:zscore(rankKey, roleId)
29   - red:zrevrank(rankKey, roleId)
  29 + red:zscore(dbKey, roleId)
  30 + red:zrevrank(dbKey, roleId)
30 31 if isPlayer then
31   - red:zscore(rankKey, matchId)
  32 + red:zscore(dbKey, matchId)
32 33 end
33 34 end)
34 35 local myScore = self:unpackPvpScore(redret[1])
... ... @@ -45,11 +46,11 @@ function Role:changePvpScore(rankKey, changeScoreCallback, matchId)
45 46  
46 47 local now = skynet.timex()
47 48 redret = redisproxy:pipelining(function(red)
48   - red:zadd(rankKey, self:packPvpScore(myScore, now), roleId)
  49 + red:zadd(dbKey, self:packPvpScore(myScore, now), roleId)
49 50 if isPlayer then
50   - red:zadd(rankKey, self:packPvpScore(matchScore, now), matchId)
  51 + red:zadd(dbKey, self:packPvpScore(matchScore, now), matchId)
51 52 end
52   - red:zrevrank(rankKey, roleId)
  53 + red:zrevrank(dbKey, roleId)
53 54 end)
54 55  
55 56 local myRank
... ... @@ -81,18 +82,42 @@ function Role:changePvpScoreCommon(matchId, isWin)
81 82 return table.unpack(result)
82 83 end
83 84  
  85 +function Role:calculatePvpHGift(division)
  86 + local now = skynet.timex()
  87 + local oldTime = self:getProperty("pvpHGTime")
  88 + local oldReward = self:getProperty("pvpHGift")
  89 +
  90 + local newTime = oldTime
  91 + local newReward = clone(oldReward)
  92 +
  93 + local divisionData = csvdb["pvp_group_divisionCsv"][division]
  94 + if oldTime == 0 then
  95 + newTime = now
  96 + else
  97 + local times = math.floor((now - oldTime) / globalCsv.pvp_high_reward_add_pre)
  98 + newTime = oldTime + times * globalCsv.pvp_high_reward_add_pre
  99 +
  100 + for itemId, count in pairs(divisionData.reward:toNumMap()) do
  101 + newReward[itemId] = math.min((newReward[itemId] or 0) + count, divisionData.limit)
  102 + end
  103 + end
  104 + return newTime, newReward
  105 +end
  106 +
84 107 function Role:changePvpScoreHigh(matchId, isWin)
  108 + local oldMyDivision
85 109 local function changeScoreCallback(myScore, matchScore)
86   - local myMinScore = 0
87   - local matchMinScore = 0
88   - for _, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
  110 + local myMinId = 0
  111 + local matchMinId = 0
  112 + for _id, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
89 113 if myScore >= division.division then
90   - myMinScore = division.division
  114 + myMinId = _id
91 115 end
92 116 if matchScore >= division.division then
93   - matchMinScore = division.division
  117 + matchMinId = _id
94 118 end
95 119 end
  120 + oldMyDivision = myMinId
96 121 if isWin then
97 122 local scoreChange = math.ceil(50 / (1 + 10 ^ ((myScore - matchScore) / 1000)))
98 123 myScore = myScore + scoreChange
... ... @@ -102,10 +127,28 @@ function Role:changePvpScoreHigh(matchId, isWin)
102 127 myScore = myScore - scoreChange
103 128 matchScore = matchScore + scoreChange
104 129 end
105   - return math.max(myScore, myMinScore), math.max(matchScore, matchMinScore)
  130 + return math.max(myScore, csvdb["pvp_group_divisionCsv"][myMinId].division), math.max(matchScore, csvdb["pvp_group_divisionCsv"][matchMinId].division)
106 131 end
107 132  
108 133 local result = self:changePvpScore(RANK_PVP_HIGHT, changeScoreCallback, matchId)
  134 + --{myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank}
  135 + local newDivision = nil
  136 + for _id, division in ipairs(csvdb["pvp_group_divisionCsv"]) do
  137 + if result[1] >= division.division then
  138 + newDivision = _id
  139 + else
  140 + break
  141 + end
  142 + end
  143 + if newDivision ~= oldMyDivision then
  144 + --刷新段位奖励
  145 + local newTime, newReward = self:calculatePvpHGift(oldMyDivision)
  146 + self:updateProperties({
  147 + pvpHGTime = newTime,
  148 + pvpHGift = newReward,
  149 + })
  150 + end
  151 +
109 152 self:refreshPvpMatchH(result[1])
110 153 return table.unpack(result)
111 154 end
... ... @@ -122,20 +165,21 @@ function Role:refreshPvpMatch(score, rankKey)
122 165 }
123 166 local mField = Fields[rankKey]
124 167 local robotCsv = RobotCsvs[rankKey]
  168 + local dbKey = self:getPvpDBKey(rankKey)
125 169  
126 170 local roleId = self:getProperty("id")
127   - score = score or self:unpackPvpScore(redisproxy:zscore(rankKey, roleId))
  171 + score = score or self:unpackPvpScore(redisproxy:zscore(dbKey, roleId))
128 172  
129 173 local function getPlayers(levels)
130 174 local redret = redisproxy:pipelining(function(red)
131 175 for _, level in ipairs(levels) do
132 176 local low, high = table.unpack(level)
133   - red:zadd(rankKey, low * PVP_RANK_TIME_SORT_PLACE, "std_temp1")
134   - red:zadd(rankKey, high * PVP_RANK_TIME_SORT_PLACE + PVP_RANK_TIME_SORT_PLACE - 1, "std_temp2")
135   - red:ZREVRANK(rankKey, "std_temp1")
136   - red:ZREVRANK(rankKey, "std_temp2")
  177 + red:zadd(dbKey, low * PVP_RANK_TIME_SORT_PLACE, "std_temp1")
  178 + red:zadd(dbKey, high * PVP_RANK_TIME_SORT_PLACE + PVP_RANK_TIME_SORT_PLACE - 1, "std_temp2")
  179 + red:ZREVRANK(dbKey, "std_temp1")
  180 + red:ZREVRANK(dbKey, "std_temp2")
137 181 end
138   - red:zrem(rankKey, "std_temp1", "std_temp2")
  182 + red:zrem(dbKey, "std_temp1", "std_temp2")
139 183 end)
140 184  
141 185 local PreGetCount = 7
... ... @@ -147,7 +191,7 @@ function Role:refreshPvpMatch(score, rankKey)
147 191 rank2 = math.randomInt(rank2, rank1 - PreGetCount + 1)
148 192 rank1 = rank2 + PreGetCount - 1
149 193 end
150   - red:ZREVRANGE(rankKey, rank2, rank1)
  194 + red:ZREVRANGE(dbKey, rank2, rank1)
151 195 end
152 196 end)
153 197 return redret
... ... @@ -288,6 +332,26 @@ function Role:refreshPvpMatchH(score)
288 332 self:refreshPvpMatch(score, RANK_PVP_HIGHT)
289 333 end
290 334  
  335 +function Role:getPvpDBKey(ptype)
  336 + local dbList
  337 + local round
  338 + if ptype == RANK_PVP_COMMON then
  339 + dbList = RANK_PVP_COMMON_KEY
  340 + round = self:getTimeResetRound(TimeReset.PvpRank)
  341 + elseif ptype == RANK_PVP_HIGHT then
  342 + dbList = RANK_PVP_HIGHT_KEY
  343 + round = self:getTimeResetRound(TimeReset.PvpHight)
  344 + end
  345 + local idx = 1
  346 + if round % 2 == 1 then
  347 + idx = 2
  348 + end
  349 + return dbList[idx]
  350 +end
  351 +
  352 +
  353 +
  354 +
291 355 end
292 356  
293 357  
... ...