| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- --------------------------------
- -- 文件名 : WeekendLoopActManger.lua
- -- 文件说明 : 周末冲刺-活动模板管理
- -- 创建时间 : 2024/11/25
- -- 创建人 : 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 WeekLoopActDef = require("WeekendLoopActivity.WeekendLoopActDefine")
- local WeekLoopActCof = require("excel.WeekLoopAct")
- local WeekLoopActHeroStar = require("WeekendLoopActivity.WeekendLoopActHeroStar")
- local YunYingLogic = require("yunying.YunYingLogic")
- local WeekLoopActGuYu = require("WeekendLoopActivity.WeekendLoopActUseGuYu")
- local weekLoopActCard = require("WeekendLoopActivity.WeekendLoopActCard")
- -- 活动信息
- tWeekActInfo = nil
- -- {
- -- nStartTime = nil, -- 开始时间
- -- nEendTime = nil, -- 结束时间
- -- isRun = nil, -- 是否在活动中
- -- }
- -- 加载的模块
- tWeekActModuel = {}
- ----------------------------------------- 内部处理开始 -------------------------------------
- -- 下发数据
- local function WeekLoopACT_SendData(tMsgData, fd)
- Msg.send(tMsgData, fd)
- end
- -- 下发活动数据
- function WeekLoopACT_SendActInfo(human)
- if not human or not tWeekActInfo then
- return
- end
- print("[WeekLoopACT_SendActInfo] 下发活动数据 开始 ")
- local tMsgData = Msg.gc.GC_WEEKLOOP_ACT_ALLINFO
- tMsgData.nStartTime = tWeekActInfo.nStartTime
- tMsgData.nEendTime = tWeekActInfo.nEendTime
- tMsgData.tActID[0] = #WeekLoopActCof.WeekLoopAct
- local nIndex = 1
- for id, v in pairs(WeekLoopActCof.WeekLoopAct) 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 tWeekActModuel[id] and tWeekActModuel[id].isRed then
- bRed = tWeekActModuel[id].isRed(human)
- end
- tActData.nRed = bRed and 1 or 0
- end
- YunYingLogic.sendBanner(human)
- WeekLoopACT_SendData(tMsgData, human.fd)
- print("[WeekLoopACT_SendActInfo] 下发活动数据 结束 ")
- end
- -- 获取记录在人物身上的结束时间
- local function WeekLoopACT_GetHumanEndTime(human)
- if not human then
- return -1
- end
- if not human.db.nWeekLoopEndTime then
- return -1
- end
- return human.db.nWeekLoopEndTime
- end
- -- 设置记录在人物身上的结束时间
- local function WeekLoopACT_SetHumanEndTime(human, nTime)
- if not human or 0 >= nTime then
- return
- end
- human.db.nWeekLoopEndTime = nTime
- end
- -- 获取记录在人物身上的奖励处理标识
- local function WeekLoopACT_GetHumanEndMail(human)
- if not human then
- return true
- end
- -- 没有 则认为未参加上一次活动
- if not human.db.nWeekLoopEndMail then
- print("[WeekLoopACT_GetHumanEndMail] 没有参加活动")
- return true
- end
- return human.db.nWeekLoopEndMail
- end
- -- 设置记录在人物身上的奖励处理标识
- local function WeekLoopACT_SetHumanEndMail(human, nValue)
- if not human or not nValue then
- return
- end
- human.db.nWeekLoopEndMail = nValue
- end
- -- 各个子活动重置活动数据
- local function WeekLoopACT_ResetData(human)
- if not human then
- return
- end
- -- 这里实际上应该 遍历modulefunc
- WeekLoopActHeroStar.WeekActHeroStar_ResetData(human)
- WeekLoopActGuYu.WeekActGuYu_ResetData(human)
- weekLoopActCard.WeekActCard_ResetData(human)
- end
- -- 各个子活动处理结束数据
- local function WeekLoopACT_HandleEndData(human)
- if not human then
- return
- end
- WeekLoopActHeroStar.WeekActHeroStar_End(human)
- end
- -- 所有活动初始化数据开始
- local function WeekLoopACT_BeginAllAct(human)
- if not human or not tWeekActInfo then
- return
- end
- local nEndTime = tWeekActInfo.nEendTime
-
- print("[WeekLoopACT_BeginAllAct] 所有活动初始化数据开始 ")
- -- 设置时间
- WeekLoopACT_SetHumanEndTime(human, nEndTime)
- -- 设置标记
- WeekLoopACT_SetHumanEndMail(human, false)
- -- 各个子活动重置数据
- WeekLoopACT_ResetData(human)
- -- 最后下发活动数据
- WeekLoopACT_SendActInfo(human)
- print("[WeekLoopACT_BeginAllAct] 所有活动初始化数据结束 ")
- end
- -- 结束所有活动
- local function WeekLoopACT_EndAllAct(human)
- -- 各个子活动处理数据
- WeekLoopACT_HandleEndData(human)
- WeekLoopACT_SetHumanEndMail(human, true)
- end
- -- 活动开始
- local function WeekLoopACT_Begin()
- if not tWeekActInfo then
- return
- end
- -- 遍历在线玩家
- for uuid, human in pairs(ObjHuman.onlineUuid) do
- WeekLoopACT_BeginAllAct(human)
- end
- end
- -- 活动结束
- local function WeekLoopACT_End()
- -- 遍历在线玩家
- for uuid, human in pairs(ObjHuman.onlineUuid) do
- WeekLoopACT_EndAllAct(human)
- end
- end
- ----------------------------------------- 外部调用开始 -------------------------------------
- function onZeroAll(funcID)
- local nNowTime = os.time()
- local tDate = os.date("*t",nNowTime)
-
- local nOpenServerDay = CommonDB.getServerOpenDay()
- if nOpenServerDay < 7 then
- return
- end
- if WeekLoopActDef.WEEKACT_TIME ~= tDate.hour then
- return
- end
- print("[WeekLoopACT_onZeroAll] 进入定时处理")
- if WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday then
- print("[WeekLoopACT_onZeroAll] 周末活动开始打印")
- tWeekActInfo = {}
- tWeekActInfo.isRun = true
- tWeekActInfo.nStartTime = nNowTime
- -- 计算过期时间,转成0时0分
- local nNextTime = nNowTime + 4 * 86400
- local tEndDate = os.date("*t",nNextTime)
- tEndDate.hour = 0
- tEndDate.min = 0
- tEndDate.sec = 0
- local nEndTime = os.time(tEndDate)
- tWeekActInfo.nEendTime = nEndTime
- -- 活动开始
- WeekLoopACT_Begin()
- print("[WeekLoopACT_onZeroAll] 时间打印 nStartTime = ".. tWeekActInfo.nStartTime.." nEendTime = "..tWeekActInfo.nEendTime)
- elseif WeekLoopActDef.WEEKACT_ENDDAY == tDate.wday then
- print("[WeekLoopACT_onZeroAll] 周末活动结束打印")
-
- WeekLoopACT_End()
- tWeekActInfo = nil
- end
- end
- -- 起服初始化
- function WeekLoopACT_Init()
- local nNowTime = os.time()
- local tDate = os.date("*t",nNowTime)
- local nOpenServerDay = CommonDB.getServerOpenDay()
- if nOpenServerDay < 7 then
- return
- end
- print("[WeekLoopACT_Init] 起服初始化 wday = "..tDate.wday.." m = "..tDate.month.." d = "..tDate.day.." h = "..tDate.hour)
- -- 等于星期六 或者 小于星期三
- if WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday or WeekLoopActDef.WEEKACT_ENDDAY > tDate.wday then
- if not tWeekActInfo then
- tWeekActInfo = {}
- tWeekActInfo.isRun = true
-
- local nDiffDay = WeekLoopActDef.WEEKACT_OPENDAY == tDate.wday and 0 or tDate.wday
- local nTime = nNowTime - nDiffDay * 86400
- local tCalDate = os.date("*t",nTime)
- tCalDate.hour = 0
- tCalDate.min = 0
- tCalDate.sec = 0
- tWeekActInfo.nStartTime = os.time(tCalDate)
- local nEndTime = tWeekActInfo.nStartTime + 4 * 86400
- tCalDate = os.date("*t",nEndTime)
- tCalDate.hour = 0
- tCalDate.min = 0
- tCalDate.sec = 0
- tWeekActInfo.nEendTime = os.time(tCalDate)
- print("[WeekLoopACT_Init] 时间打印 nStartTime = ".. tWeekActInfo.nStartTime.." nEendTime = "..tWeekActInfo.nEendTime)
- end
- end
- for nID, v in pairs(WeekLoopActCof.WeekLoopAct) do
- local moduleFn = load("return require(\"" .. v.moduleFn .. "\")")()
- if moduleFn then
- tWeekActModuel[nID] = moduleFn
- if moduleFn.Init then
- local bRet = moduleFn.Init()
- if false == bRet then
- print("[WeekLoopACT_Init] 初始化模块数据失败 nID ".. nID)
- end
- end
- else
- print("[WeekLoopACT_Init] 加载模块失败 nID ".. nID)
- end
- end
- end
- -- 是否还在活动期间
- function WeekLoopACT_IsRun()
- if not tWeekActInfo then
- return false
- end
- return tWeekActInfo.isRun
- end
- -- 玩家登录
- function onLogin(human, funcID)
- if not human then
- return
- end
- local nOpenServerDay = CommonDB.getServerOpenDay()
- if nOpenServerDay < 7 then
- print("[onLogin] 玩家登录,当前服务器开放时间不足,直接返回 nOpenServerDay = "..nOpenServerDay)
- return
- end
- local nLastEndTime = WeekLoopACT_GetHumanEndTime(human)
- local nState = WeekLoopACT_GetHumanEndMail(human)
- local nSendMail = nState and 1 or 0
- print("[onLogin] 玩家登录 nSendMail = "..nSendMail)
- -- 未开始
- if false == WeekLoopACT_IsRun() then
- if true == nState or -1 >= nLastEndTime then
- return
- end
- WeekLoopACT_EndAllAct(human)
-
- return
- end
- -- 当前活动开启,记录的结束时间比当前开始的时间都小说明是新活动
- if nLastEndTime < tWeekActInfo.nStartTime then
- if false == nState then
- -- 处理上一次的奖励数据
- WeekLoopACT_HandleEndData(human)
- end
- WeekLoopACT_BeginAllAct(human)
-
- return
- end
- -- 下发活动基础数据
- if true == WeekLoopACT_IsRun() then
- WeekLoopACT_SendActInfo(human)
- end
- end
- -- 英雄星级改变回调
- function onHeroStarChange(human, funcID, parameter, parameter2)
- if not human or "table" ~= type(parameter) then
- return
- end
- if false == WeekLoopACT_IsRun() then
- return
- end
- WeekLoopActHeroStar.WeekActHeroStar_HeroStarUp(human, parameter[1], parameter[2])
- end
- -- 是否开启
- function isOpen(human, YYInfo, funcConfig)
- local bRet = WeekLoopACT_IsRun()
- local nRet = bRet and 1 or 0
- print("WeekLoopACT_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(WeekLoopActCof.WeekLoopAct) do
- if tWeekActModuel[id] and tWeekActModuel[id].isRed then
- bRet = tWeekActModuel[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 == WeekLoopACT_IsRun() then
- return
- end
- local nGuYu = math.abs(parameter)
- if 0 >= nGuYu then
- return
- end
- WeekLoopActGuYu.WeekActGuYu_UseGuYu(human, nGuYu)
- end
- -- 高级召唤回调
- function onDrawCard(human, funcID, parameter, parameter2)
- if not human or "number" ~= type(parameter) then
- return
- end
- if false == WeekLoopACT_IsRun() then
- return
- end
- weekLoopActCard.WeekActCard_UseCard(human, parameter, WeekLoopActDef.WEEKACT_CARD_TYPE_HIGH)
- end
- -- 天命召唤回调
- function onTMDrawCard(human, funcID, parameter, parameter2)
- if not human or "number" ~= type(parameter) then
- return
- end
- if false == WeekLoopACT_IsRun() then
- return
- end
- weekLoopActCard.WeekActCard_UseCard(human, parameter, WeekLoopActDef.WEEKACT_CARD_TYPE_TIANMING)
- end
- -- 寻星回调
- function onFindStar(human, funcID, parameter, parameter2)
- if not human or "number" ~= type(parameter) then
- return
- end
- if false == WeekLoopACT_IsRun() then
- return
- end
- weekLoopActCard.WeekActCard_UseCard(human, parameter, WeekLoopActDef.WEEKACT_CARD_TYPE_FINDSTAR)
- end
- -- GM 命令
- function GMResetWeekAct(human)
- if WeekLoopACT_IsRun() then
- WeekLoopACT_EndAllAct(human)
- WeekLoopACT_BeginAllAct(human)
- end
- end
|