From 3dbbc9f35e0c5d2fd897cff7815ef9c6350b7dfe Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Fri, 29 Nov 2019 12:02:33 +0800 Subject: [PATCH] 加上新的任务 --- src/actions/FriendAction.lua | 11 ++++++++--- src/actions/PvpAction.lua | 41 ++++++++++++++++++++++++++--------------- src/models/RolePlugin.lua | 19 ++++++++++--------- src/models/RolePvp.lua | 16 ++++++++-------- src/models/RoleTask.lua | 17 ++++++++++------- 5 files changed, 62 insertions(+), 42 deletions(-) diff --git a/src/actions/FriendAction.lua b/src/actions/FriendAction.lua index 5e1a79e..b6361bd 100644 --- a/src/actions/FriendAction.lua +++ b/src/actions/FriendAction.lua @@ -378,6 +378,7 @@ function _M.listRpc(agent, data) end if next(clearRed) then redisproxy:hmset(FRIEND_KEY:format(roleId), table_unpack(clearRed)) --清除新好友标记 + role:checkTaskEnter("AddFriend", {count = #friendList}) end SendPacket(actionCodes.Friend_listRpc, MsgPack.pack({list = friendList})) @@ -518,6 +519,7 @@ function _M.pointRpc(agent, data) redisproxy:sadd(FRIEND_POINT:format(objId), roleId) giveP[objId] = 1 role.dailyData:updateProperty({field = "giveFP", value = giveP}) + role:checkTaskEnter("GiveFriendP", {count = 1}) rpcRole(objId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({newPoint = 1, roleId = roleId})) end elseif cmd == 2 then -- 领取 @@ -536,25 +538,27 @@ function _M.pointRpc(agent, data) getP[objId] = 1 reward = role:award({[ItemId.FriendPoint] = 1}) role.dailyData:updateProperty({field = "getFP", value = getP}) + role:checkTaskEnter("GetFriendP", {count = 1}) end elseif cmd == 3 then -- 一键赠送领取 -- 赠送 local giveP = role.dailyData:getProperty("giveFP") local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId)) - local change = false + local change = 0 redisproxy:pipelining(function(red) for i = 1, #friends , 2 do local objId = tonumber(friends[i]) if not giveP[objId] then giveP[objId] = 1 - change = true + change = change + 1 red:sadd(FRIEND_POINT:format(objId), roleId) rpcRole(objId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({newPoint = 1, roleId = roleId})) end end end) - if change then + if change > 0 then role.dailyData:updateProperty({field = "giveFP", value = giveP}) + role:checkTaskEnter("GiveFriendP", {count = change}) else result = 1 end @@ -578,6 +582,7 @@ function _M.pointRpc(agent, data) if getCount > 0 then reward = role:award({[ItemId.FriendPoint] = getCount}) role.dailyData:updateProperty({field = "getFP", value = getP}) + role:checkTaskEnter("GetFriendP", {count = getCount}) else result = (result or 0) + 2 end diff --git a/src/actions/PvpAction.lua b/src/actions/PvpAction.lua index 8ff1b62..0b91f40 100644 --- a/src/actions/PvpAction.lua +++ b/src/actions/PvpAction.lua @@ -22,12 +22,12 @@ function _M.formatCommonRpc(agent , data) local roleId = role:getProperty("id") local msg = MsgPack.unpack(data) local pvpTC = role:getProperty("pvpTC") - for slot, heroId in pairs(msg.heros) do + for slot, heroId in pairs(msg.heros or {}) do if not role.heros[heroId] then return end end - if not next(msg.heros) then + if not msg.heros or not next(msg.heros) then return end @@ -44,7 +44,7 @@ function _M.formatCommonRpc(agent , data) end -local function getMatchInfo(pvpList, battleCache) +local function getMatchInfo(role, pvpList, battleCache) table.clear(battleCache) local redret = redisproxy:pipelining(function(red) for _, info in ipairs(pvpList) do @@ -60,7 +60,7 @@ local function getMatchInfo(pvpList, battleCache) local curInfo = {idx = idx} if info.t == 1 then --玩家 curInfo.roleId = info.id - curInfo.score = tonumber(redret[curIdx] or 0) + curInfo.score = role:unpackPvpScore(redret[curIdx] or 0) curIdx = curIdx + 1 -- name, level, headId, battleV, heros local online, roleInfo = rpcRole(curInfo.roleId, "pvpCInfo") @@ -92,7 +92,7 @@ function _M.infoRpc(agent, data) red:zscore(RANK_PVP_COMMON, roleId) red:zrevrank(RANK_PVP_COMMON, roleId) end) - local score = tonumber(redret[1] or 0) + local score = role:unpackPvpScore(redret[1] or 0) local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp local pvpMC = role:getProperty("pvpMC") if not next(pvpMC) then --没有分配过对手 @@ -103,7 +103,7 @@ function _M.infoRpc(agent, data) response.score = score response.rank = rank - response.matches = getMatchInfo(pvpMC, _pvpBattleInfoCacheC) + response.matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC) elseif ptype == 2 then -- 高级pvp return @@ -120,7 +120,7 @@ function _M.refreshMatchCRpc(agent, data) role:refreshPvpMatchC() local pvpMC = role:getProperty("pvpMC") - local matches = getMatchInfo(pvpMC, _pvpBattleInfoCacheC) + local matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC) SendPacket(actionCodes.Pvp_refreshMatchCRpc, MsgPack.pack({matches = matches})) return true @@ -151,11 +151,15 @@ function _M.startBattleRpc(agent, data) local idx = msg.idx local revenge = msg.revenge + local pvpTC = role:getProperty("pvpTC") + if not pvpTC.heros or not next(pvpTC.heros) then return 1 end + local matchInfo, result, key, wait + local now = skynet.timex() if revenge then --复仇 local temp = _pvpRecordInfoCache[idx] - if not temp then return end + if not temp then return 2 end if not _responseRecord[temp.id] or now >= _responseRecord[temp.id] then if temp.t == 1 then @@ -169,7 +173,7 @@ function _M.startBattleRpc(agent, data) end else --打正常 local pvpMC = role:getProperty("pvpMC") - if not pvpMC[idx] then return end + if not pvpMC[idx] then return 3 end if pvpMC[idx].t == 1 then matchInfo = _pvpBattleInfoCacheC[pvpMC[idx].id] elseif pvpMC[idx].t == 2 then @@ -177,14 +181,14 @@ function _M.startBattleRpc(agent, data) end end - if not result and not matchInfo then return end + if not result and not matchInfo then return 4 end if not result then -- 次数扣一波 local pvpFree = role.dailyData:getProperty("pvpFree") if pvpFree >= globalCsv.pvp_battle_free_count then local cost = {[ItemId.PvpKey] = 1} - if not role:checkItemEnough(cost) then return end + if not role:checkItemEnough(cost) then return 5 end role:costItems(cost) else role.dailyData:updateProperty({field = "pvpFree", delta = 1}) @@ -192,6 +196,8 @@ function _M.startBattleRpc(agent, data) key = tostring(math.random()) _pvpStartBattleCache = {idx = idx, key = key, revenge = revenge} + + role:checkTaskEnter("PvpBattle") end SendPacket(actionCodes.Pvp_startBattleRpc, MsgPack.pack({matchInfo = matchInfo, key = key, result = result, wait = wait})) @@ -206,7 +212,8 @@ function _M.endBattleRpc(agent, data) if not msg.key or not _pvpStartBattleCache or msg.key ~= _pvpStartBattleCache.key then return 1 end - if not msg.idx or not msg.idx ~= _pvpStartBattleCache.idx then + + if not msg.idx or msg.idx ~= _pvpStartBattleCache.idx then return 2 end @@ -275,6 +282,10 @@ function _M.endBattleRpc(agent, data) red:trim(dbKey, 0, 9) end end) + + if isWin then + role:checkTaskEnter("PvpWin", {score = myScore}) + end SendPacket(actionCodes.Pvp_endBattleRpc, MsgPack.pack({ reward = reward, @@ -301,13 +312,13 @@ function _M.rankListRpc(agent, data) red:zrevrank(RANK_PVP_COMMON, roleId) red:zrevrange(RANK_PVP_COMMON, 0, 99, "WITHSCORES") end) - local score = tonumber(redret[1] or 0) + local score = role:unpackPvpScore(redret[1] or 0) local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp local rankList = {} for i = 1, #redret[3], 2 do local roleId = tonumber(redret[i]) - local score = tonumber(redret[i + 1]) + local score = role:unpackPvpScore(redret[i + 1]) local online, curInfo = rpcRole(roleId, "friendSInfo") curInfo.score = score curInfo.roleId = roleId @@ -345,7 +356,7 @@ function _M.recordListRpc(agent, data) end _pvpRecordInfoCache = tempList - recordList = getMatchInfo(tempList, _pvpRecordBattleInfoCache) + recordList = getMatchInfo(role, tempList, _pvpRecordBattleInfoCache) for idx, info in ipairs(recordList) do local temp = tempList[idx] info.win = temp.win diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 5d2fdb4..8c53ae9 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -835,18 +835,19 @@ function RolePlugin.bind(Role) end function Role:getTeamBattleValue(heros) - local battleV = 0 - for _, heroId in pairs(heros or {}) do - local hero = self.heros[heroId] - battleV = battleV + hero:getProperty("battleV") - end - return battleV + -- local battleV = 0 + -- for _, heroId in pairs(heros or {}) do + -- local hero = self.heros[heroId] + -- battleV = battleV + hero:getProperty("battleV") + -- end + -- return battleV + return self:getRealBattleValue(heros) end -- 不传参数 只修改保存的阵容信息 function Role:saveHangTeam(team) if not team then - team = self:getProperty("pvpTSC") + team = self:getProperty("hangTeam") else self:updateProperty({field = "hangTeam", value = team}) end @@ -859,9 +860,9 @@ function RolePlugin.bind(Role) function Role:savePvpCTeam(team) if not team then - team = self:getProperty("pvpTSC") + team = self:getProperty("pvpTC") else - self:updateProperty({field = "pvpTSC", value = team}) + self:updateProperty({field = "pvpTC", value = team}) end self:setProperties({ pvpTSC = self:getTeamHerosInfo(team.heros), diff --git a/src/models/RolePvp.lua b/src/models/RolePvp.lua index fd2d3d6..6f48377 100644 --- a/src/models/RolePvp.lua +++ b/src/models/RolePvp.lua @@ -8,17 +8,17 @@ local PVP_RANK_TIME_SORT_PLACE = 1000000 -- 时间戳占据 6位数 local PVP_RANK_TIME_SORT_PRECISION = 360 -- 时间精度 每6分钟忽略差异 local PVP_RANK_ROBOT_SCORE = 1000 -- 机器人积分 -local function unpackScore(score) + +function Role:unpackPvpScore(score) score = tonumber(score or 0) return math.floor(score / PVP_RANK_TIME_SORT_PLACE) end -local function packScore(score, now) +function Role:packPvpScore(score, now) 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 - function Role:changePvpScoreCommon(matchId, isWin) local roleId = self:getProperty("id") local isPlayer = matchId ~= -1 @@ -29,11 +29,11 @@ function Role:changePvpScoreCommon(matchId, isWin) red:zscore(RANK_PVP_COMMON, matchId) end end) - local myScore = unpackScore(redret[1]) + local myScore = self:unpackPvpScore(redret[1]) local oldMyRank = tonumber(redret[2] or -2) + 1 local matchScore = PVP_RANK_ROBOT_SCORE if isPlayer then - matchScore = unpackScore(redret[3]) + matchScore = self:unpackPvpScore(redret[3]) end local oldmyScore, oldMatchScore = myScore, matchScore @@ -52,9 +52,9 @@ function Role:changePvpScoreCommon(matchId, isWin) local now = skynet.timex() redisproxy:pipelining(function(red) - red:zadd(RANK_PVP_COMMON, packScore(myScore, now), roleId) + red:zadd(RANK_PVP_COMMON, self:packPvpScore(myScore, now), roleId) if isPlayer then - red:zadd(RANK_PVP_COMMON, packScore(matchScore, now), matchId) + red:zadd(RANK_PVP_COMMON, self:packPvpScore(matchScore, now), matchId) end red:zrevrank(RANK_PVP_COMMON, roleId) end) @@ -70,7 +70,7 @@ end function Role:refreshPvpMatchC(score) local roleId = self:getProperty("id") - local score = score or redisproxy:zscore(RANK_PVP_COMMON, roleId) or 0 + local score = score or self:unpackPvpScore(redisproxy:zscore(RANK_PVP_COMMON, roleId)) local function getPlayers(levels) local redret = redisproxy:pipelining(function(red) diff --git a/src/models/RoleTask.lua b/src/models/RoleTask.lua index 9f8ae73..87f88c6 100644 --- a/src/models/RoleTask.lua +++ b/src/models/RoleTask.lua @@ -65,22 +65,25 @@ local TaskType = { OpenBox = 702, -- 拆解时间箱 + -- pvp相关 + PvpWin = 751, -- pvp胜利 - score + PvpBattle = 752, -- pvp挑战 + + --好友相关 + GiveFriendP = 801, -- 赠送友情点 - count + AddFriend = 802, -- 加入一个好友 - count + GetFriendP = 803, -- 获得友情点 - count + --功能未实现 todo - PvpWin = 1000, -- pvp胜利 - score - PvpBattle = 1001, -- pvp挑战 AdvShop = 1002, -- 冒险商城 - GiveFriendP = 1003, -- 赠送友情点 UnionBoss = 1004, -- 工会boss UnionBattle = 1005, -- 工会战 AddUnion = 1006, -- 加入一个公会 - AddFriend = 1007, -- 加入一个好友 - count BindPhone = 1008, -- 绑定手机 WeChat = 1009, -- 关注微信 WeBlog = 1010, -- 关注微博 SignIn = 1011, -- 签到 - GetFriendP = 1012, -- 获得友情点 - count ShopAll = 1013, -- 在任意商店购买 - } local function v(value) @@ -126,7 +129,7 @@ local CommonListener = { [TaskType.HeroLevelUp] = {{v(17)}}, [TaskType.Wake] = {{v(18)}}, [TaskType.EquipUp] = {{v(19), f("count")}}, - [TaskType.GiveFriendP] = {{v(20)}}, + [TaskType.GiveFriendP] = {{v(20), f("count")}}, [TaskType.UnionBoss] = {{v(21)}}, [TaskType.GetFriendP] = {{v(22), f("count")}}, [TaskType.BonusPass] = {{v(23)}}, -- libgit2 0.21.2