HeroComeLogic.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. local AbsActExcel = require("excel.absAct")
  2. local Gm = require("chat.Gm")
  3. local Msg = require("core.Msg")
  4. local ObjHuman = require("core.ObjHuman")
  5. local Log = require("common.Log")
  6. local Broadcast = require("broadcast.Broadcast")
  7. local Lang = require("common.Lang")
  8. local ItemDefine = require("bag.ItemDefine")
  9. local HeroLogic = require("hero.HeroLogic")
  10. local BagLogic = require("bag.BagLogic")
  11. local HeroGrid = require("hero.HeroGrid")
  12. local DrawCardExcel = require("excel.drawCard").drawCard
  13. local HeroExcel = require("excel.hero").hero
  14. local MailExcel = require("excel.mail")
  15. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  16. local HeroBook = require("hero.HeroBook")
  17. local AbsActLogic = require("absAct.AbsActLogic")
  18. local AbsActDefine = require("absAct.AbsActDefine")
  19. local YunYingLogic = require("yunying.YunYingLogic")
  20. local PanelDefine = require("broadcast.PanelDefine")
  21. local DrawCardLogic = require("drawCard.DrawCardLogic")
  22. local ZhanbuLogic = require("zhanbu.ZhanbuLogic")
  23. local MailManager = require("mail.MailManager")
  24. local MailDefine = require("mail.MailIdDefine")
  25. local LimitPerpleHeroLogic = require("present.LimitPerpleHeroLogic")
  26. local CombatLogic = require("combat.CombatLogic")
  27. local Grid = require("bag.Grid")
  28. --[[
  29. absAct.xlxs-heroCome
  30. 新英雄来袭-英雄降临
  31. 1.可设置心仪英雄,若只有一个不需要设置,默认设置为第一个
  32. 2.召唤英雄,1次或10次,统一从DrawCardLogic.draw调用
  33. 3.登陆时检查活动结束回收道具
  34. DB:
  35. human.db.absAct[id] = {
  36. perpleHero = xxx, -- 心仪英雄
  37. noTargetHeroCnt = xxx, -- 距离必得英雄已完成的数量
  38. drawCardCnt = xxx, -- 召换数量
  39. }
  40. local:
  41. public:
  42. getAndSendMsg() -- 发送活动数据
  43. isRed() -- 红点提醒
  44. isActive() -- 激活状态
  45. isOpen() -- 活动开启
  46. onLogin() -- 登陆回调(YunYingLogic统一调用)
  47. setPerpleHero() -- 设置心仪英雄(默认是一个就不需要设置)
  48. onDrawCard() -- 召换(统一从DrawCardLogic.draw调用)
  49. getConfigByActID() -- 得到活动中子活动配置(统一从AbsActLogic.getLuckDraw调用)
  50. heroCombat() -- 观看英雄战斗录像
  51. --]]
  52. function getAndSendMsg(human, id)
  53. local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  54. if not state then return end
  55. AbsActLogic.checkAbsActClean(human, id)
  56. local absAct = human.db.absAct[id]
  57. if not absAct then return end
  58. local actId = AbsActExcel.absActivity[id].actId
  59. local config = AbsActExcel.heroCome[actId]
  60. local msgRet = Msg.gc.GC_ABS_ACT_HERO_COME_QUERY
  61. msgRet.perpleHero[0] = 1
  62. if not absAct.perpleHero then
  63. absAct.perpleHero = config.heroID[1]
  64. end
  65. msgRet.perpleHero[1] = absAct.perpleHero or config.heroID[1]
  66. msgRet.leftCnt = config.cnt
  67. if absAct.noTargetHeroCnt then
  68. msgRet.leftCnt = config.cnt - absAct.noTargetHeroCnt
  69. end
  70. local heroConfig = config.heroID
  71. local len = #heroConfig
  72. for i = 1,len do
  73. HeroGrid.makeHeroSimpleByID(msgRet.heroList[i], heroConfig[i], nil, nil, nil, true)
  74. end
  75. msgRet.heroList[0] = len
  76. Grid.makeItem(msgRet.aItem, config.item1[1], config.item1[2])
  77. Grid.makeItem(msgRet.bItem, config.item2[1], config.item2[2])
  78. Msg.send(msgRet,human.fd)
  79. end
  80. function isRed(human, YYInfo, funcConfig)
  81. local state = AbsActLogic.isStarted(human, funcConfig.funcID)
  82. if not state then return end
  83. local absAct = human.db.absAct[funcConfig.funcID]
  84. if not absAct then return end
  85. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  86. local config = AbsActExcel.heroCome[absConfig.actId]
  87. -- 能进行十连抽出现红点
  88. if BagLogic.getItemCnt(human, config.item2[1]) >= config.item2[2] then
  89. return true
  90. end
  91. return false
  92. end
  93. function isActive(human, YYInfo, funcConfig)
  94. return not isOpen(human, YYInfo, funcConfig)
  95. end
  96. function isOpen(human, YYInfo, funcConfig)
  97. return AbsActLogic.isStarted(human, funcConfig.funcID)
  98. end
  99. function onLogin(human, id)
  100. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  101. if state then return end
  102. local config = AbsActExcel.absActivity[id]
  103. if not config then return end
  104. local actId = config.turns[1] -- 默认选择第一期
  105. local perpleHeroConfig = AbsActExcel.heroCome[actId]
  106. if not perpleHeroConfig then return end
  107. local items = { }
  108. local len = 0
  109. local have = BagLogic.getItemCnt(human, perpleHeroConfig.item1[1])
  110. if have > 0 and perpleHeroConfig.prop > 0 then
  111. len = len + 1
  112. items[len] = { }
  113. items[len][1] = ItemDefine.ITEM_JINBI_ID
  114. items[len][2] = have * perpleHeroConfig.prop
  115. BagLogic.delItem(human, perpleHeroConfig.item1[1], have, "abs_hero_come_login")
  116. end
  117. if len > 0 then
  118. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_ABS_HERO_COME]
  119. local title = mailConfig.title
  120. local senderName = mailConfig.senderName
  121. local content = mailConfig.content
  122. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, items, senderName)
  123. end
  124. end
  125. function getConfigByActID(id)
  126. local absActConfig = AbsActExcel.absActivity[id]
  127. if not absActConfig then return end
  128. local actId = absActConfig.actId
  129. return AbsActExcel.heroCome[actId]
  130. end
  131. function setPerpleHero(human, heroID, id)
  132. local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  133. if not state then return end
  134. AbsActLogic.checkAbsActClean(human, id)
  135. local absAct = human.db.absAct[id]
  136. if not absAct then return end
  137. -- 英雄ID校验失败
  138. local config = AbsActExcel.heroCome[AbsActExcel.absActivity[id].actId].heroID
  139. local len = #config
  140. local check = false
  141. for i = 1,len do
  142. if config[i] == heroID then
  143. check = true
  144. break
  145. end
  146. end
  147. if not check then
  148. return
  149. end
  150. if absAct.perpleHero then
  151. if not ObjHuman.checkRMB(human, 2000) then
  152. return
  153. end
  154. ObjHuman.decZuanshi(human, -2000, "abs_hero_come_perple_hero")
  155. end
  156. absAct.perpleHero = heroID
  157. end
  158. function onDrawCardActive(human, id, op, actConfig, skip,isAct)
  159. local state,actID = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_19)
  160. if not state then return end
  161. AbsActLogic.checkAbsActClean(human, actID)
  162. local absAct = human.db.absAct[actID]
  163. if not absAct then return end
  164. local config = DrawCardExcel[id]
  165. if not config then return end
  166. local heroCnt = nil
  167. if op == DrawCardLogic.DRAWCARD_OP_1 then
  168. heroCnt = 1
  169. elseif op == DrawCardLogic.DRAWCARD_OP_2 then
  170. heroCnt = 10
  171. else
  172. return
  173. end
  174. if HeroLogic.getEmptyCnt(human) < heroCnt then
  175. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  176. end
  177. if not DrawCardLogic.checkUseItem(human, id, op, config,isAct) then
  178. return
  179. end
  180. local heroLen = 0
  181. local heroList = {}
  182. local heroNewList = {}
  183. local heroIndexList = {}
  184. local fenjielist = {}
  185. local heroIDs = nil
  186. local randomMin = math.random(1, heroCnt)
  187. for i = 1, heroCnt do
  188. config = DrawCardExcel[id]
  189. if id == DrawCardLogic.DRAWCARD_ID2 and op == DrawCardLogic.DRAWCARD_OP_2 and i == randomMin then
  190. config = DrawCardExcel[DrawCardLogic.DRAWCARD_ID5]
  191. elseif id == DrawCardLogic.DRAWCARD_ID2 and op == DrawCardLogic.DRAWCARD_OP_1 then
  192. config = DrawCardExcel[DrawCardLogic.DRAWCARD_ID6]
  193. end
  194. local heroID = DrawCardLogic.randHeroID(human, id, op, config, actConfig, i == randomMin, isAct)
  195. local heroConfig = HeroExcel[heroID]
  196. local star = heroConfig.star
  197. local name = heroConfig.name
  198. local grade = heroConfig.grade
  199. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  200. local heroIndex, fjlist = HeroLogic.addHero(human, heroID, nil, 1, "abs_hero_come_draw_card")
  201. heroLen = heroLen + 1
  202. heroList[heroLen] = heroID
  203. heroNewList[heroLen] = isNew
  204. heroIndexList[heroLen] = heroIndex
  205. if fjlist and type(fjlist) == "table" then
  206. for fjItemID, fjItemCnt in pairs(fjlist) do
  207. fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
  208. end
  209. end
  210. if not heroIDs then
  211. heroIDs = heroID
  212. else
  213. heroIDs = heroIDs .. "|" .. heroID
  214. end
  215. if heroID == absAct.perpleHero and absAct.noTargetHeroCnt then
  216. absAct.noTargetHeroCnt = 0
  217. end
  218. if id == DrawCardLogic.DRAWCARD_ID1 then
  219. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE3, grade, heroID)
  220. elseif id == DrawCardLogic.DRAWCARD_ID2 then
  221. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE1, grade, heroID)
  222. elseif id == DrawCardLogic.DRAWCARD_ID3 then
  223. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE2, grade, heroID)
  224. elseif id == DrawCardLogic.DRAWCARD_ID6 then
  225. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE21, grade, heroID)
  226. end
  227. end
  228. DrawCardLogic.sendDrawOp(human, id, op, heroList, fenjielist, heroNewList, heroIndexList, isAct)
  229. YunYingLogic.updateIcon(YYInfo[id], human)
  230. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_5012)
  231. Log.write(Log.LOGID_OSS_DRAWCARD, human.db._id, human.db.account, human.db.name, human.db.lv, id, heroIDs, itemID or 0, cnt or 0, zuanshi or 0, 0)
  232. absAct.drawCardCnt = absAct.drawCardCnt or 0
  233. absAct.drawCardCnt = absAct.drawCardCnt + heroCnt
  234. --ZhanbuLogic.addZhanbuItem(human, heroCnt * 5)
  235. YunYingLogic.onCallBack(human, "onDrawCard", heroCnt, nil, id)
  236. -- 进行十连抽后,若道具不足十连抽,更新去掉红点
  237. if op == DrawCardLogic.DRAWCARD_OP_2 then
  238. -- 不能进行十连抽了
  239. local absConfig = AbsActExcel.absActivity[actID]
  240. local heroComeConfig = AbsActExcel.heroCome[absConfig.actId]
  241. if BagLogic.getItemCnt(human, heroComeConfig.item2[1]) < heroComeConfig.item2[2] then
  242. YunYingLogic.sendBanner(human)
  243. YunYingLogic.updateIcon(YYInfo[id], human)
  244. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_5012)
  245. end
  246. end
  247. end
  248. function heroCombat(human, heroID)
  249. CombatLogic.combatFightVedio(human, heroID)
  250. end