Commit 4d8bd32c55e9c8dca2cce26b1c6f24e4507ef604

Authored by chenyueqi
1 parent fa565e0c

倒计时开箱子

Showing 1 changed file with 10 additions and 13 deletions   Show diff stats
src/actions/RoleAction.lua
@@ -363,7 +363,7 @@ end @@ -363,7 +363,7 @@ end
363 function _M.openTimeBoxRpc(agent, data) 363 function _M.openTimeBoxRpc(agent, data)
364 local role = agent.role 364 local role = agent.role
365 local msg = MsgPack.unpack(data) 365 local msg = MsgPack.unpack(data)
366 - local oper = msg.oper -- 操作 1 - 3 366 + local oper = msg.oper -- 操作 1 - 2
367 local slot = msg.slot -- 位置 1 - 6 367 local slot = msg.slot -- 位置 1 - 6
368 if math.illegalNum(slot, 1, globalCsv.box_timeOpen_maxNum) then return end 368 if math.illegalNum(slot, 1, globalCsv.box_timeOpen_maxNum) then return end
369 369
@@ -374,25 +374,22 @@ function _M.openTimeBoxRpc(agent, data) @@ -374,25 +374,22 @@ function _M.openTimeBoxRpc(agent, data)
374 if role:getItemCount(itemId) < 1 then return end 374 if role:getItemCount(itemId) < 1 then return end
375 local itemData = csvdb["itemCsv"][itemId] 375 local itemData = csvdb["itemCsv"][itemId]
376 local randomData = csvdb["item_randomCsv"][itemId] 376 local randomData = csvdb["item_randomCsv"][itemId]
377 - if not randomData or randomData.openTime <= 0 then return end 377 + if not itemData or not randomData or randomData.openTime <= 0 then return end
378 378
379 if boxL[slot] then return end 379 if boxL[slot] then return end
380 role:costItems({[itemId] = 1}) 380 role:costItems({[itemId] = 1})
381 boxL[slot] = {id = itemId, time = skynet.timex() + randomData.openTime} 381 boxL[slot] = {id = itemId, time = skynet.timex() + randomData.openTime}
382 382
383 - elseif oper == 2 then -- 上宝石 383 + -- 上宝石
384 local gemId = msg.gem or 0 384 local gemId = msg.gem or 0
385 - if not boxL[slot] then return end  
386 - if boxL[slot].gem or boxL[slot].time <= skynet.timex() then return end  
387 - local itemData = csvdb["itemCsv"][boxL[slot].id]  
388 - local randomData = csvdb["item_randomCsv"][itemId]  
389 local num = randomData[gemId .. "_gem_num"] 385 local num = randomData[gemId .. "_gem_num"]
390 - if not num then return end 386 + if num then
  387 + if not role:checkItemEnough({[gemId] = 1}) then return end
  388 + role:costItems({[gemId] = 1})
  389 + end
391 390
392 - if not role:checkItemEnough({[gemId] = 1}) then return end  
393 - role:costItems({[gemId] = 1})  
394 boxL[slot].gem = gemId 391 boxL[slot].gem = gemId
395 - elseif oper == 3 then -- 领取 392 + elseif oper == 2 then -- 领取
396 local quick = msg.quick 393 local quick = msg.quick
397 if not boxL[slot] then return end 394 if not boxL[slot] then return end
398 if boxL[slot].time > skynet.timex() then -- 没开完 395 if boxL[slot].time > skynet.timex() then -- 没开完
@@ -404,12 +401,12 @@ function _M.openTimeBoxRpc(agent, data) @@ -404,12 +401,12 @@ function _M.openTimeBoxRpc(agent, data)
404 end 401 end
405 402
406 local itemData = csvdb["itemCsv"][boxL[slot].id] 403 local itemData = csvdb["itemCsv"][boxL[slot].id]
407 - local randomData = csvdb["item_randomCsv"][itemId] 404 + local randomData = csvdb["item_randomCsv"][itemData.id]
408 reward = randomData.gift:toNumMap() -- 固定奖励 405 reward = randomData.gift:toNumMap() -- 固定奖励
409 -- 随机奖励 406 -- 随机奖励
410 local randomGift = randomData.random_gift 407 local randomGift = randomData.random_gift
411 local randomNum = randomData.random_num 408 local randomNum = randomData.random_num
412 - if boxL[slot].gem then 409 + if boxL[slot].gem ~= 0 then
413 randomNum = randomData[boxL[slot].gem .. "_gem_num"] 410 randomNum = randomData[boxL[slot].gem .. "_gem_num"]
414 randomGift = randomData[boxL[slot].gem .. "_gem_gift"] 411 randomGift = randomData[boxL[slot].gem .. "_gem_gift"]
415 end 412 end