DrawCardLogic.lua 33 KB

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