JjcActLogic.lua 4.5 KB

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