-- 华丽皮肤礼包:仅直购,配置读取 excel.skin.skinGift local Msg = require("core.Msg") local Grid = require("bag.Grid") local BagLogic = require("bag.BagLogic") local BuyLogic = require("topup.BuyLogic") local Lang = require("common.Lang") local Broadcast = require("broadcast.Broadcast") local SkinGiftExcel = require("excel.skin").skinGift local LOGTAG = "skinGift" local GIFT_CFG_ID = 1 local function getCfg() return SkinGiftExcel[GIFT_CFG_ID] end local function getCfgByBuyId(buyId) local cfg = getCfg() if cfg and cfg.buyID == buyId then return cfg end end local function getBuyCnt(human, buyId) local skinGiftData = human.db.skinGiftData return skinGiftData and skinGiftData[buyId] or 0 end function Query(human) local cfg = getCfg() if not cfg then return end local msgRet = Msg.gc.GC_SKIN_GIFT_QUERY BuyLogic.fontBuyItem(human, msgRet.buyItem, cfg.buyID) msgRet.giftItem[0] = #cfg.rewards for i, item in ipairs(cfg.rewards) do Grid.makeItem(msgRet.giftItem[i], item[1], item[2]) end Msg.send(msgRet, human.fd) end function onCharge(human, buyId, buyNum) local cfg = getCfgByBuyId(buyId) if not cfg then return end buyNum = buyNum or 1 local nowBuyCnt = getBuyCnt(human, buyId) if cfg.amount > 0 and buyNum + nowBuyCnt > cfg.amount then return Broadcast.sendErr(human, Lang.ABS_GIFT_BUY_LIMIT) end local itemArr = {} for i, item in ipairs(cfg.rewards) do itemArr[i] = {item[1], item[2] * buyNum} end BagLogic.addItemList(human, itemArr, LOGTAG) local skinGiftData = human.db.skinGiftData or {} skinGiftData[buyId] = nowBuyCnt + buyNum human.db.skinGiftData = skinGiftData Query(human) end function GetRemainNum(human, buyId) local cfg = getCfgByBuyId(buyId) if not cfg then return 0 end if cfg.amount == 0 then return 0 end local nowBuyCnt = getBuyCnt(human, buyId) if cfg.amount > nowBuyCnt then return cfg.amount - nowBuyCnt end return 0 end