--新商业化活动——特价商店 --db --[=[ human.db.absAct[id] = { buyRecord = { [1] = 2, --key是道具在配置中的id, value是已经购买次数 [2] = 1, } } ]=]-- local Msg = require("core.Msg") local Grid = require("bag.Grid") local BagLogic = require("bag.BagLogic") local AbsActLogic = require("absAct.AbsActLogic") local Broadcast = require("broadcast.Broadcast") local Lang = require("common.Lang") local Config = require("excel.absAct").AbsDiscountStore local CycleActivityLogic = require("yunying.CycleActivity") local LOGTAG = "AbsDiscountStore" --日志标识 function isOpen(human, YYInfo, funcConfig) -- local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID) local state, endTime, startTime = CycleActivityLogic.isStarted(human, funcConfig.funcID) return state, endTime, startTime end function isActive(human, YYInfo, funcConfig) local state = isOpen(human, YYInfo, funcConfig) return not state end --查询 function Query(human, id, isBuy) -- local state = AbsActLogic.isStarted(human, id) local state = CycleActivityLogic.isStarted(human, id) if not state then return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME) end local actData = human.db.absAct[id] if not actData then return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME) end local buyRecord = actData.buyRecord local msgRet = Msg.gc.GC_DISCOUNTSTORE_QUERY msgRet.isBuy = isBuy and 1 or 0 local itemVec = msgRet.itemVec itemVec[0] = #Config for k,v in ipairs(Config) do local singleItem = itemVec[k] singleItem.idx = k singleItem.maxBuyCnt = v.maxBuyCnt singleItem.nowBuyCnt = buyRecord and buyRecord[k] or 0 Grid.makeItem(singleItem.item, v.item[1], v.item[2]) -- singleItem.currencyId = v.currencyInfo[1] -- singleItem.currencyCnt = v.currencyInfo[2] Grid.makeItem(singleItem.currencyInfo, v.currencyInfo[1], v.currencyInfo[2]) end Msg.send(msgRet, human.fd) end --购买商品 function BuyItem(human, id, itemIdx, buyCnt) -- local state = AbsActLogic.isStarted(human, id) local state = CycleActivityLogic.isStarted(human, id) if not state then return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME) end local actData = human.db.absAct[id] if not actData then return Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME) end local itemCfg = Config[itemIdx] if not itemCfg or buyCnt <= 0 then return Broadcast.sendErr(human, Lang.COMMON_ARGUMENT_ERROR) end local buyRecord = actData.buyRecord if buyRecord and buyRecord[itemIdx] then if buyRecord[itemIdx] + buyCnt > itemCfg.maxBuyCnt then return Broadcast.sendErr(human, Lang.COMMON_BUY_NUM_NOT_ENOUGH) end end local currencyInfo = itemCfg.currencyInfo local cnt = currencyInfo[2] * buyCnt if BagLogic.getItemCnt(human, currencyInfo[1]) < cnt then return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH) end BagLogic.delItem(human, currencyInfo[1], cnt, LOGTAG) --更新数据 buyRecord = buyRecord or {} buyRecord[itemIdx] = (buyRecord[itemIdx] or 0) + buyCnt actData.buyRecord = buyRecord --发放奖励 local itemInfo = itemCfg.item BagLogic.addItemList(human, {{itemInfo[1], itemInfo[2] * buyCnt}}, LOGTAG) --下发数据 -- local msgRet = Msg.gc.GC_DISCOUNTSTORE_BUY -- msgRet.idx = itemIdx -- msgRet.nowBuyCnt = buyRecord[itemIdx] -- Msg.send(msgRet, human.fd) Query(human, id, true) end