DrawCardLogic.lua 29 KB

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