DrawCardLogic.lua 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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. function clearDrawNoGoodCnt(human, id)
  220. local info = getDrawInfo(human, id)
  221. if not info then return end
  222. info.chengjiuCnt = nil
  223. end
  224. -- 友情点
  225. function getFriendHeart(human)
  226. return human.db.friendHeart
  227. end
  228. function fontDrawCardNet(net, id, human)
  229. local config = DrawCardExcel[id]
  230. local leftCnt, leftTime = getFreeInfo(human, id)
  231. net.id = id
  232. net.leftFreeTime = leftTime
  233. net.leftFreeCnt = leftCnt
  234. net.items[0] = 0
  235. if config.item1[1] and config.item1[2] then
  236. net.items[0] = net.items[0] + 1
  237. Grid.makeItem(net.items[net.items[0]], config.item1[1], config.item1[2])
  238. end
  239. local vipArg = 100
  240. if id == DRAWCARD_ID2 then
  241. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER21)
  242. end
  243. local itemCnt,finalItemCnt = 0, 0
  244. if config.item2[1] and config.item2[2] then
  245. net.items[0] = net.items[0] + 1
  246. itemCnt = math.floor(config.item2[2] * vipArg / 100 )
  247. finalItemCnt = itemCnt
  248. if id == DRAWCARD_ID8 then
  249. local talisman_jyzh_lotter10 = getTalismanAdd(human)
  250. finalItemCnt = math.floor(finalItemCnt * talisman_jyzh_lotter10)
  251. end
  252. Grid.makeItem(net.items[net.items[0]], config.item2[1], finalItemCnt )
  253. end
  254. vipArg, itemCnt, finalItemCnt = 0, 0, 0
  255. if config.item3[1] and config.item3[2] then
  256. if id == DRAWCARD_ID2 then -- 目前只有高抽和精英两种模式有100抽
  257. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER23)
  258. end
  259. net.items[0] = net.items[0] + 1
  260. itemCnt = math.floor(config.item3[2] * vipArg / 100 )
  261. finalItemCnt = itemCnt
  262. if id == DRAWCARD_ID8 then
  263. local talisman_jyzh_lotter100 = getTalismanAdd(human)
  264. finalItemCnt = math.floor(finalItemCnt * talisman_jyzh_lotter100)
  265. end
  266. Grid.makeItem(net.items[net.items[0]], config.item3[1], finalItemCnt)
  267. end
  268. vipArg = 0
  269. if id == DRAWCARD_ID2 then
  270. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER22)
  271. end
  272. net.zuanshi[0] = 3
  273. net.zuanshi[1] = config.zuanshi1
  274. net.zuanshi[2] = config.zuanshi2 + vipArg
  275. net.zuanshi[3] = config.zuanshi3 or 0
  276. vipArg = 0
  277. if id == DRAWCARD_ID2 and net.zuanshi[3] > 0 then -- 目前只有高抽和精英两种模式有100抽
  278. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER24)
  279. net.zuanshi[3] = net.zuanshi[3] + vipArg
  280. end
  281. if id == DRAWCARD_ID8 then
  282. net.zuanshi[2] = math.floor((net.zuanshi[2] / itemCnt) * finalItemCnt)
  283. end
  284. net.isFirst = (getDraw2Cnt(human, id) < 1) and 1 or 0
  285. net.canBuy = ItemExcel.buy[config.item1[1]] and 1 or 0
  286. end
  287. -- 抽奖列表
  288. function query(human)
  289. local msgRet = Msg.gc.GC_DRAWCARD_QUERY
  290. msgRet.jifen = getJifen(human)
  291. msgRet.left = getDrawNoSSRCnt(human, DRAWCARD_ID2)
  292. msgRet.leftNoSRRCnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID2)
  293. msgRet.leftNewSRRCnt = getDrawNewSSRCnt(human, DRAWCARD_ID8)
  294. msgRet.leftNewSRR40Cnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID8)
  295. msgRet.list[0] = 0
  296. local ids = {DRAWCARD_ID1, DRAWCARD_ID2, DRAWCARD_ID3, DRAWCARD_ID8}
  297. for i = 1, #ids do
  298. msgRet.list[0] = msgRet.list[0] + 1
  299. local net = msgRet.list[msgRet.list[0]]
  300. fontDrawCardNet(net, ids[i], human)
  301. end
  302. local needItemID = ItemDefine.ITEM_XIANZHI_BAOZHU_ID
  303. Grid.makeItem(msgRet.qiyuan, needItemID, 1)
  304. msgRet.skip = human.db.drawCard.skip or 0
  305. msgRet.bShowHero = human.db.drawCard.skipHero or 0
  306. msgRet.nHighCnt = getAllDrawCnt(human, DRAWCARD_ID2)
  307. Msg.send(msgRet, human.fd)
  308. end
  309. local function sendHeroData(human, heroList, items, heroNewList, heroIndexList)
  310. heroList = heroList or {}
  311. local itemArr = {}
  312. for itemId, itemNum in pairs(items or {}) do
  313. itemArr[#itemArr+1] = {itemId, itemNum}
  314. end
  315. local len = 0
  316. local msgMaxLen = 30
  317. local maxLen = math.max(#heroList, #itemArr)
  318. local msgRet = Msg.gc.GC_DRAWCARD_OP2
  319. msgRet.heros[0] = 0
  320. msgRet.items[0] = 0
  321. msgRet.isEnd = 0
  322. for i=1, math.max(#heroList, #itemArr) do
  323. len = len + 1
  324. local heroID = heroList[i]
  325. if heroID then
  326. msgRet.heros[0] = len
  327. local isNew = heroNewList and heroNewList[i]
  328. local index = heroIndexList and heroIndexList[i]
  329. HeroGrid.makeHeroNice(msgRet.heros[len], heroID, nil, isNew, index, human)
  330. end
  331. local itemInfo = itemArr[i]
  332. if itemInfo then
  333. msgRet.items[0] = len
  334. Grid.makeItem(msgRet.items[len], itemInfo[1], itemInfo[2])
  335. end
  336. if len >= msgMaxLen then
  337. maxLen = maxLen - len
  338. if maxLen <= 0 then
  339. msgRet.isEnd = 1
  340. return Msg.send(msgRet, human.fd)
  341. end
  342. Msg.send(msgRet, human.fd)
  343. len = 0
  344. msgRet.heros[0] = len
  345. msgRet.items[0] = len
  346. end
  347. end
  348. if len > 0 then
  349. msgRet.isEnd = 1
  350. Msg.send(msgRet, human.fd)
  351. end
  352. end
  353. -- 抽奖结果
  354. function sendDrawOp(human, id, op, heroList, items, heroNewList, heroIndexList,isAct)
  355. local msgRet = Msg.gc.GC_DRAWCARD_OP
  356. msgRet.isAct = isAct or 0
  357. msgRet.leftNoSRRCnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID2)
  358. msgRet.leftNewSRRCnt = getDrawNewSSRCnt(human, DRAWCARD_ID8)
  359. msgRet.leftNewSRR40Cnt = DRAWCARD_40 - getDrawNoSSRCnt(human, DRAWCARD_ID8)
  360. msgRet.nHighCnt = getAllDrawCnt(human, DRAWCARD_ID2)
  361. local dataNet = msgRet.data
  362. dataNet.jifen = getJifen(human)
  363. dataNet.id = id
  364. dataNet.op = op
  365. if op == DRAWCARD_OP_3 then
  366. dataNet.heros[0] = 0
  367. dataNet.items[0] = 0
  368. else
  369. dataNet.heros[0] = heroList and #heroList or 0
  370. for i = 1, dataNet.heros[0] do
  371. local heroID = heroList[i]
  372. local isNew = heroNewList and heroNewList[i]
  373. local index = heroIndexList and heroIndexList[i]
  374. HeroGrid.makeHeroNice(dataNet.heros[i], heroID, nil, isNew, index, human)
  375. end
  376. dataNet.items[0] = 0
  377. if items and type(items) == "table" then
  378. for itemID, itemCnt in pairs(items) do
  379. dataNet.items[0] = dataNet.items[0] + 1
  380. Grid.makeItem(dataNet.items[dataNet.items[0]], itemID, itemCnt)
  381. end
  382. end
  383. end
  384. fontDrawCardNet(msgRet.drawData, id, human)
  385. Msg.send(msgRet, human.fd)
  386. if op == DRAWCARD_OP_3 then
  387. sendHeroData(human, heroList, items, heroNewList, heroIndexList)
  388. end
  389. end
  390. -- 积分召唤
  391. local function jifenDraw(human, isAct)
  392. local config = DrawCardExcel[DRAWCARD_ID4]
  393. if not config then return end
  394. local db = human.db.drawCard
  395. if getJifen(human) < MAX_JIFEN then
  396. return Broadcast.sendErr(human, Lang.DRAWCARD_ERR_NOJIFEN)
  397. end
  398. if HeroLogic.getEmptyCnt(human) < 1 then
  399. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  400. end
  401. local heroID = randHeroID(human, DRAWCARD_ID4, DRAWCARD_OP_1, config)
  402. updateJifen(human, -MAX_JIFEN)
  403. local heroConfig = HeroExcel[heroID]
  404. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE4, heroConfig.grade, heroID)
  405. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  406. local heroIndex, fenjielist = HeroLogic.addHero(human, heroID,nil, 1, "draw_card")
  407. --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)
  408. 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)
  409. sendDrawOp(human, DRAWCARD_ID4, 0, {heroID}, fenjielist, {isNew}, {heroIndex}, isAct)
  410. end
  411. -- 检查道具+扣道具
  412. function checkUseItem(human, id, op, config,isAct)
  413. local item = config["item" .. op]
  414. local zuanshi = config["zuanshi" .. op]
  415. if not item or not zuanshi then return end
  416. local itemID = item[1]
  417. local itemCnt = item[2]
  418. local finalItemCnt = itemCnt
  419. --精英召唤10, 100连抽的处理
  420. if id == DRAWCARD_ID8 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) then
  421. --秘宝对精英召唤10连的增益
  422. local talisman_jyzh_lotter10 = getTalismanAdd(human)
  423. finalItemCnt = math.floor(finalItemCnt * talisman_jyzh_lotter10)
  424. if zuanshi and zuanshi > 0 then
  425. zuanshi = math.floor(zuanshi * talisman_jyzh_lotter10)
  426. end
  427. end
  428. if id == DRAWCARD_ID2 then
  429. local vipArg = 100
  430. if op == DRAWCARD_OP_2 then
  431. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER21)
  432. elseif op == DRAWCARD_OP_3 then
  433. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER23)
  434. end
  435. print(" checkUseItem vipArg ", vipArg, " , old : " ,itemCnt , " , new : ", math.floor(itemCnt * vipArg / 100 ) )
  436. finalItemCnt = math.floor(itemCnt * vipArg / 100 )
  437. end
  438. print(" checkUseItem itemID itemCnt ", itemID, finalItemCnt)
  439. -- 活动只扣道具
  440. if isAct == AbsActDefine.ABS_ACT_TYPE_4 then
  441. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_4)
  442. if not state then
  443. return
  444. end
  445. local config = PerpleHeroLogic.getConfigByActID(id)
  446. itemID = config["item" .. op][1]
  447. itemCnt = config["item" .. op][2]
  448. if BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  449. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  450. return true
  451. else
  452. return
  453. end
  454. elseif isAct == AbsActDefine.ABS_ACT_TYPE_19 then
  455. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_19)
  456. if not state then
  457. return
  458. end
  459. local config = HeroComeLogic.getConfigByActID(id)
  460. itemID = config["item" .. op][1]
  461. itemCnt = config["item" .. op][2]
  462. if BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  463. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  464. return true
  465. else
  466. return
  467. end
  468. elseif isAct == AbsActDefine.OA_ACT_TYPE_501 then
  469. local limitState = LimitPerpleHeroLogic.checkOpen()
  470. if not limitState then
  471. return
  472. end
  473. local config = LimitPerpleHeroLogic.getConfigByActID()
  474. itemID = config["item" .. op][1]
  475. itemCnt = config["item" .. op][2]
  476. if BagLogic.getItemCnt(human, itemID) >= itemCnt then -- 扣道具
  477. BagLogic.delItem(human, itemID, itemCnt, "draw_card")
  478. return true
  479. else
  480. return
  481. end
  482. end
  483. if isFree(human, id, op) then -- 免费
  484. setUseFree(human, id)
  485. return true
  486. elseif BagLogic.getItemCnt(human, itemID) >= finalItemCnt then -- 扣道具
  487. BagLogic.delItem(human, itemID, finalItemCnt, "draw_card")
  488. return true
  489. elseif zuanshi > 0 then -- 扣钻石
  490. -- 抵扣道具
  491. local haveCnt = BagLogic.getItemCnt(human, itemID)
  492. local vipArg = 0
  493. if id == DRAWCARD_ID2 then
  494. if op == DRAWCARD_OP_2 then
  495. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER22)
  496. elseif op == DRAWCARD_OP_3 then
  497. vipArg = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER24)
  498. end
  499. end
  500. zuanshi = zuanshi + vipArg
  501. if haveCnt > 0 then
  502. zuanshi = zuanshi - math.floor(zuanshi * haveCnt / itemCnt)
  503. zuanshi = zuanshi > 0 and zuanshi or 0
  504. end
  505. if not ObjHuman.checkRMB(human, zuanshi) then
  506. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  507. end
  508. if haveCnt > 0 then
  509. BagLogic.delItem(human, itemID, haveCnt, "draw_card")
  510. end
  511. ObjHuman.decZuanshi(human, -zuanshi, "draw_card")
  512. return true
  513. end
  514. if zuanshi <= 0 then
  515. Broadcast.sendErr(human, Util.format(Lang.DRAWCARD_ERR_NOITEM, ItemDefine.getValue(itemID, "name")))
  516. end
  517. end
  518. --
  519. function randHeroID(human, id, op, config, actConfig, randomIndex, isAct)
  520. if isAct == 0 then
  521. if id == DRAWCARD_ID1 and op == DRAWCARD_OP_1 and getDrawCnt(human, id) == 0 then
  522. -- 首次普通单抽
  523. return SysParameter.getSysParameter(SysParameter.PARAMETER_6)
  524. elseif id == DRAWCARD_ID2 and op == DRAWCARD_OP_1 and getDrawCnt(human, id) == 0 then
  525. return SysParameter.getSysParameter(SysParameter.PARAMETER_7)
  526. end
  527. end
  528. if randomIndex and isAct == 0 then
  529. if id == DRAWCARD_ID2 and op == DRAWCARD_OP_2 then
  530. local sysHeroList = nil
  531. local draw2Cnt = getDraw2Cnt(human, id)
  532. draw2Cnt = math.floor(draw2Cnt/10)
  533. if draw2Cnt == 0 then
  534. -- sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_11)
  535. elseif draw2Cnt == 1 then
  536. sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_12)
  537. elseif draw2Cnt == 2 then
  538. -- sysHeroList = SysParameter.getSysParameterTb(SysParameter.PARAMETER_13)
  539. end
  540. if sysHeroList then
  541. local totoalWeight = 0
  542. for i=1, #sysHeroList do
  543. totoalWeight = totoalWeight + sysHeroList[i][2]
  544. end
  545. local r = math.random(1, totoalWeight)
  546. for i=1, #sysHeroList do
  547. if r <= sysHeroList[i][2] then
  548. return sysHeroList[i][1]
  549. end
  550. r = r - sysHeroList[i][2]
  551. end
  552. end
  553. end
  554. end
  555. local heroID = nil
  556. local rindex = RandomLogic.getRandom1(config.weight, nil, 2)
  557. local rconf = config.weight[rindex]
  558. local weightLv = rconf[1]
  559. if weightLv >= 8 and actConfig then
  560. local rindex2 = RandomLogic.getRandom3(actConfig)
  561. local rconf2 = rindex2 and actConfig[rindex2]
  562. if rconf2 then
  563. return rconf2.heroID
  564. end
  565. end
  566. heroID = heroID or HeroDefine.getRandHeroByWeightLv(weightLv)
  567. local actHeroID = AbsActLogic.getLuckDraw(human,luckDraw,randomIndex,isAct,op)
  568. if actHeroID then
  569. heroID = actHeroID
  570. end
  571. return heroID
  572. end
  573. --每日可抽取次数检测 新改为只是做个形式上的扣除
  574. local function dayLotteryTimesCheck(human, lotteryType, lotteryTimes)
  575. local cnt = 0
  576. local clutterType = 0
  577. if lotteryType == DRAWCARD_ID1 then
  578. clutterType = ClutterDataDefine.CLUTTER_TYPE1
  579. elseif lotteryType == DRAWCARD_ID2 then
  580. clutterType = ClutterDataDefine.CLUTTER_TYPE2
  581. elseif lotteryType == DRAWCARD_ID3 then
  582. clutterType = ClutterDataDefine.CLUTTER_TYPE3
  583. elseif lotteryType == DRAWCARD_ID8 then
  584. clutterType = ClutterDataDefine.CLUTTER_TYPE5
  585. end
  586. -- cnt = ClutterDataLogic.GetDiffLotteryTimes(human, clutterType)
  587. -- if cnt < lotteryTimes then
  588. -- return Broadcast.sendErr(human, Lang.JINBI_EXCHANGE_ERR_CNT)
  589. -- end
  590. ClutterDataLogic.UpdateDiffLotteryTimes(human, clutterType, lotteryTimes, lotteryType)
  591. -- return cnt, clutterType
  592. end
  593. -- 基础,高级,友情召唤,活动召唤
  594. local function draw(human, id, op, actConfig, skip,isAct)
  595. if isAct == AbsActDefine.ABS_ACT_TYPE_4 then
  596. PerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip,isAct)
  597. return
  598. elseif isAct == AbsActDefine.OA_ACT_TYPE_501 then
  599. LimitPerpleHeroLogic.onDrawCardActive(human, id, op, actConfig, skip,isAct)
  600. return
  601. elseif isAct == AbsActDefine.ABS_ACT_TYPE_19 then
  602. HeroComeLogic.onDrawCardActive(human, id, op, actConfig, skip,isAct)
  603. return
  604. end
  605. local config = DrawCardExcel[id]
  606. if not config then return end
  607. local heroCnt = nil
  608. if op == DRAWCARD_OP_1 then
  609. heroCnt = 1
  610. elseif op == DRAWCARD_OP_2 then
  611. heroCnt = 10
  612. elseif op == DRAWCARD_OP_3 then
  613. heroCnt = 100
  614. else
  615. return
  616. end
  617. local state, endTime, starTime = AbsActLogic.isStarted(human, NewHeroLogic.ABS_ACT_ID)
  618. if id == DRAWCARD_ID8 and not state then
  619. return Broadcast.sendErr(human, Lang.DRILL_NOT_OPEN)
  620. end
  621. if HeroLogic.getEmptyCnt(human) < heroCnt then
  622. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  623. end
  624. if not checkUseItem(human, id, op, config,isAct) then
  625. print("checkUseItem false")
  626. return
  627. end
  628. dayLotteryTimesCheck(human, id, heroCnt)
  629. if id == DRAWCARD_ID2 then
  630. MainDianLogic.MaiDian_Begin(human, MaiDianDefine.MAIDIAN_TYPE_ADV_SUMMON,{nValue = heroCnt})
  631. end
  632. setSkip(human, id, skip)
  633. local heroLen = 0
  634. local heroList = {}
  635. local heroNewList = {}
  636. local heroIndexList = {}
  637. local fenjielist = {}
  638. local heroIDs = nil
  639. local randomMin = math.random(1, heroCnt)
  640. local tag = 0
  641. for i = 1, heroCnt do
  642. config = DrawCardExcel[id]
  643. -- if id == DRAWCARD_ID2 and op == DRAWCARD_OP_2 and i == randomMin and getDraw2Cnt(human, id) > 3 then
  644. if id == DRAWCARD_ID2 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) and i == randomMin then
  645. config = DrawCardExcel[DRAWCARD_ID5]
  646. elseif id == DRAWCARD_ID2 and op == DRAWCARD_OP_1 then
  647. config = DrawCardExcel[DRAWCARD_ID6]
  648. end
  649. if id == DRAWCARD_ID8 and (op == DRAWCARD_OP_2 or op == DRAWCARD_OP_3) and i == randomMin then
  650. config = DrawCardExcel[DRAWCARD_ID10]
  651. end
  652. -- 第40抽必出SSR
  653. if id == DRAWCARD_ID2 and getDrawNoSSRCnt(human, id) >= DRAWCARD_40 - 1 then
  654. config = DrawCardExcel[DRAWCARD_ID7]
  655. end
  656. -- 高级召唤前5次10连每轮必出SSR
  657. 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
  658. config = DrawCardExcel[DRAWCARD_ID7]
  659. tag = 1
  660. end
  661. if id == DRAWCARD_ID8 and getDrawNoSSRCnt(human, id) >= DRAWCARD_40 - 1 then
  662. config = DrawCardExcel[DRAWCARD_ID11]
  663. end
  664. if id == DRAWCARD_ID8 and getDrawNewSSRCnt(human, id) >= DRAWCARD_100 - 1 then
  665. config = DrawCardExcel[DRAWCARD_ID9]
  666. end
  667. local heroID = randHeroID(human, id, op, config, actConfig, i == randomMin, isAct)
  668. local heroConfig = HeroExcel[heroID]
  669. local star = heroConfig.star
  670. local name = heroConfig.name
  671. local grade = heroConfig.grade
  672. local isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  673. local heroIndex, fjlist = HeroLogic.addHero(human, heroID,nil, 1, "draw_card")
  674. heroLen = heroLen + 1
  675. heroList[heroLen] = heroID
  676. heroNewList[heroLen] = isNew
  677. heroIndexList[heroLen] = heroIndex
  678. if fjlist and type(fjlist) == "table" then
  679. for fjItemID, fjItemCnt in pairs(fjlist) do
  680. fenjielist[fjItemID] = (fenjielist[fjItemID] or 0) + fjItemCnt
  681. end
  682. end
  683. if not heroIDs then
  684. heroIDs = heroID
  685. else
  686. heroIDs = heroIDs .. "|" .. heroID
  687. end
  688. -- 判断召唤出来的英雄是否为ssr
  689. if grade < 4 then
  690. addDrawNoSSRCnt(human, id, 1)
  691. else
  692. clearDrawNoSSRCnt(human, id)
  693. end
  694. if star < 5 then
  695. addDrawNoGoodCnt(human, id, 1)
  696. else
  697. clearDrawNoGoodCnt(human, id)
  698. end
  699. if heroID == NewHeroLogic.getNewHeroID(human) then
  700. clearDrawNewSSRCnt(human, id)
  701. elseif state then
  702. addDrawNewSSRCnt(human, id, 1)
  703. end
  704. if getDrawCnt(human, id) > 0 or getDraw2Cnt(human, id) > 0 then
  705. if id == DRAWCARD_ID1 then
  706. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE3, grade, heroID)
  707. elseif id == DRAWCARD_ID2 then
  708. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE1, grade, heroID)
  709. elseif id == DRAWCARD_ID3 then
  710. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE2, grade, heroID)
  711. elseif id == DRAWCARD_ID6 then
  712. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE21, grade, heroID)
  713. end
  714. end
  715. if op == DRAWCARD_OP_1 then
  716. addDrawCnt(human, id, 1)
  717. elseif op == DRAWCARD_OP_2 then
  718. addDraw2Cnt(human, id, 1)
  719. end
  720. if id == DRAWCARD_ID1 then
  721. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID26,1,star)
  722. elseif id == DRAWCARD_ID2 then
  723. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID27,1,star)
  724. end
  725. end
  726. if id ~= DRAWCARD_ID8 then
  727. updateJifen(human, config.jifen * heroCnt)
  728. end
  729. if id == DRAWCARD_ID2 then
  730. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_2,heroCnt)
  731. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_12,heroCnt)
  732. YunYingLogic.onCallBack(human, "onDrawCard", heroCnt,nil, id)
  733. print("[draw] 高级召唤回调开始 111")
  734. TriggerLogic.PublishEvent(TriggerDefine.DRAWCALL_SERNIOR_CNT, human.db._id, heroCnt)
  735. print("[draw] 高级召唤回调开始 222")
  736. --高级召唤周任务
  737. WeekTaskLogic.recordWeekTaskFinishCnt(human, WeekTaskLogic.WEEK_TASK_ID_2, heroCnt)
  738. WarOrder.trigger(human, 7, heroCnt) -- 招募战令
  739. end
  740. sendDrawOp(human, id, op, heroList, fenjielist, heroNewList,heroIndexList,isAct)
  741. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_401)
  742. --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))
  743. 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))
  744. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_3, heroCnt)
  745. --精英召唤
  746. if id == DRAWCARD_ID8 then
  747. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_ELITESUMMON, human.db._id, heroCnt)
  748. end
  749. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_DRAW)
  750. end
  751. function op(human, id, op, skip,isAct)
  752. if id == DRAWCARD_ID0 then
  753. jifenDraw(human, isAct)
  754. return
  755. end
  756. if id == DRAWCARD_ID1 or id == DRAWCARD_ID2 or id == DRAWCARD_ID3 or id == DRAWCARD_ID6 or id == DRAWCARD_ID8 then
  757. draw(human, id, op, nil, skip,isAct)
  758. return
  759. end
  760. end
  761. function initAfterHot()
  762. for _, config in pairs(DrawCardExcel) do
  763. local totalWeight = 0
  764. for k, v in ipairs(config.weight) do
  765. totalWeight = totalWeight + v[2]
  766. end
  767. config.totalWeight = totalWeight
  768. end
  769. end
  770. function isDot(human)
  771. if human.db.lv < 9 then
  772. return false
  773. end
  774. if isFree(human, DRAWCARD_ID1, DRAWCARD_OP_1) then
  775. return true
  776. end
  777. if isFree(human, DRAWCARD_ID2, DRAWCARD_OP_1) then
  778. return true
  779. end
  780. if BagLogic.getItemCnt(human, ItemDefine.ITEM_DRAWCARD_GAOCHOU_ID) >= 10 then
  781. return true
  782. end
  783. return false
  784. end