DrawCardLogic.lua 28 KB

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