-------------------------------- -- 文件名 : ServerCommerceActShop.lua -- 文件说明 : 跨服商业-战区钜惠 -- 创建时间 : 2025/03/31 -- 创建人 : FC -------------------------------- 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 CommonDefine = require("common.CommonDefine") local ServerCommerceConf = require("excel.ServerCommerce") local BuyConf = require("excel.buy") local CommonDB = require("common.CommonDB") local ObjHuman = require("core.ObjHuman") local ServerCommerceManager = require("serverCommerce.ServerCommerceManager") local COMMERCEACTFREEID = 1 -- 免费 local COMMERCEACTPAYID = 2 -- 付费 ----------------------------------------- 内部处理开始 ------------------------------------- -- 获取配置 local function CommerceActShop_GetCof() return ServerCommerceConf.CommerceShop end function CreatDB(human) if not human.db.ServerCommerce or not human.db.ServerCommerce.Shop then print("[CommerceActShop_CreatDB] 初始化数据失败 name = "..human.db.name) return false end local tConf = CommerceActShop_GetCof() for nID, v in ipairs(tConf) do human.db.ServerCommerce.Shop[nID] = { [COMMERCEACTFREEID] = CommonDefine.COMMON_PRIZE_STATE_NOGET, [COMMERCEACTPAYID] = CommonDefine.COMMON_PRIZE_STATE_NOGET } end return true end -- 获取免费奖励状态 local function CommerceActShop_GetFreeStatus(human, nID) return human.db.ServerCommerce.Shop[nID][COMMERCEACTFREEID] end -- 设置免费奖励状态 local function CommerceActShop_SetFreeStatus(human, nID, nStatus) human.db.ServerCommerce.Shop[nID][COMMERCEACTFREEID] = nStatus end -- 获取付费奖励状态 local function CommerceActShop_GetPayStatus(human, nID) return human.db.ServerCommerce.Shop[nID][COMMERCEACTPAYID] end -- 设置付费奖励状态 local function CommerceActShop_SetPayStatus(human, nID, nStatus) human.db.ServerCommerce.Shop[nID][COMMERCEACTPAYID] = nStatus end ----------------------------------------- 客户端请求处理开始 ------------------------------------- -- 查询数据 function CommerceActShop_Query(human) local tConf = CommerceActShop_GetCof() local tMsgData = Msg.gc.GC_SERVEERCOMMERCE_ACT_SHOPQUERY tMsgData.nNowPoint = CommonDB.GetCommerceActInfo_Point() tMsgData.list[0] = #tConf local nLen = 1 for nID, v in ipairs(tConf) do local tNodeData = tMsgData.list[nLen] nLen = nLen + 1 tNodeData.nID = nID tNodeData.nNeedPoint = v.nPoint tNodeData.nFreeState = CommerceActShop_GetFreeStatus(human, nID) tNodeData.nPayState = CommerceActShop_GetPayStatus(human, nID) -- 免费物品 tNodeData.tFreeItem[0] = #v.FreePrize for i, tData in ipairs(v.FreePrize) do Grid.makeItem(tNodeData.tFreeItem[i], tData[1], tData[2]) end tNodeData.tPayItem[0] = #v.PayPrize for i, tData in ipairs(v.PayPrize) do Grid.makeItem(tNodeData.tPayItem[i], tData[1], tData[2]) end -- 封装购买项物品 BuyLogic.fontBuyItem(human, tNodeData.buyItem, v.nBuyID) end Msg.send(tMsgData, human.fd) end -- 领取奖励 function CommerceActShop_GetPrize(human) local tConf = CommerceActShop_GetCof() local tGoods = {} for nID, v in ipairs(tConf) do local nFreeState = CommerceActShop_GetFreeStatus(human, nID) local nPayState = CommerceActShop_GetPayStatus(human, nID) if CommonDefine.COMMON_PRIZE_STATE_CANGET == nFreeState then CommerceActShop_SetFreeStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET) for _, tData in ipairs(v.FreePrize) do tGoods[tData[1]] = tGoods[tData[1]] or 0 tGoods[tData[1]] = tGoods[tData[1]] + tData[2] end end if CommonDefine.COMMON_PRIZE_STATE_CANGET == nPayState then CommerceActShop_SetPayStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET) for _, tData in ipairs(v.FreePrize) do tGoods[tData[1]] = tGoods[tData[1]] or 0 tGoods[tData[1]] = tGoods[tData[1]] + tData[2] end end end if nil ~= _G.next(tGoods) then local tItem = {} for nGoodsID, nGoodsNum in pairs(tGoods) do table.insert(tItem, {nGoodsID, nGoodsNum}) end BagLogic.addItemList(human, tItem, "servercommerce") CommerceActShop_Query(human) end end ----------------------------------------- 外部调用 ------------------------------------- -- 总积分改变 function onAllPointChange() local nNowPoint = CommonDB.GetCommerceActInfo_Point() local tConf = CommerceActShop_GetCof() local tOKID = {} for nID, v in ipairs(tConf) do if nNowPoint >= v.nPoint then table.insert(tOKID, nID) end end for _, human in pairs(ObjHuman.onlineUuid) do local bSendClient = false for _, nID in ipairs(tOKID) do local nStatus = CommerceActShop_GetFreeStatus(human, nID) if CommonDefine.COMMON_PRIZE_STATE_NOGET == nStatus then bSendClient = true CommerceActShop_SetFreeStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET) end end if true == bSendClient then CommerceActShop_Query(human) end end end function onCharge(human, price, funcID, buyID) local tConf = CommerceActShop_GetCof() local nChoseID = 0 for nID, v in ipairs(tConf) do if v.nBuyID == buyID then local nPayState = CommerceActShop_GetPayStatus(human, nID) if CommonDefine.COMMON_PRIZE_STATE_NOGET == nPayState then nChoseID = nID else print("[CommerceActShop_onCharge] 重复购买了 nBuyID = "..v.nBuyID) end break end end local tBuyCfg = BuyConf.buy[buyID] if not tBuyCfg then print("[onCharge] 不存在对应的购买项配置 buyID = "..buyID) return else local region = human.region or "CN" local nPoint = tBuyCfg[region] ServerCommerceManager.CommerveManager_AddServerPoint(nPoint) ServerCommerceManager.CommerveManager_AddHumanPint(human, nPoint) end if nChoseID == 0 then return end CommerceActShop_SetPayStatus(human, nChoseID, CommonDefine.COMMON_PRIZE_STATE_CANGET) CommerceActShop_Query(human) end -- 登录检测积分 function onLogin(human) local nNowPoint = CommonDB.GetCommerceActInfo_Point() local tConf = CommerceActShop_GetCof() for nID, v in ipairs(tConf) do if nNowPoint >= v.nPoint then local nStatus = CommerceActShop_GetFreeStatus(human, nID) if CommonDefine.COMMON_PRIZE_STATE_NOGET == nStatus then CommerceActShop_SetFreeStatus(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET) end end end end function isRed(human) local tConf = CommerceActShop_GetCof() for nID, v in ipairs(tConf) do local nFreeStatus = CommerceActShop_GetFreeStatus(human, nID) local nPayState = CommerceActShop_GetPayStatus(human, nID) if CommonDefine.COMMON_PRIZE_STATE_CANGET == nFreeStatus or CommonDefine.COMMON_PRIZE_STATE_CANGET == nPayState then return true end end return false end