JjcActLogic.lua 4.6 KB

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