YunYingLogic.lua 29 KB

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