DrawCardLogic.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. ---------------------------------------------------
  2. -- 召唤法阵
  3. -- drawCard = {jifen=0,list={[1]={},[2]={},[3]={},[4]={}}},--召唤法阵
  4. -- drawInfo = {time,cntHero,cntHero2,chengjiuCnt,isRaward}
  5. ---------------------------------------------------
  6. local ItemExcel = require("excel.item")
  7. local Msg = require("core.Msg")
  8. local ObjHuman = require("core.ObjHuman")
  9. local Util = require("common.Util")
  10. local Log = require("common.Log")
  11. local Grid = require("bag.Grid")
  12. local Broadcast = require("broadcast.Broadcast")
  13. local Lang = require("common.Lang")
  14. local CommonDefine = require("common.CommonDefine")
  15. local HeroDefine = require("hero.HeroDefine")
  16. local ItemDefine = require("bag.ItemDefine")
  17. local HeroLogic = require("hero.HeroLogic")
  18. local BagLogic = require("bag.BagLogic")
  19. local HeroGrid = require("hero.HeroGrid")
  20. local DrawCardExcel = require("excel.drawCard").drawCard
  21. local DrawCardActivityExcel = require("excel.drawCard").activity
  22. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  23. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  24. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  25. local HeroExcel = require("excel.hero").hero
  26. local MailExcel = require("excel.mail")
  27. local MailManager = require("mail.MailManager")
  28. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  29. local MonthSummon = require("monthAct.MonthSummon")
  30. local HeroBook = require("hero.HeroBook")
  31. local RoleDefine = require("role.RoleDefine")
  32. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  33. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  34. local GuideLogic = require("guide.GuideLogic")
  35. local RandomLogic = require("common.RandomLogic")
  36. local TuiSongLiBao = require("present.TuiSongLiBao")
  37. local MoshouLogic = require("moshou.MoshouLogic")
  38. local LiLianLogic = require("dailyTask.LiLianLogic")
  39. local ProjectLogic = require("platform.ProjectLogic")
  40. local SysParameter = require("common.SysParameter")
  41. local AbsActLogic = require("absAct.AbsActLogic")
  42. local AbsActDefine = require("absAct.AbsActDefine")
  43. local HeroUpLogic = require("absAct.HeroUpLogic")
  44. local PerpleHeroLogic = require("absAct.PerpleHeroLogic")
  45. local YunYingLogic = require("yunying.YunYingLogic")
  46. local PanelDefine = require("broadcast.PanelDefine")
  47. local VipLogic = require("vip.VipLogic")
  48. local MengxinLogic = require("present.MengxinLogic")
  49. local LimitPerpleHeroLogic = require("present.LimitPerpleHeroLogic")
  50. local HeroComeLogic = require("absAct.HeroComeLogic")
  51. local NewHeroLogic = require("absAct.NewHeroLogic")
  52. Json = Json or require("common.Json")
  53. DRAWCARD_ID0 = 0 -- 积分召唤
  54. DRAWCARD_ID1 = 1 -- 基础召唤
  55. DRAWCARD_ID2 = 2 -- 高级召唤
  56. DRAWCARD_ID3 = 3 -- 友情召唤
  57. DRAWCARD_ID4 = 4 -- 积分召唤权重
  58. DRAWCARD_ID5 = 5 -- 高级召唤十连抽必出
  59. DRAWCARD_ID6 = 6 -- 高级召唤单抽
  60. DRAWCARD_ID7 = 7 -- 40高抽必出SSR
  61. DRAWCARD_ID8 = 8 -- 新英雄活动抽卡
  62. DRAWCARD_ID9 = 9 -- 100高抽必出新英雄
  63. DRAWCARD_ID10 = 10 -- 新英雄活动十抽
  64. DRAWCARD_ID11 = 11 -- 新英雄活动40抽必出
  65. DRAWCARD_OP_1 = 1 -- 召唤1次
  66. DRAWCARD_OP_2 = 2 -- 召唤10次
  67. DRAWCARD_JIFEN_NEED_VIPLV = 3
  68. DRAWCARD_JIFEN_SHOW_ITEM = 801005
  69. MAX_JIFEN = 3000
  70. DRAWCARD_40 = 40 -- 40连抽,必得SSR
  71. DRAWCARD_100 = 100 -- 新英雄抽卡活动期间100抽必得
  72. -- 积分
  73. function getJifen(human)
  74. return human.db.drawCard.jifen
  75. end
  76. function updateJifen(human, d)
  77. human.db.drawCard.jifen = human.db.drawCard.jifen or 0
  78. human.db.drawCard.jifen = human.db.drawCard.jifen + d
  79. end
  80. function addJifen(human,val)
  81. human.db.drawCard.jifen = human.db.drawCard.jifen + val
  82. end
  83. -- 根据抽奖id获取相关信息
  84. function getDrawInfo(human, id)
  85. return human.db.drawCard.list[id]
  86. end
  87. -- 免费CD
  88. function getFreeInfo(human, id)
  89. if id ~= DRAWCARD_ID1 and id ~= DRAWCARD_ID2 then
  90. return 0, 0 --只有普通和高抽可以免费
  91. end
  92. local info = getDrawInfo(human, id)
  93. local config = DrawCardExcel[id]
  94. local leftCnt = 1
  95. local leftTime = 0
  96. if not info.time then
  97. return leftCnt, leftTime
  98. end
  99. leftTime = math.max(info.time - os.time(), 0)
  100. if leftTime > 1 then
  101. leftCnt = 0
  102. end
  103. return leftCnt, leftTime
  104. end
  105. -- 设置免费冷却CD
  106. function setUseFree(human, id)
  107. local info = getDrawInfo(human, id)
  108. if not info then return end
  109. local config = DrawCardExcel[id]
  110. info.time = Util.getDayStartTime(os.time()) + 86400
  111. end
  112. -- 可否买免费
  113. function isFree(human, id, op)
  114. if op ~= DRAWCARD_OP_1 then return end
  115. local leftCnt, leftTime = getFreeInfo(human, id)
  116. if leftCnt > 0 and leftTime < 1 then
  117. return true
  118. end
  119. end
  120. -- 10连次数
  121. function getDraw2Cnt(human, id)
  122. local info = getDrawInfo(human, id)
  123. if not info then return 0 end
  124. return info.cntHero2 or 0
  125. end
  126. function addDraw2Cnt(human, id, cnt)
  127. local info = getDrawInfo(human, id)
  128. if not info then return end
  129. info.cntHero2 = (info.cntHero2 or 0) + cnt
  130. end
  131. -- 单抽次数
  132. function getDrawCnt(human, id)
  133. local info = getDrawInfo(human, id)
  134. if not info then return 0 end
  135. return info.cntHero or 0
  136. end
  137. function addDrawCnt(human, id, cnt)
  138. local info = getDrawInfo(human, id)
  139. if not info then return end
  140. info.cntHero = (info.cntHero or 0) + cnt
  141. end
  142. function setSkip(human, id, skip)
  143. human.db.drawCard.skip = skip or 0
  144. end
  145. -- 连续1-4英雄次数
  146. function getDrawNoGoodCnt(human, id)
  147. local info = getDrawInfo(human, id)
  148. if not info then return 0 end
  149. return info.chengjiuCnt or 0
  150. end
  151. function addDrawNoGoodCnt(human, id, cnt)
  152. local info = getDrawInfo(human, id)
  153. if not info then return end
  154. info.chengjiuCnt = (info.chengjiuCnt or 0) + cnt
  155. end
  156. function getDrawNoSSRCnt(human, id)
  157. local info = getDrawInfo(human, id)
  158. if not info then return 0 end
  159. return info.leftSSRCnt or 0
  160. end
  161. function addDrawNoSSRCnt(human, id, cnt)
  162. local info = getDrawInfo(human, id, cnt)
  163. if not info then return end
  164. info.leftSSRCnt = (info.leftSSRCnt or 0) + cnt
  165. end
  166. function clearDrawNoSSRCnt(human, id)
  167. local info = getDrawInfo(human, id)
  168. if not info then return end
  169. info.leftSSRCnt = nil
  170. end
  171. function getDrawNewSSRCnt(human, id)
  172. local info = getDrawInfo(human, id)
  173. if not info then return 0 end
  174. return info.leftNewSRRCnt or 0
  175. end
  176. function addDrawNewSSRCnt(human, id, cnt)
  177. local info = getDrawInfo(human, id, cnt)
  178. if not info then return end
  179. info.leftNewSRRCnt = (info.leftNewSRRCnt or 0) + cnt
  180. end
  181. function clearDrawNewSSRCnt(human, id)
  182. local info = getDrawInfo(human, id)
  183. if not info then return end
  184. info.leftNewSRRCnt = nil
  185. end
  186. function clearDrawNoGoodCnt(human, id)
  187. local info = getDrawInfo(human, id)
  188. if not info then return end
  189. info.chengjiuCnt = nil
  190. end
  191. -- 友情点
  192. function getFriendHeart(human)
  193. return human.db.friendHeart
  194. end
  195. function fontDrawCardNet(net, id, human)
  196. local config = DrawCardExcel[id]
  197. local leftCnt, leftTime = getFreeInfo(human, id)
  198. net.id = id
  199. net.leftFreeTime = leftTime
  200. net.leftFreeCnt = leftCnt
  201. net.items[0] = 0
  202. if config.item1[1] and config.item1[2] then
  203. net.items[0] = net.items[0] + 1
  204. Grid.makeItem(net.items[net.items[0]], config.item1[1], config.item1[2])
  205. end
  206. local vipArg = 100
  207. if id == DRAWCARD_ID2 then
  208. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER21)
  209. end
  210. if config.item2[1] and config.item2[2] then
  211. net.items[0] = net.items[0] + 1
  212. Grid.makeItem(net.items[net.items[0]], config.item2[1], math.floor(config.item2[2] * vipArg / 100 ) )
  213. end
  214. vipArg = 0
  215. if id == DRAWCARD_ID2 then
  216. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER22)
  217. end
  218. net.zuanshi[0] = 2
  219. net.zuanshi[1] = config.zuanshi1
  220. net.zuanshi[2] = config.zuanshi2 + vipArg
  221. net.isFirst = (getDraw2Cnt(human, id) < 1) and 1 or 0
  222. net.canBuy = ItemExcel.buy[config.item1[1]] and 1 or 0
  223. end
  224. -- 抽奖列表
  225. function query(human)
  226. local msgRet = Msg.gc.GC_DRAWCARD_QUERY
  227. msgRet.jifen = getJifen(human)
  228. msgRet.left = getDrawNoSSRCnt(human, DRAWCARD_ID2)
  229. msgRet.leftNoSRRCnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID2)
  230. msgRet.leftNewSRRCnt = getDrawNewSSRCnt(human, DRAWCARD_ID8)
  231. msgRet.leftNewSRR40Cnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID8)
  232. msgRet.list[0] = 0
  233. local ids = {DRAWCARD_ID1, DRAWCARD_ID2, DRAWCARD_ID3, DRAWCARD_ID8}
  234. for i = 1, #ids do
  235. msgRet.list[0] = msgRet.list[0] + 1
  236. local net = msgRet.list[msgRet.list[0]]
  237. fontDrawCardNet(net, ids[i], human)
  238. end
  239. local needItemID = ItemDefine.ITEM_XIANZHI_BAOZHU_ID
  240. Grid.makeItem(msgRet.qiyuan, needItemID, 1)
  241. msgRet.skip = human.db.drawCard.skip or 0
  242. Msg.send(msgRet, human.fd)
  243. end
  244. -- 抽奖结果
  245. function sendDrawOp(human, id, op, heroList, items, heroNewList, heroIndexList,isAct)
  246. local msgRet = Msg.gc.GC_DRAWCARD_OP
  247. msgRet.isAct = isAct or 0
  248. msgRet.leftNoSRRCnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID2)
  249. msgRet.leftNewSRRCnt = getDrawNewSSRCnt(human, DRAWCARD_ID8)
  250. msgRet.leftNewSRR40Cnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID8)
  251. local dataNet = msgRet.data
  252. dataNet.jifen = getJifen(human)
  253. dataNet.id = id
  254. dataNet.op = op
  255. dataNet.heros[0] = heroList and #heroList or 0
  256. for i = 1, dataNet.heros[0] do
  257. local heroID = heroList[i]
  258. local isNew = heroNewList and heroNewList[i]
  259. local index = heroIndexList and heroIndexList[i]
  260. HeroGrid.makeHeroNice(dataNet.heros[i], heroID, nil, isNew, index, human)
  261. end
  262. dataNet.items[0] = 0
  263. if items and type(items) == "table" then
  264. for itemID, itemCnt in pairs(items) do
  265. dataNet.items[0] = dataNet.items[0] + 1
  266. Grid.makeItem(dataNet.items[dataNet.items[0]], itemID, itemCnt)
  267. end
  268. end
  269. fontDrawCardNet(msgRet.drawData, id, human)
  270. Msg.send(msgRet, human.fd)
  271. end
  272. -- 积分召唤
  273. local function jifenDraw(human, isAct)
  274. local config = DrawCardExcel[DRAWCARD_ID4]
  275. if not config then return end
  276. local db = human.db.drawCard
  277. if getJifen(human) < MAX_JIFEN then
  278. return Broadcast.sendErr(human, Lang.DRAWCARD_ERR_NOJIFEN)
  279. end
  280. if HeroLogic.getEmptyCnt(human) < 1 then
  281. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  282. end
  283. local heroID = randHeroID(human, DRAWCARD_ID4, DRAWCARD_OP_1, config)
  284. updateJifen(human, -MAX_JIFEN)
  285. local heroConfig = HeroExcel[heroID]
  286. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE4, heroConfig.grade, heroID)
  287. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  288. local heroIndex, fenjielist = HeroLogic.addHero(human, heroID,nil, 1, "draw_card")
  289. Log.write(Log.LOGID_OSS_DRAWCARD, human.db._id, human.db.account, human.db.name, human.db.lv, DRAWCARD_ID4, heroID, 0, 0, 0, db.jifen)
  290. sendDrawOp(human, DRAWCARD_ID4, 0, {heroID}, fenjielist, {isNew}, {heroIndex}, isAct)
  291. end
  292. -- 检查道具+扣道具
  293. function checkUseItem(human, id, op, config,isAct)
  294. local item = config["item" .. op]
  295. local zuanshi = config["zuanshi" .. op]
  296. if not item or not zuanshi then return end
  297. local itemID = item[1]
  298. local itemCnt = item[2]
  299. if id == DRAWCARD_ID2 and op == DRAWCARD_OP_2 then
  300. local vipArg = 100
  301. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER21)
  302. print(" checkUseItem vipArg ", vipArg, " , old : " ,itemCnt , " , new : ", math.floor(itemCnt * vipArg / 100 ) )
  303. itemCnt = math.floor(itemCnt * vipArg / 100 )
  304. end
  305. print(" checkUseItem itemID itemCnt ", itemID, itemCnt)
  306. -- 活动只扣道具
  307. if isAct == AbsActDefine.ABS_ACT_TYPE_4 then
  308. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_4)
  309. if not state then
  310. return
  311. end
  312. local config = PerpleHeroLogic.getConfigByActID(id)
  313. itemID = config["item" .. op][1]
  314. itemCnt = config["item" .. op][2]
  315. if BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  316. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  317. return true
  318. else
  319. return
  320. end
  321. elseif isAct == AbsActDefine.ABS_ACT_TYPE_19 then
  322. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_19)
  323. if not state then
  324. return
  325. end
  326. local config = HeroComeLogic.getConfigByActID(id)
  327. itemID = config["item" .. op][1]
  328. itemCnt = config["item" .. op][2]
  329. if BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  330. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  331. return true
  332. else
  333. return
  334. end
  335. elseif isAct == AbsActDefine.OA_ACT_TYPE_501 then
  336. local limitState = LimitPerpleHeroLogic.checkOpen()
  337. if not limitState then
  338. return
  339. end
  340. local config = LimitPerpleHeroLogic.getConfigByActID()
  341. itemID = config["item" .. op][1]
  342. itemCnt = config["item" .. op][2]
  343. if BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  344. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  345. return true
  346. else
  347. return
  348. end
  349. end
  350. if isFree(human, id, op) then -- 免费
  351. setUseFree(human, id)
  352. return true
  353. elseif BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  354. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  355. return true
  356. elseif zuanshi > 0 then -- 扣钻石
  357. -- 抵扣道具
  358. local haveCnt = BagLogic.getItemCnt(human, itemID)
  359. local vipArg = 0
  360. if id == DRAWCARD_ID2 and op == DRAWCARD_OP_2 then
  361. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER22)
  362. end
  363. zuanshi = zuanshi + vipArg
  364. if haveCnt > 0 then
  365. zuanshi = zuanshi - math.floor(zuanshi * haveCnt / itemCnt)
  366. zuanshi = zuanshi > 0 and zuanshi or 0
  367. end
  368. if not ObjHuman.checkRMB(human, zuanshi) then
  369. return
  370. end
  371. if haveCnt > 0 then
  372. BagLogic.delItem(human, itemID, haveCnt, "draw_card")
  373. end
  374. ObjHuman.decZuanshi(human, -zuanshi, "draw_card")
  375. return true
  376. end
  377. if zuanshi <= 0 then
  378. Broadcast.sendErr(human, Util.format(Lang.DRAWCARD_ERR_NOITEM, ItemDefine.getValue(itemID, "name")))
  379. end
  380. end
  381. --
  382. function randHeroID(human, id, op, config, actConfig, randomIndex, isAct)
  383. if isAct == 0 then
  384. if id == DRAWCARD_ID1 and op == DRAWCARD_OP_1 and getDrawCnt(human, id) == 0 then
  385. -- 首次普通单抽
  386. return SysParameter.getSysParameter(SysParameter.PARAMETER_6)
  387. elseif id == DRAWCARD_ID2 and op == DRAWCARD_OP_1 and getDrawCnt(human, id) == 0 then
  388. return SysParameter.getSysParameter(SysParameter.PARAMETER_7)
  389. end
  390. end
  391. if randomIndex and isAct == 0 then
  392. if id == DRAWCARD_ID2 and op == DRAWCARD_OP_2 then
  393. local sysHeroList = nil
  394. local draw2Cnt = getDraw2Cnt(human, id)
  395. draw2Cnt = math.floor(draw2Cnt/10)
  396. if draw2Cnt == 0 then
  397. sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_11)
  398. elseif draw2Cnt == 1 then
  399. sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_12)
  400. elseif draw2Cnt == 2 then
  401. sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_13)
  402. end
  403. if sysHeroList then
  404. local totoalWeight = 0
  405. for i=1, #sysHeroList do
  406. totoalWeight = totoalWeight + sysHeroList[i][2]
  407. end
  408. local r = math.random(1, totoalWeight)
  409. for i=1, #sysHeroList do
  410. if r <= sysHeroList[i][2] then
  411. return sysHeroList[i][1]
  412. end
  413. r = r - sysHeroList[i][2]
  414. end
  415. end
  416. end
  417. end
  418. local heroID = nil
  419. local rindex = RandomLogic.getRandom1(config.weight, nil, 2)
  420. local rconf = config.weight[rindex]
  421. local weightLv = rconf[1]
  422. if weightLv >= 8 and actConfig then
  423. local rindex2 = RandomLogic.getRandom3(actConfig)
  424. local rconf2 = rindex2 and actConfig[rindex2]
  425. if rconf2 then
  426. return rconf2.heroID
  427. end
  428. end
  429. heroID = heroID or HeroDefine.getRandHeroByWeightLv(weightLv)
  430. local actHeroID = AbsActLogic.getLuckDraw(human,luckDraw,randomIndex,isAct,op)
  431. if actHeroID then
  432. heroID = actHeroID
  433. end
  434. return heroID
  435. end
  436. -- 基础,高级,友情召唤,活动召唤
  437. local function draw(human, id, op, actConfig, skip,isAct)
  438. if isAct == AbsActDefine.ABS_ACT_TYPE_4 then
  439. PerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip,isAct)
  440. return
  441. elseif isAct == AbsActDefine.OA_ACT_TYPE_501 then
  442. LimitPerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip,isAct)
  443. return
  444. elseif isAct == AbsActDefine.ABS_ACT_TYPE_19 then
  445. HeroComeLogic.onDrawCardActive(human, id, op, actConfig, skip,isAct)
  446. return
  447. end
  448. local config = DrawCardExcel[id]
  449. if not config then return end
  450. local heroCnt = nil
  451. if op == DRAWCARD_OP_1 then
  452. heroCnt = 1
  453. elseif op == DRAWCARD_OP_2 then
  454. heroCnt = 10
  455. else
  456. return
  457. end
  458. local state, endTime, starTime = AbsActLogic.isStarted(human, NewHeroLogic.ABS_ACT_ID)
  459. if id == DRAWCARD_ID8 and not state then
  460. return
  461. end
  462. if HeroLogic.getEmptyCnt(human) < heroCnt then
  463. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  464. end
  465. if not checkUseItem(human, id, op, config,isAct) then
  466. print("checkUseItem false")
  467. return
  468. end
  469. setSkip(human, id, skip)
  470. local heroLen = 0
  471. local heroList = {}
  472. local heroNewList = {}
  473. local heroIndexList = {}
  474. local fenjielist = {}
  475. local heroIDs = nil
  476. local randomMin = math.random(1, heroCnt)
  477. for i = 1, heroCnt do
  478. config = DrawCardExcel[id]
  479. if id == DRAWCARD_ID2 and op == DRAWCARD_OP_2 and i == randomMin and getDraw2Cnt(human, id) > 3 then
  480. config = DrawCardExcel[DRAWCARD_ID5]
  481. elseif id == DRAWCARD_ID2 and op == DRAWCARD_OP_1 then
  482. config = DrawCardExcel[DRAWCARD_ID6]
  483. end
  484. if id == DRAWCARD_ID8 and op == DRAWCARD_OP_2 and i == randomMin then
  485. config = DrawCardExcel[DRAWCARD_ID10]
  486. end
  487. -- 第40抽必出SSR
  488. if id == DRAWCARD_ID2 and getDrawNoSSRCnt(human, id) >= DRAWCARD_40 - 1 then
  489. config = DrawCardExcel[DRAWCARD_ID7]
  490. end
  491. if id == DRAWCARD_ID8 and getDrawNoSSRCnt(human, id) >= DRAWCARD_40 - 1 then
  492. config = DrawCardExcel[DRAWCARD_ID11]
  493. end
  494. if id == DRAWCARD_ID8 and getDrawNewSSRCnt(human, id) >= DRAWCARD_100 - 1 then
  495. config = DrawCardExcel[DRAWCARD_ID9]
  496. end
  497. local heroID = randHeroID(human, id, op, config, actConfig, i == randomMin, isAct)
  498. local heroConfig = HeroExcel[heroID]
  499. local star = heroConfig.star
  500. local name = heroConfig.name
  501. local grade = heroConfig.grade
  502. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  503. local heroIndex, fjlist = HeroLogic.addHero(human, heroID,nil, 1, "draw_card")
  504. heroLen = heroLen + 1
  505. heroList[heroLen] = heroID
  506. heroNewList[heroLen] = isNew
  507. heroIndexList[heroLen] = heroIndex
  508. if fjlist and type(fjlist) == "table" then
  509. for fjItemID, fjItemCnt in pairs(fjlist) do
  510. fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
  511. end
  512. end
  513. if not heroIDs then
  514. heroIDs = heroID
  515. else
  516. heroIDs = heroIDs .. "|" .. heroID
  517. end
  518. -- 判断召唤出来的英雄是否为ssr
  519. if grade < 4 then
  520. addDrawNoSSRCnt(human, id, 1)
  521. else
  522. clearDrawNoSSRCnt(human, id)
  523. end
  524. if star < 5 then
  525. addDrawNoGoodCnt(human, id, 1)
  526. else
  527. clearDrawNoGoodCnt(human, id)
  528. end
  529. if heroID == NewHeroLogic.getNewHeroID(human) then
  530. clearDrawNewSSRCnt(human, id)
  531. elseif state then
  532. addDrawNewSSRCnt(human, id, 1)
  533. end
  534. if getDrawCnt(human, id) > 0 or getDraw2Cnt(human, id) > 0 then
  535. if id == DRAWCARD_ID1 then
  536. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE3, grade, heroID)
  537. elseif id == DRAWCARD_ID2 then
  538. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE1, grade, heroID)
  539. elseif id == DRAWCARD_ID3 then
  540. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE2, grade, heroID)
  541. elseif id == DRAWCARD_ID6 then
  542. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE21, grade, heroID)
  543. end
  544. end
  545. if op == DRAWCARD_OP_1 then
  546. addDrawCnt(human, id, 1)
  547. elseif op == DRAWCARD_OP_2 then
  548. addDraw2Cnt(human, id, 1)
  549. end
  550. if id == DRAWCARD_ID1 then
  551. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID26,1,star)
  552. elseif id == DRAWCARD_ID2 then
  553. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID27,1,star)
  554. end
  555. end
  556. if id ~= DRAWCARD_ID8 then
  557. updateJifen(human, config.jifen * heroCnt)
  558. end
  559. if id == DRAWCARD_ID2 then
  560. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_2,heroCnt)
  561. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_12,heroCnt)
  562. YunYingLogic.onCallBack(human, "onDrawCard", heroCnt,nil, id)
  563. end
  564. sendDrawOp(human, id, op, heroList, fenjielist, heroNewList,heroIndexList,isAct)
  565. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_401)
  566. 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, getJifen(human))
  567. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_3, heroCnt)
  568. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_DRAW)
  569. end
  570. function op(human, id, op, skip,isAct)
  571. if id == DRAWCARD_ID0 then
  572. jifenDraw(human, isAct)
  573. return
  574. end
  575. if id == DRAWCARD_ID1 or id == DRAWCARD_ID2 or id == DRAWCARD_ID3 or id == DRAWCARD_ID6 or id == DRAWCARD_ID8 then
  576. draw(human, id, op, nil, skip,isAct)
  577. return
  578. end
  579. end
  580. function initAfterHot()
  581. for _, config in pairs(DrawCardExcel) do
  582. local totalWeight = 0
  583. for k, v in ipairs(config.weight) do
  584. totalWeight = totalWeight + v[2]
  585. end
  586. config.totalWeight = totalWeight
  587. end
  588. end
  589. function isDot(human)
  590. if human.db.lv < 9 then
  591. return false
  592. end
  593. if isFree(human, DRAWCARD_ID1, DRAWCARD_OP_1) then
  594. return true
  595. end
  596. if isFree(human, DRAWCARD_ID2, DRAWCARD_OP_1) then
  597. return true
  598. end
  599. if BagLogic.getItemCnt(human, ItemDefine.ITEM_DRAWCARD_GAOCHOU_ID) >= 10 then
  600. return true
  601. end
  602. return false
  603. end