DrawCardLogic.lua 29 KB

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