|
|
@@ -0,0 +1,432 @@
|
|
|
+--------------------------------
|
|
|
+-- 文件名 : ServerCommerceActManger.lua
|
|
|
+-- 文件说明 : 跨服商业-活动模板管理
|
|
|
+-- 创建时间 : 2025/03/26
|
|
|
+-- 创建人 : FC
|
|
|
+--------------------------------
|
|
|
+
|
|
|
+local Util = require("common.Util")
|
|
|
+local Lang = require("common.Lang")
|
|
|
+local Broadcast = require("broadcast.Broadcast")
|
|
|
+local MailExcel = require("excel.mail")
|
|
|
+local Msg = require("core.Msg")
|
|
|
+local ObjHuman = require("core.ObjHuman")
|
|
|
+local MailManager = require("mail.MailManager")
|
|
|
+local BagLogic = require("bag.BagLogic")
|
|
|
+local Grid = require("bag.Grid")
|
|
|
+local PanelDefine = require("broadcast.PanelDefine")
|
|
|
+local CommonDB = require("common.CommonDB")
|
|
|
+local BuyLogic = require("topup.BuyLogic")
|
|
|
+local GuideLogic = require("guide.GuideLogic")
|
|
|
+local Log = require("common.Log")
|
|
|
+local YunYingLogic = require("yunying.YunYingLogic")
|
|
|
+local ServerCommerceCof = require("excel.ServerCommerce")
|
|
|
+local ServerCommerceActDefine = require("serverCommerce.ServerCommerceActDefine")
|
|
|
+local Timer = require("core.Timer")
|
|
|
+local ServerCommerceMiddle = require("serverCommerce.ServerCommerceMiddle")
|
|
|
+
|
|
|
+-- 活动信息
|
|
|
+tCommerceActInfo = nil
|
|
|
+-- {
|
|
|
+-- nStartTime = nil, -- 开始时间
|
|
|
+-- nEendTime = nil, -- 结束时间
|
|
|
+-- isRun = nil, -- 是否在活动中
|
|
|
+-- nOpen = nil, -- 是否打开
|
|
|
+-- }
|
|
|
+
|
|
|
+-- 加载的模块
|
|
|
+tCommerceActModuel = {}
|
|
|
+
|
|
|
+----------------------------------------- 内部处理开始 -------------------------------------
|
|
|
+-- 下发数据
|
|
|
+local function CommerceAct_SendData(tMsgData, fd)
|
|
|
+ Msg.send(tMsgData, fd)
|
|
|
+end
|
|
|
+
|
|
|
+-- 下发活动数据
|
|
|
+function CommerceAct_SendActInfo(human)
|
|
|
+ if not human or not tCommerceActInfo then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ print("[CommerceAct_SendActInfo] 下发活动数据 开始 ")
|
|
|
+
|
|
|
+ local tMsgData = Msg.gc.GC_SERVEERCOMMERCE_ACT_ALLINFO
|
|
|
+ tMsgData.nStartTime = tCommerceActInfo.nStartTime
|
|
|
+ tMsgData.nEendTime = tCommerceActInfo.nEendTime
|
|
|
+
|
|
|
+ tMsgData.tActID[0] = #ServerCommerceCof.CommerceAct
|
|
|
+
|
|
|
+ local nIndex = 1
|
|
|
+ for id, v in pairs(ServerCommerceCof.CommerceAct) do
|
|
|
+ local tActData = tMsgData.tActID[nIndex]
|
|
|
+ nIndex = nIndex + 1
|
|
|
+ tActData.ID = id
|
|
|
+ tActData.name = v.name
|
|
|
+ tActData.nSortID = v.sortID
|
|
|
+ tActData.nIcon = v.icon
|
|
|
+ tActData.nPanelID = v.panelID
|
|
|
+ local bRed = false
|
|
|
+ if tCommerceActModuel[id] and tCommerceActModuel[id].isRed then
|
|
|
+ bRed = tCommerceActModuel[id].isRed(human)
|
|
|
+ end
|
|
|
+
|
|
|
+ print("[CommerceAct_SendActInfo] name = "..tActData.name)
|
|
|
+ tActData.nRed = (bRed == true) and 1 or 0
|
|
|
+ end
|
|
|
+
|
|
|
+ YunYingLogic.sendBanner(human)
|
|
|
+ CommerceAct_SendData(tMsgData, human.fd)
|
|
|
+
|
|
|
+ print("[CommerceAct_SendActInfo] 下发活动数据 结束 ")
|
|
|
+end
|
|
|
+
|
|
|
+
|
|
|
+-- 各个子活动重置活动数据
|
|
|
+local function CommerceAct_ResetData(human)
|
|
|
+ if not human then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+-- 各个子活动处理结束数据
|
|
|
+local function CommerceAct_HandleEndData(human)
|
|
|
+ if not human then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+-- 所有活动初始化数据开始
|
|
|
+local function CommerceAct_BeginAllAct(human)
|
|
|
+ if not human or not tCommerceActInfo then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local nEndTime = tCommerceActInfo.nEendTime
|
|
|
+
|
|
|
+ print("[CommerceAct_BeginAllAct] 所有活动初始化数据开始 ")
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+-- 结束所有活动
|
|
|
+local function CommerceAct_EndAllAct(human)
|
|
|
+ -- 各个子活动处理数据
|
|
|
+ CommerceAct_HandleEndData(human)
|
|
|
+
|
|
|
+ CommerceAct_SetHumanEndMail(human, true)
|
|
|
+end
|
|
|
+
|
|
|
+-- 活动开始
|
|
|
+local function CommerceAct_Begin()
|
|
|
+ if not tCommerceActInfo then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 遍历在线玩家
|
|
|
+ for uuid, human in pairs(ObjHuman.onlineUuid) do
|
|
|
+ CommerceAct_BeginAllAct(human)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 清理排行榜数据
|
|
|
+ -- weekLoopActRank.WeekActRank_ResetData()
|
|
|
+end
|
|
|
+
|
|
|
+-- 活动结束
|
|
|
+local function CommerceAct_End()
|
|
|
+ -- 遍历在线玩家
|
|
|
+ for uuid, human in pairs(ObjHuman.onlineUuid) do
|
|
|
+ CommerceAct_EndAllAct(human)
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 排行榜直接处理
|
|
|
+ -- weekLoopActRank.WeekActRank_End()
|
|
|
+end
|
|
|
+
|
|
|
+-- 获取抽卡批次
|
|
|
+function CommerceAct_GetCardBatch()
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+-- 设置新的批次
|
|
|
+local function CommerceAct_SetCardBatch()
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+local function CommerceAct_ActCheckOpen_InitServer(nOpen)
|
|
|
+ if ServerCommerceActDefine.COMMERCEACT_NOOPEN ~= nOpen then
|
|
|
+ local tCommerceInfo = CommonDB.GetCommerceActInfo()
|
|
|
+ local nNowTime = os.time()
|
|
|
+ local nBeginTime, nEndTime, isRun
|
|
|
+ if not tCommerceInfo or nil == _G.next(tCommerceInfo) then
|
|
|
+ nBeginTime = nNowTime
|
|
|
+ isRun = true
|
|
|
+ nEndTime = nNowTime + ServerCommerceActDefine.COMMERCEACT_LASTDAY * 86400
|
|
|
+ local tEndDate = os.date("*t",nEndTime)
|
|
|
+ tEndDate.hour = ServerCommerceActDefine.COMMERCEACT_ENDTIME
|
|
|
+ tEndDate.min = 0
|
|
|
+ tEndDate.sec = 0
|
|
|
+ nEndTime = os.time(tEndDate)
|
|
|
+ local tData = {
|
|
|
+ nBeginTime = nNowTime,
|
|
|
+ nEndTime = nEndTime,
|
|
|
+ nBatch = 1,
|
|
|
+ }
|
|
|
+ CommonDB.SetCommerceActInfo(tData)
|
|
|
+ else
|
|
|
+ nBeginTime = tCommerceInfo.nBeginTime
|
|
|
+ nEndTime = tCommerceInfo.nEndTime
|
|
|
+ if nNowTime < tCommerceInfo.nEndTime then
|
|
|
+ isRun = true
|
|
|
+ else
|
|
|
+ isRun = false
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ tCommerceActInfo.nStartTime = nNowTime
|
|
|
+ tCommerceActInfo.nEendTime = nEndTime
|
|
|
+ tCommerceActInfo.isRun = isRun
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+----------------------------------------- 外部调用开始 -------------------------------------
|
|
|
+function onZeroAll(funcID)
|
|
|
+ local nNowTime = os.time()
|
|
|
+ local tDate = os.date("*t",nNowTime)
|
|
|
+
|
|
|
+ if ServerCommerceActDefine.COMMERCEACT_BEGINTIME == tDate.hour then
|
|
|
+ Timer.addLater(ServerCommerceActDefine.COMMERCEACT_BEGINDELATTIME, CommerceAct_GetActOpen,
|
|
|
+ ServerCommerceActDefine.COMMERCEACT_ZERO)
|
|
|
+ elseif ServerCommerceActDefine.COMMERCEACT_ENDTIME == tDate.hour then
|
|
|
+
|
|
|
+
|
|
|
+ tCommerceActInfo = nil
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 请求活动打开信息
|
|
|
+function CommerceAct_GetActOpen(nOperate)
|
|
|
+ ServerCommerceMiddle.CommerceMiddle_IsActOpen(nOperate)
|
|
|
+end
|
|
|
+
|
|
|
+-- 中心服回复活动信息
|
|
|
+function CommerceAct_ActCheckOpen(nOpen, nOperate)
|
|
|
+ if not tCommerceActInfo then
|
|
|
+ tCommerceActInfo = {}
|
|
|
+ end
|
|
|
+
|
|
|
+ tCommerceActInfo.nOpen = nOpen
|
|
|
+ if ServerCommerceActDefine.COMMERCEACT_SERVEROPEN == nOperate then
|
|
|
+ CommerceAct_ActCheckOpen_InitServer(nOpen)
|
|
|
+ else
|
|
|
+
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 起服初始化
|
|
|
+function CommerceAct_Init()
|
|
|
+ local nNowTime = os.time()
|
|
|
+
|
|
|
+ for nID, v in pairs(ServerCommerceCof.CommerceAct) do
|
|
|
+ local moduleFn = load("return require(\"" .. v.moduleFn .. "\")")()
|
|
|
+ if moduleFn then
|
|
|
+ tCommerceActModuel[nID] = moduleFn
|
|
|
+ if moduleFn.Init then
|
|
|
+ local bRet = moduleFn.Init()
|
|
|
+ if false == bRet then
|
|
|
+ print("[CommerceAct_Init] 初始化模块数据失败 nID ".. nID)
|
|
|
+ end
|
|
|
+ end
|
|
|
+ print("[CommerceAct_Init] 加载模块成功 name = "..v.name)
|
|
|
+ else
|
|
|
+ print("[CommerceAct_Init] 加载模块失败 nID ".. nID)
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ Timer.addLater(ServerCommerceActDefine.COMMERCEACT_INITSERVERTIME, CommerceAct_GetActOpen,
|
|
|
+ ServerCommerceActDefine.COMMERCEACT_SERVEROPEN)
|
|
|
+end
|
|
|
+
|
|
|
+-- 是否还在活动期间
|
|
|
+function CommerceAct_IsRun()
|
|
|
+ if not tCommerceActInfo then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ return tCommerceActInfo.isRun
|
|
|
+end
|
|
|
+
|
|
|
+function CommerceAct_IsSend()
|
|
|
+ if not tCommerceActInfo then
|
|
|
+ return false
|
|
|
+ end
|
|
|
+
|
|
|
+ return tCommerceActInfo.nSend
|
|
|
+end
|
|
|
+
|
|
|
+-- 玩家登录
|
|
|
+function onLogin(human, funcID)
|
|
|
+ if not human then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+
|
|
|
+ local nLastEndTime = CommerceAct_GetHumanEndTime(human)
|
|
|
+ local nState = CommerceAct_GetHumanEndMail(human)
|
|
|
+
|
|
|
+ local nSendMail = nState and 1 or 0
|
|
|
+ print("[onLogin] 玩家登录 nSendMail = "..nSendMail)
|
|
|
+
|
|
|
+ -- 未开始
|
|
|
+ if false == CommerceAct_IsRun() then
|
|
|
+ if true == nState or -1 >= nLastEndTime then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ CommerceAct_EndAllAct(human)
|
|
|
+
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 当前活动开启,记录的结束时间比当前开始的时间都小说明是新活动
|
|
|
+ if nLastEndTime < tCommerceActInfo.nStartTime then
|
|
|
+ if false == nState then
|
|
|
+ -- 处理上一次的奖励数据
|
|
|
+ CommerceAct_HandleEndData(human)
|
|
|
+ end
|
|
|
+
|
|
|
+ CommerceAct_BeginAllAct(human)
|
|
|
+
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 下发活动基础数据
|
|
|
+ if true == CommerceAct_IsRun() then
|
|
|
+ CommerceAct_SendActInfo(human)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+-- 英雄星级改变回调
|
|
|
+function onHeroStarChange(human, funcID, parameter, parameter2)
|
|
|
+ if not human or "table" ~= type(parameter) then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ if false == CommerceAct_IsRun() then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+-- 是否开启
|
|
|
+function isOpen(human, YYInfo, funcConfig)
|
|
|
+ local bRet = CommerceAct_IsRun()
|
|
|
+ local nRet = bRet and 1 or 0
|
|
|
+ print("CommerceAct_isOpen 结束 nRet = "..nRet)
|
|
|
+ return bRet
|
|
|
+end
|
|
|
+
|
|
|
+--
|
|
|
+function isActive(human, YYInfo, funcConfig)
|
|
|
+ return not isOpen(human, YYInfo, funcConfig)
|
|
|
+end
|
|
|
+
|
|
|
+function isRed(human, YYInfo, funcConfig)
|
|
|
+ local bRet = false
|
|
|
+ for id, v in pairs(ServerCommerceCof.WeekLoopAct) do
|
|
|
+ if tCommerceActModuel[id] and tCommerceActModuel[id].isRed then
|
|
|
+ bRet = tCommerceActModuel[id].isRed(human)
|
|
|
+ if true == bRet then
|
|
|
+ break
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ return bRet
|
|
|
+end
|
|
|
+
|
|
|
+-- 消耗古玉回调
|
|
|
+function onDecZuanshi(human, funcID, parameter, parameter2)
|
|
|
+ if not human or "number" ~= type(parameter) then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ if false == CommerceAct_IsRun() then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ local nGuYu = math.abs(parameter)
|
|
|
+ if 0 >= nGuYu then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+-- 高级召唤回调
|
|
|
+function onDrawCard(human, funcID, parameter, parameter2)
|
|
|
+ if not human or "number" ~= type(parameter) then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ if false == CommerceAct_IsRun() then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ print("[onDrawCard] 高级召唤回调 parameter = "..parameter)
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+-- 天命召唤回调
|
|
|
+function onTMDrawCard(human, funcID, parameter, parameter2)
|
|
|
+ if not human or "number" ~= type(parameter) then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ if false == CommerceAct_IsRun() then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ print("[onDrawCard] 天命召唤回调 parameter = "..parameter)
|
|
|
+
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+-- 寻星回调
|
|
|
+function onFindStar(human, funcID, parameter, parameter2)
|
|
|
+ if not human or "number" ~= type(parameter) then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ if false == CommerceAct_IsRun() then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ print("[onDrawCard] 寻星回调 parameter = "..parameter)
|
|
|
+
|
|
|
+end
|
|
|
+
|
|
|
+-- GM 命令
|
|
|
+function GMResetWeekAct(human)
|
|
|
+ if CommerceAct_IsRun() then
|
|
|
+ CommerceAct_EndAllAct(human)
|
|
|
+
|
|
|
+ CommerceAct_SetCardBatch()
|
|
|
+ CommerceAct_BeginAllAct(human)
|
|
|
+ end
|
|
|
+end
|
|
|
+
|
|
|
+function onCharge(human, price, funcID, buyID)
|
|
|
+ if not human then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ if false == CommerceAct_IsRun() then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ print("[onCharge] 玩家充值回调开始 name = "..human.db.name.." price = "..price)
|
|
|
+
|
|
|
+
|
|
|
+end
|