From 89760dbef7c42fdd2af3b350e2b6171d57c31d46 Mon Sep 17 00:00:00 2001 From: chenyueqi Date: Thu, 24 Dec 2020 20:52:17 +0800 Subject: [PATCH] 拆解室功能重写 --- src/GlobalVar.lua | 1 - src/actions/RoleAction.lua | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------ src/models/RolePlugin.lua | 24 ++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 61 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 009752d..281e9fd 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -134,7 +134,6 @@ ItemId = { RuneFragment = 24, HeroFC = {700, 701, 702, 703}, --通用角色碎片 AdvKey = 80, -- 冒险钥匙 - BoxKey = 60, -- 拆解工具 AdvPower = 4701, -- 拾荒体力 CrisisScore = 8010, -- 积分 } diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index bc3996b..af4f166 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -537,82 +537,129 @@ function _M.openTimeBoxRpc(agent, data) local slot = msg.slot -- 位置 1 - 6 -- 特权卡时间箱额外栏位 - local privExtraCnt = role.storeData:getTimeBoxSlotExtraCount() - if oper == 1 then - if math.illegalNum(slot, 1, role:getFuncLv(FuncOpenType.TimeBoxSlot) + privExtraCnt) then return end - end + -- local privExtraCnt = role.storeData:getTimeBoxSlotExtraCount() + -- if oper == 1 then + -- if math.illegalNum(slot, 1, role:getFuncLv(FuncOpenType.TimeBoxSlot) + privExtraCnt) then return end + -- end local boxL = role:getProperty("boxL") - local reward, change = {} - if oper == 1 then -- 打开 + local reward, change + if oper == 1 then -- 构建开始(包括切换构建的id) local itemId = msg.itemId - if role:getItemCount(itemId) < 1 then return end local itemData = csvdb["itemCsv"][itemId] - local randomData = csvdb["item_randomCsv"][itemId] - if not itemData or not randomData or randomData.openTime <= 0 then return end - - if boxL[slot] then return end - role:costItems({[itemId] = 1}, {log = {desc = "openTimeBox"}}) - boxL[slot] = {id = itemId, time = skynet.timex() + randomData.openTime} - role:pushMsg({type = "box", slot = slot, time = randomData.openTime}) - elseif oper == 2 then -- 领取 + if not itemData then return 1 end + if not boxL[slot] then + boxL[slot] = {} + else + local oldId, process, time = boxL[slot].id, boxL[slot].process, boxL[slot].time + local unitTime = globalCsv.box_key_time[oldId] * 60 + local doneCnt = math.floor((process + skynet.timex() - time) / unitTime) + if doneCnt > 0 then + reward = role:award({[oldId] = doneCnt}, {log = {desc = "openTimeBox", int1 = slot}}) + end + end + local limit = globalCsv.box_key_max[itemId] or 5 + if role:getItemCount(itemId) >= limit then return 3 end + + boxL[slot] = {id = itemId, process = 0, time = skynet.timex()} + role:pushMsg({type = "box", slot = slot, time = skynet.timex() + globalCsv.box_productLine_time * 3600}) + elseif oper == 2 then -- 重置运行时间(可以使用加速) local quick = msg.quick - if not boxL[slot] then return end - local costKey = 0 - if boxL[slot].time > skynet.timex() then -- 没开完 - if not quick then return end + if not boxL[slot] then return 4 end + + local itemId, process, time = boxL[slot].id, boxL[slot].process, boxL[slot].time + local nowTime = skynet.timex() + local stopTime = nowTime + local itemData = csvdb["itemCsv"][itemId] + local unitTime = globalCsv.box_key_time[itemId] * 60 + if quick then + stopTime = time + globalCsv.box_productLine_time * 3600 local cost_pre = globalCsv.box_timeOpen_diamond:toArray(true, "=") - costKey = math.ceil((boxL[slot].time - skynet.timex()) / (cost_pre[1] * 60)) * cost_pre[2] - if not role:checkItemEnough({[ItemId.BoxKey] = costKey}) then return end - role:costItems({[ItemId.BoxKey] = costKey}, {log = {desc = "openTimeBox"}}) - role:pushCancel({type = "box", slot = slot}) + local costKey = math.ceil((stopTime - nowTime) / (cost_pre[1] * 60)) * cost_pre[2] + if not role:checkItemEnough({[ItemId.Diamond] = costKey}) then return 5 end + role:costItems({[ItemId.Diamond] = costKey}, {log = {desc = "openTimeBox", int1 = slot}}) end - local boxId = boxL[slot].id - local itemData = csvdb["itemCsv"][boxId] - local randomData = csvdb["item_randomCsv"][itemData.id] - local costTime = skynet.timex() - (boxL[slot].time - randomData.openTime) - -- 随机奖励 + role:pushCancel({type = "box", slot = slot}) + + local doneCnt = math.floor((process + stopTime - time) / unitTime) + if doneCnt > 0 then + reward = role:award({[itemId] = doneCnt}, {log = {desc = "openTimeBox", int1 = slot}}) + end + if role:getItemCount(itemId) >= globalCsv.box_key_max[itemId] then + nowTime = 0 + end + + boxL[slot] = {id = itemId, process = (process + stopTime - time) % unitTime, time = nowTime} + role:pushMsg({type = "box", slot = slot, time = nowTime + globalCsv.box_productLine_time * 3600}) + elseif oper == 3 then -- 开箱子 + local costId = msg.costId + local costs = (msg.costs or ""):toNumMap() + if not costId or not csvdb["itemCsv"][costId] or not next(costs) then return 6 end + + local costIdData = csvdb["itemCsv"][costId] + local count = 0 + for itemId, num in pairs(costs) do + local itemIdData = csvdb["itemCsv"][itemId] + if not itemIdData or not csvdb["item_randomCsv"][itemId] or costIdData.quality ~= itemIdData.quality then return 7 end + count = count + num + end + + if role:getItemCount(costId) < count then return 8 end + + role:costItems({[costId] = count}, {log = {desc = "openTimeBox"}}) + reward = {} - for i = 1, 10 do - local num = randomData["num" .. i] - local gift = randomData["gift" .. i] - if num and gift and num > 0 and gift ~= "" then - local pool = {} - for _, temp in ipairs(gift:toArray()) do - local set = temp:toArray(true, "=") - table.insert(pool, set) + for itemId, value in pairs(costs) do + local tempReward = {} + local randomData = csvdb["item_randomCsv"][itemId] + local itemData = csvdb["itemCsv"][itemId] + role:costItems({[itemId] = value}, {log = {desc = "openTimeBox"}}) + for _ = 1, value do + for i = 1, 10 do + local num = randomData["num" .. i] + local gift = randomData["gift" .. i] + if num and gift and num > 0 and gift ~= "" then + local pool = {} + for _, temp in ipairs(gift:toArray()) do + local set = temp:toArray(true, "=") + table.insert(pool, set) + end + + local needCount = math.min(#pool, num) + for j = 1, needCount do + local idx = math.randWeight(pool, 3) + tempReward[pool[idx][1]] = (tempReward[pool[idx][1]] or 0) + pool[idx][2] + table.remove(pool, idx) + end + end end + end + tempReward[0] = nil + role:checkTaskEnter("OpenBox", {id = itemId, count=value, quality=itemData.quality}) + role:log("carriage_dismantle", { + item_id = itemId, -- 道具id + item_type = itemData.type, -- 道具类型,具体见枚举表中道具类型枚举表 + item_level = 0, -- 道具等级 + item_number = 1, -- 道具变化数量的绝对值 + carriage_dismantle_type = 1, -- 拆解方式,时间到期:0,钥匙开启:1 + carriage_dismantle_time = 0, -- 拆解耗时,填写实际耗时 + carriage_dismantle_cost = value, -- 拆解花费钥匙数量,未使用填写0 + carriage_dismantle_rwd = tempReward, -- 拆解获得物资,json格式记录,{'itemid1':2,'itemid2':3,…………..} + }) - local needCount = math.min(#pool, num) - for j = 1, needCount do - local idx = math.randWeight(pool, 3) - reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2] - table.remove(pool, idx) - end + for id, num in pairs(tempReward) do + reward[id] = (reward[id] or 0) + num end end - reward[0] = nil - - boxL[slot] = nil - reward, change = role:award(reward, {log = {desc = "openTimeBox", int1 = boxId}}) - role:checkTaskEnter("OpenBox", {id = boxId, count=1, quality=itemData.quality}) - - role:log("carriage_dismantle", { - item_id = boxId, -- 道具id - item_type = itemData.type, -- 道具类型,具体见枚举表中道具类型枚举表 - item_level = 0, -- 道具等级 - item_number = 1, -- 道具变化数量的绝对值 - carriage_dismantle_type = quick and 1 or 0, -- 拆解方式,时间到期:0,钥匙开启:1 - carriage_dismantle_time = costTime, -- 拆解耗时,填写实际耗时 - carriage_dismantle_cost = costKey, -- 拆解花费钥匙数量,未使用填写0 - carriage_dismantle_rwd = reward, -- 拆解获得物资,json格式记录,{'itemid1':2,'itemid2':3,…………..} - }) + reward, change = role:award(reward, {log = {desc = "openTimeBox", int1 = costId}}) else return end - role:setProperty("boxL") --刷新 - role:changeUpdates({{type = "boxL", field = slot, value = boxL[slot], isOnlyToC = true}}) -- 通知客户端 + role:setProperty("boxL",boxL) --刷新 + if slot then + role:changeUpdates({{type = "boxL", field = slot, value = boxL[slot], isOnlyToC = true}}) -- 通知客户端 + end SendPacket(actionCodes.Role_openTimeBoxRpc, MsgPack.pack(role:packReward(reward, change))) return true end diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index d367650..1f27d19 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -362,10 +362,34 @@ function RolePlugin.bind(Role) pms.itemId = itemId pms.count = - count self:addItem(pms) + self:itemDeltaEvent(pms) end return true end + function Role:itemDeltaEvent(pms) + self:eventBoxL(pms) + end + + -- 拆解室的生产线启动 + function Role:eventBoxL(pms) + local limit = globalCsv.box_key_max[pms.itemId] + if not limit then return end + + local update = false + local boxL = self:getProperty("boxL") or {} + for slot, data in pairs(boxL) do + if data.time == 0 and data.id == pms.itemId and self:getItemCount(pms.itemId) < limit then + update = true + data.time = skynet.timex() + end + end + + if update then + self:updateProperty({field = "boxL", value = boxL}) + end + end + function Role:getItemCount(itemId) if itemId == ItemId.Diamond then return self:getAllDiamond() -- libgit2 0.21.2