YunYingLogic.lua 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  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. print("============ panel not open ",panelID)
  430. return
  431. end
  432. local msgRet = Msg.gc.GC_YUNYING_GROUP_LIST
  433. msgRet.panelID = panelID
  434. msgRet.list[0] = 0
  435. for i = 1, #YYInfo.config.funcs do
  436. local funcID = YYInfo.config.funcs[i]
  437. local funcConfig = getFuncConfig(funcID)
  438. local state = false
  439. local endTime = nil
  440. local startTime = nil
  441. local leftTime = nil
  442. if human.db.lv >= funcConfig.openLv then
  443. if YYInfo.moduleList[funcID] ~= nil and
  444. YYInfo.moduleList[funcID].isOpen ~= nil then
  445. state, endTime, startTime = YYInfo.moduleList[funcID].isOpen(human, YYInfo, funcConfig)
  446. if endTime then
  447. leftTime = endTime - os.time()
  448. end
  449. else
  450. state = true
  451. end
  452. end
  453. if state then
  454. msgRet.list[0] = msgRet.list[0] + 1
  455. if YYInfo.moduleList[funcID] ~= nil and
  456. YYInfo.moduleList[funcID].getLeftTime ~= nil then
  457. leftTime = YYInfo.moduleList[funcID].getLeftTime(human, YYInfo, funcConfig)
  458. end
  459. local net = msgRet.list[msgRet.list[0]]
  460. net.id = funcID
  461. net.icon = funcConfig.icon
  462. net.red = 0
  463. net.leftTime = leftTime or 0
  464. net.endTime = endTime or 0
  465. net.startTime = startTime or 0
  466. net.name = funcConfig.actName or ""
  467. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].isRed and YYInfo.moduleList[funcID].isRed(human, YYInfo, funcConfig) == true then
  468. net.red = 1
  469. end
  470. net.panelID = funcConfig.panelID
  471. net.effect = funcConfig.effect
  472. net.param = funcID
  473. end
  474. end
  475. Msg.send(msgRet, human.fd)
  476. end
  477. -- 刷新标签页红点
  478. function sendGroupUpdate(YYInfo, human, subPanelID, param)
  479. if not YYInfo then print(" not YYInfo param ", param, " panelID ", subPanelID) return end
  480. local msgRet = Msg.gc.GC_YUNYING_GROUP_UPDATE
  481. msgRet.panelID = YYInfo.config.panelID
  482. local state = false
  483. local endTime = nil
  484. local startTime = nil
  485. local id = nil
  486. local len = 0
  487. for i = 1, #YYInfo.config.funcs do
  488. local funcID = YYInfo.config.funcs[i]
  489. local funcConfig = getFuncConfig(funcID)
  490. if (not param and funcConfig.panelID == subPanelID) or
  491. (param and funcConfig.param == param and funcConfig.panelID == subPanelID) then -- 同一个 面板的 多期活动
  492. if YYInfo.moduleList[funcID] ~= nil and
  493. YYInfo.moduleList[funcID].isOpen ~= nil then
  494. state, endTime, startTime = YYInfo.moduleList[funcID].isOpen(human, YYInfo, funcConfig)
  495. else
  496. state = true
  497. end
  498. if not state then return end
  499. local leftTime = nil
  500. if YYInfo.moduleList[funcID] ~= nil and
  501. YYInfo.moduleList[funcID].getLeftTime ~= nil then
  502. leftTime = YYInfo.moduleList[funcID].getLeftTime(human, YYInfo, funcConfig)
  503. end
  504. len = len + 1
  505. msgRet.data.id = funcID
  506. msgRet.data.icon = funcConfig.icon
  507. msgRet.data.name = funcConfig.actName or ""
  508. msgRet.data.red = 0
  509. msgRet.data.leftTime = leftTime or 0
  510. msgRet.data.endTime = endTime or 0
  511. msgRet.data.startTime = startTime or 0
  512. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].isRed and YYInfo.moduleList[funcID].isRed(human, YYInfo, funcConfig) == true then
  513. msgRet.data.red = 1
  514. end
  515. msgRet.data.panelID = funcConfig.panelID
  516. msgRet.data.effect = funcConfig.effect
  517. msgRet.data.param = funcID
  518. break
  519. end
  520. end
  521. if len == 0 then return end
  522. Msg.send(msgRet, human.fd)
  523. end
  524. -- 推送开放等级
  525. function sendOpenLv(human, panelID)
  526. local openLv = getOpenLvByPanelID(panelID)
  527. if not openLv then return end
  528. local msgRet = Msg.gc.GC_YUNYING_OPEN_LV
  529. msgRet.openLv = openLv
  530. msgRet.panelID = panelID
  531. Msg.send(msgRet, human.fd)
  532. end
  533. -- 一次性广告面板
  534. function sendFirstBanner(human)
  535. local funcID = YunYingDefine.YUNYING_ID_101
  536. local moduleFn = getYYFuncInfo(funcID)
  537. if not moduleFn then return end
  538. local funcConfig = YunYingExcel.func[funcID]
  539. if not funcConfig then return end
  540. if not moduleFn.isOpen(human, moduleFn.YYInfo[funcID], funcConfig) then return end
  541. local dialogLv = SysParameter.getSysParameter(SysParameter.PARAMETER_14)
  542. local firstPanel = nil
  543. if human.db.lv >= dialogLv then
  544. if human.db.guide.firstPanel == nil then
  545. firstPanel = PanelDefine.PANEL_ID_3302
  546. human.db.guide.firstPanel = 1
  547. end
  548. end
  549. if not firstPanel then return end
  550. local msgRet = Msg.gc.GC_YUNYING_FIRST_BANNER_QUERY
  551. msgRet.panelID = firstPanel
  552. Msg.send(msgRet, human.fd)
  553. end
  554. -- 广告面板
  555. local function bannerCmp(a, b)
  556. return a[2] < b[2]
  557. end
  558. local function makeBannerNet(net, bannerID, dot, banner)
  559. print("#### bannerID: ", bannerID)
  560. local config = BannerExcel.banner[bannerID]
  561. if not config then return end
  562. local jSonParam = {}
  563. net.icon = config.icon
  564. net.panelID = config.panelID
  565. local moduleFn = getYYFuncInfo(config.funcID[1])
  566. if moduleFn then
  567. jSonParam.yyID = moduleFn.yyID[config.funcID[1]]
  568. jSonParam.tsStart = banner[4]
  569. jSonParam.tsEnd = banner[5]
  570. jSonParam.leftTs = banner[6]
  571. jSonParam.ad = 0
  572. jSonParam.dot = dot
  573. jSonParam.param = banner[10]
  574. if moduleFn.makeBanner then
  575. moduleFn.makeBanner(jSonParam, banner[9])
  576. end
  577. local funcConfig = getFuncConfig(config.funcID[1])
  578. net.panelID = funcConfig.panelID
  579. end
  580. net.param = Json.Encode(jSonParam)
  581. end
  582. function sendBanner(human)
  583. local bannerList = { }
  584. local len = 0
  585. for k, _id in ipairs(BANNER_LIST_SERVER) do
  586. local config = BannerExcel.banner[_id]
  587. local lenth = #config.funcID
  588. local dot = nil
  589. for i = 1,lenth do
  590. local moduleFn = getYYFuncInfo(config.funcID[i])
  591. if moduleFn and inServerIndex(config.serverIndex) then
  592. local YYInfo = moduleFn.YYInfo[config.funcID[i]]
  593. local funcConfig = getFuncConfig(moduleFn.funcID[config.funcID[i]])
  594. local active = nil
  595. if moduleFn.isActive and
  596. not moduleFn.isActive(human, YYInfo, funcConfig) then
  597. if dot ~= true then
  598. dot = moduleFn.isRed and moduleFn.isRed(human, YYInfo, funcConfig)
  599. end
  600. end
  601. end
  602. end
  603. if _id == 4 or _id == 34 then
  604. dot = nil
  605. end
  606. local moduleFn = getYYFuncInfo(config.funcID[1])
  607. if moduleFn and inServerIndex(config.serverIndex) then
  608. local YYInfo = moduleFn.YYInfo[config.funcID[1]]
  609. local funcConfig = getFuncConfig(moduleFn.funcID[config.funcID[1]])
  610. local active = nil
  611. if moduleFn.isActive and
  612. not moduleFn.isActive(human, YYInfo, funcConfig) then
  613. local leftTime, endTime, startTime = 0
  614. local state = false
  615. if isAbsfunc(moduleFn.funcID[config.funcID[1]]) then
  616. state, endTime, startTime = moduleFn.isOpen(human, YYInfo, funcConfig)
  617. if state then
  618. leftTime = endTime - os.time()
  619. end
  620. end
  621. len = len + 1
  622. bannerList[len] = { _id, config.sortID, dot, startTime, endTime, leftTime, state, YYInfo.yyID, funcConfig.funcID, funcConfig.param }
  623. end
  624. end
  625. end
  626. local bannerID = 1
  627. local dot = 0
  628. local sortID = 0
  629. if len > 0 then
  630. table.sort(bannerList, bannerCmp)
  631. sortID = bannerList[1][2]
  632. end
  633. local msgRet = Msg.gc.GC_BANNER_QUERY
  634. local count = 0
  635. for i = 1,len do
  636. if bannerList[i][2] == sortID then
  637. count = count + 1
  638. bannerID = bannerList[i][1]
  639. if not bannerList[i][3] then
  640. dot = 0
  641. else
  642. dot = 1
  643. end
  644. makeBannerNet(msgRet.bannerList[count], bannerID, dot, bannerList[i])
  645. end
  646. if count >= 6 then
  647. break
  648. end
  649. end
  650. if count == 0 then
  651. count = count + 1
  652. bannerID = 1
  653. dot = 0
  654. makeBannerNet(msgRet.bannerList[count], bannerID, dot, bannerList[1])
  655. end
  656. msgRet.bannerList[0] = count
  657. Msg.send(msgRet, human.fd)
  658. end
  659. -- 登陆处理
  660. function onLogin(human)
  661. AbsActLogic.onLogin(human)
  662. for yyID, YYInfo in pairs(ID2YYInfo) do
  663. for i = 1, #YYInfo.config.funcs do
  664. local funcID = YYInfo.config.funcs[i]
  665. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onLogin then
  666. YYInfo.moduleList[funcID].onLogin(human, funcID)
  667. end
  668. end
  669. end
  670. sendIcons(human)
  671. sendBanner(human)
  672. sendFirstBanner(human)
  673. end
  674. -- 隔天处理
  675. function updateDaily(human)
  676. for yyID, YYInfo in pairs(ID2YYInfo) do
  677. for i = 1, #YYInfo.config.funcs do
  678. local funcID = YYInfo.config.funcs[i]
  679. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].updateDaily then
  680. YYInfo.moduleList[funcID].updateDaily(human, funcID)
  681. end
  682. end
  683. updateIcon(YYInfo, human, true)
  684. end
  685. sendBanner(human)
  686. end
  687. -- 充值接口
  688. function onCharge(human, price, buyID)
  689. for yyID, YYInfo in pairs(ID2YYInfo) do
  690. for i = 1, #YYInfo.config.funcs do
  691. local funcID = YYInfo.config.funcs[i]
  692. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onCharge then
  693. YYInfo.moduleList[funcID].onCharge(human, price, funcID, buyID)
  694. end
  695. end
  696. end
  697. sendBanner(human)
  698. end
  699. -- 0点
  700. function onZeroHuman(human)
  701. for yyID, YYInfo in pairs(ID2YYInfo) do
  702. for i = 1, #YYInfo.config.funcs do
  703. local funcID = YYInfo.config.funcs[i]
  704. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onZero then
  705. YYInfo.moduleList[funcID].onZero(human, funcID)
  706. end
  707. end
  708. end
  709. sendIcons(human)
  710. end
  711. -- 0点
  712. function onZero()
  713. for yyID, YYInfo in pairs(ID2YYInfo) do
  714. for i = 1, #YYInfo.config.funcs do
  715. local funcID = YYInfo.config.funcs[i]
  716. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onZeroAll then
  717. YYInfo.moduleList[funcID].onZeroAll(funcID)
  718. end
  719. end
  720. end
  721. handleAbs()
  722. end
  723. -- 升级回调
  724. function onLevelUp(human, oldLv, newLv)
  725. for yyID, YYInfo in pairs(ID2YYInfo) do
  726. for i = 1, #YYInfo.config.funcs do
  727. local funcID = YYInfo.config.funcs[i]
  728. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID].onLevelUp then
  729. YYInfo.moduleList[funcID].onLevelUp(human, oldLv, newLv, funcID)
  730. end
  731. end
  732. end
  733. for yyID, YYInfo in pairs(ID2YYInfo) do
  734. if oldLv < YYInfo.openLv and YYInfo.openLv <= newLv then
  735. if isOpen(YYInfo, human, true) then
  736. sendIconUpdate(yyID, human)
  737. end
  738. end
  739. end
  740. end
  741. -- 购买礼包的回调
  742. function onBuy(human, buyConf, isFirst, cnt)
  743. for yyID, YYInfo in pairs(ID2YYInfo) do
  744. for i = 1, #YYInfo.config.funcs do
  745. local funcID = YYInfo.config.funcs[i]
  746. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID][buyConf.cmd] then
  747. YYInfo.moduleList[funcID][buyConf.cmd](human, funcID, buyConf, isFirst, cnt)
  748. end
  749. end
  750. end
  751. end
  752. function CG_YUNYING_UPDATE(human, yyID)
  753. if not human.yunyings then return end
  754. -- 未初始不发
  755. local YYInfo = ID2YYInfo[yyID]
  756. if not YYInfo then return end
  757. updateIcon(YYInfo, human, true)
  758. end
  759. function onServerOpenTime()
  760. handleAbs()
  761. for _, human in pairs(ObjHuman.onlineUuid) do
  762. sendIcons(human)
  763. end
  764. end
  765. ---
  766. --各个模块回调
  767. function onCallBack(human, cmd, parameter, bNoSend, parameter2)
  768. for yyID, YYInfo in pairs(ID2YYInfo) do
  769. for i = 1, #YYInfo.config.funcs do
  770. local funcID = YYInfo.config.funcs[i]
  771. local funcConfig = getFuncConfig(funcID)
  772. if YYInfo.moduleList[funcID] and YYInfo.moduleList[funcID][cmd] then
  773. local isStart = true
  774. if isAbsfunc(funcID) then
  775. isStart = AbsActLogic.isStarted(human, funcID)
  776. end
  777. if isStart then
  778. local result = YYInfo.moduleList[funcID][cmd](human, funcID, parameter, parameter2)
  779. if result then
  780. updateIcon(YYInfo, human)
  781. sendGroupUpdate(YYInfo, human, funcConfig.panelID)
  782. end
  783. if bNoSend then
  784. return result
  785. end
  786. end
  787. end
  788. end
  789. end
  790. if bNoSend then
  791. return 0
  792. end
  793. end