YunYingLogic.lua 28 KB

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