LimitPerpleHeroLogic.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. local OpenActExcel = require("excel.openAct")
  2. local CommonDB = require("common.CommonDB")
  3. local Util = require("common.Util")
  4. local Gm = require("chat.Gm")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local Log = require("common.Log")
  8. local Broadcast = require("broadcast.Broadcast")
  9. local Lang = require("common.Lang")
  10. local ItemDefine = require("bag.ItemDefine")
  11. local HeroLogic = require("hero.HeroLogic")
  12. local BagLogic = require("bag.BagLogic")
  13. local HeroGrid = require("hero.HeroGrid")
  14. local DrawCardExcel = require("excel.drawCard").drawCard
  15. local HeroExcel = require("excel.hero").hero
  16. local MailExcel = require("excel.mail")
  17. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  18. local HeroBook = require("hero.HeroBook")
  19. local AbsActLogic = require("absAct.AbsActLogic")
  20. local AbsActDefine = require("absAct.AbsActDefine")
  21. local YunYingLogic = require("yunying.YunYingLogic")
  22. local PanelDefine = require("broadcast.PanelDefine")
  23. local DrawCardLogic = require("drawCard.DrawCardLogic")
  24. local ZhanbuLogic = require("zhanbu.ZhanbuLogic")
  25. local MailManager = require("mail.MailManager")
  26. local MailDefine = require("mail.MailIdDefine")
  27. function initAfterHot()
  28. local oepenTime = CommonDB.getServerOpenTime()
  29. if oepenTime == 0 then return end
  30. local oneDay = 24 * 60 * 60
  31. for k, config in pairs(OpenActExcel.limitPerpleHero) do
  32. local time = (config.openStart - 1) * oneDay + oepenTime
  33. local time2 = config.openEnd * oneDay + oepenTime
  34. local startTime = Util.getDayStartTime(time)
  35. local endTime = Util.getDayStartTime(time2) - 1
  36. -- ����ǵ���ͽ����Ļ
  37. if config.openStart == config.openEnd then
  38. endTime = startTime + oneDay - 1
  39. end
  40. config.startTime = startTime
  41. config.endTime = endTime
  42. end
  43. end
  44. function onLogin(human)
  45. end
  46. function initDB(human)
  47. local config = getConfigByActID()
  48. if human.db.limitPerpleHero then
  49. if human.db.limitPerpleHero.endTime ~= config.endTime then
  50. -- ����
  51. human.db.limitPerpleHero = {}
  52. human.db.limitPerpleHero.endTime = config.endTime
  53. human.db.limitPerpleHero.like = config.heroID[1]
  54. end
  55. else
  56. human.db.limitPerpleHero = {}
  57. human.db.limitPerpleHero.endTime = config.endTime
  58. human.db.limitPerpleHero.like = config.heroID[1]
  59. end
  60. end
  61. function checkOpen()
  62. local now = os.time()
  63. for k , config in pairs(OpenActExcel.limitPerpleHero) do
  64. if config.startTime and now >= config.startTime and now < config.endTime then
  65. return true
  66. end
  67. end
  68. end
  69. function isOpen(human, YYInfo, funcConfig)
  70. local config = OpenActExcel.limitPerpleHero[funcConfig.param]
  71. if not config then return end
  72. if not config.startTime then return end
  73. local now = os.time()
  74. if now >= config.startTime and now <= config.endTime then
  75. return true
  76. end
  77. end
  78. --
  79. function getLeftTime(human, YYInfo, funcConfig)
  80. if isOpen(human, YYInfo, funcConfig) then
  81. local config = OpenActExcel.limitPerpleHero[funcConfig.param]
  82. return config.endTime - os.time()
  83. end
  84. return 0
  85. end
  86. -- ���ػ����
  87. function getAndSendMsg(human, param)
  88. local config = OpenActExcel.limitPerpleHero[param]
  89. if not config then return end
  90. local now = os.time()
  91. if now < config.startTime and now > config.endTime then
  92. return
  93. end
  94. -- ��������
  95. local msgRet = Msg.gc.GC_OA_LIMIT_PERPLEHERO_QUERY
  96. msgRet.startTime = config.startTime
  97. msgRet.endTime = config.endTime
  98. initDB(human)
  99. local perpleHero = human.db.limitPerpleHero
  100. if not perpleHero.like then
  101. perpleHero.like = config.heroID[1]
  102. end
  103. msgRet.perpleHero = perpleHero.like
  104. msgRet.leftCnt = config.cnt
  105. if perpleHero.noTargetHeroCnt then
  106. msgRet.leftCnt = config.cnt - perpleHero.noTargetHeroCnt
  107. end
  108. local len = #config.heroID
  109. for i = 1,len do
  110. HeroGrid.makeHeroSimpleByID(msgRet.heroList[i], config.heroID[i],nil,nil,nil,true)
  111. end
  112. msgRet.heroList[0] = len
  113. Msg.send(msgRet,human.fd)
  114. end
  115. -- ��������Ӣ��
  116. function setPerpleHero(human, heroID, param)
  117. local config = OpenActExcel.limitPerpleHero[param]
  118. if not config then return end
  119. local now = os.time()
  120. if now < config.startTime and now >= config.endTime then
  121. return
  122. end
  123. local check = false
  124. for k, id in ipairs(config.heroID) do
  125. if id == heroID then
  126. check = true
  127. break
  128. end
  129. end
  130. if not check then return end
  131. initDB(human)
  132. local perpleHero = human.db.limitPerpleHero
  133. if perpleHero.like then
  134. if not ObjHuman.checkRMB(human, 2000) then
  135. return
  136. end
  137. ObjHuman.decZuanshi(human,-2000,"abs_perpleHero")
  138. end
  139. perpleHero.like = heroID
  140. end
  141. function onDrawCardActive(human, id, op, actConfig, skip,isAct)
  142. local state = false
  143. local now = os.time()
  144. for k, config in pairs(OpenActExcel.limitPerpleHero) do
  145. if now >= config.startTime and now <= config.endTime then
  146. state = true
  147. end
  148. end
  149. -- û�л����
  150. if not state then
  151. return
  152. end
  153. local config = DrawCardExcel[id]
  154. if not config then return end
  155. local heroCnt = nil
  156. if op == DrawCardLogic.DRAWCARD_OP_1 then
  157. heroCnt = 1
  158. elseif op == DrawCardLogic.DRAWCARD_OP_2 then
  159. heroCnt = 10
  160. else
  161. return
  162. end
  163. if HeroLogic.getEmptyCnt(human) < heroCnt then
  164. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  165. end
  166. if not DrawCardLogic.checkUseItem(human, id, op, config,isAct) then
  167. return
  168. end
  169. initDB(human)
  170. local perpleHero = human.db.limitPerpleHero
  171. local heroLen = 0
  172. local heroList = {}
  173. local heroNewList = {}
  174. local heroIndexList = {}
  175. local fenjielist = {}
  176. local heroIDs = nil
  177. local perpleHero = human.db.limitPerpleHero
  178. local randomMin = math.random(1, heroCnt)
  179. local actConfig = getConfigByActID()
  180. local noTargetHeroCnt2 = perpleHero.noTargetHeroCnt or 0
  181. if op == DrawCardLogic.DRAWCARD_OP_2 then
  182. noTargetHeroCnt2 = noTargetHeroCnt2 + 10
  183. else
  184. noTargetHeroCnt2 = noTargetHeroCnt2 + 1
  185. end
  186. for i = 1, heroCnt do
  187. config = DrawCardExcel[id]
  188. if id == DrawCardLogic.DRAWCARD_ID2 and op == DrawCardLogic.DRAWCARD_OP_1 then
  189. config = DrawCardExcel[DrawCardLogic.DRAWCARD_ID6]
  190. end
  191. local indexState = i == randomMin
  192. if noTargetHeroCnt2 >= actConfig.cnt then
  193. indexState = false
  194. end
  195. if id == DrawCardLogic.DRAWCARD_ID2 and op == DrawCardLogic.DRAWCARD_OP_2 and indexState then
  196. config = DrawCardExcel[DrawCardLogic.DRAWCARD_ID5]
  197. elseif id == DrawCardLogic.DRAWCARD_ID2 and op == DrawCardLogic.DRAWCARD_OP_1 then
  198. config = DrawCardExcel[DrawCardLogic.DRAWCARD_ID6]
  199. end
  200. local heroID = DrawCardLogic.randHeroID(human, id, op, config, actConfig, indexState, isAct)
  201. local heroConfig = HeroExcel[heroID]
  202. local star = heroConfig.star
  203. local name = heroConfig.name
  204. local grade = heroConfig.grade
  205. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  206. local heroIndex, fjlist = HeroLogic.addHero(human, heroID,nil, 1, "abs_perpleHero")
  207. heroLen = heroLen + 1
  208. heroList[heroLen] = heroID
  209. heroNewList[heroLen] = isNew
  210. heroIndexList[heroLen] = heroIndex
  211. if fjlist and type(fjlist) == "table" then
  212. for fjItemID, fjItemCnt in pairs(fjlist) do
  213. fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
  214. end
  215. end
  216. if not heroIDs then
  217. heroIDs = heroID
  218. else
  219. heroIDs = heroIDs .. "|" .. heroID
  220. end
  221. perpleHero.noTargetHeroCnt = perpleHero.noTargetHeroCnt or 0
  222. perpleHero.noTargetHeroCnt = perpleHero.noTargetHeroCnt + 1
  223. if heroID == perpleHero.like then
  224. perpleHero.noTargetHeroCnt = 0
  225. end
  226. if id == DrawCardLogic.DRAWCARD_ID1 then
  227. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE3, grade, heroID)
  228. elseif id == DrawCardLogic.DRAWCARD_ID2 then
  229. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE1, grade, heroID)
  230. elseif id == DrawCardLogic.DRAWCARD_ID3 then
  231. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE2, grade, heroID)
  232. elseif id == DrawCardLogic.DRAWCARD_ID6 then
  233. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE21, grade, heroID)
  234. end
  235. end
  236. DrawCardLogic.sendDrawOp(human, id, op, heroList, fenjielist, heroNewList,heroIndexList,isAct)
  237. for k, v in pairs(funcID) do
  238. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3608)
  239. break
  240. end
  241. --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)
  242. 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)
  243. perpleHero.drawCardCnt = perpleHero.drawCardCnt or 0
  244. perpleHero.drawCardCnt = perpleHero.drawCardCnt + heroCnt
  245. if perpleHero.drawCardCnt >= 10 then
  246. perpleHero.drawCardCnt = perpleHero.drawCardCnt - 10
  247. ZhanbuLogic.addZhanbuItem(human,1)
  248. end
  249. YunYingLogic.onCallBack(human, "onDrawCard", heroCnt, nil, id)
  250. end
  251. function getConfigByActID()
  252. local id
  253. local now = os.time()
  254. for k, config in pairs(OpenActExcel.limitPerpleHero) do
  255. if now >= config.startTime and now <= config.endTime then
  256. id = k
  257. break
  258. end
  259. end
  260. return OpenActExcel.limitPerpleHero[id], id
  261. end
  262. function getLuckDraw(human, op)
  263. local actConfig = getConfigByActID()
  264. local randomNum = math.random(1,10000)
  265. local luckDraw = false
  266. if randomNum <= actConfig.rate then
  267. luckDraw = true
  268. end
  269. local perpleHero = human.db.limitPerpleHero
  270. local noTargetHeroCnt = perpleHero.noTargetHeroCnt or 0
  271. noTargetHeroCnt = noTargetHeroCnt + 1
  272. if luckDraw == false and noTargetHeroCnt >= actConfig.cnt then
  273. luckDraw = true
  274. end
  275. if luckDraw then
  276. return perpleHero.like
  277. end
  278. end
  279. function heroCombat(human,heroID)
  280. Gm.d3.combat2(human,heroID)
  281. end
  282. function isRed(human, YYInfo, funcConfig)
  283. if BagLogic.getItemCnt(human, ItemDefine.ITEM_DRAWCARD_JINGYING_ID) >= 10 then
  284. return true
  285. end
  286. end
  287. function isActive(human, YYInfo, funcConfig)
  288. return not isOpen(human, YYInfo, funcConfig)
  289. end