Commit c581c6e9c49c39ced131baf5e327a21e2b3df88d
1 parent
b2e41074
pvp 优化
Showing
3 changed files
with
17 additions
and
12 deletions
Show diff stats
src/actions/PvpAction.lua
@@ -961,11 +961,11 @@ function _M.crossBetRpc(agent, data) | @@ -961,11 +961,11 @@ function _M.crossBetRpc(agent, data) | ||
961 | local roleId = role:getProperty("id") | 961 | local roleId = role:getProperty("id") |
962 | local msg = MsgPack.unpack(data) | 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 | role:log("pvp_action", {desc = "crossBet"}) | 970 | role:log("pvp_action", {desc = "crossBet"}) |
971 | SendPacket(actionCodes.Pvp_crossBetRpc, MsgPack.pack(result)) | 971 | SendPacket(actionCodes.Pvp_crossBetRpc, MsgPack.pack(result)) |
src/models/RolePvp.lua
@@ -468,31 +468,33 @@ function Role:getCrossServerPvpBetInfo() | @@ -468,31 +468,33 @@ function Role:getCrossServerPvpBetInfo() | ||
468 | end | 468 | end |
469 | 469 | ||
470 | function Role:setCrossServerPvpBet(idx) | 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 | local crossTime = skynet.timex() - self:getTimeResetStartTime(TimeReset.PvpCross) | 472 | local crossTime = skynet.timex() - self:getTimeResetStartTime(TimeReset.PvpCross) |
473 | local aday = 3600 * 24 | 473 | local aday = 3600 * 24 |
474 | local day = math.ceil(crossTime / aday) -- 当前是第几个比赛日 | 474 | local day = math.ceil(crossTime / aday) -- 当前是第几个比赛日 |
475 | local ctime = crossTime % aday -- 当前在本天 经过多少时间 | 475 | local ctime = crossTime % aday -- 当前在本天 经过多少时间 |
476 | 476 | ||
477 | if day > globalCsv.pvp_cross_server_day or ctime >= globalCsv.pvp_cross_server_stop_stake then | 477 | if day > globalCsv.pvp_cross_server_day or ctime >= globalCsv.pvp_cross_server_stop_stake then |
478 | - return | 478 | + return false , 2 |
479 | end | 479 | end |
480 | local pvpBet = self:getProperty("pvpBet") | 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 | if ok then | 488 | if ok then |
488 | if result then | 489 | if result then |
489 | self:costItems(cost, {log = {desc = "crossPvpBet", short1 = day}}) | 490 | self:costItems(cost, {log = {desc = "crossPvpBet", short1 = day}}) |
490 | pvpBet[day] = {idx, cost[ItemId.Gold]} | 491 | pvpBet[day] = {idx, cost[ItemId.Gold]} |
491 | self:setProperty("pvpBet", pvpBet) | 492 | self:setProperty("pvpBet", pvpBet) |
492 | end | 493 | end |
493 | - return result | 494 | + return result, 5 |
494 | else | 495 | else |
495 | print(result) | 496 | print(result) |
497 | + return false , 6 | ||
496 | end | 498 | end |
497 | end | 499 | end |
498 | 500 |
src/services/pvpd.lua
@@ -208,6 +208,7 @@ function CMD.getBetInfo() | @@ -208,6 +208,7 @@ function CMD.getBetInfo() | ||
208 | betInfo[cday] = math.randomInt(1, #(MatchCache[cday] or {1})) | 208 | betInfo[cday] = math.randomInt(1, #(MatchCache[cday] or {1})) |
209 | if cday == lastDay then | 209 | if cday == lastDay then |
210 | betNum = {} | 210 | betNum = {} |
211 | + redisproxy:del("cross:pvpInfo:bet:" .. cday) | ||
211 | end | 212 | end |
212 | end | 213 | end |
213 | end | 214 | end |
@@ -221,7 +222,7 @@ function CMD.getBetInfo() | @@ -221,7 +222,7 @@ function CMD.getBetInfo() | ||
221 | return pvpInfo:getProperties({"betInfo", "betNum"}) | 222 | return pvpInfo:getProperties({"betInfo", "betNum"}) |
222 | end | 223 | end |
223 | 224 | ||
224 | -function CMD.setBet(idx) | 225 | +function CMD.setBet(idx, roleId, costNum) |
225 | local day, ctime = getDayAndTime() | 226 | local day, ctime = getDayAndTime() |
226 | if day > globalCsv.pvp_cross_server_day or ctime >= globalCsv.pvp_cross_server_stop_stake then return end | 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,6 +232,8 @@ function CMD.setBet(idx) | ||
231 | local betNum = pvpInfo:getProperty("betNum") | 232 | local betNum = pvpInfo:getProperty("betNum") |
232 | betNum[idx] = (betNum[idx] or 0) + 1 | 233 | betNum[idx] = (betNum[idx] or 0) + 1 |
233 | pvpInfo:setProperty("betNum", betNum) | 234 | pvpInfo:setProperty("betNum", betNum) |
235 | + | ||
236 | + redisproxy:hset("cross:pvpInfo:bet:" .. day, roleId, costNum * 10 + idx) | ||
234 | return {betNum = betNum} | 237 | return {betNum = betNum} |
235 | end | 238 | end |
236 | 239 |