DrawCardLogic.lua 29 KB

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