PerpleHeroLogic.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. function onLogin(human, id)
  29. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  30. if state then return end
  31. local config = AbsActExcel.absActivity[id]
  32. if not config then return end
  33. local actId = config.turns[1] -- 默认选择第一期
  34. local perpleHeroConfig = AbsActExcel.perpleHero[actId]
  35. if not perpleHeroConfig then return end
  36. local items = { }
  37. local len = 0
  38. local have = BagLogic.getItemCnt(human, perpleHeroConfig.item1[1])
  39. if have > 0 and perpleHeroConfig.prop > 0 then
  40. len = len + 1
  41. items[len] = { }
  42. items[len][1] = ItemDefine.ITEM_JINBI_ID
  43. items[len][2] = have * perpleHeroConfig.prop
  44. BagLogic.delItem(human, perpleHeroConfig.item1[1], have, "abs_perpleHero")
  45. end
  46. if len > 0 then
  47. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_ABS_PERPHERO]
  48. local title = mailConfig.title
  49. local senderName = mailConfig.senderName
  50. local content = mailConfig.content
  51. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, items, senderName)
  52. end
  53. end
  54. -- 返回活动数据
  55. function getAndSendMsg(human,id)
  56. local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  57. local absActConfig = AbsActExcel.absActivity[id]
  58. -- 活动未开
  59. if not state then
  60. return
  61. end
  62. AbsActLogic.checkAbsActClean(human, id)
  63. local absAct = human.db.absAct[id]
  64. -- 没有活动数据
  65. if not absAct then
  66. return
  67. end
  68. local actId = absActConfig.actId
  69. local config = AbsActExcel.perpleHero[actId]
  70. -- 发送数据
  71. local msgRet = Msg.gc.GC_ABS_ACT_PERPLE_HERO_QUERY
  72. msgRet.perpleHero[0] = 1
  73. if not absAct.perpleHero then
  74. absAct.perpleHero = config.heroID[1]
  75. end
  76. msgRet.perpleHero[1] = absAct.perpleHero or config.heroID[1]
  77. msgRet.leftCnt = config.cnt
  78. if absAct.noTargetHeroCnt then
  79. msgRet.leftCnt = config.cnt - absAct.noTargetHeroCnt
  80. end
  81. local heroConfig = config.heroID
  82. local len = #heroConfig
  83. for i = 1,len do
  84. HeroGrid.makeHeroSimpleByID(msgRet.heroList[i], heroConfig[i],nil,nil,nil,true)
  85. end
  86. msgRet.heroList[0] = len
  87. Grid.makeItem(msgRet.aItem, config.item1[1], config.item1[2])
  88. Grid.makeItem(msgRet.bItem, config.item2[1], config.item2[2])
  89. Msg.send(msgRet,human.fd)
  90. end
  91. -- 设置心仪英雄
  92. function setPerpleHero(human,heroID,id)
  93. local state,endTime, starTime = AbsActLogic.isStarted(human, id)
  94. local absActConfig = AbsActExcel.absActivity[id]
  95. -- 活动未开
  96. if not state then
  97. return
  98. end
  99. AbsActLogic.checkAbsActClean(human, id)
  100. local absAct = human.db.absAct[id]
  101. -- 没有活动数据
  102. if not absAct then
  103. return
  104. end
  105. -- 英雄ID校验失败
  106. local config = AbsActExcel.perpleHero[absActConfig.actId].heroID
  107. local len = #config
  108. local check = false
  109. for i = 1,len do
  110. if config[i] == heroID then
  111. check = true
  112. break
  113. end
  114. end
  115. if not check then
  116. return
  117. end
  118. if absAct.perpleHero then
  119. if not ObjHuman.checkRMB(human, 2000) then
  120. return
  121. end
  122. ObjHuman.decZuanshi(human,-2000,"abs_perpleHero")
  123. end
  124. absAct.perpleHero = heroID
  125. end
  126. function onDrawCardActive(human, id, op, actConfig, skip,isAct)
  127. local state,actID = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_4)
  128. if not state then
  129. return
  130. end
  131. AbsActLogic.checkAbsActClean(human, actID)
  132. local absAct = human.db.absAct[actID]
  133. -- 没有活动数据
  134. if not absAct then
  135. return
  136. end
  137. local config = DrawCardExcel[id]
  138. if not config then return end
  139. local heroCnt = nil
  140. if op == DrawCardLogic.DRAWCARD_OP_1 then
  141. heroCnt = 1
  142. elseif op == DrawCardLogic.DRAWCARD_OP_2 then
  143. heroCnt = 10
  144. else
  145. return
  146. end
  147. if HeroLogic.getEmptyCnt(human) < heroCnt then
  148. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  149. end
  150. if not DrawCardLogic.checkUseItem(human, id, op, config,isAct) then
  151. return
  152. end
  153. local heroLen = 0
  154. local heroList = {}
  155. local heroNewList = {}
  156. local heroIndexList = {}
  157. local fenjielist = {}
  158. local heroIDs = nil
  159. local randomMin = math.random(1, heroCnt)
  160. for i = 1, heroCnt do
  161. config = DrawCardExcel[id]
  162. if id == DrawCardLogic.DRAWCARD_ID2 and op == DrawCardLogic.DRAWCARD_OP_2 and i == randomMin then
  163. config = DrawCardExcel[DrawCardLogic.DRAWCARD_ID5]
  164. elseif id == DrawCardLogic.DRAWCARD_ID2 and op == DrawCardLogic.DRAWCARD_OP_1 then
  165. config = DrawCardExcel[DrawCardLogic.DRAWCARD_ID6]
  166. end
  167. local heroID = DrawCardLogic.randHeroID(human, id, op, config, actConfig, i == randomMin, isAct)
  168. local heroConfig = HeroExcel[heroID]
  169. local star = heroConfig.star
  170. local name = heroConfig.name
  171. local grade = heroConfig.grade
  172. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  173. local heroIndex, fjlist = HeroLogic.addHero(human, heroID,nil, 1, "abs_perpleHero")
  174. heroLen = heroLen + 1
  175. heroList[heroLen] = heroID
  176. heroNewList[heroLen] = isNew
  177. heroIndexList[heroLen] = heroIndex
  178. if fjlist and type(fjlist) == "table" then
  179. for fjItemID, fjItemCnt in pairs(fjlist) do
  180. fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
  181. end
  182. end
  183. if not heroIDs then
  184. heroIDs = heroID
  185. else
  186. heroIDs = heroIDs .. "|" .. heroID
  187. end
  188. if heroID == absAct.perpleHero and absAct.noTargetHeroCnt then
  189. absAct.noTargetHeroCnt = 0
  190. end
  191. if id == DrawCardLogic.DRAWCARD_ID1 then
  192. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE3, grade, heroID)
  193. elseif id == DrawCardLogic.DRAWCARD_ID2 then
  194. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE1, grade, heroID)
  195. elseif id == DrawCardLogic.DRAWCARD_ID3 then
  196. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE2, grade, heroID)
  197. elseif id == DrawCardLogic.DRAWCARD_ID6 then
  198. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE21, grade, heroID)
  199. end
  200. end
  201. DrawCardLogic.sendDrawOp(human, id, op, heroList, fenjielist, heroNewList,heroIndexList,isAct)
  202. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3704)
  203. 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)
  204. absAct.drawCardCnt = absAct.drawCardCnt or 0
  205. absAct.drawCardCnt = absAct.drawCardCnt + heroCnt
  206. --if absAct.drawCardCnt >= 1 then
  207. -- absAct.drawCardCnt = absAct.drawCardCnt - 1
  208. -- ZhanbuLogic.addZhanbuItem(human)
  209. --end
  210. ZhanbuLogic.addZhanbuItem(human,heroCnt*5)
  211. YunYingLogic.onCallBack(human, "onDrawCard", heroCnt, nil, id)
  212. end
  213. function getConfigByActID(id)
  214. local absActConfig = AbsActExcel.absActivity[id]
  215. if not absActConfig then return end
  216. local actId = absActConfig.actId
  217. return AbsActExcel.perpleHero[actId]
  218. end
  219. function heroCombat(human, heroID)
  220. CombatLogic.combatFightVedio(human, heroID)
  221. end
  222. function isRed(human, YYInfo, funcConfig)
  223. return false
  224. end
  225. function isActive(human, YYInfo, funcConfig)
  226. return not isOpen(human, YYInfo, funcConfig)
  227. end
  228. function isOpen(human, YYInfo, funcConfig)
  229. return AbsActLogic.isStarted(human, funcConfig.funcID)
  230. end