YunYingLogic.lua 33 KB

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