DrawCardLogic.lua 28 KB

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