DrawCardLogic.lua 26 KB

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