1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- --[[
- Descripttion:开箱子
- version:
- Author: Neo,Huang
- Date: 2023-11-15 22:34:35
- LastEditors: Neo,Huang
- LastEditTime: 2023-11-15 22:42:18
- --]]
- local code = require("code")
- local util_box = require("utils.util_box")
- local gameConst = require("const.gameConst")
- local itemUtil = require("utils.itemUtil")
- local boxAdapt = require("adapt.boxAdapt")
- local bagData = require("data.bag")
- local root = {}
- -- 盲盒 - 模块信息
- function root:box_blind_get_info(role, msg)
- local id = msg.id
- local ret = {
- boxInfoList = util_box:pack_box_info_list(id)
- }
- return code.OK, ret
- end
- -- 盲盒 -开盲盒
- function root:box_blind_open(role, msg)
- local id = msg.id
- local count = msg.count or 1
- if is_empty(id) then
- return code.PARAMTER_ERROR
- end
- local uid = role.uid
- local conf = boxAdapt:blind_get_box_key_info(id)
- local items = nil
- for i = 1, count do
- -- 掉落物品
- local itemId, itemCount = util_box:get_box_drop_item_and_count(id)
- if not is_empty(itemId) and not is_empty(itemCount) then
- local ok, costItems = bagData:is_enough(uid, {{id = gameConst.ITEM_ID.DIAMOND, count = conf.price}})
- if not ok then
- break
- end
- -- 消耗
- local eventId = string.format("box-blind-%s", tostring(id))
- bagData:consume_items(uid, costItems, eventId)
- -- 获取物品
- local _items = {{id = itemId, count = itemCount}}
- bagData:add_items(uid, _items, eventId)
- items = itemUtil.items_merge(items, _items)
- end
- end
- if is_empty(items) then
- return code.BAG.ITEM_NOT_ENOUGH
- end
- local ret = {
- items = items,
- boxInfo = util_box:pack_box_info(id)
- }
- return code.OK, ret
- end
- return root
|