PerpleHeroLogic.lua 9.3 KB

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