From da89807497f99247dab8949528a61278a7e374dd Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Fri, 27 Mar 2020 17:13:31 +0800 Subject: [PATCH] pvp 高级领奖 --- src/GlobalVar.lua | 26 +++++++++++++++++++++++--- src/ProtocolCode.lua | 2 ++ src/RedisKeys.lua | 2 ++ src/actions/HeroAction.lua | 2 +- src/actions/HttpAction.lua | 6 +++--- src/actions/PvpAction.lua | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- src/actions/RoleAction.lua | 20 +++++++++----------- src/agent.lua | 14 ++++++++------ src/models/RolePvp.lua | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------- 9 files changed, 231 insertions(+), 63 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index f5fe51c..ab5ba46 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -1,6 +1,12 @@ XXTEA_KEY = "699D448D6D24f7F941E9F6E99F823E18" RESET_TIME = 4 -RESET_RANK_TIME = 8 + +START_RESET_TIME_BASE = 1584921600 -- 0时区 +TIME_ZONE = math.floor(os.difftime(START_RESET_TIME_BASE, os.time(os.date("!*t", START_RESET_TIME_BASE))) / 3600) -- 本地时区 + +START_RESET_TIME = START_RESET_TIME_BASE - TIME_ZONE * 3600 + + MAX_ROLE_NUM = 1000000 -- 属性枚举 AttsEnum = { @@ -98,17 +104,31 @@ ItemId = { BreakCost = 10, -- 突破材料 EquipUp = 11, -- 装备升级材料 DinerCoin = 12, --后勤物资 - LoveUp = 14, --好感度提升道具 + PvpCoin = 14, --挑战货币 OldCoin = 15, --古代金币 AdvPoint = 16, -- 探险点 DinerSpTask = 20, -- 餐厅任务采购券 LoveBreak = 21, --好感度突破道具 PvpKey = 22, -- pvp钥匙 LunchFragment = 23, - HeroFC = {700, 701, 702, 703}, -- 通用角色碎片 + HeroFC = {700, 701, 702, 703}, --通用角色碎片 AdvKey = 80, -- 冒险钥匙 BoxKey = 60, -- 拆解工具 } + +TimeReset = { + CrossDay = 1, --通用跨天 + CrossWeek = 2, --通用跨周 + DinerRank = 1, -- 餐厅排行榜 + PvpRank = 2, -- pvp排行榜 + PvpHight = 11, --高级竞技场 + PvpCross = 12, -- 跨服竞技场 + PvpShop = 13, -- 竞技场商城 + DailyBattle1 = 14, -- 特殊-每日副本(贴纸) + DailyBattle2 = 15, -- 特殊-每日副本(装备) + DailyBattle2 = 16, -- 特殊-每日副本(时钟箱) +} + --客户端不需要知道这个 AdvSpecialStage = { [1]= "In", diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 933358d..a90171b 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -160,6 +160,8 @@ actionCodes = { Pvp_refreshMatchHRpc = 509, Pvp_startBattleHRpc = 510, Pvp_endBattleHRpc = 511, + Pvp_highDivisionGiftRpc = 512, + Pvp_shopBuyRpc = 513, Store_rechargeRpc = 550, diff --git a/src/RedisKeys.lua b/src/RedisKeys.lua index 8137130..ed97eaf 100644 --- a/src/RedisKeys.lua +++ b/src/RedisKeys.lua @@ -24,8 +24,10 @@ RANK_DINER = {"rank:diner1", "rank:diner2"} -- 餐厅排行榜 两个每天互 RANK_DINER_INFO = "rank:diner:info" RANK_PVP_COMMON = "rank:pvpc" +RANK_PVP_COMMON_KEY = {"rank:pvpc1", "rank:pvpc2"} RECORD_PVP_COMMON = "record:pvpc:%d" RANK_PVP_HIGHT = "rank:pvph" +RANK_PVP_HIGHT_KEY = {"rank:pvph1", "rank:pvph2"} RECORD_PVP_HIGH = "record:pvph:%d" diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index a1a1d16..ea685e6 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -245,7 +245,7 @@ function _M.commentHeroRpc(agent, data) result.status = 1 else local commentKey = getCommentKey(heroType) - local SERV = string.format("NAMED%d", math.random(1, 5)) + local SERV = string.format(".NAMED%d", math.random(1, 5)) local legal, mod = skynet.call(SERV, "lua", "check", content) if not legal then content = mod or "" diff --git a/src/actions/HttpAction.lua b/src/actions/HttpAction.lua index 2a33f4a..9941434 100644 --- a/src/actions/HttpAction.lua +++ b/src/actions/HttpAction.lua @@ -43,7 +43,7 @@ function _M.reload_csvdata(query, body) return "code error" end - local ok, status = pcall(skynet.call, 'CSVDATA', "lua", "reload", body) + local ok, status = pcall(skynet.call, '.CSVDATA', "lua", "reload", body) if status == "ok" then skynet.error(string.format("reload_csvdata time: %s, code: %s", skynet.timex(), body)) return 'success' @@ -69,7 +69,7 @@ function _M.hotfix_csvdata(query, body) if not ok or type(result) ~= 'table' then return "decode error" end - local ok, status = pcall(skynet.call, 'CSVDATA', "lua", "hotfix", result) + local ok, status = pcall(skynet.call, '.CSVDATA', "lua", "hotfix", result) if status == "ok" then skynet.error(string.format("hotfix_csvdata time: %s, code: %s", skynet.timex(), body)) @@ -150,7 +150,7 @@ function _M.hotfix_code(query, body) skynet.error(string.format("hotfix_code time: %s, code: %s", skynet.timex(), body)) - pcall(skynet.call, 'WATCHDOG', "lua", "hotfix", body) + pcall(skynet.call, '.WATCHDOG', "lua", "hotfix", body) return 'success' end diff --git a/src/actions/PvpAction.lua b/src/actions/PvpAction.lua index 10fe9f7..bcf261f 100644 --- a/src/actions/PvpAction.lua +++ b/src/actions/PvpAction.lua @@ -103,6 +103,7 @@ end local function getMatchInfo(role, pvpList, battleCache, dbKey, infoFuncName, infoCache) table.clear(battleCache) + local dbKey = role:getPvpDBKey(dbKey) local redret = redisproxy:pipelining(function(red) for _, info in ipairs(pvpList) do if info.t == 1 then @@ -125,8 +126,9 @@ local function getMatchInfo(role, pvpList, battleCache, dbKey, infoFuncName, inf if k == "battleInfo" then battleCache[curInfo.roleId] = v else - if k == "heros" and infoCache then - infoCache[curInfo.roleId] = v + if (k == "heros" or k == "battleV") and infoCache then + infoCache[curInfo.roleId] = infoCache[curInfo.roleId] or {} + infoCache[curInfo.roleId][k] = v end curInfo[k] = v end @@ -150,9 +152,10 @@ function _M.infoRpc(agent, data) local response = {} if ptype == 1 then -- 普通pvp + local dbKey = role:getPvpDBKey(RANK_PVP_COMMON) local redret = redisproxy:pipelining(function(red) - red:zscore(RANK_PVP_COMMON, roleId) - red:zrevrank(RANK_PVP_COMMON, roleId) + red:zscore(dbKey, roleId) + red:zrevrank(dbKey, roleId) end) local score = role:unpackPvpScore(redret[1]) local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp @@ -168,9 +171,11 @@ function _M.infoRpc(agent, data) response.score = score response.matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo") elseif ptype == 2 then -- 高级pvp + if not role:isTimeResetOpen(TimeReset.PvpHight) then return end + local dbKey = role:getPvpDBKey(RANK_PVP_HIGHT) local redret = redisproxy:pipelining(function(red) - red:zscore(RANK_PVP_HIGHT, roleId) - red:zrevrank(RANK_PVP_HIGHT, roleId) + red:zscore(dbKey, roleId) + red:zrevrank(dbKey, roleId) end) local score = role:unpackPvpScore(redret[1]) local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp @@ -207,6 +212,8 @@ end function _M.refreshMatchHRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) + if not role:isTimeResetOpen(TimeReset.PvpHight) then return end + role:refreshPvpMatchH() local pvpMH = role:getProperty("pvpMH") @@ -397,9 +404,10 @@ function _M.startBattleHRpc(agent, data) local idx = msg.idx local revenge = msg.revenge + if not role:isTimeResetOpen(TimeReset.PvpHight) then return end local pvpTH = role:getProperty("pvpTH") - if not pvpTH.heros or not next(pvpTH.heros) then return 1 end + if not next(pvpTH) then return 1 end -- 检查并记录玩家队伍 local pvpTH = {} @@ -460,7 +468,7 @@ function _M.startBattleHRpc(agent, data) if not pvpMH[idx] then return 3 end if pvpMH[idx].t == 1 then enemyTeamRecord = _pvpBattleInfoCacheH[pvpMH[idx].id] - enemyT = _pvpHeroInfoCacheH[temp.id] + enemyT = _pvpHeroInfoCacheH[pvpMH[idx].id] elseif pvpMH[idx].t == 2 then enemyTeamRecord = {robot = pvpMH[idx].id} end @@ -581,7 +589,7 @@ function _M.endBattleHRpc(agent, data) local round = #_pvpStartBattleCacheH.result + 1 local matchInfo = nil if _pvpStartBattleCacheH.enemyTB.robot then - matchInfo = _pvpStartBattleCacheH.enemyTB.robot + matchInfo = _pvpStartBattleCacheH.enemyTB else matchInfo = _pvpStartBattleCacheH.enemyTB[round] end @@ -597,10 +605,12 @@ function _M.endBattleHRpc(agent, data) end -- 战斗结束了发奖 - local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpBonus, true) + local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpgroupBonus, true) local reward = role:award({[temp[1]] = temp[2]}) - local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = role:changePvpScoreHigh(match.t == 1 and match.id or -1, isWin) - + 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 -- 加入战斗记录 local selfTeam = {} @@ -608,7 +618,10 @@ function _M.endBattleHRpc(agent, data) for _idx, info in ipairs(_pvpStartBattleCacheH.result) do info.winId = info.isWin and roleId or match.id info.isWin = nil - selfTeam[_idx] = role:getTeamHerosInfo(_pvpStartBattleCacheH.pvpTH[_idx].heros) + selfTeam[_idx] = { + heros = role:getTeamHerosInfo(_pvpStartBattleCacheH.pvpTH[_idx].heros), + battleV = role:getTeamBattleValue(_pvpStartBattleCacheH.pvpTH[_idx].heros) + } if match.t == 1 and _pvpStartBattleCacheH.enemyT then enemyTeam[_idx] = _pvpStartBattleCacheH.enemyT[_idx] end @@ -681,10 +694,11 @@ function _M.rankListRpc(agent, data) local response = {} if ptype == 1 then -- 普通pvp + local dbKey = role:getPvpDBKey(RANK_PVP_COMMON) local redret = redisproxy:pipelining(function(red) - red:zscore(RANK_PVP_COMMON, roleId) - red:zrevrank(RANK_PVP_COMMON, roleId) - red:zrevrange(RANK_PVP_COMMON, 0, 99, "WITHSCORES") + red:zscore(dbKey, roleId) + red:zrevrank(dbKey, roleId) + red:zrevrange(dbKey, 0, 99, "WITHSCORES") end) local score = role:unpackPvpScore(redret[1]) local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp @@ -703,10 +717,11 @@ function _M.rankListRpc(agent, data) response.rankList = rankList elseif ptype == 2 then -- 高级pvp + local dbKey = role:getPvpDBKey(RANK_PVP_HIGHT) local redret = redisproxy:pipelining(function(red) - red:zscore(RANK_PVP_HIGHT, roleId) - red:zrevrank(RANK_PVP_HIGHT, roleId) - red:zrevrange(RANK_PVP_HIGHT, 0, 99, "WITHSCORES") + red:zscore(dbKey, roleId) + red:zrevrank(dbKey, roleId) + red:zrevrange(dbKey, 0, 99, "WITHSCORES") end) local score = role:unpackPvpScore(redret[1]) local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp @@ -714,7 +729,7 @@ function _M.rankListRpc(agent, data) for i = 1, #redret[3], 2 do local roleId = tonumber(redret[3][i]) local score = role:unpackPvpScore(redret[3][i + 1]) - local online, curInfo = rpcRole(roleId, "friendSInfo") + local online, curInfo = rpcRole(roleId, "pvpHRankInfo") curInfo.score = score curInfo.roleId = roleId table.insert(rankList, curInfo) @@ -784,4 +799,69 @@ function _M.recordListRpc(agent, data) return true end +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 = {}, + }) + + local reward = role:award(newReward) + + 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 + + role:costItems({[ItemId.PvpCoin] = csvData.cost * count}) + 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 + local reward = role:award(gift) + + + SendPacket(actionCodes.Pvp_shopBuyRpc, MsgPack.pack({reward = reward})) + return true +end + return _M \ No newline at end of file diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index c44a01c..c04b152 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -22,7 +22,7 @@ local function validName(name) local exist = redisproxy:exists(string_format("user:%s", name)) if exist then return "existed" end - local SERV = string_format("NAMED%d", math.random(1, 5)) + local SERV = string_format(".NAMED%d", math.random(1, 5)) local legal = skynet.call(SERV, "lua", "check", name) return legal and "ok" or "illegal" end @@ -119,8 +119,7 @@ function _M.loginRpc( agent, data ) role:advEndlessSeasonCheck(true) -- 冒险赛季更新检查 -- 跨天登陆事件 - role:onCrossDay(now) - role:onResetRank(now) + role:updateTimeReset(now) role:setProperty("ltime", now) redisproxy:zadd(FRIEND_RECOMMEND, now, roleId) @@ -217,7 +216,7 @@ function _M.loginRpc( agent, data ) -- 发下缓存的世界消息 local worldChatResponse = {worldChats = {}} - local ok, msgs = pcall(skynet.call, 'GLOBALD', "lua", "getWorldMsg", role._channelIdx) + local ok, msgs = pcall(skynet.call, '.GLOBALD', "lua", "getWorldMsg", role._channelIdx) if not ok then msgs = {} end @@ -246,7 +245,7 @@ function _M.loginRpc( agent, data ) role:saveHangTeam() role:savePvpCTeam() - role:log("login", {ip = agent.ip}) + role:log("login", {key1 = agent.ip:toArray(false, ":")[1]}) return true end @@ -297,7 +296,7 @@ function _M.createRpc(agent, data) -- 欢迎邮件 redisproxy:insertEmail({roleId = roleId, emailId = 1}) - newRole:log("create", { ip = agent.ip}) + newRole:log("create", {key1 = agent.ip:toArray(false, ":")[1]}) SendPacket(actionCodes.Role_createRpc, MsgPack.pack(response)) return true @@ -357,7 +356,7 @@ function _M.changeIntroRpc(agent, data) local content = msg.content if not content or type(content) ~= "string" then return end - local SERV = string_format("CHATED%d", math.random(1, 5)) + local SERV = string_format(".CHATED%d", math.random(1, 5)) local legal, mod = skynet.call(SERV, "lua", "check", content) if not legal then content = mod or "" @@ -472,9 +471,8 @@ function _M.openTimeBoxRpc(agent, data) local boxId = boxL[slot].id local itemData = csvdb["itemCsv"][boxId] local randomData = csvdb["item_randomCsv"][itemData.id] - reward = randomData.gift:toNumMap() -- 固定奖励 -- 随机奖励 - local reward = {} + reward = {} for i = 1, 10 do local num = randomData["num" .. i] local gift = randomData["gift" .. i] @@ -743,7 +741,7 @@ function _M.chatRpc(agent, data) -- 判断禁言 local result = nil - local SERV = string_format("CHATED%d", math.random(1, 5)) + local SERV = string_format(".CHATED%d", math.random(1, 5)) local legal, mod = skynet.call(SERV, "lua", "check", content) if not legal then content = mod or "" @@ -798,7 +796,7 @@ function _M.chatRpc(agent, data) end end mcast_util.pub_world(actionCodes.Role_chat, MsgPack.pack(response)) - pcall(skynet.send, 'GLOBALD', "lua", "sendWorldMsg", role._channelIdx, response) + pcall(skynet.send, '.GLOBALD', "lua", "sendWorldMsg", role._channelIdx, response) end, -- 私聊 [2] = function () diff --git a/src/agent.lua b/src/agent.lua index f8e59da..b4ea7c9 100644 --- a/src/agent.lua +++ b/src/agent.lua @@ -5,7 +5,6 @@ require "GlobalVar" require "RedisKeys" require "skynet.manager" -local harbor = require "skynet.harbor" local queue = require "skynet.queue" local netpack = require "skynet.netpack" local socket = require "skynet.socket" @@ -115,7 +114,11 @@ function rpcRole(roleId, funcName, ...) end else local roleCross = require("models.RoleCross") - return false, roleCross.handle(funcName, roleId, ...) + if funcName == "getProperties" then + return false, roleCross.handle(funcName, roleId, fields) + else + return false, roleCross.handle(funcName, roleId, ...) + end end end @@ -236,13 +239,12 @@ function CMD.close() mcast_util.usub_union() local role = agentInfo.role if not role then return end - role:log("logout", {online = skynet.timex()-role:getProperty("ltime")}) + role:log("logout", {int1 = skynet.timex()-role:getProperty("ltime")}) role:onOfflineEvent() end function CMD.exit() if agentInfo.role then - -- role:log("logout", {online = skynet.timex()-role:getProperty("ltime")}) datacenter.set("agent", agentInfo.role:getProperty("id"), nil) end skynet.exit() @@ -298,9 +300,9 @@ skynet.start(function() end end) - redisd = harbor.queryname("REDIS") + redisd = skynet.localname(".REDIS") if tonumber(skynet.getenv "logd") == 1 then - logd = harbor.queryname("LOGD") + logd = skynet.localname(".LOGD") end cs = queue() diff --git a/src/models/RolePvp.lua b/src/models/RolePvp.lua index 8711fa0..60fa64c 100644 --- a/src/models/RolePvp.lua +++ b/src/models/RolePvp.lua @@ -22,13 +22,14 @@ end function Role:changePvpScore(rankKey, changeScoreCallback, matchId) + local dbKey = self:getPvpDBKey(rankKey) local roleId = self:getProperty("id") local isPlayer = matchId ~= -1 local redret = redisproxy:pipelining(function(red) - red:zscore(rankKey, roleId) - red:zrevrank(rankKey, roleId) + red:zscore(dbKey, roleId) + red:zrevrank(dbKey, roleId) if isPlayer then - red:zscore(rankKey, matchId) + red:zscore(dbKey, matchId) end end) local myScore = self:unpackPvpScore(redret[1]) @@ -45,11 +46,11 @@ function Role:changePvpScore(rankKey, changeScoreCallback, matchId) local now = skynet.timex() redret = redisproxy:pipelining(function(red) - red:zadd(rankKey, self:packPvpScore(myScore, now), roleId) + red:zadd(dbKey, self:packPvpScore(myScore, now), roleId) if isPlayer then - red:zadd(rankKey, self:packPvpScore(matchScore, now), matchId) + red:zadd(dbKey, self:packPvpScore(matchScore, now), matchId) end - red:zrevrank(rankKey, roleId) + red:zrevrank(dbKey, roleId) end) local myRank @@ -81,18 +82,42 @@ function Role:changePvpScoreCommon(matchId, isWin) return table.unpack(result) end +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 + newReward[itemId] = math.min((newReward[itemId] or 0) + count, divisionData.limit) + end + end + return newTime, newReward +end + function Role:changePvpScoreHigh(matchId, isWin) + local oldMyDivision local function changeScoreCallback(myScore, matchScore) - local myMinScore = 0 - local matchMinScore = 0 - for _, division in ipairs(csvdb["pvp_group_divisionCsv"]) do + local myMinId = 0 + local matchMinId = 0 + for _id, division in ipairs(csvdb["pvp_group_divisionCsv"]) do if myScore >= division.division then - myMinScore = division.division + myMinId = _id end if matchScore >= division.division then - matchMinScore = division.division + matchMinId = _id end end + oldMyDivision = myMinId if isWin then local scoreChange = math.ceil(50 / (1 + 10 ^ ((myScore - matchScore) / 1000))) myScore = myScore + scoreChange @@ -102,10 +127,28 @@ function Role:changePvpScoreHigh(matchId, isWin) myScore = myScore - scoreChange matchScore = matchScore + scoreChange end - return math.max(myScore, myMinScore), math.max(matchScore, matchMinScore) + return math.max(myScore, csvdb["pvp_group_divisionCsv"][myMinId].division), math.max(matchScore, csvdb["pvp_group_divisionCsv"][matchMinId].division) end local result = self:changePvpScore(RANK_PVP_HIGHT, changeScoreCallback, matchId) + --{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 + if newDivision ~= oldMyDivision then + --刷新段位奖励 + local newTime, newReward = self:calculatePvpHGift(oldMyDivision) + self:updateProperties({ + pvpHGTime = newTime, + pvpHGift = newReward, + }) + end + self:refreshPvpMatchH(result[1]) return table.unpack(result) end @@ -122,20 +165,21 @@ function Role:refreshPvpMatch(score, rankKey) } 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(rankKey, roleId)) + 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(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") + 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(rankKey, "std_temp1", "std_temp2") + red:zrem(dbKey, "std_temp1", "std_temp2") end) local PreGetCount = 7 @@ -147,7 +191,7 @@ function Role:refreshPvpMatch(score, rankKey) rank2 = math.randomInt(rank2, rank1 - PreGetCount + 1) rank1 = rank2 + PreGetCount - 1 end - red:ZREVRANGE(rankKey, rank2, rank1) + red:ZREVRANGE(dbKey, rank2, rank1) end end) return redret @@ -288,6 +332,26 @@ function Role:refreshPvpMatchH(score) self:refreshPvpMatch(score, RANK_PVP_HIGHT) end +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 + + + + end -- libgit2 0.21.2