--[[ absAct[od] = { coustom[id] = { selectItem[1] = selectItem[2] = selectItem[3] = state = cnt = } } ]] local AbsActLogic = require("absAct.AbsActLogic") local AbsActExcel = require("excel.absAct") local BuyExcel = require("excel.buy") local Util = require("common.Util") local Msg = require("core.Msg") local Grid = require("bag.Grid") local BagLogic = require("bag.BagLogic") local BuyLogic = require("topup.BuyLogic") local ObjHuman = require("core.ObjHuman") local Lang = require("common.Lang") local Broadcast = require("broadcast.Broadcast") function isOpen(human, YYInfo, funcConfig) local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID) if not state then return end local absAct = human.db.absAct[funcConfig.funcID] if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then return false end return true, endTime, startTime end function isActive(human, YYInfo, funcConfig) return not isOpen(human, YYInfo, funcConfig) end --���Ͷ���������� -- id �id function getAndSendMsg(human,id,actID) -- �δ�������� local state, endTime, starTime = AbsActLogic.isStarted(human, id) if not state then return end local absConfig = AbsActExcel.absActivity[id] if not absConfig then return end local absAct = human.db.absAct[id] if not absAct then return end -- ��ʼ��custom���� absAct.custom = absAct.custom or {} -- �������� local msgRet = Msg.gc.GC_ABS_ND_CUSTOM_QUERY local config = AbsActExcel.custom local len = 0 for k,v in pairs(config) do if len >= 3 then msgRet.giftList[0] =len msgRet.isEnd = 0 Msg.send(msgRet,human.fd) len = 0 msgRet = Msg.gc.GC_ABS_ND_CUSTOM_QUERY end if v.actId == absConfig.actId then len = len + 1 local net = msgRet.giftList[len] net.id = k net.limitCnt = v.limitCnt net.price = v.price net.name = v.name net.nowCnt = absAct.custom[k] and absAct.custom[k].cnt or 0 net.state = absAct.custom[k] and absAct.custom[k].state or 0 net.buyItem[0] = 1 if v.buyID ~= 0 then BuyLogic.fontBuyItem(human, net.buyItem[1], v.buyID) else net.buyItem[0] = 0 end local warehouseLen = #v.fixed for j = 1,warehouseLen do local itemID = v.fixed[j][1] local itemCnt = v.fixed[j][2] Grid.makeItem(net.fixed[j],itemID,itemCnt) end net.fixed[0] = warehouseLen if net.nowCnt >= net.limitCnt then net.first[0] = 0 net.second[0] = 0 net.third[0] = 0 else warehouseLen = #v.first for j = 1,warehouseLen do local itemID = v.first[j][1] local itemCnt = v.first[j][2] Grid.makeItem(net.first[j],itemID,itemCnt) end net.first[0] = warehouseLen warehouseLen = #v.second for j = 1,warehouseLen do local itemID = v.second[j][1] local itemCnt = v.second[j][2] Grid.makeItem(net.second[j],itemID,itemCnt) end net.second[0] = warehouseLen warehouseLen = #v.third for j = 1,warehouseLen do local itemID = v.third[j][1] local itemCnt = v.third[j][2] Grid.makeItem(net.third[j],itemID,itemCnt) end net.third[0] = warehouseLen end -- ״̬Ϊ0����ʾδѡ����Ʒ��������Ʒ�� if net.state == 0 then net.one[0] = 0 net.two[0] = 0 net.three[0] = 0 else -- ״̬��Ϊ0����ʾ���������ѡ����Ʒ��չʾ��ѡ����Ʒ Grid.makeItem(net.one[1],absAct.custom[k].selectItem[1][1],absAct.custom[k].selectItem[1][2]) Grid.makeItem(net.two[1],absAct.custom[k].selectItem[2][1],absAct.custom[k].selectItem[2][2]) net.one[0] = 1 net.two[0] = 1 net.three[0] = 0 if absAct.custom[k].selectItem[3] then Grid.makeItem(net.three[1],absAct.custom[k].selectItem[3][1],absAct.custom[k].selectItem[3][2]) net.three[0] = 1 end end end end msgRet.giftList[0] = len msgRet.isEnd = 1 Msg.send(msgRet,human.fd) end -- ѡ����Ʒ function selectItem(human,id,giftId,first,second,third) local msgRet = Msg.gc.GC_ABS_ND_CUSTOM_SELECT msgRet.ret = 1 -- �δ�����޷�ѡ����Ʒ local state, endTime, starTime = AbsActLogic.isStarted(human, id) if not state then msgRet.ret = 0 Msg.send(msgRet,human.fd) return end local absConfig = AbsActExcel.absActivity[id] if not absConfig then msgRet.ret = 0 Msg.send(msgRet,human.fd) return end local absAct = human.db.absAct[id] if not absAct then msgRet.ret = 0 Msg.send(msgRet,human.fd) return end -- ����������޷�ѡ����Ʒ if absAct.custom and absAct.custom[giftId] and absAct.custom[giftId].state == 2 then msgRet.ret = 0 Msg.send(msgRet,human.fd) return end -- ��ʼ������ absAct.custom = absAct.custom or {} absAct.custom[giftId] = absAct.custom[giftId] or {} absAct.custom[giftId].cnt = absAct.custom[giftId].cnt or 0 absAct.custom[giftId].state = absAct.custom[giftId].state or 0 absAct.custom[giftId].selectItem = absAct.custom[giftId].selectItem or {} -- У����Ʒ�Ƿ���� local config = AbsActExcel.custom[giftId] if config == nil or config.first[first] == nil or config.second[second] == nil or (config.third[third] == nil and third ~= 0) then msgRet.ret = 0 Msg.send(msgRet,human.fd) return end if (first == 0 and #config.first ~= 0) or (second == 0 and #config.second ~= 0) or (third == 0 and #config.third ~= 0) then return end -- ����ѡ����Ʒ�������ݿ� absAct.custom[giftId].selectItem[1] = {} absAct.custom[giftId].selectItem[1][1] = config.first[first][1] absAct.custom[giftId].selectItem[1][2] = config.first[first][2] absAct.custom[giftId].selectItem[2] = {} absAct.custom[giftId].selectItem[2][1] = config.second[second][1] absAct.custom[giftId].selectItem[2][2] = config.second[second][2] -- ���������������ѡ��3����Ʒ if third ~= 0 then absAct.custom[giftId].selectItem[3] = {} absAct.custom[giftId].selectItem[3][1] = config.third[third][1] absAct.custom[giftId].selectItem[3][2] = config.third[third][2] end Msg.send(msgRet,human.fd) absAct.custom[giftId].state = 1 end -- ������� function custom(human,funcID,conf) customBuy(human,conf.args[1],funcID) end function customBuy(human,args,id) -- �δ�������� local state, endTime, starTime = AbsActLogic.isStarted(human, id) if not state then return end local absConfig = AbsActExcel.absActivity[id] if not absConfig then return end local absAct = human.db.absAct[id] if not absAct then return end -- ����״̬��Ϊ�ɹ��򣬷��� if not absAct.custom or not absAct.custom[args] or absAct.custom[args].state ~= 1 then return end -- δѡ����Ʒ������ if #absAct.custom[args].selectItem <= 0 then return end -- �Ѵﵽ�޹����������� local config = AbsActExcel.custom[args] if absAct.custom[args].cnt >= config.limitCnt then return end -- ��ʯ�۸�Ϊ0ʱ����ʾ��ʯ���������ж���ʯ�Ƿ��㹻 if config.price ~= 0 then if not ObjHuman.checkRMB(human, config.price) then return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI) end ObjHuman.decZuanshi(human, -config.price, "abs_custom") end -- �����������һ�� absAct.custom[args].cnt = absAct.custom[args].cnt + 1 -- ״̬����Ϊ�����꣬��ʱ��Ϊ��ֹ�������������¿����޹��򣬹�������Ϊ�޷��������� absAct.custom[args].state = 2 -- ͳ����Ʒ�������� local item = {} for i = 1, #config.fixed do item[#item+1] = {config.fixed[i][1],config.fixed[i][2]} end for i = 1,#absAct.custom[args].selectItem do item[#item+1] = {absAct.custom[args].selectItem[i][1],absAct.custom[args].selectItem[i][2]} end BagLogic.addItemList(human, item, "abs_custom") -- �ж��Ƿ�ﵽ�޹�������δ�ﵽ�򽫹���״̬��Ϊѡ����Ʒ if absAct.custom[args].cnt < config.limitCnt then --absAct.custom[args].selectItem = {} absAct.custom[args].state = 0 else absAct.custom[args].state = 2 end getAndSendMsg(human,id) end