DrawCardLogic.lua 27 KB

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