DrawCardLogic.lua 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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 > 3 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. -- 首次普通单抽
  476. return SysParameter.getSysParameter(SysParameter.PARAMETER_6)
  477. elseif id == DRAWCARD_ID2 and op == DRAWCARD_OP_1 and getDrawCnt(human, id) == 1 then
  478. return SysParameter.getSysParameter(SysParameter.PARAMETER_7)
  479. end
  480. end
  481. local heroID = nil
  482. local rindex = RandomLogic.getRandom1(config.weight, nil, 2)
  483. local rconf = config.weight[rindex]
  484. local grade = rconf[1]
  485. local campWeightConfig = CampWeightExcel[id]
  486. if not campWeightConfig then return end
  487. local rindex2 = RandomLogic.getRandom1(campWeightConfig.weight, nil, 2)
  488. local rconf2 = campWeightConfig.weight[rindex2]
  489. local camp = rconf2[1]
  490. if grade < 0 or camp < 0 then
  491. return heroID
  492. end
  493. heroID = heroID or HeroDefine.getRandHeroByGradeAndCamp(grade, camp)
  494. return heroID
  495. end
  496. -- 基础,高级,友情召唤,活动召唤
  497. local function draw(human, id, op, actConfig, skip, isAct)
  498. if isAct == AbsActDefine.ABS_ACT_TYPE_4 then
  499. PerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip, isAct)
  500. return
  501. elseif isAct == AbsActDefine.OA_ACT_TYPE_501 then
  502. LimitPerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip, isAct)
  503. return
  504. elseif isAct == AbsActDefine.ABS_ACT_TYPE_19 then
  505. HeroComeLogic.onDrawCardActive(human, id, op, actConfig, skip, isAct)
  506. return
  507. end
  508. local config = DrawCardExcel[id]
  509. if not config then return end
  510. local heroCnt = nil
  511. if op == DRAWCARD_OP_1 then
  512. heroCnt = 1
  513. elseif op == DRAWCARD_OP_2 then
  514. heroCnt = 10
  515. else
  516. return
  517. end
  518. if HeroLogic.getEmptyCnt(human) < heroCnt then
  519. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  520. end
  521. if not checkUseItem(human, id, op, config, isAct) then
  522. return
  523. end
  524. setSkip(human, id, skip)
  525. local heroLen = 0
  526. local heroList = {}
  527. local heroNewList = {}
  528. local heroIndexList = {}
  529. local fenjielist = {}
  530. local heroIDs = nil
  531. local randomMin = math.random(1, heroCnt)
  532. for i = 1, heroCnt do
  533. config = DrawCardExcel[id]
  534. if id == DRAWCARD_ID2 and op == DRAWCARD_OP_2 and i == randomMin and getDraw2Cnt(human, id) > 3 then
  535. config = DrawCardExcel[DRAWCARD_ID5]
  536. elseif id == DRAWCARD_ID2 and op == DRAWCARD_OP_1 then
  537. config = DrawCardExcel[DRAWCARD_ID6]
  538. end
  539. -- 第40抽必出SSR
  540. if id == DRAWCARD_ID2 and getDrawNoSSRCnt(human, id) >= DRAWCARD_40 - 1 then
  541. config = DrawCardExcel[DRAWCARD_ID7]
  542. end
  543. local heroID = randHeroID(human, id, op, config, actConfig, i == randomMin, isAct)
  544. local heroConfig = HeroExcel[heroID]
  545. local star = heroConfig.star
  546. local name = heroConfig.name
  547. local grade = heroConfig.grade
  548. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  549. local heroIndex, fjlist = HeroLogic.addHero(human, heroID, nil, 1, "draw_card")
  550. heroLen = heroLen + 1
  551. heroList[heroLen] = heroID
  552. heroNewList[heroLen] = isNew
  553. heroIndexList[heroLen] = heroIndex
  554. if fjlist and type(fjlist) == "table" then
  555. for fjItemID, fjItemCnt in pairs(fjlist) do
  556. fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
  557. end
  558. end
  559. if not heroIDs then
  560. heroIDs = heroID
  561. else
  562. heroIDs = heroIDs .. "|" .. heroID
  563. end
  564. -- 判断召唤出来的英雄是否为ssr
  565. if grade < 4 then
  566. addDrawNoSSRCnt(human, id, 1)
  567. else
  568. clearDrawNoSSRCnt(human, id)
  569. end
  570. if star < 5 then
  571. addDrawNoGoodCnt(human, id, 1)
  572. else
  573. clearDrawNoGoodCnt(human, id)
  574. end
  575. if getDrawCnt(human, id) > 0 or getDraw2Cnt(human, id) > 0 then
  576. if id == DRAWCARD_ID1 then
  577. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE3, grade, heroID)
  578. elseif id == DRAWCARD_ID2 then
  579. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE1, grade, heroID)
  580. elseif id == DRAWCARD_ID3 then
  581. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE2, grade, heroID)
  582. elseif id == DRAWCARD_ID6 then
  583. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE21, grade, heroID)
  584. end
  585. end
  586. if op == DRAWCARD_OP_1 then
  587. addDrawCnt(human, id, 1)
  588. elseif op == DRAWCARD_OP_2 then
  589. addDraw2Cnt(human, id, 1)
  590. end
  591. if id == DRAWCARD_ID1 then
  592. LiLianLogic.onCallback(human, LiLianLogic.LILIAN_OUTID26, 1, star)
  593. elseif id == DRAWCARD_ID2 then
  594. LiLianLogic.onCallback(human, LiLianLogic.LILIAN_OUTID27, 1, star)
  595. end
  596. end
  597. updateJifen(human, config.jifen * heroCnt)
  598. if id == DRAWCARD_ID2 then
  599. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_2, heroCnt)
  600. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_12, heroCnt)
  601. YunYingLogic.onCallBack(human, "onDrawCard", heroCnt,nil, id)
  602. end
  603. sendDrawOp(human, id, op, heroList, fenjielist, heroNewList, heroIndexList, isAct)
  604. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_401)
  605. Log.write(Log.LOGID_OSS_DRAWCARD, human.db._id, human.db.account, human.db.name, human.db.lv, id, heroIDs,
  606. itemID or 0, cnt or 0, zuanshi or 0, getJifen(human))
  607. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_3, heroCnt)
  608. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_DRAW)
  609. end
  610. -- 高级召唤 新版本
  611. local function drawV2(human, id, op, actConfig, skip, isAct)
  612. if isAct == AbsActDefine.ABS_ACT_TYPE_4 then
  613. PerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip, isAct)
  614. return
  615. elseif isAct == AbsActDefine.OA_ACT_TYPE_501 then
  616. LimitPerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip, isAct)
  617. return
  618. elseif isAct == AbsActDefine.ABS_ACT_TYPE_19 then
  619. HeroComeLogic.onDrawCardActive(human, id, op, actConfig, skip, isAct)
  620. return
  621. end
  622. local config = DrawCardExcel[id]
  623. if not config then return end
  624. local weightConf = DrawCardV2Excel[getDrawLv(human, id)]
  625. if not weightConf then return end
  626. local heroCnt = nil
  627. if op == DRAWCARD_OP_1 then
  628. heroCnt = 1
  629. elseif op == DRAWCARD_OP_2 then
  630. heroCnt = 10
  631. else
  632. return
  633. end
  634. if HeroLogic.getEmptyCnt(human) < heroCnt then
  635. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  636. end
  637. if not checkUseItem(human, id, op, config, isAct) then
  638. return
  639. end
  640. setSkip(human, id, skip)
  641. local heroLen = 0
  642. local heroList = {}
  643. local heroNewList = {}
  644. local heroIndexList = {}
  645. local fenjielist = {}
  646. local heroIDs = nil
  647. local randomMin = math.random(1, heroCnt)
  648. for i = 1, heroCnt do
  649. config = DrawCardExcel[id]
  650. weightConf = DrawCardV2Excel[getDrawLv(human, id)]
  651. local heroID = randHeroIDV2(human, id, op, weightConf, isAct)
  652. local heroConfig = HeroExcel[heroID]
  653. local star = heroConfig.star
  654. local name = heroConfig.name
  655. local grade = heroConfig.grade
  656. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  657. local heroIndex, fjlist = HeroLogic.addHero(human, heroID, nil, 1, "draw_card")
  658. heroLen = heroLen + 1
  659. heroList[heroLen] = heroID
  660. heroNewList[heroLen] = isNew
  661. heroIndexList[heroLen] = heroIndex
  662. if fjlist and type(fjlist) == "table" then
  663. for fjItemID, fjItemCnt in pairs(fjlist) do
  664. fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
  665. end
  666. end
  667. if not heroIDs then
  668. heroIDs = heroID
  669. else
  670. heroIDs = heroIDs .. "|" .. heroID
  671. end
  672. -- 判断召唤出来的英雄是否为ssr
  673. if grade < 4 then
  674. addDrawNoSSRCnt(human, id, 1)
  675. else
  676. clearDrawNoSSRCnt(human, id)
  677. end
  678. if star < 5 then
  679. addDrawNoGoodCnt(human, id, 1)
  680. else
  681. clearDrawNoGoodCnt(human, id)
  682. end
  683. if getDrawCnt(human, id) > 0 or getDraw2Cnt(human, id) > 0 then
  684. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE1, grade, heroID)
  685. end
  686. if op == DRAWCARD_OP_1 then
  687. addDrawCnt(human, id, 1)
  688. elseif op == DRAWCARD_OP_2 then
  689. addDraw2Cnt(human, id, 1)
  690. end
  691. --更新抽卡等级
  692. addDrawLv(human, id, 1)
  693. LiLianLogic.onCallback(human, LiLianLogic.LILIAN_OUTID27, 1, star)
  694. end
  695. updateJifen(human, config.jifen * heroCnt)
  696. if id == DRAWCARD_ID2 then
  697. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_2, heroCnt)
  698. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_12, heroCnt)
  699. YunYingLogic.onCallBack(human, "onDrawCard", heroCnt, id)
  700. end
  701. sendDrawOp(human, id, op, heroList, fenjielist, heroNewList, heroIndexList, isAct)
  702. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_401)
  703. Log.write(Log.LOGID_OSS_DRAWCARD, human.db._id, human.db.account, human.db.name, human.db.lv, id, heroIDs,
  704. itemID or 0, cnt or 0, zuanshi or 0, getJifen(human))
  705. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_3, heroCnt)
  706. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_DRAW)
  707. end
  708. function op(human, id, op, skip, isAct)
  709. if id == DRAWCARD_ID0 then
  710. jifenDraw(human, isAct)
  711. return
  712. end
  713. -- 高级召唤走新逻辑
  714. if id == DRAWCARD_ID2 then
  715. --drawV2(human, id, op, nil, skip, isAct)
  716. --return
  717. end
  718. if id == DRAWCARD_ID1 or id == DRAWCARD_ID2 or id == DRAWCARD_ID3 or id == DRAWCARD_ID6 then
  719. draw(human, id, op, nil, skip, isAct)
  720. return
  721. end
  722. end
  723. function initAfterHot()
  724. for _, config in pairs(DrawCardExcel) do
  725. local totalWeight = 0
  726. for k, v in ipairs(config.weight) do
  727. totalWeight = totalWeight + v[2]
  728. end
  729. config.totalWeight = totalWeight
  730. end
  731. end
  732. function isDot(human)
  733. if human.db.lv < 9 then
  734. return false
  735. end
  736. if isFree(human, DRAWCARD_ID1, DRAWCARD_OP_1) then
  737. return true
  738. end
  739. if isFree(human, DRAWCARD_ID2, DRAWCARD_OP_1) then
  740. return true
  741. end
  742. if BagLogic.getItemCnt(human, ItemDefine.ITEM_DRAWCARD_GAOCHOU_ID) >= 10 then
  743. return true
  744. end
  745. return false
  746. end