HeroLogLogic.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. local AbsActLogic = require("absAct.AbsActLogic")
  2. local AbsActExcel = require("excel.absAct")
  3. local Msg = require("core.Msg")
  4. local Grid = require("bag.Grid")
  5. local BagLogic = require("bag.BagLogic")
  6. local AbsActDefine = require("absAct.AbsActDefine")
  7. local YunYingLogic = require("yunying.YunYingLogic")
  8. local PanelDefine = require("broadcast.PanelDefine")
  9. HERO_LOG_TYPE_1 = 1 --每日登录
  10. HERO_LOG_TYPE_2 = 2 --冠军联赛挑战X次
  11. HERO_LOG_TYPE_3 = 3 --扫荡X次
  12. HERO_LOG_TYPE_4 = 4 --领取X次5星以上悬赏任务
  13. HERO_LOG_TYPE_5 = 5 --任意难度勇者试炼通关X次
  14. HERO_LOG_TYPE_6 = 6 --累计消耗X钻石
  15. HERO_LOG_TYPE_7 = 7 --获得任务中指定的英雄
  16. HERO_LOG_TYPE_8 = 8 --获得任务中指定的英雄升到多少星
  17. function getAndSendMsg(human,id)
  18. local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  19. local absActConfig = AbsActExcel.absActivity[id]
  20. -- 活动未开
  21. if not state then
  22. return
  23. end
  24. AbsActLogic.checkAbsActClean(human, id)
  25. local absAct = human.db.absAct[id]
  26. -- 没有活动数据
  27. if not absAct then
  28. return
  29. end
  30. local msgRet = Msg.gc.GC_ABS_ACT_HERO_LOG_QUERY
  31. local config = AbsActExcel.heroLog
  32. local len = 0
  33. for k,v in pairs(config) do
  34. if v.actID == id then
  35. len = len + 1
  36. msgRet.taskList[len].id = k
  37. msgRet.taskList[len].state = 0
  38. msgRet.taskList[len].maxCnt = v.maxCnt
  39. msgRet.taskList[len].desc = v.desc
  40. msgRet.taskList[len].panelID = v.panelID
  41. if not absAct.task or not absAct.task[k] then
  42. msgRet.taskList[len].nowCnt = 0
  43. else
  44. msgRet.taskList[len].nowCnt = absAct.task[k].cnt
  45. msgRet.taskList[len].state = absAct.task[k].state
  46. end
  47. local lenItem = #v.item
  48. for i = 1,lenItem do
  49. Grid.makeItem(msgRet.taskList[len].item[i],v.item[i][1],v.item[i][2])
  50. end
  51. msgRet.taskList[len].item[0] = lenItem
  52. msgRet.box[len].id = len
  53. if not absAct.box or not absAct.box[len] then
  54. msgRet.box[len].state = 0
  55. else
  56. msgRet.box[len].state = absAct.box[len]
  57. end
  58. lenItem = #v.boxItem
  59. for i = 1,lenItem do
  60. Grid.makeItem(msgRet.box[len].item[i],v.boxItem[i][1],v.boxItem[i][2])
  61. end
  62. msgRet.box[len].item[0] = lenItem
  63. end
  64. end
  65. msgRet.taskList[0] = len
  66. msgRet.box[0] = len
  67. Msg.send(msgRet,human.fd)
  68. end
  69. function getBoxReward(human,index,id)
  70. local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  71. local absActConfig = AbsActExcel.absActivity[id]
  72. -- 活动未开
  73. if not state then
  74. return
  75. end
  76. AbsActLogic.checkAbsActClean(human, id)
  77. local absAct = human.db.absAct[id]
  78. -- 没有活动数据
  79. if not absAct or not absAct.box then
  80. return
  81. end
  82. local configIndex = 0
  83. local key = nil
  84. for i = 1,#AbsActExcel.heroLog do
  85. if AbsActExcel.heroLog[i].actID == id then
  86. configIndex = configIndex + 1
  87. if configIndex == index then
  88. key = i
  89. break
  90. end
  91. end
  92. end
  93. if not key then
  94. return
  95. end
  96. -- 不可领或已领过
  97. if absAct.box[key] ~= 1 then
  98. return
  99. end
  100. -- 可领
  101. absAct.box[key] = 2
  102. BagLogic.addItemList(human, AbsActExcel.heroLog[key].boxItem, "abs_herolog")
  103. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3705)
  104. getAndSendMsg(human,id)
  105. end
  106. function isComplRuleTask(type, rules, value1, value2)
  107. if not rules then return true end
  108. local isCompl
  109. -- 特殊完成规则
  110. if type == HERO_LOG_TYPE_7 then
  111. for _,heroID in ipairs(rules) do
  112. if value1 == heroID then
  113. isCompl = true
  114. break
  115. end
  116. end
  117. elseif type == HERO_LOG_TYPE_8 then
  118. for _,rule in ipairs(rules) do
  119. if value1 == rule[1] and value2 == rule[2] then
  120. isCompl = true
  121. break
  122. end
  123. end
  124. else
  125. isCompl = true
  126. end
  127. return isCompl
  128. end
  129. function finishTaskCB(human, type, cnt, value1, value2)
  130. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_5)
  131. local absActConfig = AbsActExcel.absActivity[id]
  132. -- 活动未开
  133. if not state then
  134. return
  135. end
  136. AbsActLogic.checkAbsActClean(human, id)
  137. local absAct = human.db.absAct[id]
  138. -- 没有活动数据
  139. if not absAct then
  140. return
  141. end
  142. local config = AbsActExcel.heroLog
  143. for i = 1,#config do
  144. local v = config[i]
  145. if v.actID == absActConfig.actId and v.type == type and isComplRuleTask(type, v.rules, value1, value2) then
  146. absAct.task = absAct.task or {}
  147. if not absAct.task[i] or absAct.task[i].cnt < v.maxCnt then
  148. absAct.task[i] = absAct.task[i] or {}
  149. absAct.task[i].cnt = absAct.task[i].cnt or 0
  150. absAct.task[i].cnt = absAct.task[i].cnt + cnt
  151. absAct.task[i].state = 0
  152. if absAct.task[i].cnt >= v.maxCnt then
  153. absAct.box = absAct.box or {}
  154. local len = #absAct.box
  155. absAct.box[len + 1] = 1
  156. absAct.task[i].state = 1
  157. end
  158. end
  159. end
  160. end
  161. end
  162. function getTaskReward(human,index,id)
  163. local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  164. local absActConfig = AbsActExcel.absActivity[id]
  165. -- 活动未开
  166. if not state then
  167. return
  168. end
  169. AbsActLogic.checkAbsActClean(human, id)
  170. local absAct = human.db.absAct[id]
  171. -- 没有活动数据
  172. if not absAct or not absAct.box then
  173. return
  174. end
  175. -- 不可领或已领过
  176. if not absAct.task or not absAct.task[index] or absAct.task[index].state ~= 1 then
  177. return
  178. end
  179. absAct.task[index].state = 2
  180. BagLogic.addItemList(human, AbsActExcel.heroLog[index].item, "abs_herolog")
  181. getAndSendMsg(human,id)
  182. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3705)
  183. end
  184. function isRed(human, YYInfo, funcConfig)
  185. local state, endTime, starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  186. if not state then return end
  187. -- 没有活动数据
  188. local absAct = human.db.absAct[id]
  189. if not absAct or (not absAct.box and not absAct.task) then
  190. return
  191. end
  192. local len = #absAct.box
  193. for i = 1,len do
  194. if absAct.box and absAct.box[i] == 1 then
  195. return true
  196. end
  197. end
  198. len = #absAct.task
  199. for i = 1 ,len do
  200. if absAct.task[i] and absAct.task[i].state == 1 then
  201. return true
  202. end
  203. end
  204. return false
  205. end
  206. function isActive(human, YYInfo, funcConfig)
  207. return not isOpen(human, YYInfo, funcConfig)
  208. end
  209. function isOpen(human, YYInfo, funcConfig)
  210. return AbsActLogic.isStarted(human, funcConfig.funcID)
  211. end
  212. function getLeftTime(human)
  213. local ret, id, endTime, startTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_5)
  214. if ret == true then
  215. return endTime - os.time()
  216. else
  217. return 0
  218. end
  219. end