DrawCardLogic.lua 29 KB

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