YunYingLogic.lua 30 KB

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