JjcActLogic.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. -------------------------------------------------------
  2. -- 竞技场相关活动管理
  3. -- 列表显示用到
  4. -- getActState 活动状态
  5. -- getActDesc 活动描述
  6. -- isActRed 是否有红点
  7. -- fontActArgs 额外参数
  8. -------------------------------------------------------
  9. local JjcExcel = require("excel.jjc")
  10. local Msg = require("core.Msg")
  11. local Grid = require("bag.Grid")
  12. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  13. local JjcLogic = require("jjc.JjcLogic")
  14. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  15. local JjcNewLadderLogic = require("jjcnewladder.jjcNewLadderLogic")
  16. -- 活动状态
  17. STATE_NOOPEN = 0 -- 未开启
  18. STATE_NORMAL = 1 -- 常驻活动
  19. STATE_START = 2 -- 赛季进行中
  20. STATE_READY = 3 -- 新赛季倒计时
  21. -- id->actInfo
  22. ID_2_ACTINFO = ID_2_ACTINFO or {}
  23. ID_2_ACTINFO_MIDDLE = ID_2_ACTINFO_MIDDLE or {}
  24. local function initActInfo(list, configs)
  25. for id, cf in pairs(configs) do
  26. local moduleFn = nil
  27. if cf.moduleFn ~= "" then
  28. moduleFn = load("return require(\""..cf.moduleFn.."\")")()
  29. end
  30. if moduleFn and moduleFn.Init then
  31. moduleFn.Init()
  32. end
  33. local actInfo = {}
  34. actInfo.id = id
  35. actInfo.config = cf
  36. actInfo.module = moduleFn
  37. list[id] = actInfo
  38. end
  39. end
  40. -- 初始
  41. function init()
  42. initActInfo(ID_2_ACTINFO, JjcExcel.act)
  43. initActInfo(ID_2_ACTINFO_MIDDLE, JjcExcel.actMiddle)
  44. end
  45. -- 获取actInfo
  46. function getActInfo(isMiddle, id)
  47. local list = isMiddle and ID_2_ACTINFO_MIDDLE or ID_2_ACTINFO
  48. return list[id]
  49. end
  50. -- 获取活动状态
  51. function getActState(isMiddle, id, human)
  52. local actInfo = getActInfo(isMiddle, id)
  53. if not actInfo then
  54. return STATE_NORMAL, 0
  55. end
  56. if not actInfo.module or
  57. not actInfo.module.getActState then
  58. return STATE_NORMAL, 0
  59. end
  60. return actInfo.module.getActState(human)
  61. end
  62. -- 额外参数设置
  63. function fontActArgs(isMiddle, id, args, human)
  64. args[0] = 0
  65. local actInfo = getActInfo(isMiddle, id)
  66. if not actInfo then
  67. return
  68. end
  69. if not actInfo.module or
  70. not actInfo.module.fontActArgs then
  71. return
  72. end
  73. actInfo.module.fontActArgs(args, human)
  74. end
  75. -- 特殊描述
  76. function getActDesc(isMiddle, id, cf)
  77. local actInfo = getActInfo(isMiddle, id)
  78. if not actInfo then
  79. return cf.desc
  80. end
  81. if not actInfo.module or
  82. not actInfo.module.getActDesc then
  83. return cf.desc
  84. end
  85. return actInfo.module.getActDesc(cf.desc)
  86. end
  87. -- 是否显示红点
  88. function isActRed(isMiddle, id, human)
  89. local actInfo = getActInfo(isMiddle, id)
  90. if not actInfo then
  91. return
  92. end
  93. if not actInfo.module or
  94. not actInfo.module.isActRed then
  95. return
  96. end
  97. return actInfo.module.isActRed(human)
  98. end
  99. -- 封装活动结构体
  100. local function fontJJCActNet(net, isMiddle, id, cf, human)
  101. net.id = id
  102. net.panelID = cf.panelID
  103. net.bg = cf.bg
  104. net.name = cf.name
  105. local state, leftTime = getActState(isMiddle, id, human)
  106. if RoleSystemLogic.isOpen(human, cf.systemID) then
  107. net.desc = getActDesc(isMiddle, id, cf)
  108. net.state = state
  109. net.leftTime = leftTime
  110. else
  111. net.desc = RoleSystemLogic.getOpenDesc(cf.systemID)
  112. net.state = STATE_NOOPEN
  113. net.leftTime = 0
  114. end
  115. net.reward[0] = #cf.reward
  116. for i = 1, net.reward[0] do
  117. local itemID = cf.reward[i][1]
  118. local itemCnt = cf.reward[i][2]
  119. Grid.makeItem(net.reward[i], itemID, itemCnt)
  120. end
  121. net.isRed = isActRed(isMiddle, id, human) and 1 or 0
  122. fontActArgs(isMiddle, id, net.args, human)
  123. end
  124. -- 活动列表
  125. function sendActList(human)
  126. local msgRet = Msg.gc.GC_JJC_ACT_LIST
  127. msgRet.list[0] = 0
  128. for id, cf in ipairs(JjcExcel.act) do
  129. msgRet.list[0] = msgRet.list[0] + 1
  130. local net = msgRet.list[msgRet.list[0]]
  131. fontJJCActNet(net, false, id, cf, human)
  132. end
  133. msgRet.jjcDouble = JjcLogic.getJJCDoubleCnt(human)
  134. msgRet.worshipCnt = human.db.jjcBeWorship or 0
  135. Msg.send(msgRet, human.fd)
  136. end
  137. -- 跨服争霸活动列表
  138. function sendMiddleActList(human)
  139. local msgRet = Msg.gc.GC_JJC_MIDDLE_ACT_LIST
  140. msgRet.list[0] = 0
  141. for id, cf in ipairs(JjcExcel.actMiddle) do
  142. msgRet.list[0] = msgRet.list[0] + 1
  143. local net = msgRet.list[msgRet.list[0]]
  144. fontJJCActNet(net, true, id, cf, human)
  145. end
  146. --Msg.trace(msgRet)
  147. Msg.send(msgRet, human.fd)
  148. end
  149. -- 只有竞技场冠军试炼的
  150. function isDot(human)
  151. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1301, true) and
  152. not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1302, true) then
  153. return
  154. end
  155. if JjcLogic.championChallengeDot(human) == 1 or
  156. JjcLogic.championBillboardDot(human) == 1 or
  157. JjcLogic.championRecordDot(human) == 1 or
  158. JjcNewLadderLogic.MainJieMianDot(human) == 1 then
  159. return true
  160. end
  161. end