---------------------------------------------------
--
-- 成长礼包

-- db.giftPack
---------------------------------------------------

local PresentExcel = require("excel.present")
local Util = require("common.Util")
local Lang = require("common.Lang")
local CommonDB = require("common.CommonDB")
local Msg = require("core.Msg")
local Broadcast = require("broadcast.Broadcast")
local PanelDefine = require("broadcast.PanelDefine")
local Grid = require("bag.Grid")
local BagLogic = require("bag.BagLogic")
local BuyLogic = require("topup.BuyLogic")
local YunYingLogic = require("yunying.YunYingLogic")

-- 封装礼包结构体
function fontLibaoNet(net, id, config, libaoType, human)
    net.id = id
    net.items[0] = #config.items
    for i = 1, net.items[0] do
        local itemID = config.items[i][1]
        local itemCnt = config.items[i][2]
        Grid.makeItem(net.items[i], itemID, itemCnt)
    end
    net.name = config.name
    net.buyItem[0] = 0
    if config.buyID > 0 then
        net.buyItem[0] = 1
        BuyLogic.fontBuyItem(human, net.buyItem[1], config.buyID)
    end
end

-- 界面查询
function sendQuery(human, libaoType)
    local configs = PresentExcel.giftPack
    if not configs then return end

    local msgRet = Msg.gc.GC_GIFT_PACK_QUERY
    msgRet.list[0] = #configs
    for i = 1, msgRet.list[0] do
        local config = configs[i]
        fontLibaoNet(msgRet.list[i], i, config, libaoType, human)
    end
    Msg.send(msgRet, human.fd)
end

-- 购买礼包
function buyLibao(human, id, buyType)
    local configs = PresentExcel.giftPack
    local config = configs and configs[id]
    if not config then return end
    BagLogic.addItemList(human, config.items, "giftPack")
    sendQuery(human)
end




