| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910 |
- --------------------------------
- -- 文件名 : 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 CommonDB = require("common.CommonDB")
- 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 BuyConf = require("excel.buy")
- local ServerCommerceMiddle = require("serverCommerce.ServerCommerceMiddle")
- local ServerCommerceActCharge = require("serverCommerce.ServerCommerceActCharge")
- local ServerCommerceActRank = require("serverCommerce.ServerCommerceActRank")
- local ServerCommerceTask = require("serverCommerce.ServerCommerceActTask")
- local Config = require("Config")
- -- 活动信息
- tCommerceActInfo = nil
- -- {
- -- nStartTime = nil, -- 开始时间
- -- nEendTime = nil, -- 结束时间
- -- isRun = nil, -- 是否在活动中
- -- nOpen = nil, -- 是否打开
- -- nBatchID = nil, -- 批次
- -- }
- -- 加载的模块
- tCommerceActModuel = {}
- -- 当前的操作类型
- local nQueryOperate = nil
- ----------------------------------------- 内部处理开始 -------------------------------------
- -- 下发数据
- local function CommerceAct_SendData(tMsgData, fd)
- Msg.send(tMsgData, fd)
- end
- local function CommerceAct_CheckOpenDay()
- local nNowOpenDay = CommonDB.getServerOpenDay()
- return nNowOpenDay >= ServerCommerceActDefine.COMMERCEACT_SHOW_OPENDAY
- end
- -- 创建玩家DB数据
- function CommerceAct_CreateHumanDB(human)
- local nBatchID = 1
- local tCommonDBData = CommonDB.GetCommerceActInfo()
- if tCommonDBData and nil ~= _G.next(tCommonDBData) then
- nBatchID = tCommonDBData.nBatchID
- end
-
- human.db.ServerCommerce =
- {
- nPoint = 0, -- 当前玩家个人积分
- Task = {}, -- 任务信息
- Charge = {}, -- 连充豪礼
- Shop = {}, -- 战区钜惠
- nBatchID = nBatchID, -- 批次
- bSendPlayerMail = false, -- 是否发送个人邮件
- bSendServerMail = false, -- 是否发送全服邮件
- battleGround = {
- freeChallengeCnt = ServerCommerceActDefine.COMMERCEACT_DAILY_FREECHALLENGETIMES,
- resetTime = os.time(),
- },
- }
- for nID, module in pairs(tCommerceActModuel) do
- if module and module.CreatDB then
- local bRet = module.CreatDB(human)
- if false == bRet then
- print("[CommerceAct_CreateHumanDB] nID 初始化DB 数据失败 nID = "..nID)
- end
- end
- end
- end
- -- 下发活动数据
- function CommerceAct_SendActInfo(human)
- if not human or not tCommerceActInfo then
- return
- end
- if false == CommerceAct_CheckOpenDay() 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
- CommerceAct_CreateHumanDB(human)
- print("[CommerceAct_BeginAllAct] 所有活动初始化数据开始 ")
- end
- -- 结束所有活动
- local function CommerceAct_EndAllAct(human)
- -- 各个子活动处理数据
- CommerceAct_HandleEndData(human)
- end
- -- 活动开始
- local function CommerceAct_Begin()
- if not tCommerceActInfo then
- return
- end
- for nID, module in pairs(tCommerceActModuel) do
- if module and module.ClearCache then
- module.ClearCache()
- end
- end
- -- 遍历在线玩家
- for uuid, human in pairs(ObjHuman.onlineUuid) do
- CommerceAct_BeginAllAct(human)
- CommerceAct_SendActInfo(human)
- end
- end
- -- 活动结束
- function CommerceAct_End()
- -- 排行榜结束
- ServerCommerceMiddle.CommerceMiddle_QueryServerRank(ServerCommerceActDefine.COMMERCEACT_SENDSERVERMAIL)
- -- 处理巅峰战场活动
- local ServerCommerceActBattleGroundNS = require("serverCommerce.ServerCommerceActBattleGroundNS")
- ServerCommerceActBattleGroundNS.Act_End()
- end
- -- 延迟向中心服请求数据
- local function CommerceAct_LaterTimeQuery(nOperate)
- print("[CommerceAct_LaterTimeQuery] 延迟向中心服请求数据开始")
- Timer.addLater(ServerCommerceActDefine.COMMERCEACT_INITSERVERTIME, CommerceAct_GetActOpen, nOperate)
- end
- -- 延迟10分钟开始
- local function CommerceAct_LaterBeginAct()
- if not tCommerceActInfo then
- return
- end
- tCommerceActInfo.isRun = true
- CommerceAct_Begin()
- end
- -- 检查活动是否过期
- local function CommerceAct_CheckActIsOverTime()
- local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
- if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) then
- return true
- end
- local nEndTime = tCommerceDBInfo.nEndTime
- local nNowTime = os.time()
- return nNowTime >= nEndTime
- end
- -- 检查是否开启下一轮活动
- local function CommerceAct_CanOpenNext()
- local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
- if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) or not tCommerceDBInfo.nEndTime then
- print("[CommerceAct_CanOpenNext] 不存在对应的DB数据")
- return true
- end
- local nDiffDay = Util.diffDay(tCommerceDBInfo.nEndTime)
- if nDiffDay > ServerCommerceActDefine.COMMERCEACT_NEXTDAY then
- print("[CommerceAct_CanOpenNext] 间隔天数已经满足条件 nDiffDay = "..nDiffDay)
- return true
- end
-
- return false
- end
- -- 创建通用DB数据
- local function CommerceAct_CreateCommonDB()
- local nNowTime = os.time()
- local tCommerceInfo = CommonDB.GetCommerceActInfo()
- local nEndTime = nNowTime + (ServerCommerceActDefine.COMMERCEACT_LASTDAY - 1)* 86400
- local tEndDate = os.date("*t",nEndTime)
- tEndDate.hour = ServerCommerceActDefine.COMMERCEACT_ENDTIME
- tEndDate.min = 0
- tEndDate.sec = 0
- nEndTime = os.time(tEndDate)
- local tDBData = {
- nBeginTime = nNowTime,
- nEndTime = nEndTime,
- nPoint = 0,
- nSendRankMail = 0,
- }
- if not tCommerceInfo or nil == _G.next(tCommerceInfo) then
- print("[CommerceAct_CreateCommonDB] 不存在DB数据 批次为1")
- tDBData.nBatchID = 1
- else
- if tCommerceInfo.nBatchID then
- tDBData.nBatchID = tCommerceInfo.nBatchID + 1
- print("[CommerceAct_CreateCommonDB] 存在DB数据 批次为加1 nOldBatchID = "..tCommerceInfo.nBatchID.." nNewBatchID = "..tDBData.nBatchID)
- else
- tDBData.nBatchID = 1
- end
- end
- CommonDB.SetCommerceActInfo(tDBData)
- end
- -- 创建缓存数据
- local function CommerceAct_CreateCacheInfo(nOpen, bLater)
- local tCommerceInfo = CommonDB.GetCommerceActInfo()
- if not tCommerceInfo or nil == _G.next(tCommerceInfo) then
- print("[CommerceAct_CreateCacheInfo] 为什么会不存在数据\n")
- return
- end
- tCommerceActInfo = {}
- tCommerceActInfo.nStartTime = tCommerceInfo.nBeginTime
- tCommerceActInfo.nEendTime = tCommerceInfo.nEndTime
- tCommerceActInfo.isRun = true
- if true == bLater then
- tCommerceActInfo.isRun = false
- end
-
- tCommerceActInfo.nOpen = nOpen
- tCommerceActInfo.nBatchID = tCommerceInfo.nBatchID
- print("[CommerceAct_CreateCacheInfo] 创建缓存数据 nStartTime = "..tCommerceActInfo.nStartTime.." nEendTime = "..tCommerceActInfo.nEendTime
- .." nOpen = "..tCommerceActInfo.nOpen.." nBatchID = "
- ..tCommerceActInfo.nBatchID.." isRun = "..(tCommerceActInfo.isRun == true and 1 or 0))
- if bLater == true then
- Timer.addLater(ServerCommerceActDefine.COMMERCEACT_BEGINDELATTIME, CommerceAct_LaterBeginAct)
- else
- for uuid, human in pairs(ObjHuman.onlineUuid) do
- if not human.db.ServerCommerce then
- CommerceAct_CreateHumanDB(human)
- end
- ServerCommerceTask.CommerceActTask_HumanSubEvent(human)
- CommerceAct_SendActInfo(human)
- end
- end
- end
- -- 清理排行榜数据
- local function CommerceAct_ClearRankInfo()
- ServerCommerceMiddle.CommerceMiddle_ClearRank()
- end
- -- 请求中心服活动时间和批次数据
- local function CommerceAct_QueryActOpenTime()
- ServerCommerceMiddle.CommerceMiddle_QueryActOpenTime()
- end
- -- 起服初始化数据
- local function CommerceAct_ActCheckOpen_InitServer(nOpen, nOperate, nServerKey)
- if ServerCommerceActDefine.COMMERCEACT_NOOPEN ~= nOpen then
- nQueryOperate = nOperate
- ServerCommerceActRank.CommercerActRank_GetRankServerKey(nServerKey)
- -- 活动开启去请求时间数据
- CommerceAct_QueryActOpenTime()
- end
- end
- -- 获取玩家当前点数
- function CommerceAct_GetHumanPoint(human)
- return human.db.ServerCommerce.nPoint
- end
- -- 设置玩家当前点数
- local function CommerceAct_SetHumanPoint(human, nValue)
- human.db.ServerCommerce.nPoint = nValue
- end
- -- 获取开始时间
- function CommerceAct_GetOpenAndEndTime()
- if not tCommerceActInfo or not tCommerceActInfo.nStartTime or not tCommerceActInfo.nEendTime then
- return 0, 0
- end
- return tCommerceActInfo.nStartTime, tCommerceActInfo.nEendTime
- end
- ----------------------------------------- 外部调用开始 -------------------------------------
- function onZeroAll(funcID)
- local nNowTime = os.time()
- local tDate = os.date("*t",nNowTime)
- -- 活动未开启
- if tDate.hour == ServerCommerceActDefine.COMMERCEACT_BEGINTIME then
- -- 获取DB数据
- local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
- if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) then
- CommerceAct_LaterTimeQuery(ServerCommerceActDefine.COMMERCEACT_ZERO)
- return
- end
- -- 存在DB数据说明已经满足条件了
- if true == CommerceAct_CheckActIsOverTime() then
- local bOpenNext = CommerceAct_CanOpenNext()
- if false == bOpenNext then
- return
- end
- -- 开启下一轮
- if tCommerceDBInfo.nBatchID < ServerCommerceActDefine.COMMERCEACT_ENDBATCH then
- CommerveManager_WriteLog("[CommerveManager-onZeroAll] 当前条件满足开启下一轮活动 nOldBatchID = "..tCommerceDBInfo.nBatchID.." nNewBatchID = "..tCommerceDBInfo.nBatchID+1)
- -- 清理排行榜数据
- CommerceAct_ClearRankInfo()
- -- 重新请求活动时间数据
- CommerceAct_QueryActOpenTime()
- nQueryOperate = ServerCommerceActDefine.COMMERCEACT_ZERO
- -- CommerceAct_CreateCommonDB()
- -- -- 存在数据说明时间是满足的
- -- CommerceAct_CreateCacheInfo(ServerCommerceActDefine.COMMERCEACT_OPEN, true)
- -- -- 遍历在线玩家
- -- for uuid, human in pairs(ObjHuman.onlineUuid) do
- -- CommerceAct_BeginAllAct(human)
- -- end
- -- -- 重新请求排行榜数据
- -- ServerCommerceActRank.CommercerActRank_InitServerQueryRank()
- end
- end
- end
- end
- function onHour(hour)
- local nNowTime = os.time()
- local tDate = os.date("*t",nNowTime)
- print("[CommerceAct_onHour] 进入整点时间判断 hour = "..hour.." nNowTime = "..nNowTime)
- if tDate.hour == ServerCommerceActDefine.COMMERCEACT_ENDTIME then
- if not tCommerceActInfo then
- print("[CommerceAct_onHour] 不存在对应的数据 ")
- return
- end
- print("[CommerceAct_onHour] 进入结束时间判断 hour = "..hour.." nNowTime = "..nNowTime)
- local tCommerceDBInfo = CommonDB.GetCommerceActInfo()
- if not tCommerceDBInfo or nil == _G.next(tCommerceDBInfo) then
- print("[CommerceAct_onHour] 存在缓存数据, 但是获取不到DB数据")
- return
- end
- local nEndTime = tCommerceDBInfo.nEndTime
- print("[CommerceAct_onHour] nNowTime = "..nNowTime.." nEndTime = "..nEndTime)
- if nEndTime <= nNowTime then
- print("[CommerceAct_onHour] 活动结束 开始处理活动结束流程 ")
- local nDelayTime = math.random(5, 30)
- Timer.addLater(nDelayTime, CommerceAct_End)
- -- 活动结束处理
- tCommerceActInfo.nSendRankMail = true
- tCommerceActInfo.isRun = false
- -- 关闭活动入口
- for uuid, human in pairs(ObjHuman.onlineUuid) do
- YunYingLogic.sendBanner(human)
- end
- end
- end
- end
- -- 请求活动打开信息
- function CommerceAct_GetActOpen(nOperate)
- print("[CommerceAct_GetActOpen] 开始向中心服请求活动数据")
- ServerCommerceMiddle.CommerceMiddle_IsActOpen(nOperate)
- end
- -- 中心服回复活动信息
- function CommerceAct_ActCheckOpen(nOpen, nOperate, nServerKey)
- print("[CommerceAct_ActCheckOpen] 收到活动信息开始处理 nOpen = "..nOpen.." nOperate ="..nOperate)
- CommerceAct_ActCheckOpen_InitServer(nOpen, nOperate, nServerKey)
- end
- -- 起服初始化
- function CommerceAct_Init()
- if _G.is_middle == true then
- -- 中心服起服获取信息
- print("[CommerceAct_Init] 中心服起服请求数据开始")
- ServerCommerceMiddle.CommerceMiddle_InitServer()
- return
- end
- local nNowTime = os.time()
- for nID, v in pairs(ServerCommerceCof.CommerceAct) do
- if v.moduleFn then
- 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
- else
- print("[CommerceAct_Init] 未配置 name = "..v.name)
- end
- end
- print("[CommerceAct_Init] 延迟进行请求数据操作")
-
- -- 延迟向中心服请求数据
- CommerceAct_LaterTimeQuery(ServerCommerceActDefine.COMMERCEACT_SERVEROPEN)
- end
- -- 是否还在活动期间
- function CommerceAct_IsRun()
- if not tCommerceActInfo then
- return false
- end
- if false == CommerceAct_CheckOpenDay() then
- print("[CommerceAct_IsRun] 开服时间不符合条件 nNowOpenDay = ", CommonDB.getServerOpenDay())
- return false
- end
- return tCommerceActInfo.isRun
- end
- -- 获取到中心服活动时间数据
- function CommerceAct_GetActTime(tData)
- local tOldDBData = CommonDB.GetCommerceActInfo()
- local tNewDBData = nil
- local szText = "[CommerceAct_GetActTime] 获取到对应的中心服时间数据 nBatchID = "..tData.nBatchID.." nBeginTime = "..tData.nBeginTime.." nEndTime = ".. tData.nEndTime
- print(szText)
- if tOldDBData and nil ~= _G.next(tOldDBData) then
- if tOldDBData.nBatchID ~= tData.nBatchID or tOldDBData.nBeginTime ~= tData.nBeginTime
- or tOldDBData.nEndTime ~= tOldDBData.nEndTime then
- -- szText = szText .."当前服务器数据和获取到的中心服数据不一致进行了重置 旧的DB数据 nOldBatchID = "..tOldDBData.nBatchID
- -- .." nOldBeginTime = "..tOldDBData.nBeginTime.." nOldEndTime = ".. tOldDBData.nEndTime
- -- print(szText)
- tNewDBData = {}
- tNewDBData.nBatchID = tData.nBatchID
- tNewDBData.nBeginTime = tData.nBeginTime
- tNewDBData.nEndTime = tData.nEndTime
- CommerveManager_WriteLog(szText)
- -- 存在旧数据,看看需要重置数据
- if tData.nBeginTime > tOldDBData.nEndTime then
- tNewDBData.nPoint = 0
- tNewDBData.nSendRankMail = 0
- CommerveManager_WriteLog("[CommerceAct_GetActTime] 存在旧的数据,当前批次开启时间大于上一次结束时间, 重置点数和发送邮件数据")
- else
- tNewDBData.nPoint = tOldDBData.nPoint
- tNewDBData.nSendRankMail = tOldDBData.nSendRankMail
- end
- else
- print("[CommerceAct_GetActTime] 当前时间相同")
- end
- else
- tNewDBData = {}
- tNewDBData.nBatchID = tData.nBatchID
- tNewDBData.nBeginTime = tData.nBeginTime
- tNewDBData.nEndTime = tData.nEndTime
- tNewDBData.nPoint = 0
- tNewDBData.nSendRankMail = 0
- szText = szText.." 当前服务器不存在数据直接创建"
- CommerveManager_WriteLog(szText)
- end
- if nil ~= tNewDBData then
- CommonDB.SetCommerceActInfo(tNewDBData)
- end
- local tCommerceInfo = CommonDB.GetCommerceActInfo()
- local nNowTime = os.time()
- if nNowTime < tCommerceInfo.nEndTime then
- local bLater = nQueryOperate == ServerCommerceActDefine.COMMERCEACT_ZERO and true or false
- CommerceAct_CreateCacheInfo(1, bLater)
- ServerCommerceActRank.CommercerActRank_InitServerQueryRank()
- else
- tCommerceActInfo = {}
- tCommerceActInfo.nStartTime = tCommerceInfo.nBeginTime
- tCommerceActInfo.nEendTime = tCommerceInfo.nEndTime
- tCommerceActInfo.isRun = false
- tCommerceActInfo.nOpen = 0
- tCommerceActInfo.nBatchID = tCommerceInfo.nBatchID
- print("[CommerceAct_ActCheckOpen_InitServer] 活动不在开放时间")
- end
- end
- -- 跨天
- function updateDaily(human, funcID)
- if not human then
- return
- end
- if true == CommerceAct_IsRun() then
- for _, module in pairs(tCommerceActModuel) do
- if module and module.onLogin then
- module.updateDaily(human)
- end
- end
- end
- end
- -- 玩家登录
- function onLogin(human, funcID)
- if not human then
- return
- end
- -- 下发活动基础数据
- if true == CommerceAct_IsRun() then
- print("[CommerceManger_onLogin] 玩家进入进行注册")
- local tCommonDBData = CommonDB.GetCommerceActInfo()
- if not tCommonDBData or nil == _G.next(tCommonDBData) then
- print("[CommerceManger_onLogin] 玩家登录不存在对应的数据通用DB数据!!!!")
- return
- end
- -- 不存在数据直接创建
- if not human.db.ServerCommerce then
- CommerceAct_CreateHumanDB(human)
- else
- -- 用记在玩家身上的批次 和 CommonDB 中的数据比较
- local nOldBatchID = human.db.ServerCommerce.nBatchID
- local nNowBatchID = tCommonDBData.nBatchID
- if nNowBatchID ~= nOldBatchID then
- CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家登录 记录的批次不一致 nOldBatchID = "..nOldBatchID.." nNowBatchID = "..nNowBatchID, human)
- print("[CommerceManger_onLogin] 玩家登录批次不一致, 重置玩家数据 name = "..human.db.name)
- CommerceAct_CreateHumanDB(human)
- end
- end
-
- CommerceAct_SendActInfo(human)
- for _, module in pairs(tCommerceActModuel) do
- if module and module.onLogin then
- module.onLogin(human)
- end
- end
- else
- -- 不在活动中
- local tCommonDBData = CommonDB.GetCommerceActInfo()
- if not tCommonDBData or nil == _G.next(tCommonDBData) then
- print("[CommerceManger_onLogin] 玩家登录不存在对应的数据通用DB数据!!!!")
- return
- end
- if false == CommerceAct_CheckActIsOverTime() then
- print("[CommerceManger_onLogin] 当前还在活动时间内,返回")
- return
- end
- -- 不存在对应DB数据
- if not human.db.ServerCommerce then
- return
- end
- -- 未发送个人邮件都是未上榜的
- local bSendPlayerMail = CommerveManager_GetHumanSendPlayerMail(human)
- local nHumanPoint = CommerceAct_GetHumanPoint(human)
- if false == bSendPlayerMail and nHumanPoint >= 1 then
- print("[CommerceManger_onLogin] 发送个人奖励 name = "..human.db.name)
- CommerveManager_SetHumanSendPlayerMail(human, true)
- ServerCommerceActRank.CommercerActRank_SendHumanMailHumanLogin(human)
- else
- --CommerveManager_SetHumanSendPlayerMail(human, true)
- CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家条件不满足发送个人奖励邮件 nSendServer = "..(bSendPlayerMail == true and 1 or 0).." nHumanPoint = "
- ..nHumanPoint, human)
- end
- -- 全服邮件
- local bSendServerMail = CommerveManager_GetHumanSendServerMail(human)
- local nSendServer = true == bSendServerMail and 1 or 0
- if false == bSendServerMail and 1 == tCommonDBData.nSendRankMail and CommerceAct_GetHumanPoint(human) >= 1 then
- print("[CommerceManger_onLogin] 全服邮件奖励开始发送 name = "..human.db.name)
- CommerveManager_SetHumanSendServerMail(human, true)
- ServerCommerceActRank.CommercerActRank_SendServerMailHumanLogin(human)
- else
- CommerveManager_WriteLog("[CommerceManger_onLogin] 玩家条件不满足 nSendServer = "..nSendServer.." nHumanPoint = "
- ..nHumanPoint.." tCommonDBData.nSendRankMail = "..tCommonDBData.nSendRankMail, human)
- --CommerveManager_SetHumanSendServerMail(human, true)
- print("[CommerceManger_onLogin] 全服邮件奖励 已经发送过了或积分不满足条件 name = "..human.db.name)
- end
- end
- end
- -- 是否开启
- function isOpen(human, YYInfo, funcConfig)
- local bRet = CommerceAct_IsRun()
- local nRet = bRet and 1 or 0
- print("CommerceAct_isOpen 结束 开启为1, 未开启为0 nRet = "..nRet)
- return bRet
- end
- --
- function isActive(human, YYInfo, funcConfig)
- return not isOpen(human, YYInfo, funcConfig)
- end
- function isRed(human, YYInfo, funcConfig)
- if false == CommerceAct_IsRun() then
- return
- end
- if false == CommerceAct_CheckOpenDay() then
- return
- end
- if not human.db.ServerCommerce then
- CommerceAct_CreateHumanDB(human)
- end
- local bRet
- for _, module in pairs(tCommerceActModuel) do
- if module and module.isRed then
- bRet = module.isRed(human)
- if true == bRet then
- break
- end
- end
- end
- return bRet
- end
- function onCharge(human, price, funcID, buyID)
- if not human then
- return
- end
- if false == CommerceAct_IsRun() then
- return
- end
-
- if not human.db.ServerCommerce then
- CommerceAct_CreateHumanDB(human)
- end
- print("[onCharge] 跨服商业活动 玩家充值回调开始 name = "..human.db.name.." price = "..price)
- for _, module in pairs(tCommerceActModuel) do
- if module and module.onCharge then
- module.onCharge(human, price, funcID, buyID)
- end
- end
- local tBuyCfg = BuyConf.buy[buyID]
- if tBuyCfg then
- local region = human.region or "CN"
- local nPoint = tBuyCfg[region]
- CommerveManager_AddServerPoint(nPoint)
- CommerveManager_AddHumanPint(human, nPoint)
- end
- end
- -- 增加整个服务器的点数
- function CommerveManager_AddServerPoint(nAddPoint)
- if false == CommerceAct_IsRun() then
- return
- end
- local tCommonDBData = CommonDB.GetCommerceActInfo()
- local nNewPoint = tCommonDBData.nPoint + nAddPoint
- CommonDB.SetCommerceActInfo_Point(nNewPoint)
- print("[CommerveManager_AddServerPoint] 增加整个服务器的点数 nAddPoint = "..nAddPoint.." nNewPoint = "..nNewPoint)
- for _, module in pairs(tCommerceActModuel) do
- if module and module.onAllPointChange then
- module.onAllPointChange()
- end
- end
- local szText = "[CommerveManager_AddServerPoint] 增加了整个服务器的积分 nAddPoint = "..nAddPoint.." nNewPoint = "..nNewPoint.." 寻宝"..Config.NEW_SVR_INDEX.."区"
- CommerveManager_WriteLog(szText)
- end
- -- 增加个人积分
- function CommerveManager_AddHumanPint(human, nPoint)
- if false == CommerceAct_IsRun() then
- return
- end
- local nNowPoint = CommerceAct_GetHumanPoint(human)
- local nNewPoint = nNowPoint + nPoint
- CommerceAct_SetHumanPoint(human ,nNewPoint)
- print("[CommerveManager_AddHumanPint] 增加个人积分 nAddPoint = "..nPoint.." nNewPoint = "..nNewPoint.." name = "..human.db.name)
- ServerCommerceActRank.CommercerActRank_HumanPointChange(human, nNewPoint)
- local szText = "[CommerveManager_AddHumanPint] 增加了个人积分 nAddPoint = "..nPoint.." nNewPoint = "..nNewPoint
- CommerveManager_WriteLog(szText, human)
- end
- -- 写日志
- function CommerveManager_WriteLog(szLogText, human)
- if human then
- szLogText = szLogText.." name = "..human.db.name.." id = "..human.db._id
- end
- Log.write(Log.LOGID_OSS_COMMON_ACT, szLogText)
- end
- -- 设置全服发送邮件奖励
- function CommerveManager_SetCommDBSendMail(nValue)
- local tCommonDBData = CommonDB.GetCommerceActInfo()
- if not tCommonDBData then
- print("[CommerveManager_SetCommDBSendMail] 居然不存在对应的数据")
- return
- end
- local tNewDBData =
- {
- nBeginTime = tCommonDBData.nBeginTime,
- nEndTime = tCommonDBData.nEndTime,
- nPoint = tCommonDBData.nPoint,
- nSendRankMail = nValue,
- nBatchID = tCommonDBData.nBatchID
- }
- CommonDB.SetCommerceActInfo(tNewDBData)
- print("[CommerveManager_SetCommDBSendMail] 设置全服邮件奖信息结束")
- -- table.print_lua_table(tNewDBData)
- end
- -- 获取全服发送邮件标识
- function CommerveManager_GetCommDBSendMail()
- return CommonDB.GetCommerceActInfo_SendServerMail()
- end
- -- 设置玩家已经获取了全服奖励邮件
- function CommerveManager_SetHumanSendServerMail(human, nValue)
- human.db.ServerCommerce.bSendServerMail = nValue
- end
- -- 获取玩家全服奖励邮件状态
- function CommerveManager_GetHumanSendServerMail(human)
- return human.db.ServerCommerce.bSendServerMail
- end
- -- 设置玩家已经获取了个人奖励邮件
- function CommerveManager_SetHumanSendPlayerMail(human, nValue)
- human.db.ServerCommerce.bSendPlayerMail = nValue
- end
- -- 获取玩家全服奖励邮件状态
- function CommerveManager_GetHumanSendPlayerMail(human)
- return human.db.ServerCommerce.bSendPlayerMail
- end
- -- GM 清理数据
- function CommerveManager_GMClear(human)
- human.db.ServerCommerce =
- {
- nPoint = 0, -- 当前玩家个人积分
- Task = {}, -- 任务信息
- Charge = {}, -- 连充豪礼
- Shop = {}, -- 战区钜惠
- nBatchID = 1, -- 批次
- bSendPlayerMail = false, -- 是否发送个人邮件
- bSendServerMail = false, -- 是否发送全服邮件
- }
- for nID, module in pairs(tCommerceActModuel) do
- if module and module.CreatDB then
- local bRet = module.CreatDB(human)
- if false == bRet then
- print("[CommerceAct_CreateHumanDB] nID 初始化DB 数据失败 nID = "..nID)
- end
- end
- end
- -- table.print_lua_table(human.db.ServerCommerce)
- print("[CommerveManager_GMClear] 玩家重置数据完成 name = "..human.db.name)
- end
- -- GM 增加个人积分
- function CommerveManager_GMAddHumanPoint(human, nNum)
- CommerveManager_AddHumanPint(human, nNum)
- end
- -- GM 增加服务器积分
- function CommerveManager_GMAddServerPoint(nNum)
- CommerveManager_AddServerPoint(nNum)
- end
- -- GM 发送邮件
- function CommerveManager_SendMail()
- CommerveManager_SetCommDBSendMail(0)
- CommerceAct_End()
- end
- function CommerceMiddle_AddTaskPoint(human, nNum)
- ServerCommerceTask.CommerceTask_AddPoint(human, nNum)
- end
- function CommerveManager_GMRest(human)
- ServerCommerceMiddle.CommerceMiddle_GMClearMiddleMail()
- end
- function CommerveManager_GMRestCommonDB()
- local nNowTime = os.time()
- local tCommerceInfo = CommonDB.GetCommerceActInfo()
- local nEndTime = nNowTime + (ServerCommerceActDefine.COMMERCEACT_LASTDAY - 1)* 86400
- local tEndDate = os.date("*t",nEndTime)
- tEndDate.hour = ServerCommerceActDefine.COMMERCEACT_ENDTIME
- tEndDate.min = 0
- tEndDate.sec = 0
- nEndTime = os.time(tEndDate)
- local tDBData = {
- nBeginTime = nNowTime,
- nEndTime = nEndTime,
- nPoint = 0,
- nSendRankMail = 0,
- nBatchID = 1,
- }
- CommonDB.SetCommerceActInfo(tDBData)
- print("[CommerveManager_GMRestCommonDB] 重置通用DB数据完成")
- end
- function CommerveManager_GMClearMiddleMail()
- ServerCommerceMiddle.CommerceMiddle_GMClearMiddleMail()
- end
- function CommerveManager_GMSendHumanMail(human)
- ServerCommerceActRank.CommercerActRank_SendHumanMailHumanLogin(human)
- end
- -- function GetRemainNum(human, nBuyID)
- -- for _, module in pairs(tCommerceActModuel) do
- -- if module and module.onCharge then
- -- if module.IsHaveBuyID and module.IsHaveBuyID(nBuyID) then
- -- return module.GetRemainNum(human, nBuyID)
- -- end
- -- end
- -- end
-
- -- return 0
- -- end
|