DrawCardLogic.lua 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  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 DrawCardActivityExcel = require("excel.drawCard").activity
  22. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  23. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  24. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  25. local HeroExcel = require("excel.hero").hero
  26. -- local MailExcel = require("excel.mail")
  27. -- local MailManager = require("mail.MailManager")
  28. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  29. -- local MonthSummon = require("monthAct.MonthSummon")
  30. local HeroBook = require("hero.HeroBook")
  31. -- local RoleDefine = require("role.RoleDefine")
  32. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  33. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  34. local GuideLogic = require("guide.GuideLogic")
  35. local RandomLogic = require("common.RandomLogic")
  36. -- local TuiSongLiBao = require("present.TuiSongLiBao")
  37. -- local MoshouLogic = require("moshou.MoshouLogic")
  38. local LiLianLogic = require("dailyTask.LiLianLogic")
  39. -- local ProjectLogic = require("platform.ProjectLogic")
  40. local SysParameter = require("common.SysParameter")
  41. local AbsActLogic = require("absAct.AbsActLogic")
  42. local AbsActDefine = require("absAct.AbsActDefine")
  43. -- local HeroUpLogic = require("absAct.HeroUpLogic")
  44. local PerpleHeroLogic = require("absAct.PerpleHeroLogic")
  45. local YunYingLogic = require("yunying.YunYingLogic")
  46. -- local PanelDefine = require("broadcast.PanelDefine")
  47. local VipLogic = require("vip.VipLogic")
  48. local MengxinLogic = require("present.MengxinLogic")
  49. local LimitPerpleHeroLogic = require("present.LimitPerpleHeroLogic")
  50. local HeroComeLogic = require("absAct.HeroComeLogic")
  51. local NewHeroLogic = require("absAct.NewHeroLogic")
  52. Json = Json or require("common.Json")
  53. local TalismanLogic = require("talisman.TalismanLogic")
  54. local MainDianLogic = require("MaiDian.MaiDianLogic")
  55. local MaiDianDefine = require("MaiDian.MaiDianDefine")
  56. local TriggerDefine = require("trigger.TriggerDefine")
  57. local TriggerLogic = require("trigger.TriggerLogic")
  58. local WeekTaskLogic = require("dailyTask.WeekTaskLogic")
  59. local ClutterDataLogic = require("clutter.ClutterDataLogic")
  60. local ClutterDataDefine = require("clutter.ClutterDataDefine")
  61. local WarOrder = require("shop.WarOrder")
  62. DRAWCARD_ID0 = 0 -- 积分召唤
  63. DRAWCARD_ID1 = 1 -- 基础召唤
  64. DRAWCARD_ID2 = 2 -- 高级召唤
  65. DRAWCARD_ID3 = 3 -- 友情召唤
  66. DRAWCARD_ID4 = 4 -- 积分召唤权重
  67. DRAWCARD_ID5 = 5 -- 高级召唤十连抽必出
  68. DRAWCARD_ID6 = 6 -- 高级召唤单抽
  69. DRAWCARD_ID7 = 7 -- 40高抽必出SSR
  70. DRAWCARD_ID8 = 8 -- 新英雄活动抽卡
  71. DRAWCARD_ID9 = 9 -- 100高抽必出新英雄
  72. DRAWCARD_ID10 = 10 -- 新英雄活动十抽
  73. DRAWCARD_ID11 = 11 -- 新英雄活动40抽必出
  74. DRAWCARD_OP_1 = 1 -- 召唤1次
  75. DRAWCARD_OP_2 = 2 -- 召唤10次
  76. DRAWCARD_OP_3 = 3 -- 召唤100次
  77. DRAWCARD_JIFEN_NEED_VIPLV = 3
  78. DRAWCARD_JIFEN_SHOW_ITEM = 801005
  79. MAX_JIFEN = 3000
  80. DRAWCARD_40 = 40 -- 40连抽,必得SSR
  81. DRAWCARD_100 = 100 -- 新英雄抽卡活动期间100抽必得
  82. DRAWCARD_ID2_CNT = 50 --高级召唤前5次10连每次必出SSR
  83. local function getTalismanAdd(human)
  84. local jyzh_lottery10 = TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.JYZH_LOTTERY10) or 0
  85. if jyzh_lottery10 <= 0 then
  86. jyzh_lottery10 = 100
  87. end
  88. jyzh_lottery10 = jyzh_lottery10 / 100
  89. return jyzh_lottery10
  90. end
  91. -- 积分
  92. function getJifen(human)
  93. return human.db.drawCard.jifen
  94. end
  95. function updateJifen(human, d)
  96. human.db.drawCard.jifen = human.db.drawCard.jifen or 0
  97. human.db.drawCard.jifen = human.db.drawCard.jifen + d
  98. end
  99. function addJifen(human,val)
  100. human.db.drawCard.jifen = human.db.drawCard.jifen + val
  101. end
  102. -- 根据抽奖id获取相关信息
  103. function getDrawInfo(human, id)
  104. if not human.db.drawCard.list[id] then
  105. human.db.drawCard.list[id] = {}
  106. end
  107. return human.db.drawCard.list[id]
  108. end
  109. -- 免费CD
  110. function getFreeInfo(human, id)
  111. if id ~= DRAWCARD_ID1 and id ~= DRAWCARD_ID2 then
  112. return 0, 0 --只有普通和高抽可以免费
  113. end
  114. local info = getDrawInfo(human, id)
  115. local config = DrawCardExcel[id]
  116. local leftCnt = 1
  117. local leftTime = 0
  118. if not info.time then
  119. return leftCnt, leftTime
  120. end
  121. leftTime = math.max(info.time - os.time(), 0)
  122. if leftTime > 1 then
  123. leftCnt = 0
  124. end
  125. return leftCnt, leftTime
  126. end
  127. -- 设置免费冷却CD
  128. function setUseFree(human, id)
  129. local info = getDrawInfo(human, id)
  130. if not info then return end
  131. local config = DrawCardExcel[id]
  132. info.time = Util.getDayStartTime(os.time()) + 86400
  133. end
  134. -- 可否买免费
  135. function isFree(human, id, op)
  136. if op ~= DRAWCARD_OP_1 then return end
  137. local leftCnt, leftTime = getFreeInfo(human, id)
  138. if leftCnt > 0 and leftTime < 1 then
  139. return true
  140. end
  141. end
  142. -- 10连次数
  143. function getDraw2Cnt(human, id)
  144. local info = getDrawInfo(human, id)
  145. if not info then return 0 end
  146. return info.cntHero2 or 0
  147. end
  148. function addDraw2Cnt(human, id, cnt)
  149. local info = getDrawInfo(human, id)
  150. if not info then return end
  151. info.cntHero2 = (info.cntHero2 or 0) + cnt
  152. end
  153. -- 单抽次数
  154. function getDrawCnt(human, id)
  155. local info = getDrawInfo(human, id)
  156. if not info then return 0 end
  157. return info.cntHero or 0
  158. end
  159. function addDrawCnt(human, id, cnt)
  160. local info = getDrawInfo(human, id)
  161. if not info then return end
  162. info.cntHero = (info.cntHero or 0) + cnt
  163. end
  164. -- 获取总抽卡次数
  165. function getAllDrawCnt(human, id)
  166. local info = getDrawInfo(human, id)
  167. if not info then return 0 end
  168. local nAllCnt = info.cntHero or 0
  169. nAllCnt = info.cntHero2 and nAllCnt + info.cntHero2 or nAllCnt
  170. return nAllCnt
  171. end
  172. function setSkip(human, id, skip)
  173. human.db.drawCard.skip = skip or 0
  174. end
  175. function SetHeroSkip(human, bOperate)
  176. human.db.drawCard.skipHero = bOperate
  177. end
  178. -- 连续1-4英雄次数
  179. function getDrawNoGoodCnt(human, id)
  180. local info = getDrawInfo(human, id)
  181. if not info then return 0 end
  182. return info.chengjiuCnt or 0
  183. end
  184. function addDrawNoGoodCnt(human, id, cnt)
  185. local info = getDrawInfo(human, id)
  186. if not info then return end
  187. info.chengjiuCnt = (info.chengjiuCnt or 0) + cnt
  188. end
  189. function getDrawNoSSRCnt(human, id)
  190. local info = getDrawInfo(human, id)
  191. if not info then return 0 end
  192. return info.leftSSRCnt or 0
  193. end
  194. function addDrawNoSSRCnt(human, id, cnt)
  195. local info = getDrawInfo(human, id, cnt)
  196. if not info then return end
  197. info.leftSSRCnt = (info.leftSSRCnt or 0) + cnt
  198. end
  199. function clearDrawNoSSRCnt(human, id)
  200. local info = getDrawInfo(human, id)
  201. if not info then return end
  202. info.leftSSRCnt = nil
  203. end
  204. function getDrawNewSSRCnt(human, id)
  205. local info = getDrawInfo(human, id)
  206. if not info then return 0 end
  207. return info.leftNewSRRCnt or 0
  208. end
  209. function addDrawNewSSRCnt(human, id, cnt)
  210. local info = getDrawInfo(human, id, cnt)
  211. if not info then return end
  212. info.leftNewSRRCnt = (info.leftNewSRRCnt or 0) + cnt
  213. end
  214. function clearDrawNewSSRCnt(human, id)
  215. local info = getDrawInfo(human, id)
  216. if not info then return end
  217. info.leftNewSRRCnt = nil
  218. end
  219. -- 精英召唤活动切换时重置40抽/100抽计数
  220. local function checkNewHeroDrawActSwitch(human)
  221. local actId = NewHeroLogic.getActiveActId(human)
  222. if not actId then
  223. return
  224. end
  225. local info = getDrawInfo(human, DRAWCARD_ID8)
  226. if info.newHeroActId and info.newHeroActId ~= actId then
  227. clearDrawNoSSRCnt(human, DRAWCARD_ID8)
  228. clearDrawNewSSRCnt(human, DRAWCARD_ID8)
  229. end
  230. info.newHeroActId = actId
  231. end
  232. function clearDrawNoGoodCnt(human, id)
  233. local info = getDrawInfo(human, id)
  234. if not info then return end
  235. info.chengjiuCnt = nil
  236. end
  237. -- 友情点
  238. function getFriendHeart(human)
  239. return human.db.friendHeart
  240. end
  241. function fontDrawCardNet(net, id, human)
  242. local configId = id
  243. if id == DRAWCARD_ID8 then
  244. configId = NewHeroLogic.getNewHeroDrawConfigIds(NewHeroLogic.getActiveActId(human))
  245. end
  246. local config = DrawCardExcel[configId]
  247. if not config then return end
  248. local leftCnt, leftTime = getFreeInfo(human, id)
  249. net.id = id
  250. net.leftFreeTime = leftTime
  251. net.leftFreeCnt = leftCnt
  252. net.items[0] = 0
  253. if config.item1[1] and config.item1[2] then
  254. net.items[0] = net.items[0] + 1
  255. Grid.makeItem(net.items[net.items[0]], config.item1[1], config.item1[2])
  256. end
  257. local vipArg = 100
  258. if id == DRAWCARD_ID2 then
  259. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER21)
  260. end
  261. local itemCnt,finalItemCnt = 0, 0
  262. if config.item2[1] and config.item2[2] then
  263. net.items[0] = net.items[0] + 1
  264. itemCnt = math.floor(config.item2[2] * vipArg / 100 )
  265. finalItemCnt = itemCnt
  266. if id == DRAWCARD_ID8 then
  267. local talisman_jyzh_lotter10 = getTalismanAdd(human)
  268. finalItemCnt = math.floor(finalItemCnt * talisman_jyzh_lotter10)
  269. end
  270. Grid.makeItem(net.items[net.items[0]], config.item2[1], finalItemCnt )
  271. end
  272. vipArg = 100
  273. itemCnt, finalItemCnt = 0, 0
  274. if config.item3[1] and config.item3[2] then
  275. if id == DRAWCARD_ID2 then -- 目前只有高抽和精英两种模式有100抽
  276. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER23)
  277. end
  278. net.items[0] = net.items[0] + 1
  279. itemCnt = math.floor(config.item3[2] * vipArg / 100 )
  280. finalItemCnt = itemCnt
  281. if id == DRAWCARD_ID8 then
  282. local talisman_jyzh_lotter100 = getTalismanAdd(human)
  283. finalItemCnt = math.floor(finalItemCnt * talisman_jyzh_lotter100)
  284. end
  285. Grid.makeItem(net.items[net.items[0]], config.item3[1], finalItemCnt)
  286. end
  287. vipArg = 0
  288. if id == DRAWCARD_ID2 then
  289. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER22)
  290. end
  291. net.zuanshi[0] = 3
  292. net.zuanshi[1] = config.zuanshi1
  293. net.zuanshi[2] = config.zuanshi2 + vipArg
  294. net.zuanshi[3] = config.zuanshi3 or 0
  295. vipArg = 0
  296. if id == DRAWCARD_ID2 and net.zuanshi[3] > 0 then -- 目前只有高抽和精英两种模式有100抽
  297. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER24)
  298. net.zuanshi[3] = net.zuanshi[3] + vipArg
  299. end
  300. if id == DRAWCARD_ID8 then
  301. net.zuanshi[2] = math.floor((net.zuanshi[2] / itemCnt) * finalItemCnt)
  302. net.zuanshi[3] = math.floor((net.zuanshi[3] / itemCnt) * finalItemCnt)
  303. end
  304. net.isFirst = (getDraw2Cnt(human, id) < 1) and 1 or 0
  305. net.canBuy = ItemExcel.buy[config.item1[1]] and 1 or 0
  306. end
  307. -- 抽奖列表
  308. function query(human)
  309. checkNewHeroDrawActSwitch(human)
  310. local msgRet = Msg.gc.GC_DRAWCARD_QUERY
  311. msgRet.jifen = getJifen(human)
  312. msgRet.left = getDrawNoSSRCnt(human, DRAWCARD_ID2)
  313. msgRet.leftNoSRRCnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID2)
  314. msgRet.leftNewSRRCnt = getDrawNewSSRCnt(human, DRAWCARD_ID8)
  315. msgRet.leftNewSRR40Cnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID8)
  316. msgRet.list[0] = 0
  317. local ids = {DRAWCARD_ID1, DRAWCARD_ID2, DRAWCARD_ID3, DRAWCARD_ID8}
  318. for i = 1, #ids do
  319. msgRet.list[0] = msgRet.list[0] + 1
  320. local net = msgRet.list[msgRet.list[0]]
  321. fontDrawCardNet(net, ids[i], human)
  322. end
  323. local needItemID = ItemDefine.ITEM_XIANZHI_BAOZHU_ID
  324. Grid.makeItem(msgRet.qiyuan, needItemID, 1)
  325. msgRet.skip = human.db.drawCard.skip or 0
  326. msgRet.bShowHero = human.db.drawCard.skipHero or 0
  327. msgRet.nHighCnt = getAllDrawCnt(human, DRAWCARD_ID2)
  328. Msg.send(msgRet, human.fd)
  329. end
  330. local function sendHeroData(human, heroList, items, heroNewList, heroIndexList)
  331. heroList = heroList or {}
  332. local itemArr = {}
  333. for itemId, itemNum in pairs(items or {}) do
  334. itemArr[#itemArr+1] = {itemId, itemNum}
  335. end
  336. local len = 0
  337. local msgMaxLen = 30
  338. local maxLen = math.max(#heroList, #itemArr)
  339. local msgRet = Msg.gc.GC_DRAWCARD_OP2
  340. msgRet.heros[0] = 0
  341. msgRet.items[0] = 0
  342. msgRet.isEnd = 0
  343. for i=1, math.max(#heroList, #itemArr) do
  344. len = len + 1
  345. local heroID = heroList[i]
  346. if heroID then
  347. msgRet.heros[0] = len
  348. local isNew = heroNewList and heroNewList[i]
  349. local index = heroIndexList and heroIndexList[i]
  350. HeroGrid.makeHeroNice(msgRet.heros[len], heroID, nil, isNew, index, human)
  351. end
  352. local itemInfo = itemArr[i]
  353. if itemInfo then
  354. msgRet.items[0] = len
  355. Grid.makeItem(msgRet.items[len], itemInfo[1], itemInfo[2])
  356. end
  357. if len >= msgMaxLen then
  358. maxLen = maxLen - len
  359. if maxLen <= 0 then
  360. msgRet.isEnd = 1
  361. return Msg.send(msgRet, human.fd)
  362. end
  363. Msg.send(msgRet, human.fd)
  364. len = 0
  365. msgRet.heros[0] = len
  366. msgRet.items[0] = len
  367. end
  368. end
  369. if len > 0 then
  370. msgRet.isEnd = 1
  371. Msg.send(msgRet, human.fd)
  372. end
  373. end
  374. -- 抽奖结果
  375. function sendDrawOp(human, id, op, heroList, items, heroNewList, heroIndexList,isAct)
  376. local msgRet = Msg.gc.GC_DRAWCARD_OP
  377. msgRet.isAct = isAct or 0
  378. msgRet.leftNoSRRCnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID2)
  379. msgRet.leftNewSRRCnt = getDrawNewSSRCnt(human, DRAWCARD_ID8)
  380. msgRet.leftNewSRR40Cnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID8)
  381. msgRet.nHighCnt = getAllDrawCnt(human, DRAWCARD_ID2)
  382. local dataNet = msgRet.data
  383. dataNet.jifen = getJifen(human)
  384. dataNet.id = id
  385. dataNet.op = op
  386. if op == DRAWCARD_OP_3 then
  387. dataNet.heros[0] = 0
  388. dataNet.items[0] = 0
  389. else
  390. dataNet.heros[0] = heroList and #heroList or 0
  391. for i = 1, dataNet.heros[0] do
  392. local heroID = heroList[i]
  393. local isNew = heroNewList and heroNewList[i]
  394. local index = heroIndexList and heroIndexList[i]
  395. HeroGrid.makeHeroNice(dataNet.heros[i], heroID, nil, isNew, index, human)
  396. end
  397. dataNet.items[0] = 0
  398. if items and type(items) == "table" then
  399. for itemID, itemCnt in pairs(items) do
  400. dataNet.items[0] = dataNet.items[0] + 1
  401. Grid.makeItem(dataNet.items[dataNet.items[0]], itemID, itemCnt)
  402. end
  403. end
  404. end
  405. fontDrawCardNet(msgRet.drawData, id, human)
  406. Msg.send(msgRet, human.fd)
  407. if op == DRAWCARD_OP_3 then
  408. sendHeroData(human, heroList, items, heroNewList, heroIndexList)
  409. end
  410. end
  411. -- 积分召唤
  412. local function jifenDraw(human, isAct)
  413. local config = DrawCardExcel[DRAWCARD_ID4]
  414. if not config then return end
  415. local db = human.db.drawCard
  416. if getJifen(human) < MAX_JIFEN then
  417. return Broadcast.sendErr(human, Lang.DRAWCARD_ERR_NOJIFEN)
  418. end
  419. if HeroLogic.getEmptyCnt(human) < 1 then
  420. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  421. end
  422. local heroID = randHeroID(human, DRAWCARD_ID4, DRAWCARD_OP_1, config)
  423. updateJifen(human, -MAX_JIFEN)
  424. local heroConfig = HeroExcel[heroID]
  425. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE4, heroConfig.grade, heroID)
  426. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  427. local heroIndex, fenjielist = HeroLogic.addHero(human, heroID,nil, 1, "draw_card")
  428. --Log.write(Log.LOGID_OSS_DRAWCARD, human.db._id, human.db.account, human.db.name, human.db.lv, DRAWCARD_ID4, heroID, 0, 0, 0, db.jifen)
  429. Log.write(Log.LOGID_OSS_DRAWCARD, human.db._id, human.db.newUniqueTag, human.db.name, human.db.lv, DRAWCARD_ID4, heroID, 0, 0, 0, db.jifen)
  430. sendDrawOp(human, DRAWCARD_ID4, 0, {heroID}, fenjielist, {isNew}, {heroIndex}, isAct)
  431. end
  432. -- 检查道具+扣道具
  433. function checkUseItem(human, id, op, config,isAct)
  434. local item = config["item" .. op]
  435. local zuanshi = config["zuanshi" .. op]
  436. if not item or not zuanshi then return end
  437. local itemID = item[1]
  438. local itemCnt = item[2]
  439. local finalItemCnt = itemCnt
  440. --精英召唤10, 100连抽的处理
  441. if id == DRAWCARD_ID8 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) then
  442. --秘宝对精英召唤10连的增益
  443. local talisman_jyzh_lotter10 = getTalismanAdd(human)
  444. finalItemCnt = math.floor(finalItemCnt * talisman_jyzh_lotter10)
  445. if zuanshi and zuanshi > 0 then
  446. zuanshi = math.floor(zuanshi * talisman_jyzh_lotter10)
  447. end
  448. end
  449. if id == DRAWCARD_ID2 then
  450. local vipArg = 100
  451. if op == DRAWCARD_OP_2 then
  452. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER21)
  453. elseif op == DRAWCARD_OP_3 then
  454. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER23)
  455. end
  456. print(" checkUseItem vipArg ", vipArg, " , old : " ,itemCnt , " , new : ", math.floor(itemCnt * vipArg / 100 ) )
  457. finalItemCnt = math.floor(itemCnt * vipArg / 100 )
  458. end
  459. print(" checkUseItem itemID itemCnt ", itemID, finalItemCnt)
  460. -- 活动只扣道具
  461. if isAct == AbsActDefine.ABS_ACT_TYPE_4 then
  462. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_4)
  463. if not state then
  464. return
  465. end
  466. local config = PerpleHeroLogic.getConfigByActID(id)
  467. itemID = config["item" .. op][1]
  468. itemCnt = config["item" .. op][2]
  469. if BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  470. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  471. return true
  472. else
  473. return
  474. end
  475. elseif isAct == AbsActDefine.ABS_ACT_TYPE_19 then
  476. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_19)
  477. if not state then
  478. return
  479. end
  480. local config = HeroComeLogic.getConfigByActID(id)
  481. itemID = config["item" .. op][1]
  482. itemCnt = config["item" .. op][2]
  483. if BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  484. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  485. return true
  486. else
  487. return
  488. end
  489. elseif isAct == AbsActDefine.OA_ACT_TYPE_501 then
  490. local limitState = LimitPerpleHeroLogic.checkOpen()
  491. if not limitState then
  492. return
  493. end
  494. local config = LimitPerpleHeroLogic.getConfigByActID()
  495. itemID = config["item" .. op][1]
  496. itemCnt = config["item" .. op][2]
  497. if BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  498. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  499. return true
  500. else
  501. return
  502. end
  503. end
  504. if isFree(human, id, op) then -- 免费
  505. setUseFree(human, id)
  506. return true
  507. elseif BagLogic.getItemCnt(human, itemID) >= finalItemCnt then -- 扣道具
  508. BagLogic.delItem(human, itemID, finalItemCnt, "draw_card")
  509. return true
  510. elseif zuanshi > 0 then -- 扣钻石
  511. -- 抵扣道具
  512. local haveCnt = BagLogic.getItemCnt(human, itemID)
  513. local vipArg = 0
  514. if id == DRAWCARD_ID2 then
  515. if op == DRAWCARD_OP_2 then
  516. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER22)
  517. elseif op == DRAWCARD_OP_3 then
  518. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER24)
  519. end
  520. end
  521. zuanshi = zuanshi + vipArg
  522. if haveCnt > 0 then
  523. zuanshi = zuanshi - math.floor(zuanshi * haveCnt / itemCnt)
  524. zuanshi = zuanshi > 0 and zuanshi or 0
  525. end
  526. if not ObjHuman.checkRMB(human, zuanshi) then
  527. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  528. end
  529. if haveCnt > 0 then
  530. BagLogic.delItem(human, itemID, haveCnt, "draw_card")
  531. end
  532. ObjHuman.decZuanshi(human, -zuanshi, "draw_card")
  533. return true
  534. end
  535. if zuanshi <= 0 then
  536. Broadcast.sendErr(human, Util.format(Lang.DRAWCARD_ERR_NOITEM, ItemDefine.getValue(itemID, "name")))
  537. end
  538. end
  539. --
  540. function randHeroID(human, id, op, config, actConfig, randomIndex, isAct)
  541. if isAct == 0 then
  542. if id == DRAWCARD_ID1 and op == DRAWCARD_OP_1 and getDrawCnt(human, id) == 0 then
  543. -- 首次普通单抽
  544. return SysParameter.getSysParameter(SysParameter.PARAMETER_6)
  545. elseif id == DRAWCARD_ID2 and op == DRAWCARD_OP_1 and getDrawCnt(human, id) == 0 then
  546. return SysParameter.getSysParameter(SysParameter.PARAMETER_7)
  547. end
  548. end
  549. if randomIndex and isAct == 0 then
  550. if id == DRAWCARD_ID2 and op == DRAWCARD_OP_2 then
  551. local sysHeroList = nil
  552. local draw2Cnt = getDraw2Cnt(human, id)
  553. draw2Cnt = math.floor(draw2Cnt/10)
  554. if draw2Cnt == 0 then
  555. -- sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_11)
  556. elseif draw2Cnt == 1 then
  557. sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_12)
  558. elseif draw2Cnt == 2 then
  559. -- sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_13)
  560. end
  561. if sysHeroList then
  562. local totoalWeight = 0
  563. for i=1, #sysHeroList do
  564. totoalWeight = totoalWeight + sysHeroList[i][2]
  565. end
  566. local r = math.random(1, totoalWeight)
  567. for i=1, #sysHeroList do
  568. if r <= sysHeroList[i][2] then
  569. return sysHeroList[i][1]
  570. end
  571. r = r - sysHeroList[i][2]
  572. end
  573. end
  574. end
  575. end
  576. local heroID = nil
  577. local rindex = RandomLogic.getRandom1(config.weight, nil, 2)
  578. local rconf = config.weight[rindex]
  579. local weightLv = rconf[1]
  580. if weightLv >= 8 and actConfig then
  581. local rindex2 = RandomLogic.getRandom3(actConfig)
  582. local rconf2 = rindex2 and actConfig[rindex2]
  583. if rconf2 then
  584. return rconf2.heroID
  585. end
  586. end
  587. heroID = heroID or HeroDefine.getRandHeroByWeightLv(weightLv)
  588. local actHeroID = AbsActLogic.getLuckDraw(human,luckDraw,randomIndex,isAct,op)
  589. if actHeroID then
  590. heroID = actHeroID
  591. end
  592. return heroID
  593. end
  594. --每日可抽取次数检测 新改为只是做个形式上的扣除
  595. local function dayLotteryTimesCheck(human, lotteryType, lotteryTimes)
  596. local cnt = 0
  597. local clutterType = 0
  598. if lotteryType == DRAWCARD_ID1 then
  599. clutterType = ClutterDataDefine.CLUTTER_TYPE1
  600. elseif lotteryType == DRAWCARD_ID2 then
  601. clutterType = ClutterDataDefine.CLUTTER_TYPE2
  602. elseif lotteryType == DRAWCARD_ID3 then
  603. clutterType = ClutterDataDefine.CLUTTER_TYPE3
  604. elseif lotteryType == DRAWCARD_ID8 then
  605. clutterType = ClutterDataDefine.CLUTTER_TYPE5
  606. end
  607. -- cnt = ClutterDataLogic.GetDiffLotteryTimes(human, clutterType)
  608. -- if cnt < lotteryTimes then
  609. -- return Broadcast.sendErr(human, Lang.JINBI_EXCHANGE_ERR_CNT)
  610. -- end
  611. ClutterDataLogic.UpdateDiffLotteryTimes(human, clutterType, lotteryTimes, lotteryType)
  612. -- return cnt, clutterType
  613. end
  614. -- 基础,高级,友情召唤,活动召唤
  615. local function draw(human, id, op, actConfig, skip,isAct)
  616. if isAct == AbsActDefine.ABS_ACT_TYPE_4 then
  617. PerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip,isAct)
  618. return
  619. elseif isAct == AbsActDefine.OA_ACT_TYPE_501 then
  620. LimitPerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip,isAct)
  621. return
  622. elseif isAct == AbsActDefine.ABS_ACT_TYPE_19 then
  623. HeroComeLogic.onDrawCardActive(human, id, op, actConfig, skip,isAct)
  624. return
  625. end
  626. local config = DrawCardExcel[id]
  627. if not config then return end
  628. local heroCnt = nil
  629. if op == DRAWCARD_OP_1 then
  630. heroCnt = 1
  631. elseif op == DRAWCARD_OP_2 then
  632. heroCnt = 10
  633. elseif op == DRAWCARD_OP_3 then
  634. heroCnt = 100
  635. else
  636. return
  637. end
  638. local actId = NewHeroLogic.getActiveActId(human)
  639. local state = actId and AbsActLogic.isStarted(human, actId)
  640. if id == DRAWCARD_ID8 and not state then
  641. return Broadcast.sendErr(human, Lang.ABS_JYZH_NOT_OPEN)
  642. end
  643. if id == DRAWCARD_ID8 then
  644. checkNewHeroDrawActSwitch(human)
  645. end
  646. local newHeroMainId, newHeroId100, newHeroId10, newHeroId40
  647. if id == DRAWCARD_ID8 and actId then
  648. newHeroMainId, newHeroId100, newHeroId10, newHeroId40 = NewHeroLogic.getNewHeroDrawConfigIds(actId)
  649. config = DrawCardExcel[newHeroMainId]
  650. if not config then return end
  651. end
  652. if HeroLogic.getEmptyCnt(human) < heroCnt then
  653. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  654. end
  655. if not checkUseItem(human, id, op, config,isAct) then
  656. print("checkUseItem false")
  657. return
  658. end
  659. dayLotteryTimesCheck(human, id, heroCnt)
  660. if id == DRAWCARD_ID2 then
  661. MainDianLogic.MaiDian_Begin(human, MaiDianDefine.MAIDIAN_TYPE_ADV_SUMMON,{nValue = heroCnt})
  662. end
  663. setSkip(human, id, skip)
  664. local heroLen = 0
  665. local heroList = {}
  666. local heroNewList = {}
  667. local heroIndexList = {}
  668. local fenjielist = {}
  669. local heroIDs = nil
  670. -- local randomMin = math.random(1, heroCnt)
  671. local randomMinSet = {}
  672. if id == DRAWCARD_ID2 or id == DRAWCARD_ID8 then
  673. if op == DRAWCARD_OP_2 then
  674. -- 十连:1个保底位置
  675. randomMinSet[math.random(1, 10)] = true
  676. elseif op == DRAWCARD_OP_3 then
  677. -- 百连:分成10组,每组10抽里随机1个保底位置,共10次
  678. for group = 0, 9 do
  679. local pos = math.random(1, 10) + group * 10
  680. randomMinSet[pos] = true
  681. end
  682. end
  683. end
  684. local tag = 0
  685. for i = 1, heroCnt do
  686. if id == DRAWCARD_ID8 then
  687. config = DrawCardExcel[newHeroMainId]
  688. else
  689. config = DrawCardExcel[id]
  690. end
  691. -- if id == DRAWCARD_ID2 and op == DRAWCARD_OP_2 and i == randomMin and getDraw2Cnt(human, id) > 3 then
  692. -- if id == DRAWCARD_ID2 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) and i == randomMin then
  693. if id == DRAWCARD_ID2 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) and randomMinSet[i] then
  694. config = DrawCardExcel[DRAWCARD_ID5]
  695. elseif id == DRAWCARD_ID2 and op == DRAWCARD_OP_1 then
  696. config = DrawCardExcel[DRAWCARD_ID6]
  697. end
  698. -- if id == DRAWCARD_ID8 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) and i == randomMin then
  699. if id == DRAWCARD_ID8 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) and randomMinSet[i] then
  700. config = DrawCardExcel[newHeroId10]
  701. end
  702. -- 第40抽必出SSR
  703. if id == DRAWCARD_ID2 and getDrawNoSSRCnt(human, id) >= DRAWCARD_40 - 1 then
  704. config = DrawCardExcel[DRAWCARD_ID7]
  705. end
  706. -- 高级召唤前5次10连每轮必出SSR
  707. -- if id == DRAWCARD_ID2 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) and getDraw2Cnt(human, id) < DRAWCARD_ID2_CNT and i ~= randomMin and tag == 0 then
  708. if id == DRAWCARD_ID2 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) and getDraw2Cnt(human, id) < DRAWCARD_ID2_CNT and not randomMinSet[i] and tag == 0 then
  709. config = DrawCardExcel[DRAWCARD_ID7]
  710. tag = 1
  711. end
  712. if id == DRAWCARD_ID8 and getDrawNoSSRCnt(human, id) >= DRAWCARD_40 - 1 then
  713. config = DrawCardExcel[newHeroId40]
  714. end
  715. if id == DRAWCARD_ID8 and getDrawNewSSRCnt(human, id) >= DRAWCARD_100 - 1 then
  716. config = DrawCardExcel[newHeroId100]
  717. end
  718. -- local heroID = randHeroID(human, id, op, config, actConfig, i == randomMin, isAct)
  719. local heroID = randHeroID(human, id, op, config, actConfig, randomMinSet[i], isAct)
  720. local heroConfig = HeroExcel[heroID]
  721. local star = heroConfig.star
  722. local name = heroConfig.name
  723. local grade = heroConfig.grade
  724. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  725. local heroIndex, fjlist = HeroLogic.addHero(human, heroID,nil, 1, "draw_card")
  726. heroLen = heroLen + 1
  727. heroList[heroLen] = heroID
  728. heroNewList[heroLen] = isNew
  729. heroIndexList[heroLen] = heroIndex
  730. if fjlist and type(fjlist) == "table" then
  731. for fjItemID, fjItemCnt in pairs(fjlist) do
  732. fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
  733. end
  734. end
  735. if not heroIDs then
  736. heroIDs = heroID
  737. else
  738. heroIDs = heroIDs .. "|" .. heroID
  739. end
  740. -- 判断召唤出来的英雄是否为ssr
  741. if grade < 4 then
  742. addDrawNoSSRCnt(human, id, 1)
  743. else
  744. clearDrawNoSSRCnt(human, id)
  745. end
  746. if star < 5 then
  747. addDrawNoGoodCnt(human, id, 1)
  748. else
  749. clearDrawNoGoodCnt(human, id)
  750. end
  751. if heroID == NewHeroLogic.getNewHeroID(human) then
  752. clearDrawNewSSRCnt(human, id)
  753. elseif state then
  754. addDrawNewSSRCnt(human, id, 1)
  755. end
  756. if getDrawCnt(human, id) > 0 or getDraw2Cnt(human, id) > 0 then
  757. if id == DRAWCARD_ID1 then
  758. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE3, grade, heroID)
  759. elseif id == DRAWCARD_ID2 then
  760. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE1, grade, heroID)
  761. elseif id == DRAWCARD_ID3 then
  762. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE2, grade, heroID)
  763. elseif id == DRAWCARD_ID6 then
  764. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE21, grade, heroID)
  765. end
  766. end
  767. if op == DRAWCARD_OP_1 then
  768. addDrawCnt(human, id, 1)
  769. elseif op == DRAWCARD_OP_2 then
  770. addDraw2Cnt(human, id, 1)
  771. end
  772. if id == DRAWCARD_ID1 then
  773. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID26,1,star)
  774. elseif id == DRAWCARD_ID2 then
  775. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID27,1,star)
  776. end
  777. end
  778. if id ~= DRAWCARD_ID8 then
  779. updateJifen(human, config.jifen * heroCnt)
  780. end
  781. if id == DRAWCARD_ID2 then
  782. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_2,heroCnt)
  783. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_12,heroCnt)
  784. YunYingLogic.onCallBack(human, "onDrawCard", heroCnt,nil, id)
  785. print("[draw] 高级召唤回调开始 111")
  786. TriggerLogic.PublishEvent(TriggerDefine.DRAWCALL_SERNIOR_CNT, human.db._id, heroCnt)
  787. print("[draw] 高级召唤回调开始 222")
  788. --高级召唤周任务
  789. WeekTaskLogic.recordWeekTaskFinishCnt(human, WeekTaskLogic.WEEK_TASK_ID_2, heroCnt)
  790. WarOrder.trigger(human, 7, heroCnt) -- 招募战令
  791. end
  792. sendDrawOp(human, id, op, heroList, fenjielist, heroNewList,heroIndexList,isAct)
  793. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_401)
  794. --Log.write(Log.LOGID_OSS_DRAWCARD, human.db._id, human.db.account, human.db.name, human.db.lv, id, heroIDs, itemID or 0, cnt or 0, zuanshi or 0, getJifen(human))
  795. Log.write(Log.LOGID_OSS_DRAWCARD, human.db._id, human.db.newUniqueTag, human.db.name, human.db.lv, id, heroIDs, itemID or 0, cnt or 0, zuanshi or 0, getJifen(human))
  796. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_3, heroCnt)
  797. --精英召唤
  798. if id == DRAWCARD_ID8 then
  799. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_ELITESUMMON, human.db._id, heroCnt)
  800. end
  801. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_DRAW)
  802. end
  803. function op(human, id, op, skip,isAct)
  804. if id == DRAWCARD_ID0 then
  805. jifenDraw(human, isAct)
  806. return
  807. end
  808. if id == DRAWCARD_ID1 or id == DRAWCARD_ID2 or id == DRAWCARD_ID3 or id == DRAWCARD_ID6 or id == DRAWCARD_ID8 then
  809. draw(human, id, op, nil, skip,isAct)
  810. return
  811. end
  812. end
  813. function initAfterHot()
  814. for _, config in pairs(DrawCardExcel) do
  815. local totalWeight = 0
  816. for k, v in ipairs(config.weight) do
  817. totalWeight = totalWeight + v[2]
  818. end
  819. config.totalWeight = totalWeight
  820. end
  821. end
  822. function isDot(human)
  823. if human.db.lv < 9 then
  824. return false
  825. end
  826. if isFree(human, DRAWCARD_ID1, DRAWCARD_OP_1) then
  827. return true
  828. end
  829. if isFree(human, DRAWCARD_ID2, DRAWCARD_OP_1) then
  830. return true
  831. end
  832. if BagLogic.getItemCnt(human, ItemDefine.ITEM_DRAWCARD_GAOCHOU_ID) >= 10 then
  833. return true
  834. end
  835. return false
  836. end