DrawCardLogic.lua 25 KB

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