--[[ Descripttion:接口 - 开箱子 version: Author: Neo,Huang Date: 2022-07-05 17:32:01 LastEditors: Neo,Huang LastEditTime: 2022-07-05 20:29:29 --]] 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, count = util_box:get_box_drop_item_and_count(id) if not is_empty(itemId) and not is_empty(count) then local costItems = {{id = gameConst.ITEM_ID.DIAMOND, count = conf.diamondPrice}} if not bagData:is_enough(uid, costItems) then -- 绑金不足,使用金币 costItems = {{id = gameConst.ITEM_ID.GOLD, count = conf.goldPrice}} if not bagData:is_enough(uid, costItems) then break end end -- 消耗 local eventId = string.format("box-blind-%s", tostring(id)) bagData:consume_items(uid, costItems, eventId) -- 获取物品 local _items = {{id = itemId, count = count}} 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