Commit 9b35bf6e8bf1d1711e8a960d47cd23283affaefe
1 parent
36482c8b
开启时间箱
Showing
3 changed files
with
81 additions
and
1 deletions
Show diff stats
src/ProtocolCode.lua
src/actions/RoleAction.lua
| ... | ... | @@ -306,7 +306,7 @@ function _M.openItemRpc(agent, data) |
| 306 | 306 | local itemData = csvdb["itemCsv"][itemId] |
| 307 | 307 | if itemData.use_type ~= 2 then return end |
| 308 | 308 | local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] |
| 309 | - if not randomData then return end | |
| 309 | + if not randomData or randomData.openTime > 0 then return end | |
| 310 | 310 | |
| 311 | 311 | local reward = randomData.gift:toNumMap() |
| 312 | 312 | for _id, _count in pairs(reward) do |
| ... | ... | @@ -333,6 +333,82 @@ function _M.openItemRpc(agent, data) |
| 333 | 333 | return true |
| 334 | 334 | end |
| 335 | 335 | |
| 336 | +function _M.openTimeBoxRpc(agent, data) | |
| 337 | + local role = agent.role | |
| 338 | + local msg = MsgPack.unpack(data) | |
| 339 | + local oper = msg.oper -- 操作 1 - 3 | |
| 340 | + local slot = msg.slot -- 位置 1 - 6 | |
| 341 | + if math.illegalNum(slot, 1, globalCsv.box_timeOpen_maxNum) then return end | |
| 342 | + | |
| 343 | + local boxL = role:getProperty("boxL") | |
| 344 | + local reward | |
| 345 | + if oper == 1 then -- 打开 | |
| 346 | + local itemId = msg.itemId | |
| 347 | + if role:getItemCount(itemId) < 1 then return end | |
| 348 | + local itemData = csvdb["itemCsv"][itemId] | |
| 349 | + local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] | |
| 350 | + if not randomData or randomData.openTime <= 0 then return end | |
| 351 | + | |
| 352 | + if boxL[slot] then return end | |
| 353 | + role:costItems({[itemId] = 1}) | |
| 354 | + boxL[slot] = {id = itemId, time = skynet.timex() + randomData.openTime} | |
| 355 | + | |
| 356 | + elseif oper == 2 then -- 上宝石 | |
| 357 | + local gemId = msg.gem or 0 | |
| 358 | + if not boxL[slot] then return end | |
| 359 | + if boxL[slot].gem or boxL[slot].time <= skynet.timex() then return end | |
| 360 | + local itemData = csvdb["itemCsv"][boxL[slot].id] | |
| 361 | + local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] | |
| 362 | + local costCount = randomData[gemId .. "_gem_num"] | |
| 363 | + if not costCount then return end | |
| 364 | + | |
| 365 | + if not role:checkItemEnough({[gemId]] = costCount}) then return end | |
| 366 | + role:costItems({[gemId] = costCount}) | |
| 367 | + boxL[slot].gem = gemId | |
| 368 | + elseif oper == 3 then -- 领取 | |
| 369 | + local quick = msg.quick | |
| 370 | + if not boxL[slot] then return end | |
| 371 | + if boxL[slot].time > skynet.timex() then -- 没开完 | |
| 372 | + if not quick then return end | |
| 373 | + local cost_pre = globalCsv.box_timeOpen_Diamond:toArray(true, "=") | |
| 374 | + local costD = math.ceil((boxL[slot].time - skynet.timex()) / (cost_pre[1] * 60)) * cost_pre[2] | |
| 375 | + if not role:checkItemEnough({[ItemId.Diamond] = costD}) then return end | |
| 376 | + role:costItems({[ItemId.Diamond] = costD}) | |
| 377 | + end | |
| 378 | + | |
| 379 | + local itemData = csvdb["itemCsv"][boxL[slot].id] | |
| 380 | + local randomData = csvdb["item_randomCsv"][tonumber(itemData.use_effect)] | |
| 381 | + reward = randomData.gift:toNumMap() -- 固定奖励 | |
| 382 | + -- 随机奖励 | |
| 383 | + local randomGift = randomData.random_gift | |
| 384 | + if boxL[slot].gem then | |
| 385 | + randomGift = randomData[boxL[slot].gem .. "_gem_gift"] | |
| 386 | + end | |
| 387 | + if randomData.random_num > 0 and randomGift and randomGift ~= "" then | |
| 388 | + local pool = {} | |
| 389 | + for _, temp in ipairs(randomGift:toArray()) do | |
| 390 | + table.insert(pool, temp:toArray(true, "=")) | |
| 391 | + end | |
| 392 | + local needCount = math.min(#pool, randomData.random_num) | |
| 393 | + for j = 1, needCount do | |
| 394 | + local idx = math.randWeight(pool, 3) | |
| 395 | + reward[pool[idx][1]] = (reward[pool[idx][1]] or 0) + pool[idx][2] | |
| 396 | + table.remove(pool, idx) | |
| 397 | + end | |
| 398 | + end | |
| 399 | + | |
| 400 | + | |
| 401 | + boxL[slot] = nil | |
| 402 | + reward = role:award(reward) | |
| 403 | + else | |
| 404 | + return | |
| 405 | + end | |
| 406 | + | |
| 407 | + self:setProperty("boxL") --刷新 | |
| 408 | + self:changeUpdates({{type = "boxL", field = slot, value = boxL[slot], isOnlyToC = true}}) -- 通知客户端 | |
| 409 | + SendPacket(actionCodes.Role_openTimeBoxRpc, MsgPack.pack({reward = reward})) | |
| 410 | +end | |
| 411 | + | |
| 336 | 412 | function _M.storyBookRewardRpc(agent, data) |
| 337 | 413 | local role = agent.role |
| 338 | 414 | local msg = MsgPack.unpack(data) | ... | ... |
src/models/Role.lua
| ... | ... | @@ -58,6 +58,8 @@ Role.schema = { |
| 58 | 58 | storyB = {"table", {}}, -- 剧情记录 |
| 59 | 59 | |
| 60 | 60 | equips = {"table", {}}, -- 装备简化下, 目前的设计足够支撑 -- {t = {l = c}} -- 接口设计好 底层扩展就重写~ |
| 61 | + | |
| 62 | + boxL = {"table", {}}, -- boxList 正开启的箱子 -- {[1] = {id = 1010, gem = 101, time = 1313}} | |
| 61 | 63 | } |
| 62 | 64 | |
| 63 | 65 | |
| ... | ... | @@ -182,6 +184,7 @@ function Role:data() |
| 182 | 184 | potionBag = self:getProperty("potionBag"), |
| 183 | 185 | storyB = self:getProperty("storyB"), |
| 184 | 186 | equips = self:getProperty("equips"), |
| 187 | + boxL = self:getProperty("boxL"), | |
| 185 | 188 | |
| 186 | 189 | } |
| 187 | 190 | end | ... | ... |