YunYingLogic.lua 28 KB

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