diff --git a/src/RedisKeys.lua b/src/RedisKeys.lua index f18b255..8137130 100644 --- a/src/RedisKeys.lua +++ b/src/RedisKeys.lua @@ -26,6 +26,8 @@ RANK_DINER_INFO = "rank:diner:info" RANK_PVP_COMMON = "rank:pvpc" RECORD_PVP_COMMON = "record:pvpc:%d" RANK_PVP_HIGHT = "rank:pvph" +RECORD_PVP_HIGH = "record:pvph:%d" + diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index 18aac6f..ce59e56 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -769,6 +769,7 @@ function _M.entrustRpc(agent , data) end reward = role:award(curData.reward) + table.remove(entrust, 1) elseif ctype == 2 then -- 放弃 table.remove(entrust, 1) else diff --git a/src/actions/PvpAction.lua b/src/actions/PvpAction.lua index 37c0490..10fe9f7 100644 --- a/src/actions/PvpAction.lua +++ b/src/actions/PvpAction.lua @@ -9,10 +9,16 @@ local remoteUrl = skynet.getenv("codeurl") local _M = {} local _pvpBattleInfoCacheC = {} --查询列表 缓存pvp战斗相关数据缓存 -local _pvpStartBattleCache = nil -- - -local _pvpRecordInfoCache = {} -- 记录缓存 -local _pvpRecordBattleInfoCache = {} -- 记录战斗数据缓存 +local _pvpBattleInfoCacheH = {} --查询列表 缓存pvp战斗相关数据缓存 +local _pvpHeroInfoCacheH = {} --查询列表 缓存pvp 英雄相关数据缓存 +local _pvpStartBattleCacheC = nil -- 当前战斗缓存 +local _pvpStartBattleCacheH = nil -- 当前战斗缓存 + +local _pvpRecordInfoCacheC = {} -- 记录缓存 +local _pvpRecordInfoCacheH = {} -- 记录缓存 +local _pvpRecordBattleInfoCacheC = {} -- 记录战斗数据缓存 +local _pvpRecordBattleInfoCacheH = {} -- 记录战斗数据缓存 +local _pvpRecordHeroInfoCacheH = {} --查询列表 缓存pvp 英雄相关数据缓存 local _revengeRecord = {} -- 复仇对单人1分钟间隔 local RevengeWaitTime = 60 @@ -50,13 +56,57 @@ function _M.formatCommonRpc(agent , data) return true end +function _M.formatHighRpc(agent , data) + local role = agent.role + local roleId = role:getProperty("id") + local msg = MsgPack.unpack(data) + + local pvpTH = {} + local had = {} -- 上阵的角色 + local supportHad = {} + for i = 1, 3 do + local team = msg.teams[i] + if not team then return end + + if not team.heros or not next(team.heros) then + return + end -local function getMatchInfo(role, pvpList, battleCache) + for slot, heroId in pairs(team.heros or {}) do + if not role.heros[heroId] or had[heroId] then + return + end + had[heroId] = 1 + end + + local supports = {} + for slot, support in pairs(team.supports) do + if slot ~= 1 and slot ~= 2 then return end + local level = role.dinerData:getProperty("dishTree"):getv(support, 0) + if level <= 0 or supportHad[support] then return end + supports[slot] = support + supportHad[support] = 1 + end + + local curTeam = {} + curTeam.heros = team.heros + curTeam.leader = team.leader + curTeam.supports = supports + + table.insert(pvpTH, curTeam) + end + + role:savePvpHTeam(pvpTH) + SendPacket(actionCodes.Pvp_formatHighRpc, '') + return true +end + +local function getMatchInfo(role, pvpList, battleCache, dbKey, infoFuncName, infoCache) table.clear(battleCache) local redret = redisproxy:pipelining(function(red) for _, info in ipairs(pvpList) do if info.t == 1 then - red:zscore(RANK_PVP_COMMON, info.id) + red:zscore(dbKey, info.id) end end end) @@ -70,11 +120,14 @@ local function getMatchInfo(role, pvpList, battleCache) curInfo.score = role:unpackPvpScore(redret[curIdx] or 0) curIdx = curIdx + 1 -- name, level, headId, battleV, heros - local online, roleInfo = rpcRole(curInfo.roleId, "pvpCInfo") + local online, roleInfo = rpcRole(curInfo.roleId, infoFuncName) for k , v in pairs(roleInfo) do if k == "battleInfo" then battleCache[curInfo.roleId] = v else + if k == "heros" and infoCache then + infoCache[curInfo.roleId] = v + end curInfo[k] = v end end @@ -113,10 +166,25 @@ function _M.infoRpc(agent, data) response.rank = rank response.score = score - response.matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC) - + response.matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo") elseif ptype == 2 then -- 高级pvp - return + local redret = redisproxy:pipelining(function(red) + red:zscore(RANK_PVP_HIGHT, roleId) + red:zrevrank(RANK_PVP_HIGHT, roleId) + end) + local score = role:unpackPvpScore(redret[1]) + local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp + + local pvpMH = role:getProperty("pvpMH") + if not next(pvpMH) then --没有分配过对手 + role:refreshPvpMatchH(score) + pvpMH = role:getProperty("pvpMH") + end + if not next(pvpMH) then return end + + response.rank = rank + response.score = score + response.matches = getMatchInfo(role, pvpMH, _pvpBattleInfoCacheH, RANK_PVP_HIGHT, "pvpHInfo", _pvpHeroInfoCacheH) else return end @@ -130,12 +198,24 @@ function _M.refreshMatchCRpc(agent, data) role:refreshPvpMatchC() local pvpMC = role:getProperty("pvpMC") - local matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC) + local matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo") SendPacket(actionCodes.Pvp_refreshMatchCRpc, MsgPack.pack({matches = matches})) return true end +function _M.refreshMatchHRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + role:refreshPvpMatchH() + + local pvpMH = role:getProperty("pvpMH") + local matches = getMatchInfo(role, pvpMH, _pvpBattleInfoCacheH, RANK_PVP_HIGHT, "pvpHInfo", _pvpHeroInfoCacheH) + + SendPacket(actionCodes.Pvp_refreshMatchHRpc, MsgPack.pack({matches = matches})) + return true +end + function _M.buyCountRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) @@ -168,12 +248,12 @@ function _M.startBattleRpc(agent, data) local now = skynet.timex() if revenge then --复仇 - local temp = _pvpRecordInfoCache[idx] + local temp = _pvpRecordInfoCacheC[idx] if not temp then return 2 end if not _revengeRecord[temp.id] or now >= _revengeRecord[temp.id] then if temp.t == 1 then - matchInfo = _pvpRecordBattleInfoCache[temp.id] + matchInfo = _pvpRecordBattleInfoCacheC[temp.id] elseif temp.t == 2 then matchInfo = {robot = temp.id} end @@ -205,7 +285,7 @@ function _M.startBattleRpc(agent, data) end key = tostring(math.random()) - _pvpStartBattleCache = {idx = idx, key = key, revenge = revenge} + _pvpStartBattleCacheC = {idx = idx, key = key, revenge = revenge} role:checkTaskEnter("PvpBattle") end @@ -219,21 +299,21 @@ function _M.endBattleRpc(agent, data) local roleId = role:getProperty("id") local msg = MsgPack.unpack(data) - if not msg.key or not _pvpStartBattleCache or msg.key ~= _pvpStartBattleCache.key then + if not msg.key or not _pvpStartBattleCacheC or msg.key ~= _pvpStartBattleCacheC.key then return 1 end - if not msg.idx or msg.idx ~= _pvpStartBattleCache.idx then + if not msg.idx or msg.idx ~= _pvpStartBattleCacheC.idx then return 2 end local isWin = msg.starNum and msg.starNum > 0 local now = skynet.timex() - local revenge = _pvpStartBattleCache.revenge + local revenge = _pvpStartBattleCacheC.revenge local match if revenge then - match = _pvpRecordInfoCache[msg.idx] + match = _pvpRecordInfoCacheC[msg.idx] _revengeRecord[match.id] = now + RevengeWaitTime -- 1分钟内不能再打 else local pvpMC = role:getProperty("pvpMC") @@ -247,9 +327,9 @@ function _M.endBattleRpc(agent, data) local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = role:changePvpScoreCommon(match.t == 1 and match.id or -1, isWin) _pvpBattleInfoCacheC = {} --重新发阵容了 没毛病 - _pvpRecordInfoCache = {} -- 记录刷新了 - _pvpRecordBattleInfoCache = {} -- 取新纪录的时候搞 - _pvpStartBattleCache = nil + _pvpRecordInfoCacheC = {} -- 记录刷新了 + _pvpRecordBattleInfoCacheC = {} -- 取新纪录的时候搞 + _pvpStartBattleCacheC = nil -- 请求上传录像 local params = { @@ -310,6 +390,289 @@ function _M.endBattleRpc(agent, data) return true end + +function _M.startBattleHRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + + local idx = msg.idx + local revenge = msg.revenge + + local pvpTH = role:getProperty("pvpTH") + if not pvpTH.heros or not next(pvpTH.heros) then return 1 end + + -- 检查并记录玩家队伍 + local pvpTH = {} + local had = {} -- 上阵的角色 + local supportHad = {} + for i = 1, 3 do + local team = msg.teams[i] + if not team then return end + + if not team.heros or not next(team.heros) then + return + end + + for slot, heroId in pairs(team.heros or {}) do + if not role.heros[heroId] or had[heroId] then + return + end + had[heroId] = 1 + end + + local supports = {} + for slot, support in pairs(team.supports) do + if slot ~= 1 and slot ~= 2 then return end + local level = role.dinerData:getProperty("dishTree"):getv(support, 0) + if level <= 0 or supportHad[support] then return end + supports[slot] = support + supportHad[support] = 1 + end + + local curTeam = {} + curTeam.heros = team.heros + curTeam.leader = team.leader + curTeam.supports = supports + + table.insert(pvpTH, curTeam) + end + + local enemyTeamRecord, result, key, wait, enemyT, matchInfo + + local now = skynet.timex() + if revenge then --复仇 + local temp = _pvpRecordInfoCacheH[idx] + if not temp then return 2 end + + if not _revengeRecord[temp.id] or now >= _revengeRecord[temp.id] then + if temp.t == 1 then + enemyTeamRecord = _pvpRecordBattleInfoCacheH[temp.id] + enemyT = _pvpRecordHeroInfoCacheH[temp.id] + elseif temp.t == 2 then + enemyTeamRecord = {robot = temp.id} + end + else + result = 1 + wait = _revengeRecord[temp.id] - now + end + else --打正常 + local pvpMH = role:getProperty("pvpMH") + if not pvpMH[idx] then return 3 end + if pvpMH[idx].t == 1 then + enemyTeamRecord = _pvpBattleInfoCacheH[pvpMH[idx].id] + enemyT = _pvpHeroInfoCacheH[temp.id] + elseif pvpMH[idx].t == 2 then + enemyTeamRecord = {robot = pvpMH[idx].id} + end + end + + if not result and not enemyTeamRecord then return 4 end + + if not result then + -- 次数扣一波 + local pvpFreeH = role.dailyData:getProperty("pvpFreeH") + if pvpFreeH >= globalCsv.pvp_battle_free_count_high then + local cost = {[ItemId.PvpKey] = globalCsv.pvp_battle_high_cost} + if not role:checkItemEnough(cost) then return 5 end + role:costItems(cost) + else + role.dailyData:updateProperty({field = "pvpFreeH", delta = 1}) + end + + + -- 只发送指定的那个敌人 + if enemyTeamRecord.robot then + matchInfo = enemyTeamRecord + else + matchInfo = enemyTeamRecord[1] + end + + key = tostring(math.random()) + _pvpStartBattleCacheH = { + idx = idx, -- 数据索引 + key = key, -- 战斗校验 key + revenge = revenge, -- 是否是复仇 + result = {}, -- 战斗记录 + pvpTH = pvpTH, -- 我方队伍缓存 + enemyTB = enemyTeamRecord, --敌方战斗队伍缓存 + enemyT = enemyT, + } + + role:checkTaskEnter("PvpBattle") + end + + SendPacket(actionCodes.Pvp_startBattleHRpc, MsgPack.pack({ + matchInfo = matchInfo, --敌方队伍 信息 + key = key, --战斗校验 key + round = 1, -- 战斗场数索引 + result = result, -- 返回状态 + wait = wait -- 等待复仇时间 + })) + return true +end + +function _M.endBattleHRpc(agent, data) + local role = agent.role + local roleId = role:getProperty("id") + local msg = MsgPack.unpack(data) + + if not msg.key or not _pvpStartBattleCacheH or msg.key ~= _pvpStartBattleCacheH.key then + return 1 + end + + if not msg.idx or msg.idx ~= _pvpStartBattleCacheH.idx then + return 2 + end + + local isWin = msg.starNum and msg.starNum > 0 + local now = skynet.timex() + + local revenge = _pvpStartBattleCacheH.revenge + local match + if revenge then + match = _pvpRecordInfoCacheH[msg.idx] + _revengeRecord[match.id] = now + RevengeWaitTime -- 1分钟内不能再打 + else + local pvpMH = role:getProperty("pvpMH") + match = pvpMH[msg.idx] + end + + if not match then return end + + -- 请求上传录像 + local params = { + ["roleid"] = roleId, + ["key"] = "zhaolugame20191016", + ["time"] = now, + } + local status, body = httpc.get(remoteUrl, "/applyvideo?" .. httpGetFormatData(params), {}, {}) + local video = nil + if tonumber(status) == 200 then + local result = json.decode(body) + video = result.name + else + skynet.error("applyvideo", "error", status, body, content) + end + + table.insert(_pvpStartBattleCacheH.result, { + isWin = isWin, + video = video, + }) + + -- 检查是否结束战斗 + local winCount, loseCount = 0, 0 + for _, status in pairs(_pvpStartBattleCacheH.result) do + if status.isWin then + winCount = winCount + 1 + else + loseCount = loseCount + 1 + end + end + + if winCount >= 2 then + isWin = true + elseif loseCount >= 2 then + isWin = false + else -- 没结束 + -- 返回继续战斗 + + local key = tostring(math.random()) + _pvpStartBattleCacheH.key = key + local round = #_pvpStartBattleCacheH.result + 1 + local matchInfo = nil + if _pvpStartBattleCacheH.enemyTB.robot then + matchInfo = _pvpStartBattleCacheH.enemyTB.robot + else + matchInfo = _pvpStartBattleCacheH.enemyTB[round] + end + + -- 继续战斗 + SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({ + matchInfo = matchInfo, --敌方队伍 信息 + key = key, --战斗校验 key + round = round, -- 战斗场数索引 + video = video, -- 返回让客户端上传录像 + })) + return true + end + + -- 战斗结束了发奖 + local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpBonus, 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 selfTeam = {} + local enemyTeam = {} + 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) + if match.t == 1 and _pvpStartBattleCacheH.enemyT then + enemyTeam[_idx] = _pvpStartBattleCacheH.enemyT[_idx] + end + end + local recordBattle = { + result = _pvpStartBattleCacheH.result, + [roleId] = selfTeam, + [match.id] = enemyTeam + } + + redisproxy:pipelining(function(red) + local dbKey = string.format(RECORD_PVP_HIGH, roleId) + red:lpush(dbKey, MsgPack.pack({ + id = match.id, + t = match.t, + win = isWin, + time = now, + sdelta = myScore - oldmyScore, + -- 队伍信息 + record = recordBattle, + })) + red:ltrim(dbKey, 0, 9) + -- 对方加入战斗记录 + if match.t == 1 then + dbKey = string.format(RECORD_PVP_HIGH, match.id) + red:lpush(dbKey, MsgPack.pack({ + id = roleId, + t = 1, + win = not isWin, + time = now, + sdelta = matchScore - oldMatchScore, + -- 队伍信息 + record = recordBattle, + })) + red:ltrim(dbKey, 0, 9) + end + end) + + _pvpBattleInfoCacheH = {} --重新发阵容了 没毛病 + _pvpRecordInfoCacheH = {} -- 记录刷新了 + _pvpRecordBattleInfoCacheH = {} -- 取新纪录的时候搞 + _pvpStartBattleCacheH = nil + _pvpHeroInfoCacheH = {} + _pvpRecordHeroInfoCacheH = {} + + if isWin then + role:checkTaskEnter("PvpWin", {score = myScore}) + end + + SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({ + reward = reward, + myScore = myScore, + matchScore = matchScore, + oldmyScore = oldmyScore, + oldMatchScore = oldMatchScore, + myRank = myRank, + oldMyRank = oldMyRank, + video = video, + isWin = isWin, + })) + return true +end + + function _M.rankListRpc(agent, data) local role = agent.role local roleId = role:getProperty("id") @@ -340,7 +703,26 @@ function _M.rankListRpc(agent, data) response.rankList = rankList elseif ptype == 2 then -- 高级pvp - return + 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") + end) + local score = role:unpackPvpScore(redret[1]) + local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp + local rankList = {} + 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") + curInfo.score = score + curInfo.roleId = roleId + table.insert(rankList, curInfo) + end + + response.score = score + response.rank = rank + response.rankList = rankList else return end @@ -365,9 +747,9 @@ function _M.recordListRpc(agent, data) table.insert(tempList, one) end end - _pvpRecordInfoCache = tempList + _pvpRecordInfoCacheC = tempList - recordList = getMatchInfo(role, tempList, _pvpRecordBattleInfoCache) + recordList = getMatchInfo(role, tempList, _pvpRecordBattleInfoCacheC, RANK_PVP_COMMON, "pvpCInfo") for idx, info in ipairs(recordList) do local temp = tempList[idx] info.win = temp.win @@ -377,7 +759,24 @@ function _M.recordListRpc(agent, data) end elseif ptype == 2 then -- 高级pvp - return + local rlist = redisproxy:lrange(string.format(RECORD_PVP_HIGH, roleId), 0 , 9) + local tempList = {} + for _, temp in ipairs(rlist) do + local one = MsgPack.unpack(temp) + if now - one.time <= globalCsv.pvp_record_keep_time then -- 大于一天的弃之 + table.insert(tempList, one) + end + end + _pvpRecordInfoCacheH = tempList + + recordList = getMatchInfo(role, tempList, _pvpRecordBattleInfoCacheH, RANK_PVP_HIGHT, "pvpHInfo", _pvpRecordHeroInfoCacheH) + for idx, info in ipairs(recordList) do + local temp = tempList[idx] + info.win = temp.win + info.time = temp.time + info.sdelta = temp.sdelta + info.record = temp.record + end else return end diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index c5c34e0..c44a01c 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -245,8 +245,9 @@ function _M.loginRpc( agent, data ) -- 玩家登陆做的一些操作 role:saveHangTeam() role:savePvpCTeam() - -- role:log("login", { ip = agent.ip, diamond = role:getProperty("diamond"), reDiamond = role:getProperty("reDiamond")}) + role:log("login", {ip = agent.ip}) + return true end @@ -675,18 +676,18 @@ function _M.achiveRpc(agent, data) if not role:isFuncUnlock(FuncUnlock.TaskAchiv) then return end local achiveTask = csvdb["achievementCsv"][taskId] - if not achiveTask then return end + if not achiveTask then return 1 end local achiveT = role:getProperty("achiveT") local achiveV = role:getProperty("achiveV") - if achiveV[taskId] then return end + if achiveV[taskId] then return 2 end local curStatus = achiveT[achiveTask.type] or 0 local maxc = achiveTask.condition1 if maxc > curStatus then - return + return 3 end local reward = role:award(achiveTask.reward) @@ -716,7 +717,7 @@ function _M.achiveRpc(agent, data) attachments = pData.reward, contentPms = {pData.level}, }) - elseif pData.request > newP then + elseif pData.request > overCount then break end end diff --git a/src/models/Daily.lua b/src/models/Daily.lua index afe60fc..38adb06 100644 --- a/src/models/Daily.lua +++ b/src/models/Daily.lua @@ -19,6 +19,7 @@ Daily.schema = { giveFP = {"table", {}}, -- 给谁送过心心 getFP = {"table", {}}, -- 领过谁的心心 pvpFree = {"number", 0}, -- pvp使用免费次数 + pvpFreeH = {"number", 0}, -- 高级pvp使用免费次数 dailySDC = {"table", {}}, -- daily shop diamond count {[id] = count} -- 每日商城购买次数统计 dailySDD = {"table", {}}, -- daily shop diamond disount {[id] = 1} -- 每日商城折扣统计 @@ -92,6 +93,7 @@ function Daily:data() giveFP = self:getProperty("giveFP"), getFP = self:getProperty("getFP"), pvpFree = self:getProperty("pvpFree"), + pvpFreeH = self:getProperty("pvpFreeH"), dailySDC = self:getProperty("dailySDC"), dailySDD = self:getProperty("dailySDD"), advSupRe = self:getProperty("advSupRe"), diff --git a/src/models/Role.lua b/src/models/Role.lua index dfb2460..12de7c7 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -1,5 +1,6 @@ local Role = class("Role", require("shared.ModelBase")) +local RoleLog = import(".RoleLog") local RolePlugin = import(".RolePlugin") local RoleTask = import(".RoleTask") local RoleActivity = import(".RoleActivity") @@ -7,6 +8,7 @@ local RoleChangeStruct = import(".RoleChangeStruct") local RolePvp = import(".RolePvp") local RoleCross = import(".RoleCross") +RoleLog.bind(Role) RolePlugin.bind(Role) RoleTask.bind(Role) RoleActivity.bind(Role) diff --git a/src/models/RoleCross.lua b/src/models/RoleCross.lua index eb01f5b..c1c2fe4 100644 --- a/src/models/RoleCross.lua +++ b/src/models/RoleCross.lua @@ -42,6 +42,19 @@ RoleCross.bind = function (Role) return info end + -- pvp 数据 + function Role:pvpHInfo() + local info = { + name = self:getProperty("name"), + level = self:getProperty("level"), + headId = self:getProperty("headId"), + battleV = self:getProperty("pvpTBVH"), + heros = self:getProperty("pvpTSH"), + battleInfo = self:getProperty("pvpTBH") + } + return info + end + function Role:accountInit(initData) -- 道具 local reward = {} @@ -270,6 +283,18 @@ function CMD.pvpCInfo(roleId) } end +function CMD.pvpHInfo(roleId) + local info = CMD.getProperties(roleId, {"name", "level", "headId", "pvpTBVH", "pvpTSH", "pvpTBH"}) + return { + name = info.name, + level = info.level, + headId = info.headId, + battleV = info.pvpTBVH, + heros = info.pvpTSH, + battleInfo = info.pvpTBH + } +end + RoleCross.handle = function(cmd, roleId, ...) SRole = SRole or require("models.Role") if CMD[cmd] then diff --git a/src/models/RoleLog.lua b/src/models/RoleLog.lua new file mode 100644 index 0000000..606e960 --- /dev/null +++ b/src/models/RoleLog.lua @@ -0,0 +1,65 @@ + + +-- logType 日志 mapping 信息(确定后不能更改类型) 修改需要设置 es 日志mapping + + + +local LogType = { + create = { + ip = "string" + }, + login = { + ip = "string" + }, + logout = { + online = "number" + }, + +} + + +-- 所有的日志都包括的部分 role 里面的信息 +local commonField = { + name = "string", + id = "number", + uid = "string", + sId = "number", + device = "string", + ctime = "number", + ltime = "number", + level = "number", + rmbC = "number", +} + +local RoleLog = {} + +function RoleLog.bind(Role) + + function Role:log(logType, contents) + + local _logType = LogType[logType] + if not _logType then return end + + + if not logd then return end + + contents = contents or {} + local doc = {} + for field, _typ in pairs(commonField) do + doc[field] = self:getProperty(field) + end + for field, value in pairs(contents) do + if _logType[field] then + doc[field] = value + else + print(string.format("LOG ERROR: %s had new field %s no type.", logType, field)) + end + end + + doc.mid = doc.uid:sub(-2, -1) + pcall(skynet.send, logd, "lua", "log", logType, doc) + end + +end + +return RoleLog \ No newline at end of file diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 03c0583..a0888db 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -4,10 +4,6 @@ local RolePlugin = {} function RolePlugin.bind(Role) - function Role:log() - - end - function Role:loadAll() self:loadDaily() self:loadEquips() diff --git a/src/models/RolePvp.lua b/src/models/RolePvp.lua index 8127950..8711fa0 100644 --- a/src/models/RolePvp.lua +++ b/src/models/RolePvp.lua @@ -20,14 +20,15 @@ function Role:packPvpScore(score, now) return math.floor(score * PVP_RANK_TIME_SORT_PLACE + (PVP_RANK_TIME_SORT_STD - now) / PVP_RANK_TIME_SORT_PRECISION) end -function Role:changePvpScoreCommon(matchId, isWin) + +function Role:changePvpScore(rankKey, changeScoreCallback, matchId) local roleId = self:getProperty("id") local isPlayer = matchId ~= -1 local redret = redisproxy:pipelining(function(red) - red:zscore(RANK_PVP_COMMON, roleId) - red:zrevrank(RANK_PVP_COMMON, roleId) + red:zscore(rankKey, roleId) + red:zrevrank(rankKey, roleId) if isPlayer then - red:zscore(RANK_PVP_COMMON, matchId) + red:zscore(rankKey, matchId) end end) local myScore = self:unpackPvpScore(redret[1]) @@ -38,51 +39,103 @@ function Role:changePvpScoreCommon(matchId, isWin) end local oldmyScore, oldMatchScore = 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 - + myScore, matchScore = changeScoreCallback(myScore, matchScore) myScore = math.max(myScore, 0) matchScore = math.max(matchScore, 0) local now = skynet.timex() redret = redisproxy:pipelining(function(red) - red:zadd(RANK_PVP_COMMON, self:packPvpScore(myScore, now), roleId) + red:zadd(rankKey, self:packPvpScore(myScore, now), roleId) if isPlayer then - red:zadd(RANK_PVP_COMMON, self:packPvpScore(matchScore, now), matchId) + red:zadd(rankKey, self:packPvpScore(matchScore, now), matchId) end - red:zrevrank(RANK_PVP_COMMON, roleId) + red:zrevrank(rankKey, roleId) end) + local myRank if isPlayer then myRank = tonumber(redret[3] or -2) + 1 else myRank = tonumber(redret[2] or -2) + 1 end - self:refreshPvpMatchC(myScore) - return myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank + + return {myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank} end -function Role:refreshPvpMatchC(score) +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] + local roleId = self:getProperty("id") - score = score or self:unpackPvpScore(redisproxy:zscore(RANK_PVP_COMMON, roleId)) - + score = score or self:unpackPvpScore(redisproxy:zscore(rankKey, 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(RANK_PVP_COMMON, low * PVP_RANK_TIME_SORT_PLACE, "std_temp1") - red:zadd(RANK_PVP_COMMON, high * PVP_RANK_TIME_SORT_PLACE + PVP_RANK_TIME_SORT_PLACE - 1, "std_temp2") - red:ZREVRANK(RANK_PVP_COMMON, "std_temp1") - red:ZREVRANK(RANK_PVP_COMMON, "std_temp2") + 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") end - red:zrem(RANK_PVP_COMMON, "std_temp1", "std_temp2") + red:zrem(rankKey, "std_temp1", "std_temp2") end) local PreGetCount = 7 @@ -94,7 +147,7 @@ function Role:refreshPvpMatchC(score) rank2 = math.randomInt(rank2, rank1 - PreGetCount + 1) rank1 = rank2 + PreGetCount - 1 end - red:ZREVRANGE(RANK_PVP_COMMON, rank2, rank1) + red:ZREVRANGE(rankKey, rank2, rank1) end end) return redret @@ -131,10 +184,10 @@ function Role:refreshPvpMatchC(score) end local result = getPlayers(levels) - local matchC = self:getProperty("pvpMC") + local match = self:getProperty(mField) local hadPlayer = {[roleId] = 1} local hadRobot = {} - for _, one in pairs(matchC) do + for _, one in pairs(match) do if one.t == 1 then hadPlayer[one.id] = 1 elseif one.t == 2 then @@ -168,12 +221,12 @@ function Role:refreshPvpMatchC(score) end end - local tempMatchC = {} + local tempMatch = {} local curCount = 0 for i = 1, 3 do local objId = getPlayer(i) if objId then - tempMatchC[i] = {t = 1, id = objId} + tempMatch[i] = {t = 1, id = objId} curCount = curCount + 1 end end @@ -201,7 +254,7 @@ function Role:refreshPvpMatchC(score) local curIdx = math.randomInt(1, #result) local objId = result[curIdx] table.remove(result, curIdx) - tempMatchC[i] = {t = 1, id = objId} + tempMatch[i] = {t = 1, id = objId} curCount = curCount + 1 if not next(result) then break @@ -215,19 +268,25 @@ function Role:refreshPvpMatchC(score) if curCount < 3 then for i = curCount + 1, 3 do while true do - local id = math.randomInt(1, #csvdb["pvp_robotCsv"]) + local id = math.randomInt(1, #csvdb[robotCsv]) if not hadRobot[id] then hadRobot[id] = 1 - tempMatchC[i] = {t = 2, id = id} + tempMatch[i] = {t = 2, id = id} break end end end end + self:setProperty(mField, tempMatch) +end - self:setProperty("pvpMC", tempMatchC) +function Role:refreshPvpMatchC(score) + self:refreshPvpMatch(score, RANK_PVP_COMMON) end +function Role:refreshPvpMatchH(score) + self:refreshPvpMatch(score, RANK_PVP_HIGHT) +end end -- libgit2 0.21.2