DrawCardLogic.lua 28 KB

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