Commit 3dbbc9f35e0c5d2fd897cff7815ef9c6350b7dfe

Authored by zhouhaihai
1 parent 85083dba

加上新的任务

src/actions/FriendAction.lua
... ... @@ -378,6 +378,7 @@ function _M.listRpc(agent, data)
378 378 end
379 379 if next(clearRed) then
380 380 redisproxy:hmset(FRIEND_KEY:format(roleId), table_unpack(clearRed)) --清除新好友标记
  381 + role:checkTaskEnter("AddFriend", {count = #friendList})
381 382 end
382 383  
383 384 SendPacket(actionCodes.Friend_listRpc, MsgPack.pack({list = friendList}))
... ... @@ -518,6 +519,7 @@ function _M.pointRpc(agent, data)
518 519 redisproxy:sadd(FRIEND_POINT:format(objId), roleId)
519 520 giveP[objId] = 1
520 521 role.dailyData:updateProperty({field = "giveFP", value = giveP})
  522 + role:checkTaskEnter("GiveFriendP", {count = 1})
521 523 rpcRole(objId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({newPoint = 1, roleId = roleId}))
522 524 end
523 525 elseif cmd == 2 then -- 领取
... ... @@ -536,25 +538,27 @@ function _M.pointRpc(agent, data)
536 538 getP[objId] = 1
537 539 reward = role:award({[ItemId.FriendPoint] = 1})
538 540 role.dailyData:updateProperty({field = "getFP", value = getP})
  541 + role:checkTaskEnter("GetFriendP", {count = 1})
539 542 end
540 543 elseif cmd == 3 then -- 一键赠送领取
541 544 -- 赠送
542 545 local giveP = role.dailyData:getProperty("giveFP")
543 546 local friends = redisproxy:hgetall(FRIEND_KEY:format(roleId))
544   - local change = false
  547 + local change = 0
545 548 redisproxy:pipelining(function(red)
546 549 for i = 1, #friends , 2 do
547 550 local objId = tonumber(friends[i])
548 551 if not giveP[objId] then
549 552 giveP[objId] = 1
550   - change = true
  553 + change = change + 1
551 554 red:sadd(FRIEND_POINT:format(objId), roleId)
552 555 rpcRole(objId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({newPoint = 1, roleId = roleId}))
553 556 end
554 557 end
555 558 end)
556   - if change then
  559 + if change > 0 then
557 560 role.dailyData:updateProperty({field = "giveFP", value = giveP})
  561 + role:checkTaskEnter("GiveFriendP", {count = change})
558 562 else
559 563 result = 1
560 564 end
... ... @@ -578,6 +582,7 @@ function _M.pointRpc(agent, data)
578 582 if getCount > 0 then
579 583 reward = role:award({[ItemId.FriendPoint] = getCount})
580 584 role.dailyData:updateProperty({field = "getFP", value = getP})
  585 + role:checkTaskEnter("GetFriendP", {count = getCount})
581 586 else
582 587 result = (result or 0) + 2
583 588 end
... ...
src/actions/PvpAction.lua
... ... @@ -22,12 +22,12 @@ function _M.formatCommonRpc(agent , data)
22 22 local roleId = role:getProperty("id")
23 23 local msg = MsgPack.unpack(data)
24 24 local pvpTC = role:getProperty("pvpTC")
25   - for slot, heroId in pairs(msg.heros) do
  25 + for slot, heroId in pairs(msg.heros or {}) do
26 26 if not role.heros[heroId] then
27 27 return
28 28 end
29 29 end
30   - if not next(msg.heros) then
  30 + if not msg.heros or not next(msg.heros) then
31 31 return
32 32 end
33 33  
... ... @@ -44,7 +44,7 @@ function _M.formatCommonRpc(agent , data)
44 44 end
45 45  
46 46  
47   -local function getMatchInfo(pvpList, battleCache)
  47 +local function getMatchInfo(role, pvpList, battleCache)
48 48 table.clear(battleCache)
49 49 local redret = redisproxy:pipelining(function(red)
50 50 for _, info in ipairs(pvpList) do
... ... @@ -60,7 +60,7 @@ local function getMatchInfo(pvpList, battleCache)
60 60 local curInfo = {idx = idx}
61 61 if info.t == 1 then --玩家
62 62 curInfo.roleId = info.id
63   - curInfo.score = tonumber(redret[curIdx] or 0)
  63 + curInfo.score = role:unpackPvpScore(redret[curIdx] or 0)
64 64 curIdx = curIdx + 1
65 65 -- name, level, headId, battleV, heros
66 66 local online, roleInfo = rpcRole(curInfo.roleId, "pvpCInfo")
... ... @@ -92,7 +92,7 @@ function _M.infoRpc(agent, data)
92 92 red:zscore(RANK_PVP_COMMON, roleId)
93 93 red:zrevrank(RANK_PVP_COMMON, roleId)
94 94 end)
95   - local score = tonumber(redret[1] or 0)
  95 + local score = role:unpackPvpScore(redret[1] or 0)
96 96 local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp
97 97 local pvpMC = role:getProperty("pvpMC")
98 98 if not next(pvpMC) then --没有分配过对手
... ... @@ -103,7 +103,7 @@ function _M.infoRpc(agent, data)
103 103  
104 104 response.score = score
105 105 response.rank = rank
106   - response.matches = getMatchInfo(pvpMC, _pvpBattleInfoCacheC)
  106 + response.matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC)
107 107  
108 108 elseif ptype == 2 then -- 高级pvp
109 109 return
... ... @@ -120,7 +120,7 @@ function _M.refreshMatchCRpc(agent, data)
120 120 role:refreshPvpMatchC()
121 121  
122 122 local pvpMC = role:getProperty("pvpMC")
123   - local matches = getMatchInfo(pvpMC, _pvpBattleInfoCacheC)
  123 + local matches = getMatchInfo(role, pvpMC, _pvpBattleInfoCacheC)
124 124  
125 125 SendPacket(actionCodes.Pvp_refreshMatchCRpc, MsgPack.pack({matches = matches}))
126 126 return true
... ... @@ -151,11 +151,15 @@ function _M.startBattleRpc(agent, data)
151 151 local idx = msg.idx
152 152 local revenge = msg.revenge
153 153  
  154 + local pvpTC = role:getProperty("pvpTC")
  155 + if not pvpTC.heros or not next(pvpTC.heros) then return 1 end
  156 +
154 157 local matchInfo, result, key, wait
  158 +
155 159 local now = skynet.timex()
156 160 if revenge then --复仇
157 161 local temp = _pvpRecordInfoCache[idx]
158   - if not temp then return end
  162 + if not temp then return 2 end
159 163  
160 164 if not _responseRecord[temp.id] or now >= _responseRecord[temp.id] then
161 165 if temp.t == 1 then
... ... @@ -169,7 +173,7 @@ function _M.startBattleRpc(agent, data)
169 173 end
170 174 else --打正常
171 175 local pvpMC = role:getProperty("pvpMC")
172   - if not pvpMC[idx] then return end
  176 + if not pvpMC[idx] then return 3 end
173 177 if pvpMC[idx].t == 1 then
174 178 matchInfo = _pvpBattleInfoCacheC[pvpMC[idx].id]
175 179 elseif pvpMC[idx].t == 2 then
... ... @@ -177,14 +181,14 @@ function _M.startBattleRpc(agent, data)
177 181 end
178 182 end
179 183  
180   - if not result and not matchInfo then return end
  184 + if not result and not matchInfo then return 4 end
181 185  
182 186 if not result then
183 187 -- 次数扣一波
184 188 local pvpFree = role.dailyData:getProperty("pvpFree")
185 189 if pvpFree >= globalCsv.pvp_battle_free_count then
186 190 local cost = {[ItemId.PvpKey] = 1}
187   - if not role:checkItemEnough(cost) then return end
  191 + if not role:checkItemEnough(cost) then return 5 end
188 192 role:costItems(cost)
189 193 else
190 194 role.dailyData:updateProperty({field = "pvpFree", delta = 1})
... ... @@ -192,6 +196,8 @@ function _M.startBattleRpc(agent, data)
192 196  
193 197 key = tostring(math.random())
194 198 _pvpStartBattleCache = {idx = idx, key = key, revenge = revenge}
  199 +
  200 + role:checkTaskEnter("PvpBattle")
195 201 end
196 202  
197 203 SendPacket(actionCodes.Pvp_startBattleRpc, MsgPack.pack({matchInfo = matchInfo, key = key, result = result, wait = wait}))
... ... @@ -206,7 +212,8 @@ function _M.endBattleRpc(agent, data)
206 212 if not msg.key or not _pvpStartBattleCache or msg.key ~= _pvpStartBattleCache.key then
207 213 return 1
208 214 end
209   - if not msg.idx or not msg.idx ~= _pvpStartBattleCache.idx then
  215 +
  216 + if not msg.idx or msg.idx ~= _pvpStartBattleCache.idx then
210 217 return 2
211 218 end
212 219  
... ... @@ -275,6 +282,10 @@ function _M.endBattleRpc(agent, data)
275 282 red:trim(dbKey, 0, 9)
276 283 end
277 284 end)
  285 +
  286 + if isWin then
  287 + role:checkTaskEnter("PvpWin", {score = myScore})
  288 + end
278 289  
279 290 SendPacket(actionCodes.Pvp_endBattleRpc, MsgPack.pack({
280 291 reward = reward,
... ... @@ -301,13 +312,13 @@ function _M.rankListRpc(agent, data)
301 312 red:zrevrank(RANK_PVP_COMMON, roleId)
302 313 red:zrevrange(RANK_PVP_COMMON, 0, 99, "WITHSCORES")
303 314 end)
304   - local score = tonumber(redret[1] or 0)
  315 + local score = role:unpackPvpScore(redret[1] or 0)
305 316 local rank = tonumber(redret[2] or -2) + 1 --排名 1 - ... -1 未上榜 没打过pvp
306 317  
307 318 local rankList = {}
308 319 for i = 1, #redret[3], 2 do
309 320 local roleId = tonumber(redret[i])
310   - local score = tonumber(redret[i + 1])
  321 + local score = role:unpackPvpScore(redret[i + 1])
311 322 local online, curInfo = rpcRole(roleId, "friendSInfo")
312 323 curInfo.score = score
313 324 curInfo.roleId = roleId
... ... @@ -345,7 +356,7 @@ function _M.recordListRpc(agent, data)
345 356 end
346 357 _pvpRecordInfoCache = tempList
347 358  
348   - recordList = getMatchInfo(tempList, _pvpRecordBattleInfoCache)
  359 + recordList = getMatchInfo(role, tempList, _pvpRecordBattleInfoCache)
349 360 for idx, info in ipairs(recordList) do
350 361 local temp = tempList[idx]
351 362 info.win = temp.win
... ...
src/models/RolePlugin.lua
... ... @@ -835,18 +835,19 @@ function RolePlugin.bind(Role)
835 835 end
836 836  
837 837 function Role:getTeamBattleValue(heros)
838   - local battleV = 0
839   - for _, heroId in pairs(heros or {}) do
840   - local hero = self.heros[heroId]
841   - battleV = battleV + hero:getProperty("battleV")
842   - end
843   - return battleV
  838 + -- local battleV = 0
  839 + -- for _, heroId in pairs(heros or {}) do
  840 + -- local hero = self.heros[heroId]
  841 + -- battleV = battleV + hero:getProperty("battleV")
  842 + -- end
  843 + -- return battleV
  844 + return self:getRealBattleValue(heros)
844 845 end
845 846  
846 847 -- 不传参数 只修改保存的阵容信息
847 848 function Role:saveHangTeam(team)
848 849 if not team then
849   - team = self:getProperty("pvpTSC")
  850 + team = self:getProperty("hangTeam")
850 851 else
851 852 self:updateProperty({field = "hangTeam", value = team})
852 853 end
... ... @@ -859,9 +860,9 @@ function RolePlugin.bind(Role)
859 860  
860 861 function Role:savePvpCTeam(team)
861 862 if not team then
862   - team = self:getProperty("pvpTSC")
  863 + team = self:getProperty("pvpTC")
863 864 else
864   - self:updateProperty({field = "pvpTSC", value = team})
  865 + self:updateProperty({field = "pvpTC", value = team})
865 866 end
866 867 self:setProperties({
867 868 pvpTSC = self:getTeamHerosInfo(team.heros),
... ...
src/models/RolePvp.lua
... ... @@ -8,17 +8,17 @@ local PVP_RANK_TIME_SORT_PLACE = 1000000 -- 时间戳占据 6位数
8 8 local PVP_RANK_TIME_SORT_PRECISION = 360 -- 时间精度 每6分钟忽略差异
9 9 local PVP_RANK_ROBOT_SCORE = 1000 -- 机器人积分
10 10  
11   -local function unpackScore(score)
  11 +
  12 +function Role:unpackPvpScore(score)
12 13 score = tonumber(score or 0)
13 14 return math.floor(score / PVP_RANK_TIME_SORT_PLACE)
14 15 end
15 16  
16   -local function packScore(score, now)
  17 +function Role:packPvpScore(score, now)
17 18 now = now or skynet.timex()
18 19 return math.floor(score * PVP_RANK_TIME_SORT_PLACE + (PVP_RANK_TIME_SORT_STD - now) / PVP_RANK_TIME_SORT_PRECISION)
19 20 end
20 21  
21   -
22 22 function Role:changePvpScoreCommon(matchId, isWin)
23 23 local roleId = self:getProperty("id")
24 24 local isPlayer = matchId ~= -1
... ... @@ -29,11 +29,11 @@ function Role:changePvpScoreCommon(matchId, isWin)
29 29 red:zscore(RANK_PVP_COMMON, matchId)
30 30 end
31 31 end)
32   - local myScore = unpackScore(redret[1])
  32 + local myScore = self:unpackPvpScore(redret[1])
33 33 local oldMyRank = tonumber(redret[2] or -2) + 1
34 34 local matchScore = PVP_RANK_ROBOT_SCORE
35 35 if isPlayer then
36   - matchScore = unpackScore(redret[3])
  36 + matchScore = self:unpackPvpScore(redret[3])
37 37 end
38 38 local oldmyScore, oldMatchScore = myScore, matchScore
39 39  
... ... @@ -52,9 +52,9 @@ function Role:changePvpScoreCommon(matchId, isWin)
52 52  
53 53 local now = skynet.timex()
54 54 redisproxy:pipelining(function(red)
55   - red:zadd(RANK_PVP_COMMON, packScore(myScore, now), roleId)
  55 + red:zadd(RANK_PVP_COMMON, self:packPvpScore(myScore, now), roleId)
56 56 if isPlayer then
57   - red:zadd(RANK_PVP_COMMON, packScore(matchScore, now), matchId)
  57 + red:zadd(RANK_PVP_COMMON, self:packPvpScore(matchScore, now), matchId)
58 58 end
59 59 red:zrevrank(RANK_PVP_COMMON, roleId)
60 60 end)
... ... @@ -70,7 +70,7 @@ end
70 70  
71 71 function Role:refreshPvpMatchC(score)
72 72 local roleId = self:getProperty("id")
73   - local score = score or redisproxy:zscore(RANK_PVP_COMMON, roleId) or 0
  73 + local score = score or self:unpackPvpScore(redisproxy:zscore(RANK_PVP_COMMON, roleId))
74 74  
75 75 local function getPlayers(levels)
76 76 local redret = redisproxy:pipelining(function(red)
... ...
src/models/RoleTask.lua
... ... @@ -65,22 +65,25 @@ local TaskType = {
65 65 OpenBox = 702, -- 拆解时间箱
66 66  
67 67  
  68 + -- pvp相关
  69 + PvpWin = 751, -- pvp胜利 - score
  70 + PvpBattle = 752, -- pvp挑战
  71 +
  72 + --好友相关
  73 + GiveFriendP = 801, -- 赠送友情点 - count
  74 + AddFriend = 802, -- 加入一个好友 - count
  75 + GetFriendP = 803, -- 获得友情点 - count
  76 +
68 77 --功能未实现 todo
69   - PvpWin = 1000, -- pvp胜利 - score
70   - PvpBattle = 1001, -- pvp挑战
71 78 AdvShop = 1002, -- 冒险商城
72   - GiveFriendP = 1003, -- 赠送友情点
73 79 UnionBoss = 1004, -- 工会boss
74 80 UnionBattle = 1005, -- 工会战
75 81 AddUnion = 1006, -- 加入一个公会
76   - AddFriend = 1007, -- 加入一个好友 - count
77 82 BindPhone = 1008, -- 绑定手机
78 83 WeChat = 1009, -- 关注微信
79 84 WeBlog = 1010, -- 关注微博
80 85 SignIn = 1011, -- 签到
81   - GetFriendP = 1012, -- 获得友情点 - count
82 86 ShopAll = 1013, -- 在任意商店购买
83   -
84 87 }
85 88  
86 89 local function v(value)
... ... @@ -126,7 +129,7 @@ local CommonListener = {
126 129 [TaskType.HeroLevelUp] = {{v(17)}},
127 130 [TaskType.Wake] = {{v(18)}},
128 131 [TaskType.EquipUp] = {{v(19), f("count")}},
129   - [TaskType.GiveFriendP] = {{v(20)}},
  132 + [TaskType.GiveFriendP] = {{v(20), f("count")}},
130 133 [TaskType.UnionBoss] = {{v(21)}},
131 134 [TaskType.GetFriendP] = {{v(22), f("count")}},
132 135 [TaskType.BonusPass] = {{v(23)}},
... ...