YunYingLogic.lua 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. ---------------------------------------------------------
  2. -- 图标管理
  3. -- updateIcon 刷新图标
  4. -- module接口
  5. -- isOpen 如果模块没有这个函数默认是开启 human, YYInfo, funcConfig
  6. -- isRed 如果模块没这个函数 默认是没红点 human, YYInfo, funcConfig
  7. -- getIcon 如果模块没这个函数 默认从yunying表里面读iconid
  8. -- isActive 跟模块关联的激活状态
  9. -- updateDaily 隔天处理
  10. -- onCharge 充值回调
  11. -- onZero 0点处理
  12. -- onLevelUp 升级回调
  13. -- onLogin 登陆回调
  14. ---------------------------------------------------------
  15. local YunYingExcel = require("excel.yunying")
  16. local Lang = require("common.Lang")
  17. local Config = require("Config")
  18. local Util = require("common.Util")
  19. local Msg = require("core.Msg")
  20. local Broadcast = require("broadcast.Broadcast")
  21. local ObjHuman = require("core.ObjHuman")
  22. local BannerExcel = require("excel.yunying")
  23. local AbsActLogic = require("absAct.AbsActLogic")
  24. local SysParameter = require("common.SysParameter")
  25. local PanelDefine = require("broadcast.PanelDefine")
  26. local HeroGrid = require("hero.HeroGrid")
  27. local HeroUpLogic = require("absAct.HeroUpLogic")
  28. local AbsActExcel = require("excel.absAct")
  29. local HtmlUtil = require("common.HtmlUtil")
  30. local Json = require("common.Json")
  31. local YunYingDefine = require("yunying.YunYingDefine")
  32. local CommonDB = require("common.CommonDB")
  33. local MiddleConnect = require("middle.MiddleConnect")
  34. local InnerMsg = require("core.InnerMsg")
  35. local AbsReachRankDB = require("absAct.AbsReachRankDB")
  36. local OpenServerActPowerUp = require("present.OpenServerActPowerUp")
  37. local WeekendLoopActManger = require("WeekendLoopActivity.WeekendLoopActManager")
  38. local OpenServerActAddUpCharge = require("present.OpenServerActAddUpCharge")
  39. local ServerCommerceActManger = require("serverCommerce.ServerCommerceManager")
  40. local CycleActivityLogic = require("yunying.CycleActivity")
  41. ID2YYInfo = ID2YYInfo or { } -- 每个id是一个主界面上方运营活动大图标入口
  42. PANELID2OPENLV = PANELID2OPENLV or { }
  43. YYFUNCINFO = YYFUNCINFO or { } -- 活动列表 用于快捷查询
  44. BANNER_LIST_SERVER = {}
  45. YUNYING_POS_TYPE1 = 1 -- 运营活动
  46. YUNYING_POS_TYPE2 = 2 -- abs活动
  47. function inServerIndex(svrIndexs)
  48. for i = 1, #svrIndexs do
  49. local index1 = svrIndexs[i][1]
  50. local index2 = svrIndexs[i][2]
  51. if Config.SVR_INDEX >= index1 and Config.SVR_INDEX <= index2 then
  52. return true
  53. end
  54. end
  55. end
  56. -- 根据funcID确定配置文件
  57. function getFuncConfig(funcID)
  58. local funcConfig = YunYingExcel.func[funcID]
  59. if not funcConfig then
  60. funcConfig = AbsActExcel.absActivity[funcID]
  61. end
  62. return funcConfig
  63. end
  64. -- 根据funcID 确定modouleFn数据
  65. local function getYYFuncInfo(funcID)
  66. if not YYFUNCINFO then return end
  67. return YYFUNCINFO[funcID]
  68. end
  69. -- 是否是运营活动
  70. local function isYYfunc(funcID)
  71. if YunYingExcel.func[funcID] then
  72. return true
  73. end
  74. return false
  75. end
  76. -- 是否是Abs活动
  77. local function isAbsfunc(funcID)
  78. if AbsActExcel.absActivity[funcID] then
  79. return true
  80. end
  81. return false
  82. end
  83. -- 初始化数据
  84. local function initYYInfo(yyID, config)
  85. local YYInfo = ID2YYInfo[yyID] or { }
  86. YYInfo.yyID = yyID
  87. YYInfo.config = config
  88. local moduleList = nil
  89. local openLv = 0
  90. for i = 1, #config.funcs do
  91. local funcID = config.funcs[i]
  92. local funcConfig = getFuncConfig(funcID)
  93. if YYFUNCINFO[funcID] then
  94. assert(nil, "initYYInfo is error!!!!"..yyID.."-"..funcID)
  95. end
  96. if funcConfig then
  97. if funcConfig.moduleFn ~= "" then
  98. moduleList = moduleList or { }
  99. local moduleFn = load("return require(\"" .. funcConfig.moduleFn .. "\")")()
  100. moduleList[funcID] = moduleFn
  101. if moduleFn then
  102. moduleFn.funcID = moduleFn.funcID or {}
  103. moduleFn.funcID[funcID] = funcID
  104. moduleFn.YYInfo = moduleFn.YYInfo or {}
  105. moduleFn.YYInfo[funcID] = YYInfo
  106. moduleFn.pos = moduleFn.pos or {}
  107. moduleFn.pos[funcID] = config.pos
  108. moduleFn.yyID = moduleFn.yyID or {}
  109. moduleFn.yyID[funcID] = yyID
  110. funcConfig.funcID = funcID
  111. YYFUNCINFO[funcID] = moduleFn
  112. PANELID2OPENLV[funcConfig.panelID] = funcConfig.openLv
  113. end
  114. end
  115. -- 取子功能里面最低等级
  116. if openLv > funcConfig.openLv or openLv == 0 then
  117. openLv = funcConfig.openLv
  118. end
  119. end
  120. end
  121. YYInfo.moduleList = moduleList
  122. YYInfo.openLv = openLv
  123. ID2YYInfo[yyID] = YYInfo
  124. return YYInfo
  125. end
  126. -- 初始化
  127. function init()
  128. ID2YYInfo = ID2YYInfo or { }
  129. YYFUNCINFO = {}
  130. BANNER_LIST_SERVER = {}
  131. for yyID, noUse in pairs(ID2YYInfo) do
  132. if YunYingExcel.config[yyID] == nil then
  133. ID2YYInfo[yyID] = nil
  134. end
  135. end
  136. for funcID, info in pairs(YYFUNCINFO) do
  137. if YunYingExcel.func[funcID] == nil then
  138. YYFUNCINFO[funcID] = nil
  139. end
  140. if AbsActExcel.absActivity[funcID] == nil then
  141. YYFUNCINFO[funcID] = nil
  142. end
  143. end
  144. for yyID, config in pairs(YunYingExcel.config) do
  145. if inServerIndex(config.serverIndex) then
  146. initYYInfo(yyID, config)
  147. end
  148. end
  149. -- 广告
  150. for k, config in pairs(BannerExcel.banner) do
  151. if inServerIndex(config.serverIndex) then
  152. BANNER_LIST_SERVER[#BANNER_LIST_SERVER + 1] = k
  153. end
  154. end
  155. handleAbs()
  156. -- 活动初始化后 才能去实始化ABS排名活动
  157. AbsReachRankDB.init()
  158. OpenServerActPowerUp.Init()
  159. WeekendLoopActManger.WeekLoopACT_Init()
  160. OpenServerActAddUpCharge.Init()
  161. ServerCommerceActManger.CommerceAct_Init()
  162. end
  163. ABS_LOOP_TYPE1 = 1 -- 指定时间的活动
  164. ABS_LOOP_TYPE2 = 2 -- 指定时间的活动 指定间隔天数 循环一次
  165. ABS_LOOP_TYPE3 = 3 -- 按开服时间 指定间隔天数 一直循环 支持间隔时间设置
  166. ABS_LOOP_TYPE4 = 4 -- 按开服时间 指定间隔天数 循环一次
  167. ABS_LOOP_TYPE5 = 5 -- 按合服时间 指定间隔天数 循环一次
  168. ABS_LOOP_TYPE6 = 6 -- 每周周几开
  169. ABS_LOOP_TYPE7 = 7 -- 每月几号开
  170. DAY_SEC = 24 * 3600
  171. -- 指定时间的活动
  172. local function handleAbsInit(openDay, now, config, funcID)
  173. config.actId = config.actId or 0
  174. config.adIcon = 0
  175. config.realStartTime = 0
  176. config.realEndTime = 0
  177. end
  178. function handleAbs7MiddleReturn(fd,msg)
  179. if msg.isOpen == 0 then
  180. return
  181. end
  182. local config = getFuncConfig(msg.funcID)
  183. local openDay = CommonDB.getServerOpenDay()
  184. if openDay == nil then return end
  185. if config.loopType ~= ABS_LOOP_TYPE7 then return end
  186. local now = os.time()
  187. local days = config.days -- 持续几天
  188. local turns = config.turns --
  189. local ad = config.ad --
  190. local eachDays = config.eachDays -- 几号开
  191. local toOpenDay = openDay - config.openDay
  192. local endDay = days + eachDays -- 几号结束
  193. local actStart = false
  194. if days > 0 and #turns > 0 then
  195. local nowMidnight = Util.getDayStartTime(now)
  196. local d = os.date("*t",now)
  197. local monthDay = d.day
  198. -- 生效期
  199. if toOpenDay >= 0 and monthDay >= config.eachDays and monthDay < endDay then
  200. local subDays = monthDay - config.eachDays
  201. local handleBeginTs = nil
  202. handleBeginTs = nowMidnight - subDays * DAY_SEC
  203. config.realStartTime = handleBeginTs
  204. config.realEndTime = handleBeginTs + days * DAY_SEC - 3600 -- 活动23点结束
  205. if now >= config.realStartTime and now < config.realEndTime then
  206. config.actId = turns[1] or 0
  207. config.adIcon = ad[1] or 0
  208. print("handleAbs7 act is started!!",Config.SVR_INDEX,msg.funcID,config.actId)
  209. actStart = true
  210. end
  211. end
  212. else
  213. assert(nil, "handleAbs ABS_LOOP_TYPE7 days or turns err !!!" .. funcID)
  214. end
  215. if actStart then
  216. for _, human in pairs(ObjHuman.onlineUuid) do
  217. print("aaaa actStart")
  218. sendIcons(human)
  219. end
  220. end
  221. end
  222. -- 初始化abs活动 开启的时间
  223. function handleAbs()
  224. local openDay = CommonDB.getServerOpenDay()
  225. if openDay == nil then return end
  226. local mergeDay = CommonDB.getServerMergeDay()
  227. local now = os.time()
  228. for yyID, YYInfo in pairs(ID2YYInfo) do
  229. for i = 1, #YYInfo.config.funcs do
  230. local funcID = YYInfo.config.funcs[i]
  231. if isAbsfunc(funcID) then
  232. local config = getFuncConfig(funcID)
  233. if not config then
  234. assert(nil, "handleAbs config is nil !!!" .. funcID)
  235. end
  236. handleAbsInit(openDay, now, config, funcID)
  237. end
  238. end
  239. end
  240. end
  241. -- panel id -> id
  242. local PANELID_2_ACTID = nil
  243. local function getActIDByPanelID(panelID)
  244. if not PANELID_2_ACTID then
  245. PANELID_2_ACTID = { }
  246. for id, config in pairs(YunYingExcel.config) do
  247. if inServerIndex(config.serverIndex) then
  248. PANELID_2_ACTID[config.panelID] = id
  249. end
  250. end
  251. end
  252. return PANELID_2_ACTID[panelID]
  253. end
  254. function getOpenLvByPanelID(panelID)
  255. return PANELID2OPENLV[panelID] or 0
  256. end
  257. -- 是否开启活动,内部使用
  258. local function isBaseOpen(YYInfo, human)
  259. if not YYInfo then return end
  260. if human.db.lv < YYInfo.openLv then return end
  261. if not YYInfo.moduleList then return end
  262. for k, v in pairs(YYInfo.moduleList) do
  263. local funcConfig = getFuncConfig(k)
  264. if v.isOpen and v.isOpen(human, YYInfo, funcConfig) == true then
  265. return true
  266. end
  267. end
  268. end
  269. -- 未开放提示
  270. local function sendNoOpen(human, noSend)
  271. if noSend then return end
  272. Broadcast.sendErr(human, Lang.YUNYING_ERR_TIME)
  273. end
  274. -- 是否开启
  275. function isOpen(YYInfo, human, noSend)
  276. if not YYInfo then
  277. return sendNoOpen(human, noSend)
  278. end
  279. if not isBaseOpen(YYInfo, human) then
  280. return sendNoOpen(human, noSend)
  281. end
  282. return true
  283. end
  284. -- 是否显示红点
  285. function isRed(YYInfo, human)
  286. if not YYInfo then return false end
  287. if not YYInfo.moduleList then return false end
  288. for k, v in pairs(YYInfo.moduleList) do
  289. local funcConfig = getFuncConfig(k)
  290. -- 开启了才判断红点
  291. if not v.isOpen or v.isOpen(human, YYInfo, funcConfig) == true then
  292. if v.isRed and v.isRed(human, YYInfo, funcConfig) == true then
  293. return true
  294. end
  295. end
  296. end
  297. return false
  298. end
  299. -- 获得图标 主要是节日活动和绝对时间活动每周的图标都不一样
  300. function getIcon(YYInfo, human)
  301. if not YYInfo then return false end
  302. if not YYInfo.moduleList then return false end
  303. if YYInfo.config.pos ~= YUNYING_POS_TYPE1 then return false end
  304. for k, v in pairs(YYInfo.moduleList) do
  305. local funcConfig = getFuncConfig(k)
  306. if v.getIcon then
  307. return v.getIcon(human, YYInfo, funcConfig)
  308. end
  309. end
  310. end
  311. -- 缓存红点
  312. function setCacheRed(human, yyID, red)
  313. human.yunyings[yyID] = red
  314. end
  315. --
  316. function getCacheRed(human, yyID)
  317. return human.yunyings and human.yunyings[yyID]
  318. end
  319. function getLeftTime(YYInfo, human)
  320. if not YYInfo then return 0 end
  321. if not YYInfo.moduleList then return 0 end
  322. local leftTime = 0
  323. for k, v in pairs(YYInfo.moduleList) do
  324. local funcConfig = getFuncConfig(k)
  325. if v.getLeftTime and funcConfig.actId ~= 0 then
  326. local rest = v.getLeftTime(human, YYInfo, funcConfig)
  327. leftTime = leftTime < rest and rest or leftTime
  328. end
  329. end
  330. return leftTime
  331. end
  332. -- 封装结构体
  333. local function fontIcon(net, YYInfo, human)
  334. local config = YYInfo.config
  335. local red = isRed(YYInfo, human)
  336. net.id = YYInfo.yyID
  337. net.red = red and 1 or 0
  338. net.leftTime = getLeftTime(YYInfo, human) or 0
  339. net.icon = getIcon(YYInfo, human)
  340. if net.icon == nil or net.icon == 0 then
  341. net.icon = config.icon
  342. end
  343. net.sortID = config.sortID
  344. net.panelID = config.panelID
  345. net.pos = config.pos or 0
  346. setCacheRed(human, YYInfo.yyID, red)
  347. end
  348. -- 运营活动列表
  349. function sendIcons(human)
  350. human.yunyings = { }
  351. local msgRet = Msg.gc.GC_YUNYING_LIST
  352. msgRet.list[0] = 0
  353. local maxLen = #msgRet.list
  354. for _, YYInfo in pairs(ID2YYInfo) do
  355. if isOpen(YYInfo, human, true) and
  356. YYInfo.config.pos == YUNYING_POS_TYPE1 then
  357. print("[sendIcons] 发送的活动ID = "..YYInfo.yyID)
  358. if msgRet.list[0] >= maxLen then
  359. break
  360. end
  361. msgRet.list[0] = msgRet.list[0] + 1
  362. fontIcon(msgRet.list[msgRet.list[0]], YYInfo, human)
  363. end
  364. end
  365. Msg.send(msgRet, human.fd)
  366. end
  367. -- 刷新图标
  368. function updateIcon(YYInfo, human, nocheckred)
  369. if not YYInfo then return end
  370. if YYInfo.config.pos ~= YUNYING_POS_TYPE1 then return end
  371. if isOpen(YYInfo, human, true) then
  372. if nocheckred or(getCacheRed(human, YYInfo.yyID) ~= isRed(YYInfo, human)) then
  373. sendIconUpdate(YYInfo.yyID, human)
  374. end
  375. else
  376. if nocheckred or getCacheRed(human, YYInfo.yyID) ~= nil then
  377. sendIconDel(YYInfo.yyID, human)
  378. end
  379. end
  380. end
  381. -- 添加或者改变
  382. function sendIconUpdate(yyID, human)
  383. if not human.yunyings then return end
  384. -- 未初始不发
  385. local YYInfo = ID2YYInfo[yyID]
  386. if not YYInfo then return end
  387. if YYInfo.config.pos ~= YUNYING_POS_TYPE1 then return end
  388. local msgRet = Msg.gc.GC_YUNYING_UPDATE
  389. if human then
  390. fontIcon(msgRet.data, YYInfo, human)
  391. Msg.send(msgRet, human.fd)
  392. else
  393. for _, human in pairs(ObjHuman.onlineUuid) do
  394. if human.fd then
  395. fontIcon(msgRet.data, YYInfo, human)
  396. Msg.send(msgRet, human.fd)
  397. end
  398. end
  399. end
  400. end
  401. -- 删除
  402. function sendIconDel(yyID, human)
  403. if not human.yunyings then return end
  404. -- 未初始不发
  405. local YYInfo = ID2YYInfo[yyID]
  406. if not YYInfo then return end
  407. if YYInfo.config.pos ~= YUNYING_POS_TYPE1 then return end
  408. local msgRet = Msg.gc.GC_YUNYING_DEL
  409. msgRet.id = yyID
  410. if human then
  411. Msg.send(msgRet, human.fd)
  412. setCacheRed(human, YYInfo.yyID)
  413. else
  414. for _, human in pairs(ObjHuman.onlineUuid) do
  415. if human.fd then
  416. Msg.send(msgRet, human.fd)
  417. setCacheRed(human, YYInfo.yyID)
  418. end
  419. end
  420. end
  421. end
  422. -- 活动组信息
  423. function sendGroupList(human, panelID)
  424. -- 获取panel运营ID
  425. local actID = getActIDByPanelID(panelID)
  426. if (not actID or actID < 1 ) and panelID ~= PanelDefine.PANEL_ID_3101 then
  427. return
  428. end
  429. -- 通过运营ID获取运营信息
  430. local YYInfo = ID2YYInfo[actID]
  431. if not isOpen(YYInfo, human, true) then
  432. return
  433. end
  434. local msgRet = Msg.gc.GC_YUNYING_GROUP_LIST
  435. msgRet.panelID = panelID
  436. msgRet.list[0] = 0
  437. for i = 1, #YYInfo.config.funcs do
  438. local funcID = YYInfo.config.funcs[i]
  439. local funcConfig = getFuncConfig(funcID)
  440. local state = false
  441. local endTime = nil
  442. local startTime = nil
  443. local leftTime = nil
  444. if human.db.lv >= funcConfig.openLv then
  445. if YYInfo.moduleList[funcID] ~= nil and
  446. YYInfo.moduleList[funcID].isOpen ~= nil then
  447. state, endTime, startTime = YYInfo.moduleList[funcID].isOpen(human, YYInfo, funcConfig)
  448. if endTime then
  449. leftTime = endTime - os.time()
  450. end
  451. else
  452. state = true
  453. end
  454. end
  455. if state then
  456. msgRet.list[0] = msgRet.list[0] + 1
  457. if YYInfo.moduleList[funcID] ~= nil and
  458. YYInfo.moduleList[funcID].getLeftTime ~= nil then
  459. leftTime = YYInfo.moduleList[funcID].getLeftTime(human, YYInfo, funcConfig)
  460. end
  461. local net = msgRet.list[msgRet.list[0]]
  462. net.id = funcID
  463. net.icon = funcConfig.icon
  464. net.red = 0
  465. net.leftTime = leftTime or 0
  466. net.endTime = endTime or 0
  467. net.startTime = startTime or 0
  468. net.name = funcConfig.actName or ""
  469. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].isRed and YYInfo.moduleList[funcID].isRed(human, YYInfo, funcConfig) == true then
  470. net.red = 1
  471. end
  472. net.panelID = funcConfig.panelID
  473. net.effect = funcConfig.effect
  474. net.param = funcID
  475. end
  476. end
  477. Msg.send(msgRet, human.fd)
  478. end
  479. -- 刷新标签页红点
  480. function sendGroupUpdate(YYInfo, human, subPanelID, param)
  481. if not YYInfo then print(" not YYInfo param ", param, " panelID ", subPanelID) return end
  482. local msgRet = Msg.gc.GC_YUNYING_GROUP_UPDATE
  483. msgRet.panelID = YYInfo.config.panelID
  484. local state = false
  485. local endTime = nil
  486. local startTime = nil
  487. local id = nil
  488. local len = 0
  489. for i = 1, #YYInfo.config.funcs do
  490. local funcID = YYInfo.config.funcs[i]
  491. local funcConfig = getFuncConfig(funcID)
  492. if (not param and funcConfig.panelID == subPanelID) or
  493. (param and funcConfig.param == param and funcConfig.panelID == subPanelID) then -- 同一个 面板的 多期活动
  494. if YYInfo.moduleList[funcID] ~= nil and
  495. YYInfo.moduleList[funcID].isOpen ~= nil then
  496. state, endTime, startTime = YYInfo.moduleList[funcID].isOpen(human, YYInfo, funcConfig)
  497. else
  498. state = true
  499. end
  500. if not state then return end
  501. local leftTime = nil
  502. if YYInfo.moduleList[funcID] ~= nil and
  503. YYInfo.moduleList[funcID].getLeftTime ~= nil then
  504. leftTime = YYInfo.moduleList[funcID].getLeftTime(human, YYInfo, funcConfig)
  505. end
  506. len = len + 1
  507. msgRet.data.id = funcID
  508. msgRet.data.icon = funcConfig.icon
  509. msgRet.data.name = funcConfig.actName or ""
  510. msgRet.data.red = 0
  511. msgRet.data.leftTime = leftTime or 0
  512. msgRet.data.endTime = endTime or 0
  513. msgRet.data.startTime = startTime or 0
  514. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].isRed and YYInfo.moduleList[funcID].isRed(human, YYInfo, funcConfig) == true then
  515. msgRet.data.red = 1
  516. end
  517. msgRet.data.panelID = funcConfig.panelID
  518. msgRet.data.effect = funcConfig.effect
  519. msgRet.data.param = funcID
  520. break
  521. end
  522. end
  523. if len == 0 then return end
  524. Msg.send(msgRet, human.fd)
  525. end
  526. -- 推送开放等级
  527. function sendOpenLv(human, panelID)
  528. local openLv = getOpenLvByPanelID(panelID)
  529. if not openLv then return end
  530. local msgRet = Msg.gc.GC_YUNYING_OPEN_LV
  531. msgRet.openLv = openLv
  532. msgRet.panelID = panelID
  533. Msg.send(msgRet, human.fd)
  534. end
  535. -- 一次性广告面板
  536. function sendFirstBanner(human)
  537. local funcID = YunYingDefine.YUNYING_ID_101
  538. local moduleFn = getYYFuncInfo(funcID)
  539. if not moduleFn then return end
  540. local funcConfig = YunYingExcel.func[funcID]
  541. if not funcConfig then return end
  542. if not moduleFn.isOpen(human, moduleFn.YYInfo[funcID], funcConfig) then return end
  543. local dialogLv = SysParameter.getSysParameter(SysParameter.PARAMETER_14)
  544. local firstPanel = nil
  545. if human.db.lv >= dialogLv then
  546. if human.db.guide.firstPanel == nil then
  547. firstPanel = PanelDefine.PANEL_ID_3302
  548. human.db.guide.firstPanel = 1
  549. end
  550. end
  551. if not firstPanel then return end
  552. local msgRet = Msg.gc.GC_YUNYING_FIRST_BANNER_QUERY
  553. msgRet.panelID = firstPanel
  554. Msg.send(msgRet, human.fd)
  555. end
  556. -- 广告面板
  557. local function bannerCmp(a, b)
  558. return a[2] < b[2]
  559. end
  560. local function makeBannerNet(net, bannerID, dot, banner)
  561. print("#### bannerID: ", bannerID)
  562. local config = BannerExcel.banner[bannerID]
  563. if not config then return end
  564. local jSonParam = {}
  565. net.icon = config.icon
  566. net.panelID = config.panelID
  567. local moduleFn = getYYFuncInfo(config.funcID[1])
  568. if moduleFn then
  569. jSonParam.yyID = moduleFn.yyID[config.funcID[1]]
  570. jSonParam.tsStart = banner[4]
  571. jSonParam.tsEnd = banner[5]
  572. jSonParam.leftTs = banner[6]
  573. jSonParam.ad = 0
  574. jSonParam.dot = dot
  575. jSonParam.param = banner[10]
  576. if moduleFn.makeBanner then
  577. moduleFn.makeBanner(jSonParam, banner[9])
  578. end
  579. local funcConfig = getFuncConfig(config.funcID[1])
  580. net.panelID = funcConfig.panelID
  581. end
  582. net.param = Json.Encode(jSonParam)
  583. end
  584. function sendBanner(human)
  585. local nNowLv = human.db.lv
  586. local bannerList = { }
  587. local len = 0
  588. for k, _id in ipairs(BANNER_LIST_SERVER) do
  589. local config = BannerExcel.banner[_id]
  590. local lenth = #config.funcID
  591. local dot = nil
  592. for i = 1,lenth do
  593. local moduleFn = getYYFuncInfo(config.funcID[i])
  594. if moduleFn and inServerIndex(config.serverIndex) then
  595. local YYInfo = moduleFn.YYInfo[config.funcID[i]]
  596. local funcConfig = getFuncConfig(moduleFn.funcID[config.funcID[i]])
  597. local active = nil
  598. if moduleFn.isActive and
  599. not moduleFn.isActive(human, YYInfo, funcConfig) and nNowLv >= funcConfig.openLv then
  600. if dot ~= true then
  601. dot = moduleFn.isRed and moduleFn.isRed(human, YYInfo, funcConfig)
  602. end
  603. end
  604. end
  605. end
  606. if _id == 4 or _id == 34 then
  607. dot = nil
  608. end
  609. local moduleFn = getYYFuncInfo(config.funcID[1])
  610. if moduleFn and inServerIndex(config.serverIndex) then
  611. local YYInfo = moduleFn.YYInfo[config.funcID[1]]
  612. local funcConfig = getFuncConfig(moduleFn.funcID[config.funcID[1]])
  613. local active = nil
  614. if moduleFn.isActive and
  615. not moduleFn.isActive(human, YYInfo, funcConfig) and nNowLv >= funcConfig.openLv then
  616. local leftTime, endTime, startTime = 0
  617. local state = false
  618. if isAbsfunc(moduleFn.funcID[config.funcID[1]]) then
  619. state, endTime, startTime = moduleFn.isOpen(human, YYInfo, funcConfig)
  620. if state then
  621. leftTime = endTime - os.time()
  622. end
  623. end
  624. len = len + 1
  625. bannerList[len] = { _id, config.sortID, dot, startTime, endTime, leftTime, state, YYInfo.yyID, funcConfig.funcID, funcConfig.param }
  626. end
  627. end
  628. end
  629. local bannerID = 1
  630. local dot = 0
  631. local sortID = 0
  632. if len > 0 then
  633. table.sort(bannerList, bannerCmp)
  634. sortID = bannerList[1][2]
  635. end
  636. local msgRet = Msg.gc.GC_BANNER_QUERY
  637. local count = 0
  638. for i = 1,len do
  639. if bannerList[i][2] == sortID then
  640. count = count + 1
  641. bannerID = bannerList[i][1]
  642. if not bannerList[i][3] then
  643. dot = 0
  644. else
  645. dot = 1
  646. end
  647. makeBannerNet(msgRet.bannerList[count], bannerID, dot, bannerList[i])
  648. end
  649. if count >= 9 then
  650. break
  651. end
  652. end
  653. if count == 0 then
  654. count = count + 1
  655. bannerID = 1
  656. dot = 0
  657. makeBannerNet(msgRet.bannerList[count], bannerID, dot, bannerList[1])
  658. end
  659. msgRet.bannerList[0] = count
  660. Msg.send(msgRet, human.fd)
  661. end
  662. -- 登陆处理
  663. function onLogin(human)
  664. AbsActLogic.onLogin(human)
  665. for yyID, YYInfo in pairs(ID2YYInfo) do
  666. for i = 1, #YYInfo.config.funcs do
  667. local funcID = YYInfo.config.funcs[i]
  668. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onLogin then
  669. YYInfo.moduleList[funcID].onLogin(human, funcID)
  670. end
  671. end
  672. end
  673. CycleActivityLogic.onLogin(human)
  674. sendIcons(human)
  675. sendBanner(human)
  676. sendFirstBanner(human)
  677. end
  678. -- 隔天处理
  679. function updateDaily(human)
  680. for yyID, YYInfo in pairs(ID2YYInfo) do
  681. for i = 1, #YYInfo.config.funcs do
  682. local funcID = YYInfo.config.funcs[i]
  683. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].updateDaily then
  684. YYInfo.moduleList[funcID].updateDaily(human, funcID)
  685. end
  686. end
  687. updateIcon(YYInfo, human, true)
  688. end
  689. sendBanner(human)
  690. end
  691. -- 充值接口
  692. function onCharge(human, price, buyID)
  693. for yyID, YYInfo in pairs(ID2YYInfo) do
  694. for i = 1, #YYInfo.config.funcs do
  695. local funcID = YYInfo.config.funcs[i]
  696. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onCharge then
  697. YYInfo.moduleList[funcID].onCharge(human, price, funcID, buyID)
  698. end
  699. end
  700. end
  701. sendBanner(human)
  702. end
  703. -- 0点
  704. function onZeroHuman(human)
  705. for yyID, YYInfo in pairs(ID2YYInfo) do
  706. for i = 1, #YYInfo.config.funcs do
  707. local funcID = YYInfo.config.funcs[i]
  708. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onZero then
  709. YYInfo.moduleList[funcID].onZero(human, funcID)
  710. end
  711. end
  712. end
  713. sendIcons(human)
  714. end
  715. -- 0点
  716. function onZero()
  717. for yyID, YYInfo in pairs(ID2YYInfo) do
  718. for i = 1, #YYInfo.config.funcs do
  719. local funcID = YYInfo.config.funcs[i]
  720. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onZeroAll then
  721. YYInfo.moduleList[funcID].onZeroAll(funcID)
  722. end
  723. end
  724. end
  725. handleAbs()
  726. end
  727. -- 整点刷新
  728. function onHour(hour)
  729. -- 0点onZero 处理了
  730. if 0 == hour then
  731. return
  732. end
  733. print("[YunYingLogic-onHour] 开启处理整点 hour = "..hour)
  734. for yyID, YYInfo in pairs(ID2YYInfo) do
  735. for i = 1, #YYInfo.config.funcs do
  736. local funcID = YYInfo.config.funcs[i]
  737. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onHour then
  738. YYInfo.moduleList[funcID].onHour(hour)
  739. end
  740. end
  741. end
  742. end
  743. -- 升级回调
  744. function onLevelUp(human, oldLv, newLv)
  745. for yyID, YYInfo in pairs(ID2YYInfo) do
  746. for i = 1, #YYInfo.config.funcs do
  747. local funcID = YYInfo.config.funcs[i]
  748. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onLevelUp then
  749. YYInfo.moduleList[funcID].onLevelUp(human, oldLv, newLv, funcID)
  750. end
  751. end
  752. end
  753. for yyID, YYInfo in pairs(ID2YYInfo) do
  754. if oldLv < YYInfo.openLv and YYInfo.openLv <= newLv then
  755. if isOpen(YYInfo, human, true) then
  756. sendIconUpdate(yyID, human)
  757. end
  758. end
  759. end
  760. sendBanner(human)
  761. end
  762. -- 购买礼包的回调
  763. function onBuy(human, buyConf, isFirst, cnt)
  764. for yyID, YYInfo in pairs(ID2YYInfo) do
  765. for i = 1, #YYInfo.config.funcs do
  766. local funcID = YYInfo.config.funcs[i]
  767. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID][buyConf.cmd] then
  768. YYInfo.moduleList[funcID][buyConf.cmd](human, funcID, buyConf, isFirst, cnt)
  769. end
  770. end
  771. end
  772. end
  773. function CG_YUNYING_UPDATE(human, yyID)
  774. if not human.yunyings then return end
  775. -- 未初始不发
  776. local YYInfo = ID2YYInfo[yyID]
  777. if not YYInfo then return end
  778. updateIcon(YYInfo, human, true)
  779. end
  780. function onServerOpenTime()
  781. handleAbs()
  782. for _, human in pairs(ObjHuman.onlineUuid) do
  783. sendIcons(human)
  784. end
  785. end
  786. ---
  787. --各个模块回调
  788. function onCallBack(human, cmd, parameter, bNoSend, parameter2)
  789. for yyID, YYInfo in pairs(ID2YYInfo) do
  790. for i = 1, #YYInfo.config.funcs do
  791. local funcID = YYInfo.config.funcs[i]
  792. local funcConfig = getFuncConfig(funcID)
  793. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID][cmd] then
  794. local isStart = true
  795. if isAbsfunc(funcID) then
  796. isStart = AbsActLogic.isStarted(human, funcID)
  797. end
  798. if isStart then
  799. local result = YYInfo.moduleList[funcID][cmd](human, funcID, parameter, parameter2)
  800. if result then
  801. updateIcon(YYInfo, human)
  802. sendGroupUpdate(YYInfo, human, funcConfig.panelID)
  803. end
  804. if bNoSend then
  805. return result
  806. end
  807. end
  808. end
  809. end
  810. end
  811. if bNoSend then
  812. return 0
  813. end
  814. end