YunYingLogic.lua 28 KB

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