DrawCardLogic.lua 26 KB

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