DrawCardLogic.lua 26 KB

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