Commit c581c6e9c49c39ced131baf5e327a21e2b3df88d

Authored by zhouhaihai
1 parent b2e41074

pvp 优化

src/actions/PvpAction.lua
... ... @@ -961,11 +961,11 @@ function _M.crossBetRpc(agent, data)
961 961 local roleId = role:getProperty("id")
962 962 local msg = MsgPack.unpack(data)
963 963  
964   - if not role:isTimeResetOpen(TimeReset.PvpCross) then return end
965   - if msg.idx ~= 1 and msg.idx ~= 2 then return end
  964 + if not role:isTimeResetOpen(TimeReset.PvpCross) then return 1 end
  965 + if msg.idx ~= 1 and msg.idx ~= 2 then return 2 end
966 966  
967   - local result = role:setCrossServerPvpBet(msg.idx)
968   - if not result then return end
  967 + local result, code = role:setCrossServerPvpBet(msg.idx)
  968 + if not result then return 10 + code end
969 969  
970 970 role:log("pvp_action", {desc = "crossBet"})
971 971 SendPacket(actionCodes.Pvp_crossBetRpc, MsgPack.pack(result))
... ...
src/models/RolePvp.lua
... ... @@ -468,31 +468,33 @@ function Role:getCrossServerPvpBetInfo()
468 468 end
469 469  
470 470 function Role:setCrossServerPvpBet(idx)
471   - if not self:isTimeResetOpen(TimeReset.PvpCross) then return end
  471 + if not self:isTimeResetOpen(TimeReset.PvpCross) then return false , 1 end
472 472 local crossTime = skynet.timex() - self:getTimeResetStartTime(TimeReset.PvpCross)
473 473 local aday = 3600 * 24
474 474 local day = math.ceil(crossTime / aday) -- 当前是第几个比赛日
475 475 local ctime = crossTime % aday -- 当前在本天 经过多少时间
476 476  
477 477 if day > globalCsv.pvp_cross_server_day or ctime >= globalCsv.pvp_cross_server_stop_stake then
478   - return
  478 + return false , 2
479 479 end
480 480 local pvpBet = self:getProperty("pvpBet")
481   - if pvpBet[day] then return end
  481 + if pvpBet[day] then return false , 3 end
482 482  
483   - local cost = {[ItemId.Gold] = self:getProperty("level") * globalCsv.pvp_cross_bet_pre_level}
484   - if not self:checkItemEnough(cost) then return end
  483 + local costNum = self:getProperty("level") * globalCsv.pvp_cross_bet_pre_level
  484 + local cost = {[ItemId.Gold] = costNum}
  485 + if not self:checkItemEnough(cost) then return false , 4 end
485 486  
486   - local ok, result = pcall(skynet.call, pvpd, "lua", "setBet", idx)
  487 + local ok, result = pcall(skynet.call, pvpd, "lua", "setBet", idx, self:getProperty("id"), costNum)
487 488 if ok then
488 489 if result then
489 490 self:costItems(cost, {log = {desc = "crossPvpBet", short1 = day}})
490 491 pvpBet[day] = {idx, cost[ItemId.Gold]}
491 492 self:setProperty("pvpBet", pvpBet)
492 493 end
493   - return result
  494 + return result, 5
494 495 else
495 496 print(result)
  497 + return false , 6
496 498 end
497 499 end
498 500  
... ...
src/services/pvpd.lua
... ... @@ -208,6 +208,7 @@ function CMD.getBetInfo()
208 208 betInfo[cday] = math.randomInt(1, #(MatchCache[cday] or {1}))
209 209 if cday == lastDay then
210 210 betNum = {}
  211 + redisproxy:del("cross:pvpInfo:bet:" .. cday)
211 212 end
212 213 end
213 214 end
... ... @@ -221,7 +222,7 @@ function CMD.getBetInfo()
221 222 return pvpInfo:getProperties({"betInfo", "betNum"})
222 223 end
223 224  
224   -function CMD.setBet(idx)
  225 +function CMD.setBet(idx, roleId, costNum)
225 226 local day, ctime = getDayAndTime()
226 227 if day > globalCsv.pvp_cross_server_day or ctime >= globalCsv.pvp_cross_server_stop_stake then return end
227 228  
... ... @@ -231,6 +232,8 @@ function CMD.setBet(idx)
231 232 local betNum = pvpInfo:getProperty("betNum")
232 233 betNum[idx] = (betNum[idx] or 0) + 1
233 234 pvpInfo:setProperty("betNum", betNum)
  235 +
  236 + redisproxy:hset("cross:pvpInfo:bet:" .. day, roleId, costNum * 10 + idx)
234 237 return {betNum = betNum}
235 238 end
236 239  
... ...