ServerCommerceManager.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. --------------------------------
  2. -- 文件名 : ServerCommerceActManger.lua
  3. -- 文件说明 : 跨服商业-活动模板管理
  4. -- 创建时间 : 2025/03/26
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Util = require("common.Util")
  8. local Lang = require("common.Lang")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local MailExcel = require("excel.mail")
  11. local Msg = require("core.Msg")
  12. local ObjHuman = require("core.ObjHuman")
  13. local MailManager = require("mail.MailManager")
  14. local BagLogic = require("bag.BagLogic")
  15. local Grid = require("bag.Grid")
  16. local PanelDefine = require("broadcast.PanelDefine")
  17. local CommonDB = require("common.CommonDB")
  18. local BuyLogic = require("topup.BuyLogic")
  19. local GuideLogic = require("guide.GuideLogic")
  20. local Log = require("common.Log")
  21. local YunYingLogic = require("yunying.YunYingLogic")
  22. local ServerCommerceCof = require("excel.ServerCommerce")
  23. local ServerCommerceActDefine = require("serverCommerce.ServerCommerceActDefine")
  24. local Timer = require("core.Timer")
  25. local ServerCommerceMiddle = require("serverCommerce.ServerCommerceMiddle")
  26. -- 活动信息
  27. tCommerceActInfo = nil
  28. -- {
  29. -- nStartTime = nil, -- 开始时间
  30. -- nEendTime = nil, -- 结束时间
  31. -- isRun = nil, -- 是否在活动中
  32. -- nOpen = nil, -- 是否打开
  33. -- }
  34. -- 加载的模块
  35. tCommerceActModuel = {}
  36. ----------------------------------------- 内部处理开始 -------------------------------------
  37. -- 下发数据
  38. local function CommerceAct_SendData(tMsgData, fd)
  39. Msg.send(tMsgData, fd)
  40. end
  41. -- 下发活动数据
  42. function CommerceAct_SendActInfo(human)
  43. if not human or not tCommerceActInfo then
  44. return
  45. end
  46. print("[CommerceAct_SendActInfo] 下发活动数据 开始 ")
  47. local tMsgData = Msg.gc.GC_SERVEERCOMMERCE_ACT_ALLINFO
  48. tMsgData.nStartTime = tCommerceActInfo.nStartTime
  49. tMsgData.nEendTime = tCommerceActInfo.nEendTime
  50. tMsgData.tActID[0] = #ServerCommerceCof.CommerceAct
  51. local nIndex = 1
  52. for id, v in pairs(ServerCommerceCof.CommerceAct) do
  53. local tActData = tMsgData.tActID[nIndex]
  54. nIndex = nIndex + 1
  55. tActData.ID = id
  56. tActData.name = v.name
  57. tActData.nSortID = v.sortID
  58. tActData.nIcon = v.icon
  59. tActData.nPanelID = v.panelID
  60. local bRed = false
  61. if tCommerceActModuel[id] and tCommerceActModuel[id].isRed then
  62. bRed = tCommerceActModuel[id].isRed(human)
  63. end
  64. print("[CommerceAct_SendActInfo] name = "..tActData.name)
  65. tActData.nRed = (bRed == true) and 1 or 0
  66. end
  67. YunYingLogic.sendBanner(human)
  68. CommerceAct_SendData(tMsgData, human.fd)
  69. print("[CommerceAct_SendActInfo] 下发活动数据 结束 ")
  70. end
  71. -- 各个子活动重置活动数据
  72. local function CommerceAct_ResetData(human)
  73. if not human then
  74. return
  75. end
  76. end
  77. -- 各个子活动处理结束数据
  78. local function CommerceAct_HandleEndData(human)
  79. if not human then
  80. return
  81. end
  82. end
  83. -- 所有活动初始化数据开始
  84. local function CommerceAct_BeginAllAct(human)
  85. if not human or not tCommerceActInfo then
  86. return
  87. end
  88. local nEndTime = tCommerceActInfo.nEendTime
  89. print("[CommerceAct_BeginAllAct] 所有活动初始化数据开始 ")
  90. end
  91. -- 结束所有活动
  92. local function CommerceAct_EndAllAct(human)
  93. -- 各个子活动处理数据
  94. CommerceAct_HandleEndData(human)
  95. CommerceAct_SetHumanEndMail(human, true)
  96. end
  97. -- 活动开始
  98. local function CommerceAct_Begin()
  99. if not tCommerceActInfo then
  100. return
  101. end
  102. -- 遍历在线玩家
  103. for uuid, human in pairs(ObjHuman.onlineUuid) do
  104. CommerceAct_BeginAllAct(human)
  105. end
  106. -- 清理排行榜数据
  107. -- weekLoopActRank.WeekActRank_ResetData()
  108. end
  109. -- 活动结束
  110. local function CommerceAct_End()
  111. -- 遍历在线玩家
  112. for uuid, human in pairs(ObjHuman.onlineUuid) do
  113. CommerceAct_EndAllAct(human)
  114. end
  115. -- 排行榜直接处理
  116. -- weekLoopActRank.WeekActRank_End()
  117. end
  118. -- 获取抽卡批次
  119. function CommerceAct_GetCardBatch()
  120. end
  121. -- 设置新的批次
  122. local function CommerceAct_SetCardBatch()
  123. end
  124. local function CommerceAct_ActCheckOpen_InitServer(nOpen)
  125. if ServerCommerceActDefine.COMMERCEACT_NOOPEN ~= nOpen then
  126. local tCommerceInfo = CommonDB.GetCommerceActInfo()
  127. local nNowTime = os.time()
  128. local nBeginTime, nEndTime, isRun
  129. if not tCommerceInfo or nil == _G.next(tCommerceInfo) then
  130. nBeginTime = nNowTime
  131. isRun = true
  132. nEndTime = nNowTime + ServerCommerceActDefine.COMMERCEACT_LASTDAY * 86400
  133. local tEndDate = os.date("*t",nEndTime)
  134. tEndDate.hour = ServerCommerceActDefine.COMMERCEACT_ENDTIME
  135. tEndDate.min = 0
  136. tEndDate.sec = 0
  137. nEndTime = os.time(tEndDate)
  138. local tData = {
  139. nBeginTime = nNowTime,
  140. nEndTime = nEndTime,
  141. nBatch = 1,
  142. }
  143. CommonDB.SetCommerceActInfo(tData)
  144. else
  145. nBeginTime = tCommerceInfo.nBeginTime
  146. nEndTime = tCommerceInfo.nEndTime
  147. if nNowTime < tCommerceInfo.nEndTime then
  148. isRun = true
  149. else
  150. isRun = false
  151. end
  152. end
  153. tCommerceActInfo.nStartTime = nNowTime
  154. tCommerceActInfo.nEendTime = nEndTime
  155. tCommerceActInfo.isRun = isRun
  156. end
  157. end
  158. ----------------------------------------- 外部调用开始 -------------------------------------
  159. function onZeroAll(funcID)
  160. local nNowTime = os.time()
  161. local tDate = os.date("*t",nNowTime)
  162. if ServerCommerceActDefine.COMMERCEACT_BEGINTIME == tDate.hour then
  163. Timer.addLater(ServerCommerceActDefine.COMMERCEACT_BEGINDELATTIME, CommerceAct_GetActOpen,
  164. ServerCommerceActDefine.COMMERCEACT_ZERO)
  165. elseif ServerCommerceActDefine.COMMERCEACT_ENDTIME == tDate.hour then
  166. tCommerceActInfo = nil
  167. end
  168. end
  169. -- 请求活动打开信息
  170. function CommerceAct_GetActOpen(nOperate)
  171. ServerCommerceMiddle.CommerceMiddle_IsActOpen(nOperate)
  172. end
  173. -- 中心服回复活动信息
  174. function CommerceAct_ActCheckOpen(nOpen, nOperate)
  175. if not tCommerceActInfo then
  176. tCommerceActInfo = {}
  177. end
  178. tCommerceActInfo.nOpen = nOpen
  179. if ServerCommerceActDefine.COMMERCEACT_SERVEROPEN == nOperate then
  180. CommerceAct_ActCheckOpen_InitServer(nOpen)
  181. else
  182. end
  183. end
  184. -- 起服初始化
  185. function CommerceAct_Init()
  186. local nNowTime = os.time()
  187. for nID, v in pairs(ServerCommerceCof.CommerceAct) do
  188. local moduleFn = load("return require(\"" .. v.moduleFn .. "\")")()
  189. if moduleFn then
  190. tCommerceActModuel[nID] = moduleFn
  191. if moduleFn.Init then
  192. local bRet = moduleFn.Init()
  193. if false == bRet then
  194. print("[CommerceAct_Init] 初始化模块数据失败 nID ".. nID)
  195. end
  196. end
  197. print("[CommerceAct_Init] 加载模块成功 name = "..v.name)
  198. else
  199. print("[CommerceAct_Init] 加载模块失败 nID ".. nID)
  200. end
  201. end
  202. Timer.addLater(ServerCommerceActDefine.COMMERCEACT_INITSERVERTIME, CommerceAct_GetActOpen,
  203. ServerCommerceActDefine.COMMERCEACT_SERVEROPEN)
  204. end
  205. -- 是否还在活动期间
  206. function CommerceAct_IsRun()
  207. if not tCommerceActInfo then
  208. return false
  209. end
  210. return tCommerceActInfo.isRun
  211. end
  212. function CommerceAct_IsSend()
  213. if not tCommerceActInfo then
  214. return false
  215. end
  216. return tCommerceActInfo.nSend
  217. end
  218. -- 玩家登录
  219. function onLogin(human, funcID)
  220. if not human then
  221. return
  222. end
  223. local nLastEndTime = CommerceAct_GetHumanEndTime(human)
  224. local nState = CommerceAct_GetHumanEndMail(human)
  225. local nSendMail = nState and 1 or 0
  226. print("[onLogin] 玩家登录 nSendMail = "..nSendMail)
  227. -- 未开始
  228. if false == CommerceAct_IsRun() then
  229. if true == nState or -1 >= nLastEndTime then
  230. return
  231. end
  232. CommerceAct_EndAllAct(human)
  233. return
  234. end
  235. -- 当前活动开启,记录的结束时间比当前开始的时间都小说明是新活动
  236. if nLastEndTime < tCommerceActInfo.nStartTime then
  237. if false == nState then
  238. -- 处理上一次的奖励数据
  239. CommerceAct_HandleEndData(human)
  240. end
  241. CommerceAct_BeginAllAct(human)
  242. return
  243. end
  244. -- 下发活动基础数据
  245. if true == CommerceAct_IsRun() then
  246. CommerceAct_SendActInfo(human)
  247. end
  248. end
  249. -- 英雄星级改变回调
  250. function onHeroStarChange(human, funcID, parameter, parameter2)
  251. if not human or "table" ~= type(parameter) then
  252. return
  253. end
  254. if false == CommerceAct_IsRun() then
  255. return
  256. end
  257. end
  258. -- 是否开启
  259. function isOpen(human, YYInfo, funcConfig)
  260. local bRet = CommerceAct_IsRun()
  261. local nRet = bRet and 1 or 0
  262. print("CommerceAct_isOpen 结束 nRet = "..nRet)
  263. return bRet
  264. end
  265. --
  266. function isActive(human, YYInfo, funcConfig)
  267. return not isOpen(human, YYInfo, funcConfig)
  268. end
  269. function isRed(human, YYInfo, funcConfig)
  270. local bRet = false
  271. for id, v in pairs(ServerCommerceCof.WeekLoopAct) do
  272. if tCommerceActModuel[id] and tCommerceActModuel[id].isRed then
  273. bRet = tCommerceActModuel[id].isRed(human)
  274. if true == bRet then
  275. break
  276. end
  277. end
  278. end
  279. return bRet
  280. end
  281. -- 消耗古玉回调
  282. function onDecZuanshi(human, funcID, parameter, parameter2)
  283. if not human or "number" ~= type(parameter) then
  284. return
  285. end
  286. if false == CommerceAct_IsRun() then
  287. return
  288. end
  289. local nGuYu = math.abs(parameter)
  290. if 0 >= nGuYu then
  291. return
  292. end
  293. end
  294. -- 高级召唤回调
  295. function onDrawCard(human, funcID, parameter, parameter2)
  296. if not human or "number" ~= type(parameter) then
  297. return
  298. end
  299. if false == CommerceAct_IsRun() then
  300. return
  301. end
  302. print("[onDrawCard] 高级召唤回调 parameter = "..parameter)
  303. end
  304. -- 天命召唤回调
  305. function onTMDrawCard(human, funcID, parameter, parameter2)
  306. if not human or "number" ~= type(parameter) then
  307. return
  308. end
  309. if false == CommerceAct_IsRun() then
  310. return
  311. end
  312. print("[onDrawCard] 天命召唤回调 parameter = "..parameter)
  313. end
  314. -- 寻星回调
  315. function onFindStar(human, funcID, parameter, parameter2)
  316. if not human or "number" ~= type(parameter) then
  317. return
  318. end
  319. if false == CommerceAct_IsRun() then
  320. return
  321. end
  322. print("[onDrawCard] 寻星回调 parameter = "..parameter)
  323. end
  324. -- GM 命令
  325. function GMResetWeekAct(human)
  326. if CommerceAct_IsRun() then
  327. CommerceAct_EndAllAct(human)
  328. CommerceAct_SetCardBatch()
  329. CommerceAct_BeginAllAct(human)
  330. end
  331. end
  332. function onCharge(human, price, funcID, buyID)
  333. if not human then
  334. return
  335. end
  336. if false == CommerceAct_IsRun() then
  337. return
  338. end
  339. print("[onCharge] 玩家充值回调开始 name = "..human.db.name.." price = "..price)
  340. end