HeroComeLogic.lua 12 KB

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