Commit 0a093ba8c1349c426d6a76448e012e053bdaf39a

Authored by chenyueqi
1 parent 14f57eed

重写拆解室功能

@@ -134,7 +134,6 @@ ItemId = { @@ -134,7 +134,6 @@ ItemId = {
134 RuneFragment = 24, 134 RuneFragment = 24,
135 HeroFC = {700, 701, 702, 703}, --通用角色碎片 135 HeroFC = {700, 701, 702, 703}, --通用角色碎片
136 AdvKey = 80, -- 冒险钥匙 136 AdvKey = 80, -- 冒险钥匙
137 - BoxKey = 60, -- 拆解工具  
138 AdvPower = 4701, -- 拾荒体力 137 AdvPower = 4701, -- 拾荒体力
139 CrisisScore = 8010, -- 积分 138 CrisisScore = 8010, -- 积分
140 } 139 }
src/actions/RoleAction.lua
@@ -537,82 +537,129 @@ function _M.openTimeBoxRpc(agent, data) @@ -537,82 +537,129 @@ function _M.openTimeBoxRpc(agent, data)
537 local slot = msg.slot -- 位置 1 - 6 537 local slot = msg.slot -- 位置 1 - 6
538 538
539 -- 特权卡时间箱额外栏位 539 -- 特权卡时间箱额外栏位
540 - local privExtraCnt = role.storeData:getTimeBoxSlotExtraCount()  
541 - if oper == 1 then  
542 - if math.illegalNum(slot, 1, role:getFuncLv(FuncOpenType.TimeBoxSlot) + privExtraCnt) then return end  
543 - end 540 + -- local privExtraCnt = role.storeData:getTimeBoxSlotExtraCount()
  541 + -- if oper == 1 then
  542 + -- if math.illegalNum(slot, 1, role:getFuncLv(FuncOpenType.TimeBoxSlot) + privExtraCnt) then return end
  543 + -- end
544 544
545 local boxL = role:getProperty("boxL") 545 local boxL = role:getProperty("boxL")
546 - local reward, change = {}  
547 - if oper == 1 then -- 打开 546 + local reward, change
  547 + if oper == 1 then -- 构建开始(包括切换构建的id)
548 local itemId = msg.itemId 548 local itemId = msg.itemId
549 - if role:getItemCount(itemId) < 1 then return end  
550 local itemData = csvdb["itemCsv"][itemId] 549 local itemData = csvdb["itemCsv"][itemId]
551 - local randomData = csvdb["item_randomCsv"][itemId]  
552 - if not itemData or not randomData or randomData.openTime <= 0 then return end  
553 -  
554 - if boxL[slot] then return end  
555 - role:costItems({[itemId] = 1}, {log = {desc = "openTimeBox"}})  
556 - boxL[slot] = {id = itemId, time = skynet.timex() + randomData.openTime}  
557 - role:pushMsg({type = "box", slot = slot, time = randomData.openTime})  
558 - elseif oper == 2 then -- 领取 550 + if not itemData then return 1 end
  551 + if not boxL[slot] then
  552 + boxL[slot] = {}
  553 + else
  554 + local oldId, process, time = boxL[slot].id, boxL[slot].process, boxL[slot].time
  555 + local unitTime = globalCsv.box_key_time[oldId] * 60
  556 + local doneCnt = math.floor((process + skynet.timex() - time) / unitTime)
  557 + if doneCnt > 0 then
  558 + reward = role:award({[oldId] = doneCnt}, {log = {desc = "openTimeBox", int1 = slot}})
  559 + end
  560 + end
  561 + local limit = globalCsv.box_key_max[itemId] or 5
  562 + if role:getItemCount(itemId) >= limit then return 3 end
  563 +
  564 + boxL[slot] = {id = itemId, process = 0, time = skynet.timex()}
  565 + role:pushMsg({type = "box", slot = slot, time = skynet.timex() + globalCsv.box_productLine_time * 3600})
  566 + elseif oper == 2 then -- 重置运行时间(可以使用加速)
559 local quick = msg.quick 567 local quick = msg.quick
560 - if not boxL[slot] then return end  
561 - local costKey = 0  
562 - if boxL[slot].time > skynet.timex() then -- 没开完  
563 - if not quick then return end 568 + if not boxL[slot] then return 4 end
  569 +
  570 + local itemId, process, time = boxL[slot].id, boxL[slot].process, boxL[slot].time
  571 + local nowTime = skynet.timex()
  572 + local stopTime = nowTime
  573 + local itemData = csvdb["itemCsv"][itemId]
  574 + local unitTime = globalCsv.box_key_time[itemId] * 60
  575 + if quick then
  576 + stopTime = time + globalCsv.box_productLine_time * 3600
564 local cost_pre = globalCsv.box_timeOpen_diamond:toArray(true, "=") 577 local cost_pre = globalCsv.box_timeOpen_diamond:toArray(true, "=")
565 - costKey = math.ceil((boxL[slot].time - skynet.timex()) / (cost_pre[1] * 60)) * cost_pre[2]  
566 - if not role:checkItemEnough({[ItemId.BoxKey] = costKey}) then return end  
567 - role:costItems({[ItemId.BoxKey] = costKey}, {log = {desc = "openTimeBox"}})  
568 - role:pushCancel({type = "box", slot = slot}) 578 + local costKey = math.ceil((stopTime - nowTime) / (cost_pre[1] * 60)) * cost_pre[2]
  579 + if not role:checkItemEnough({[ItemId.Diamond] = costKey}) then return 5 end
  580 + role:costItems({[ItemId.Diamond] = costKey}, {log = {desc = "openTimeBox", int1 = slot}})
569 end 581 end
570 - local boxId = boxL[slot].id  
571 - local itemData = csvdb["itemCsv"][boxId]  
572 - local randomData = csvdb["item_randomCsv"][itemData.id]  
573 - local costTime = skynet.timex() - (boxL[slot].time - randomData.openTime)  
574 - -- 随机奖励 582 + role:pushCancel({type = "box", slot = slot})
  583 +
  584 + local doneCnt = math.floor((process + stopTime - time) / unitTime)
  585 + if doneCnt > 0 then
  586 + reward = role:award({[itemId] = doneCnt}, {log = {desc = "openTimeBox", int1 = slot}})
  587 + end
  588 + if role:getItemCount(itemId) >= globalCsv.box_key_max[itemId] then
  589 + nowTime = 0
  590 + end
  591 +
  592 + boxL[slot] = {id = itemId, process = (process + stopTime - time) % unitTime, time = nowTime}
  593 + role:pushMsg({type = "box", slot = slot, time = nowTime + globalCsv.box_productLine_time * 3600})
  594 + elseif oper == 3 then -- 开箱子
  595 + local costId = msg.costId
  596 + local costs = (msg.costs or ""):toNumMap()
  597 + if not costId or not csvdb["itemCsv"][costId] or not next(costs) then return 6 end
  598 +
  599 + local costIdData = csvdb["itemCsv"][costId]
  600 + local count = 0
  601 + for itemId, num in pairs(costs) do
  602 + local itemIdData = csvdb["itemCsv"][itemId]
  603 + if not itemIdData or not csvdb["item_randomCsv"][itemId] or costIdData.quality ~= itemIdData.quality then return 7 end
  604 + count = count + num
  605 + end
  606 +
  607 + if role:getItemCount(costId) < count then return 8 end
  608 +
  609 + role:costItems({[costId] = count}, {log = {desc = "openTimeBox"}})
  610 +
575 reward = {} 611 reward = {}
576 - for i = 1, 10 do  
577 - local num = randomData["num" .. i]  
578 - local gift = randomData["gift" .. i]  
579 - if num and gift and num > 0 and gift ~= "" then  
580 - local pool = {}  
581 - for _, temp in ipairs(gift:toArray()) do  
582 - local set = temp:toArray(true, "=")  
583 - table.insert(pool, set) 612 + for itemId, value in pairs(costs) do
  613 + local tempReward = {}
  614 + local randomData = csvdb["item_randomCsv"][itemId]
  615 + local itemData = csvdb["itemCsv"][itemId]
  616 + role:costItems({[itemId] = value}, {log = {desc = "openTimeBox"}})
  617 + for _ = 1, value do
  618 + for i = 1, 10 do
  619 + local num = randomData["num" .. i]
  620 + local gift = randomData["gift" .. i]
  621 + if num and gift and num > 0 and gift ~= "" then
  622 + local pool = {}
  623 + for _, temp in ipairs(gift:toArray()) do
  624 + local set = temp:toArray(true, "=")
  625 + table.insert(pool, set)
  626 + end
  627 +
  628 + local needCount = math.min(#pool, num)
  629 + for j = 1, needCount do
  630 + local idx = math.randWeight(pool, 3)
  631 + tempReward[pool[idx][1]] = (tempReward[pool[idx][1]] or 0) + pool[idx][2]
  632 + table.remove(pool, idx)
  633 + end
  634 + end
584 end 635 end
  636 + end
  637 + tempReward[0] = nil
  638 + role:checkTaskEnter("OpenBox", {id = itemId, count=value, quality=itemData.quality})
  639 + role:log("carriage_dismantle", {
  640 + item_id = itemId, -- 道具id
  641 + item_type = itemData.type, -- 道具类型,具体见枚举表中道具类型枚举表
  642 + item_level = 0, -- 道具等级
  643 + item_number = 1, -- 道具变化数量的绝对值
  644 + carriage_dismantle_type = 1, -- 拆解方式,时间到期:0,钥匙开启:1
  645 + carriage_dismantle_time = 0, -- 拆解耗时,填写实际耗时
  646 + carriage_dismantle_cost = value, -- 拆解花费钥匙数量,未使用填写0
  647 + carriage_dismantle_rwd = tempReward, -- 拆解获得物资,json格式记录,{'itemid1':2,'itemid2':3,…………..}
  648 + })
585 649
586 - local needCount = math.min(#pool, num)  
587 - for j = 1, needCount do  
588 - local idx = math.randWeight(pool, 3)  
589 - reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2]  
590 - table.remove(pool, idx)  
591 - end 650 + for id, num in pairs(tempReward) do
  651 + reward[id] = (reward[id] or 0) + num
592 end 652 end
593 end 653 end
594 - reward[0] = nil  
595 -  
596 - boxL[slot] = nil  
597 - reward, change = role:award(reward, {log = {desc = "openTimeBox", int1 = boxId}})  
598 - role:checkTaskEnter("OpenBox", {id = boxId, count=1, quality=itemData.quality})  
599 -  
600 - role:log("carriage_dismantle", {  
601 - item_id = boxId, -- 道具id  
602 - item_type = itemData.type, -- 道具类型,具体见枚举表中道具类型枚举表  
603 - item_level = 0, -- 道具等级  
604 - item_number = 1, -- 道具变化数量的绝对值  
605 - carriage_dismantle_type = quick and 1 or 0, -- 拆解方式,时间到期:0,钥匙开启:1  
606 - carriage_dismantle_time = costTime, -- 拆解耗时,填写实际耗时  
607 - carriage_dismantle_cost = costKey, -- 拆解花费钥匙数量,未使用填写0  
608 - carriage_dismantle_rwd = reward, -- 拆解获得物资,json格式记录,{'itemid1':2,'itemid2':3,…………..}  
609 - }) 654 + reward, change = role:award(reward, {log = {desc = "openTimeBox", int1 = costId}})
610 else 655 else
611 return 656 return
612 end 657 end
613 658
614 - role:setProperty("boxL") --刷新  
615 - role:changeUpdates({{type = "boxL", field = slot, value = boxL[slot], isOnlyToC = true}}) -- 通知客户端 659 + role:setProperty("boxL",boxL) --刷新
  660 + if slot then
  661 + role:changeUpdates({{type = "boxL", field = slot, value = boxL[slot], isOnlyToC = true}}) -- 通知客户端
  662 + end
616 SendPacket(actionCodes.Role_openTimeBoxRpc, MsgPack.pack(role:packReward(reward, change))) 663 SendPacket(actionCodes.Role_openTimeBoxRpc, MsgPack.pack(role:packReward(reward, change)))
617 return true 664 return true
618 end 665 end
src/models/RolePlugin.lua
@@ -362,10 +362,34 @@ function RolePlugin.bind(Role) @@ -362,10 +362,34 @@ function RolePlugin.bind(Role)
362 pms.itemId = itemId 362 pms.itemId = itemId
363 pms.count = - count 363 pms.count = - count
364 self:addItem(pms) 364 self:addItem(pms)
  365 + self:itemDeltaEvent(pms)
365 end 366 end
366 return true 367 return true
367 end 368 end
368 369
  370 + function Role:itemDeltaEvent(pms)
  371 + self:eventBoxL(pms)
  372 + end
  373 +
  374 + -- 拆解室的生产线启动
  375 + function Role:eventBoxL(pms)
  376 + local limit = globalCsv.box_key_max[pms.itemId]
  377 + if not limit then return end
  378 +
  379 + local update = false
  380 + local boxL = self:getProperty("boxL") or {}
  381 + for slot, data in pairs(boxL) do
  382 + if data.time == 0 and data.id == pms.itemId and self:getItemCount(pms.itemId) < limit then
  383 + update = true
  384 + data.time = skynet.timex()
  385 + end
  386 + end
  387 +
  388 + if update then
  389 + self:updateProperty({field = "boxL", value = boxL})
  390 + end
  391 + end
  392 +
369 function Role:getItemCount(itemId) 393 function Role:getItemCount(itemId)
370 if itemId == ItemId.Diamond then 394 if itemId == ItemId.Diamond then
371 return self:getAllDiamond() 395 return self:getAllDiamond()