DrumBlastingLogic.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. --[[
  2. absAct[id] = {
  3. drum = {
  4. [id] = cnt,state
  5. [id] = cnt,state
  6. }
  7. blasting = {
  8. [id] = cnt,state
  9. }
  10. box = {
  11. [id] = state
  12. }
  13. blastingCnt = 0
  14. buling = 0
  15. }
  16. ]]
  17. local AbsActLogic = require("absAct.AbsActLogic")
  18. local AbsActExcel = require("excel.absAct")
  19. local BuyExcel = require("excel.buy")
  20. local Util = require("common.Util")
  21. local Msg = require("core.Msg")
  22. local Grid = require("bag.Grid")
  23. local BagLogic = require("bag.BagLogic")
  24. local BuyLogic = require("topup.BuyLogic")
  25. local YunYingLogic = require("yunying.YunYingLogic")
  26. function isOpen(human, YYInfo, funcConfig)
  27. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  28. if not state then return end
  29. local absAct = human.db.absAct[funcConfig.funcID]
  30. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  31. return false
  32. end
  33. return true, endTime, startTime
  34. end
  35. function isActive(human, YYInfo, funcConfig)
  36. return not isOpen(human, YYInfo, funcConfig)
  37. end
  38. -- ��ʼ�����ݿ�
  39. function initDB(human,id)
  40. local absAct = human.db.absAct[id]
  41. absAct.drum = absAct.drum or {}
  42. absAct.blasting = absAct.blasting or {}
  43. absAct.box = absAct.box or {}
  44. absAct.blastingCnt = absAct.blastingCnt or 0
  45. absAct.buling = absAct.buling or 0
  46. end
  47. -- ��������
  48. function getAndSendMsg(human,id,actID)
  49. -- �жϻ�Ƿ���
  50. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  51. if not state then return end
  52. local absConfig = AbsActExcel.absActivity[id]
  53. if not absConfig then return end
  54. local absAct = human.db.absAct[id]
  55. if not absAct then
  56. return
  57. end
  58. initDB(human,id)
  59. local nowDay = Util.diffDay(starTime) + 1
  60. -- ��������
  61. local msgRet = Msg.gc.GC_ABS_ND_TASK_QUERY
  62. -- ������
  63. local taskConfig = AbsActExcel.drum
  64. local len = #taskConfig
  65. local count = 0
  66. msgRet.day = nowDay
  67. BuyLogic.fontBuyItem(human, msgRet.buyItem, AbsActExcel.blastingBox[1].buyID)
  68. for i = 1,len do
  69. local v = taskConfig[i]
  70. if v.day == nowDay then
  71. count = count + 1
  72. local net = msgRet.drumList[count]
  73. net.id = i
  74. net.desc = v.desc
  75. net.name = v.name
  76. net.needCnt = v.needCnt
  77. net.panelID = v.panelID
  78. net.nowCnt = absAct.drum[i] and absAct.drum[i].cnt or 0
  79. net.state = absAct.drum[i] and absAct.drum[i].state or 0
  80. for j = 1,#v.item do
  81. Grid.makeItem(net.item[j],v.item[j][1],v.item[j][2])
  82. end
  83. net.item[0] = #v.item
  84. end
  85. end
  86. msgRet.drumList[0] = count
  87. -- ������
  88. taskConfig = AbsActExcel.blasting
  89. len = #taskConfig
  90. for i = 1,len do
  91. local v = taskConfig[i]
  92. local net = msgRet.blastingList[i]
  93. net.id = i
  94. net.desc = v.desc
  95. net.name = v.name
  96. net.needCnt = v.needCnt
  97. net.nowCnt = absAct.blasting[i] and absAct.blasting[i].cnt or 0
  98. net.state = absAct.blasting[i] and absAct.blasting[i].state or 0
  99. local itemLen = type(v.item[nowDay]) == "table" and #v.item[nowDay] or 0
  100. for j = 1,itemLen do
  101. Grid.makeItem(net.item[j],v.item[nowDay][j][1],v.item[nowDay][j][2])
  102. end
  103. net.item[0] = itemLen --#v.item[nowDay]
  104. net.panelID = v.panelID or 0
  105. end
  106. msgRet.blastingList[0] = len
  107. -- ��������
  108. taskConfig = AbsActExcel.blastingBox
  109. len = #taskConfig
  110. for i = 1,len do
  111. local v = taskConfig[i]
  112. local net = msgRet.boxList[i]
  113. net.id = i
  114. net.needCnt = v.needCnt
  115. net.state = absAct.box[i] or 0
  116. for j = 1,#v.item do
  117. Grid.makeItem(net.item[j],v.item[j][1],v.item[j][2])
  118. end
  119. net.item[0] = #v.item
  120. end
  121. msgRet.boxList[0] = len
  122. msgRet.blastingCnt = absAct.blastingCnt
  123. Msg.send(msgRet,human.fd)
  124. end
  125. -- ��ȡ��Ʒ
  126. -- type 1��,2��,3��
  127. function get(human,index,itemType,id)
  128. -- �жϻ�Ƿ���
  129. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  130. if not state then return end
  131. local absConfig = AbsActExcel.absActivity[id]
  132. if not absConfig then return end
  133. local absAct = human.db.absAct[id]
  134. if not absAct then
  135. return
  136. end
  137. initDB(human,id)
  138. local nowDay = Util.diffDay(starTime) + 1
  139. local allItems = {} -- ����������ȡʱ�ռ����н���
  140. -- ���indexΪ0��nil����������ȡ��type�����п���ȡ�Ľ���
  141. if index then
  142. local hasReward = false
  143. if itemType == 1 then
  144. -- �������񣺱�������drum������ȡ״̬Ϊ1��
  145. local taskConfig = AbsActExcel.drum
  146. for i = 1, #taskConfig do
  147. local v = taskConfig[i]
  148. if v.day == nowDay then
  149. -- ȷ�����ݽṹ����
  150. absAct.drum[i] = absAct.drum[i] or {}
  151. local taskState = absAct.drum[i].state or 0
  152. if taskState == 1 then
  153. hasReward = true
  154. -- �ռ�����
  155. for j = 1, #v.item do
  156. table.insert(allItems, v.item[j])
  157. end
  158. -- ����״̬
  159. absAct.drum[i].state = 2
  160. end
  161. end
  162. end
  163. elseif itemType == 2 then
  164. -- ���ڽ�������������blasting����ȡ״̬Ϊ1��
  165. local taskConfig = AbsActExcel.blasting
  166. for i = 1, #taskConfig do
  167. local v = taskConfig[i]
  168. -- ȷ�����ݽṹ����
  169. absAct.blasting[i] = absAct.blasting[i] or {}
  170. local blastingState = absAct.blasting[i].state or 0
  171. if blastingState == 1 then
  172. hasReward = true
  173. -- �ռ�����
  174. local itemLen = type(v.item[nowDay]) == "table" and #v.item[nowDay] or 0
  175. for j = 1, itemLen do
  176. table.insert(allItems, v.item[nowDay][j])
  177. end
  178. -- ����״̬
  179. absAct.blasting[i].state = 2
  180. -- ����һ�Σ��ۼƷ��ڴ������ж��Ƿ�ﵽ���Ƚ�����ȡֵ
  181. absAct.blastingCnt = (absAct.blastingCnt or 0) + 1
  182. for j = 1, #AbsActExcel.blastingBox do
  183. if absAct.blastingCnt - 1 < AbsActExcel.blastingBox[j].needCnt and absAct.blastingCnt == AbsActExcel.blastingBox[j].needCnt then
  184. absAct.box[j] = 1
  185. break
  186. end
  187. end
  188. end
  189. end
  190. elseif itemType == 3 then
  191. -- ���Ƚ�������������box����ȡ״̬Ϊ1��
  192. local taskConfig = AbsActExcel.blastingBox
  193. for i = 1, #taskConfig do
  194. local v = taskConfig[i]
  195. local boxState = absAct.box[i] or 0
  196. if boxState == 1 then
  197. hasReward = true
  198. -- �ռ�����
  199. for j = 1, #v.item do
  200. table.insert(allItems, v.item[j])
  201. end
  202. -- ����״̬
  203. absAct.box[i] = 2
  204. end
  205. end
  206. end
  207. -- ����н������򷢷�
  208. if hasReward and #allItems > 0 then
  209. BagLogic.addItemList(human, allItems, "abs_drumblasting")
  210. getAndSendMsg(human, id, absConfig.actID)
  211. YunYingLogic.sendBanner(human)
  212. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  213. end
  214. return
  215. end
  216. -- ԭ���߼���������ȡ
  217. local item = nil
  218. -- ѡ���Ӧ����?
  219. local config = nil
  220. local state = nil
  221. if itemType == 1 then
  222. config = AbsActExcel.drum[index]
  223. state = absAct.drum[index] and absAct.drum[index].state or 0
  224. elseif itemType == 2 then
  225. config = AbsActExcel.blasting[index]
  226. state = absAct.blasting[index] and absAct.blasting[index].state or 0
  227. elseif itemType == 3 then
  228. config = AbsActExcel.blastingBox[index]
  229. state = absAct.box[index] or 0
  230. end
  231. -- �����������?
  232. if not config then
  233. return
  234. end
  235. -- ״̬��Ϊ����ȡ
  236. if state ~= 1 then
  237. return
  238. end
  239. -- �ı�״̬
  240. if itemType == 1 then
  241. item = config.item
  242. absAct.drum[index].state = 2
  243. elseif itemType == 2 then
  244. item = config.item[nowDay]
  245. absAct.blasting[index].state = 2
  246. -- ����һ��,�����ۼƴ��������ж��Ƿ�ﵽ������ȡ���?
  247. absAct.blastingCnt = absAct.blastingCnt + 1
  248. for i = 1,#AbsActExcel.blastingBox do
  249. if absAct.blastingCnt - 1 < AbsActExcel.blastingBox[i].needCnt and absAct.blastingCnt == AbsActExcel.blastingBox[i].needCnt then
  250. absAct.box[i] = 1
  251. break
  252. end
  253. end
  254. elseif itemType == 3 then
  255. item = config.item
  256. absAct.box[index] = 2
  257. else
  258. return
  259. end
  260. BagLogic.addItemList(human, item, "abs_drumblasting")
  261. getAndSendMsg(human,id,absConfig.actID)
  262. YunYingLogic.sendBanner(human)
  263. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  264. end
  265. -- ÿ�������Ծ��?
  266. function onDailyTask(human,funcID, parameter)
  267. drumTaskCallBack(human,funcID,1,parameter)
  268. end
  269. -- �ٻ�
  270. function onDrawCard(human,funcID, parameter)
  271. drumTaskCallBack(human,funcID,2,parameter)
  272. end
  273. -- ��ħ֮��
  274. function onHuangjingTower(human,funcID, parameter)
  275. drumTaskCallBack(human,funcID,3,parameter)
  276. end
  277. -- ��ֵ
  278. function onCharge(human, parameter,funcID)
  279. -- 临时处理
  280. drumTaskCallBack(human,funcID,4,parameter)
  281. end
  282. -- ��������
  283. function onDrill(human,funcID, parameter)
  284. drumTaskCallBack(human,funcID,5,parameter)
  285. end
  286. -- Ů��ɭ��
  287. function onCopyChallenge(human,funcID, parameter)
  288. drumTaskCallBack(human,funcID,6,parameter)
  289. end
  290. -- �ھ�����
  291. function onJjcFight(human,funcID, parameter)
  292. drumTaskCallBack(human,funcID,7,parameter)
  293. end
  294. -- ����̵깺��?
  295. function onShopBuy(human,funcID,parameter)
  296. drumTaskCallBack(human,funcID,8,parameter)
  297. end
  298. -- ð��ɨ��
  299. function onMopup(human,funcID,parameter)
  300. drumTaskCallBack(human,funcID,9,parameter)
  301. end
  302. -- ������Ѩ
  303. function onBinglong(human,funcID,parameter)
  304. drumTaskCallBack(human,funcID,10,parameter)
  305. end
  306. -- ���?
  307. function onExchangeJinbi(human,funcID,parameter)
  308. drumTaskCallBack(human,funcID,11,parameter)
  309. end
  310. -- ����
  311. function onBarTaskgetDo(human,funcID,parameter)
  312. drumTaskCallBack(human,funcID,12,parameter)
  313. end
  314. -- ����
  315. function onUnionDonate(human,funcID,parameter)
  316. drumTaskCallBack(human,funcID,13,parameter)
  317. end
  318. -- ���ḱ��
  319. function onUnionEctypeFight(human,funcID,parameter)
  320. drumTaskCallBack(human,funcID,14,parameter)
  321. end
  322. -- ռ��
  323. function onZhanBuBuyCard(human,funcID,parameter)
  324. -- ZhanbuLogic.lua 436�? 传的数值为�?, 不知道哪�?监听该事件的地方需要数值为负,所以只处理当前模块
  325. if parameter < 0 then
  326. return
  327. end
  328. drumTaskCallBack(human,funcID,15,parameter)
  329. end
  330. -- ������ʯ
  331. function onDecZuanshi(human,funcID,parameter)
  332. drumTaskCallBack(human,funcID,16,parameter)
  333. end
  334. -- ������Ԩ
  335. function onLianyu(human,funcID,parameter)
  336. drumTaskCallBack(human,funcID,17,parameter)
  337. end
  338. -- �ϳɷ���
  339. function onFuwenHecheng(human,funcID,parameter)
  340. drumTaskCallBack(human,funcID,18,parameter)
  341. end
  342. -- �ص�
  343. function drumTaskCallBack(human,id,type,cnt)
  344. AbsActLogic.checkAbsActClean(human, id)
  345. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  346. -- 活動�?開啓
  347. if not state or os.time() > endTime then
  348. return
  349. end
  350. local absConfig = AbsActExcel.absActivity[id]
  351. if not absConfig then return end
  352. local absActData = human.db.absAct[id]
  353. if not absActData then
  354. return
  355. end
  356. initDB(human,id)
  357. local nowDay = Util.diffDay(starTime) + 1
  358. -- ������������������
  359. local taskConfig = AbsActExcel.drum
  360. for k = 1,#taskConfig do
  361. if taskConfig[k].type == type and taskConfig[k].day == nowDay then
  362. local taskID = k
  363. human.db.absAct[id].drum[taskID] = human.db.absAct[id].drum[taskID] or {}
  364. human.db.absAct[id].drum[taskID].cnt = human.db.absAct[id].drum[taskID].cnt or 0
  365. human.db.absAct[id].drum[taskID].state = human.db.absAct[id].drum[taskID].state or 0
  366. human.db.absAct[id].drum[taskID].cnt = human.db.absAct[id].drum[taskID].cnt + cnt
  367. if human.db.absAct[id].drum[taskID].state ~= 0 and cnt < 0 then
  368. human.db.absAct[id].drum[taskID].cnt = human.db.absAct[id].drum[taskID].cnt - cnt
  369. end
  370. local config = AbsActExcel.drum[taskID]
  371. -- ��������
  372. if human.db.absAct[id].drum[taskID].cnt >= config.needCnt and human.db.absAct[id].drum[taskID].state == 0 then
  373. human.db.absAct[id].drum[taskID].state = 1
  374. -- �ж��Ƿ���������
  375. for i = 1,#config.blasting do
  376. local blastingID = config.blasting[i]
  377. local blastingConfig = AbsActExcel.blasting[blastingID]
  378. human.db.absAct[id].blasting[blastingID] = human.db.absAct[id].blasting[blastingID] or {}
  379. human.db.absAct[id].blasting[blastingID].cnt = human.db.absAct[id].blasting[blastingID].cnt or 0
  380. human.db.absAct[id].blasting[blastingID].state = human.db.absAct[id].blasting[blastingID].state or 0
  381. human.db.absAct[id].blasting[blastingID].cnt = human.db.absAct[id].blasting[blastingID].cnt + 1
  382. if human.db.absAct[id].blasting[blastingID].cnt >= 3 and human.db.absAct[id].blasting[blastingID].state ~= 2 then
  383. human.db.absAct[id].blasting[blastingID].state = 1
  384. end
  385. end
  386. end
  387. end
  388. end
  389. YunYingLogic.sendBanner(human)
  390. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  391. end
  392. -- ÿ�����ùģ���״̬
  393. function updateDaily(human,id)
  394. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  395. if not state then return end
  396. local config = AbsActExcel.absActivity[id]
  397. if not config then return end
  398. AbsActLogic.checkAbsActClean(human, id)
  399. local absAct = human.db.absAct[id] or {}
  400. absAct.drum = {}
  401. absAct.blasting = {}
  402. absAct.box = absAct.box or {}
  403. absAct.blastingCnt = absAct.blastingCnt or 0
  404. human.db.absAct[id] = absAct
  405. end
  406. -- 因为玩�?�在活动�?开�?前完成了活跃度任务,活动开�?后没法完成活跃度任务,所以在玩�?�上线时,做一次更新活跃度数据操作
  407. function specialFunc(human, id)
  408. AbsActLogic.checkAbsActClean(human, id)
  409. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  410. -- 活動�?開啓
  411. if not state or os.time() > endTime then
  412. return
  413. end
  414. local absConfig = AbsActExcel.absActivity[id]
  415. if not absConfig then return end
  416. local absActData = human.db.absAct[id]
  417. if not absActData then
  418. return
  419. end
  420. initDB(human,id)
  421. local nowHuoYue = human.db.dailyTask and human.db.dailyTask.nowHuoYue or 0
  422. if nowHuoYue > 0 then
  423. local nowDay = Util.diffDay(starTime) + 1
  424. local actType = 1
  425. -- ������������������
  426. local singleData
  427. local isChange = false
  428. local taskConfig = AbsActExcel.drum
  429. for k = 1,#taskConfig do
  430. if taskConfig[k].type == actType and taskConfig[k].day == nowDay then
  431. local taskID = k
  432. human.db.absAct[id].drum[taskID] = human.db.absAct[id].drum[taskID] or {}
  433. singleData = human.db.absAct[id].drum[taskID]
  434. singleData.cnt = singleData.cnt or 0
  435. singleData.state = singleData.state or 0
  436. if singleData.cnt > 0 then
  437. break
  438. end
  439. singleData.cnt = nowHuoYue
  440. isChange = true
  441. -- if human.db.absAct[id].drum[taskID].state ~= 0 and cnt < 0 then
  442. -- human.db.absAct[id].drum[taskID].cnt = human.db.absAct[id].drum[taskID].cnt - cnt
  443. -- end
  444. local config = AbsActExcel.drum[taskID]
  445. -- ��������
  446. if singleData.cnt >= config.needCnt and singleData.state == 0 then
  447. singleData.state = 1
  448. -- �ж��Ƿ���������
  449. for i = 1,#config.blasting do
  450. local blastingID = config.blasting[i]
  451. local blastingConfig = AbsActExcel.blasting[blastingID]
  452. human.db.absAct[id].blasting[blastingID] = human.db.absAct[id].blasting[blastingID] or {}
  453. human.db.absAct[id].blasting[blastingID].cnt = human.db.absAct[id].blasting[blastingID].cnt or 0
  454. human.db.absAct[id].blasting[blastingID].state = human.db.absAct[id].blasting[blastingID].state or 0
  455. human.db.absAct[id].blasting[blastingID].cnt = human.db.absAct[id].blasting[blastingID].cnt + 1
  456. if human.db.absAct[id].blasting[blastingID].cnt >= 3 and human.db.absAct[id].blasting[blastingID].state ~= 2 then
  457. human.db.absAct[id].blasting[blastingID].state = 1
  458. end
  459. end
  460. end
  461. end
  462. end
  463. if isChange then
  464. YunYingLogic.sendBanner(human)
  465. YunYingLogic.sendGroupUpdate(YYInfo[id], human, absConfig.panelID)
  466. end
  467. end
  468. end
  469. function onLogin(human, id)
  470. specialFunc(human, id)
  471. end
  472. function isRed(human, YYInfo, funcConfig)
  473. local state = AbsActLogic.isStarted(human, funcConfig.funcID)
  474. if not state then return end
  475. local absConfig = AbsActExcel.absActivity[funcConfig.funcID]
  476. local absAct = human.db.absAct[funcConfig.funcID]
  477. if not absAct then return true end
  478. initDB(human,funcConfig.funcID)
  479. for k,v in pairs(absAct.drum) do
  480. if v.state == 1 then
  481. return true
  482. end
  483. end
  484. for k,v in pairs(absAct.blasting) do
  485. if v.state == 1 then
  486. return true
  487. end
  488. end
  489. for k,v in pairs(absAct.box) do
  490. if v == 1 then
  491. return true
  492. end
  493. end
  494. return false
  495. end
  496. -- ������
  497. function buling(human,funcID,conf)
  498. -- ����������Ϊ30��
  499. AbsActLogic.checkAbsActClean(human, funcID)
  500. initDB(human,funcID)
  501. local absConfig = AbsActExcel.absActivity[funcID]
  502. --
  503. local absAct = human.db.absAct[funcID]
  504. if absAct.buling == 1 then
  505. return
  506. end
  507. absAct.buling = 1
  508. local config = AbsActExcel.blastingBox
  509. local len = #config
  510. for i = 1,len do
  511. if config[i].needCnt > absAct.blastingCnt then
  512. absAct.blastingCnt = config[i].needCnt
  513. absAct.box[i] = 1
  514. end
  515. end
  516. getAndSendMsg(human,id,absConfig.actID)
  517. end