diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index cc0eb38..18b0433 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -27,6 +27,7 @@ actionCodes = { Role_updateRune = 113, Role_storyBookRewardRpc = 114, Role_unLockStoryBookRpc = 115, + Role_openTimeBoxRpc = 116, Adv_startAdvRpc = 151, Adv_roleFormatRpc = 152, diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 5748331..1af0d10 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -306,7 +306,7 @@ function _M.openItemRpc(agent, data) local itemData = csvdb["itemCsv"][itemId] if itemData.use_type ~= 2 then return end local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] - if not randomData then return end + if not randomData or randomData.openTime > 0 then return end local reward = randomData.gift:toNumMap() for _id, _count in pairs(reward) do @@ -333,6 +333,82 @@ function _M.openItemRpc(agent, data) return true end +function _M.openTimeBoxRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local oper = msg.oper -- 操作 1 - 3 + local slot = msg.slot -- 位置 1 - 6 + if math.illegalNum(slot, 1, globalCsv.box_timeOpen_maxNum) then return end + + local boxL = role:getProperty("boxL") + local reward + if oper == 1 then -- 打开 + local itemId = msg.itemId + if role:getItemCount(itemId) < 1 then return end + local itemData = csvdb["itemCsv"][itemId] + local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] + if not randomData or randomData.openTime <= 0 then return end + + if boxL[slot] then return end + role:costItems({[itemId] = 1}) + boxL[slot] = {id = itemId, time = skynet.timex() + randomData.openTime} + + elseif oper == 2 then -- 上宝石 + local gemId = msg.gem or 0 + if not boxL[slot] then return end + if boxL[slot].gem or boxL[slot].time <= skynet.timex() then return end + local itemData = csvdb["itemCsv"][boxL[slot].id] + local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] + local costCount = randomData[gemId .. "_gem_num"] + if not costCount then return end + + if not role:checkItemEnough({[gemId]] = costCount}) then return end + role:costItems({[gemId] = costCount}) + boxL[slot].gem = gemId + elseif oper == 3 then -- 领取 + local quick = msg.quick + if not boxL[slot] then return end + if boxL[slot].time > skynet.timex() then -- 没开完 + if not quick then return end + local cost_pre = globalCsv.box_timeOpen_Diamond:toArray(true, "=") + local costD = math.ceil((boxL[slot].time - skynet.timex()) / (cost_pre[1] * 60)) * cost_pre[2] + if not role:checkItemEnough({[ItemId.Diamond] = costD}) then return end + role:costItems({[ItemId.Diamond] = costD}) + end + + local itemData = csvdb["itemCsv"][boxL[slot].id] + local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] + reward = randomData.gift:toNumMap() -- 固定奖励 + -- 随机奖励 + local randomGift = randomData.random_gift + if boxL[slot].gem then + randomGift = randomData[boxL[slot].gem .. "_gem_gift"] + end + if randomData.random_num > 0 and randomGift and randomGift ~= "" then + local pool = {} + for _, temp in ipairs(randomGift:toArray()) do + table.insert(pool, temp:toArray(true, "=")) + end + local needCount = math.min(#pool, randomData.random_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 + end + + + boxL[slot] = nil + reward = role:award(reward) + else + return + end + + self:setProperty("boxL") --刷新 + self:changeUpdates({{type = "boxL", field = slot, value = boxL[slot], isOnlyToC = true}}) -- 通知客户端 + SendPacket(actionCodes.Role_openTimeBoxRpc, MsgPack.pack({reward = reward})) +end + function _M.storyBookRewardRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) diff --git a/src/models/Role.lua b/src/models/Role.lua index 07a7d8a..dd80291 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -58,6 +58,8 @@ Role.schema = { storyB = {"table", {}}, -- 剧情记录 equips = {"table", {}}, -- 装备简化下, 目前的设计足够支撑 -- {t = {l = c}} -- 接口设计好 底层扩展就重写~ + + boxL = {"table", {}}, -- boxList 正开启的箱子 -- {[1] = {id = 1010, gem = 101, time = 1313}} } @@ -182,6 +184,7 @@ function Role:data() potionBag = self:getProperty("potionBag"), storyB = self:getProperty("storyB"), equips = self:getProperty("equips"), + boxL = self:getProperty("boxL"), } end -- libgit2 0.21.2