MangHeLogic.lua 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. local AbsActExcel = require("excel.absAct")
  2. local Lang = require("common.Lang")
  3. local Util = require("common.Util")
  4. local Msg = require("core.Msg")
  5. local Broadcast = require("broadcast.Broadcast")
  6. local Grid = require("bag.Grid")
  7. local BagLogic = require("bag.BagLogic")
  8. local ItemDefine = require("bag.ItemDefine")
  9. local BuyLogic = require("topup.BuyLogic")
  10. local AbsActDefine = require("absAct.AbsActDefine")
  11. local AbsActLogic = require("absAct.AbsActLogic")
  12. local YunYingLogic = require("yunying.YunYingLogic")
  13. local EquipLogic = require("equip.EquipLogic")
  14. local PanelDefine = require("broadcast.PanelDefine")
  15. MANGHE_ONE_NEED = 1
  16. MANGHE_TEN_NEED = 10
  17. MANGHE_MR_1 = 1 -- 每日登陆奖励
  18. MANGHE_MR_2 = 2 -- 每日活跃度奖励
  19. MANGHE_MR_3 = 3 -- 每日充值奖励
  20. MANGHE_MR_STATUS_1 = 1 --可领取
  21. MANGHE_MR_STATUS_2 = 2 --已领取
  22. MANGHE_RARE_MAX = nil -- 权重和
  23. MANGHE_RARE_MUM = nil -- 保底权重和
  24. local MANGHE_ABS_ID = 2001
  25. local function initMrDb(human, id, mrId)
  26. local absAct = human.db.absAct[id]
  27. if not absAct then return end
  28. local manheMrConfig = AbsActExcel.mangHeMr[mrId]
  29. if not manheMrConfig then return end
  30. absAct.mrReward = absAct.mrReward or {}
  31. absAct.mrReward[mrId] = absAct.mrReward[mrId] or {}
  32. absAct.mrReward[mrId].status = absAct.mrReward[mrId].status or 0
  33. absAct.mrReward[mrId].cur = absAct.mrReward[mrId].cur or 0
  34. end
  35. function refreshRare()
  36. if MANGHE_RARE_MAX then return end
  37. for _, v in ipairs(AbsActExcel.mangHe) do
  38. MANGHE_RARE_MAX = MANGHE_RARE_MAX or 0
  39. MANGHE_RARE_MAX = MANGHE_RARE_MAX + v.rare
  40. if v.mum ~= 0 then
  41. MANGHE_RARE_MUM = MANGHE_RARE_MUM or 0
  42. MANGHE_RARE_MUM = MANGHE_RARE_MUM + v.rare
  43. end
  44. end
  45. end
  46. -- 封装 礼包
  47. function fontGift(human, id , net)
  48. local config = AbsActExcel.mangHeGift[1]
  49. net.id = 1
  50. for i = 1, #config.reward do
  51. Grid.makeItem(net.item[i], config.reward[i][1], config.reward[i][2])
  52. end
  53. net.item[0] = #config.reward
  54. net.name = config.name or ""
  55. net.cnt = human.db.absAct[id].buyCnt and human.db.absAct[id].buyCnt or 0
  56. net.maxCnt = config.cnt
  57. BuyLogic.fontBuyItem(human, net.buyMsg[1], config.buyID)
  58. net.buyMsg[0]=1
  59. net.needItem[0]=0
  60. net.icon = 0
  61. end
  62. -- 封装成就
  63. function fontCj(human, id, net)
  64. local getID = human.db.absAct[id].getID and human.db.absAct[id].getID or 0
  65. local nextID = getID + 1
  66. nextID = AbsActExcel.mangHeCj[nextID] and nextID or getID
  67. local config = AbsActExcel.mangHeCj[nextID]
  68. net.cjNow = human.db.absAct[id].drawCnt and human.db.absAct[id].drawCnt or 0
  69. net.cjMax = config.need
  70. net.cjGet = getID
  71. net.cjItemID = nextID
  72. Grid.makeItem(net.cjItem, config.item[1], config.item[2])
  73. end
  74. -- 封装每日奖励
  75. function fontMr(human, id, mrId, net, actId)
  76. local manheMrConfig = AbsActExcel.mangHeMr[mrId]
  77. local absAct = human.db.absAct[id]
  78. net.id = mrId
  79. net.desc = manheMrConfig.desc
  80. net.status = absAct.mrReward and absAct.mrReward[mrId] and absAct.mrReward[mrId].status or 0
  81. net.cur = absAct.mrReward and absAct.mrReward[mrId] and absAct.mrReward[mrId].cur or 0
  82. net.max = 1
  83. if MANGHE_MR_2 == mrId then
  84. net.max = 100
  85. end
  86. if mrId == MANGHE_MR_1 and net.status == 0 then
  87. -- 每日登陆 奖励必完成 ( 存在极小概率 玩家在0点 login updateDaliy 快于 yunyingLogic 的活动更换 导致每日登陆标记失败)
  88. mrActive(human, mrId, id)
  89. net.status = MANGHE_MR_STATUS_1
  90. end
  91. if net.cur >= net.max then
  92. net.cur = net.max
  93. end
  94. Grid.makeItem(net.item, manheMrConfig.item[actId][1], manheMrConfig.item[actId][2])
  95. end
  96. -- 查询
  97. function query(human, id)
  98. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  99. if not state then return end
  100. local absActConfig = AbsActExcel.absActivity[id]
  101. local absAct = human.db.absAct[id]
  102. local bdCnt = absAct.bdCnt or 0
  103. local msgRet = Msg.gc.GC_ABS_ACT_MANGHE_QUERY
  104. msgRet.startTime = starTime
  105. msgRet.endTime = endTime
  106. msgRet.bdCnt = 30 - bdCnt
  107. msgRet.templateId = absActConfig.adIcon
  108. fontCj(human, id, msgRet)
  109. fontGift(human, id, msgRet.gift)
  110. Grid.makeItem(msgRet.oneNeed, absActConfig.param[1], absActConfig.param[2])
  111. Grid.makeItem(msgRet.tenNeed, absActConfig.param[1], absActConfig.param[2] * MANGHE_TEN_NEED)
  112. fontMr(human, id, MANGHE_MR_1, msgRet.mrReward[MANGHE_MR_1], id)
  113. fontMr(human, id, MANGHE_MR_2, msgRet.mrReward[MANGHE_MR_2], id)
  114. fontMr(human, id, MANGHE_MR_3, msgRet.mrReward[MANGHE_MR_3], id)
  115. msgRet.mrReward[0] = MANGHE_MR_3
  116. msgRet.qiPao = absAct.qiPao or 1
  117. absAct.qiPao = 2
  118. Msg.send(msgRet, human.fd)
  119. end
  120. -- 随机一个道具
  121. function random(isLast)
  122. if not isLast then
  123. local random = math.random(1, MANGHE_RARE_MAX)
  124. for k, v in ipairs(AbsActExcel.mangHe) do
  125. if random <= v.rare then
  126. return v
  127. else
  128. random = random - v.rare
  129. end
  130. end
  131. else
  132. local random = math.random(1, MANGHE_RARE_MUM)
  133. for k, v in ipairs(AbsActExcel.mangHe) do
  134. if v.mum ~= 0 then
  135. if random <= v.rare then
  136. return v
  137. else
  138. random = random - v.rare
  139. end
  140. end
  141. end
  142. end
  143. end
  144. function addCj(human, id, cnt)
  145. human.db.absAct[id].drawCnt = human.db.absAct[id].drawCnt or 0
  146. human.db.absAct[id].drawCnt = human.db.absAct[id].drawCnt + cnt
  147. end
  148. -- 抽奖
  149. function draw(human, cnt)
  150. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_2)
  151. if not state then return end
  152. if not cnt or (cnt ~= 1 and cnt ~= 10) then
  153. return
  154. end
  155. local absAct = human.db.absAct[id]
  156. if not absAct then return end
  157. absAct.bdCnt = absAct.bdCnt or 0
  158. local absActConfig = AbsActExcel.absActivity[id]
  159. if not absActConfig then return end
  160. refreshRare()
  161. AbsActLogic.checkAbsActClean(human, id)
  162. -- 检查道具是否足够
  163. local needCnt = cnt * absActConfig.param[2]
  164. if needCnt > BagLogic.getItemCnt(human, absActConfig.param[1]) then
  165. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, ItemDefine.getValue(ItemDefine.ITEM_MANGHE_ID, "name")))
  166. end
  167. BagLogic.delItem(human, absActConfig.param[1], needCnt, "abs_manghe")
  168. local getList = {}
  169. local isLast = nil
  170. for i = 1, cnt do
  171. isLast = nil
  172. absAct.bdCnt = absAct.bdCnt + 1
  173. if absAct.bdCnt == 30 then
  174. isLast = true
  175. absAct.bdCnt = 0
  176. end
  177. getList[#getList + 1] = random(isLast)
  178. end
  179. addCj(human, id, cnt)
  180. local msgRet = Msg.gc.GC_ABS_ACT_MANGHE_DO
  181. local len = 0
  182. for i = 1, #getList do
  183. local config = getList[i]
  184. BagLogic.addItem(human, config.item[1], config.item[2], "abs_manghe", nil, config.item[3])
  185. if not ItemDefine.isEquip(config.item[1]) then
  186. len = len + 1
  187. Grid.makeItem(msgRet.list[len], config.item[1] , config.item[2])
  188. end
  189. end
  190. msgRet.list[0] = len
  191. msgRet.list[0] = EquipLogic.makeEquipItem(human, msgRet.list, msgRet.list[0])
  192. YunYingLogic.updateIcon(YYInfo[id], human)
  193. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3702)
  194. Msg.send(msgRet, human.fd)
  195. query(human, id)
  196. end
  197. -- 概率查询
  198. function queryRare(human)
  199. local msgRet = Msg.gc.GC_ABS_ACT_MANGHE_RARE_QUERY
  200. refreshRare()
  201. msgRet.isStart = 0
  202. msgRet.isEnd = 0
  203. local len = 0
  204. for k, config in ipairs(AbsActExcel.mangHe) do
  205. if config.show == 1 then
  206. if len <= 0 then
  207. msgRet.isStart = 1
  208. end
  209. len = len + 1
  210. local net = msgRet.list[len]
  211. net.id = k
  212. net.rare = math.floor(config.rare / MANGHE_RARE_MAX * 10000)
  213. net.rare = net.rare > 0 and net.rare or 1
  214. Grid.makeItem(net.item, config.item[1], config.item[2], nil, nil, nil, nil, config.item[3])
  215. if len >= 30 then
  216. msgRet.list[0] = len
  217. Msg.send(msgRet, human.fd)
  218. len = 0
  219. msgRet.isStart = 0
  220. end
  221. end
  222. end
  223. msgRet.list[0] = len
  224. msgRet.isEnd = 1
  225. Msg.send(msgRet, human.fd)
  226. end
  227. MANGHE_CJ_STATE = nil
  228. -- 成就查询
  229. function queryCj(human)
  230. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_2)
  231. if not state then return end
  232. local msgRet = Msg.gc.GC_ABS_ACT_MANGHE_CJ_QUERY
  233. if not MANGHE_CJ_STATE then
  234. for k, config in ipairs(AbsActExcel.mangHeCj) do
  235. local net = msgRet.list[k]
  236. net.id = k
  237. net.need = config.need
  238. Grid.makeItem(net.item, config.item[1], config.item[2])
  239. end
  240. msgRet.list[0] = #AbsActExcel.mangHeCj
  241. msgRet.cjMax = AbsActExcel.mangHeCj[#AbsActExcel.mangHeCj].need
  242. end
  243. msgRet.now =human.db.absAct[id].drawCnt and human.db.absAct[id].drawCnt or 0
  244. Msg.send(msgRet, human.fd)
  245. end
  246. -- 成就 领取(一键领取所有可领取的成就奖励)
  247. function cjGet(human)
  248. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_2)
  249. if not state then return end
  250. local absAct = human.db.absAct[id]
  251. if not absAct then return end
  252. local getID = absAct.getID and absAct.getID or 0
  253. local now = absAct.drawCnt and absAct.drawCnt or 0
  254. -- 清空临时列表
  255. BagLogic.cleanMomentItemList()
  256. local hasReward = false
  257. local lastGetID = getID
  258. -- 遍历所有成就配置,从下一个未领取的成就开始
  259. for i = getID + 1, #AbsActExcel.mangHeCj do
  260. local config = AbsActExcel.mangHeCj[i]
  261. if not config then break end
  262. -- 检查是否达到领取条件
  263. if now >= config.need then
  264. -- 合并奖励到临时列表
  265. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, config.item[1], config.item[2])
  266. lastGetID = i
  267. hasReward = true
  268. else
  269. -- 如果当前成就未达到条件,后续成就也不会达到(因为need是递增的)
  270. break
  271. end
  272. end
  273. -- 如果有奖励,一次性添加所有奖励并更新getID
  274. if hasReward then
  275. absAct.getID = lastGetID
  276. BagLogic.addMomentItemList(human, "abs_manghe")
  277. YunYingLogic.sendBanner(human)
  278. end
  279. query(human, id)
  280. YunYingLogic.updateIcon(YYInfo[id], human)
  281. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3702)
  282. end
  283. -- 每日奖励 领取
  284. function mrGet(human, mrId)
  285. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_2)
  286. if not state then return end
  287. local absConfig = AbsActExcel.absActivity[id]
  288. if not absConfig then return end
  289. if absConfig.actId == 0 then return end
  290. local absAct = human.db.absAct[id]
  291. if not absAct then return end
  292. -- 忽略前端参数,固定领取 1、2、3 三个活动的奖励
  293. local mrIdList = {MANGHE_MR_1, MANGHE_MR_2, MANGHE_MR_3}
  294. absAct.mrReward = absAct.mrReward or {}
  295. BagLogic.cleanMomentItemList()
  296. local hasReward = false
  297. -- 遍历所有需要领取的 mrId
  298. for _, checkMrId in ipairs(mrIdList) do
  299. local manheMrConfig = AbsActExcel.mangHeMr[checkMrId]
  300. if manheMrConfig then
  301. absAct.mrReward[checkMrId] = absAct.mrReward[checkMrId] or {}
  302. absAct.mrReward[checkMrId].status = absAct.mrReward[checkMrId].status or 0
  303. -- 检查是否可领取
  304. if absAct.mrReward[checkMrId].status == MANGHE_MR_STATUS_1 then
  305. -- 更新状态为已领取
  306. absAct.mrReward[checkMrId].status = MANGHE_MR_STATUS_2
  307. -- 合并奖励到临时列表
  308. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, manheMrConfig.item[absConfig.actId][1], manheMrConfig.item[absConfig.actId][2])
  309. hasReward = true
  310. end
  311. end
  312. end
  313. -- 如果有奖励,一次性添加所有奖励
  314. if hasReward then
  315. BagLogic.addMomentItemList(human, "abs_manghe")
  316. YunYingLogic.sendBanner(human)
  317. end
  318. query(human, id)
  319. YunYingLogic.updateIcon(YYInfo[id], human)
  320. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3702)
  321. end
  322. -- 盲盒礼包 购买
  323. function mangHeGift(human, id, buyConf, isFirst, cnt, buyNum)
  324. local state = AbsActLogic.isStarted(human, id)
  325. if not state then return end
  326. AbsActLogic.checkAbsActClean(human, id)
  327. local config = AbsActExcel.mangHeGift[1]
  328. local buyCnt = human.db.absAct[id].buyCnt and human.db.absAct[id].buyCnt or 0
  329. if config.cnt <= buyCnt then
  330. return
  331. end
  332. -- if buyCnt + buyNum >= config.cnt then
  333. -- return
  334. -- end
  335. -- human.db.absAct[id].buyCnt = buyCnt + buyNum
  336. -- local tItemList = {}
  337. -- for index, v in ipairs(config.reward) do
  338. -- table.insert(tItemList, {v[1], v[2]*buyNum})
  339. -- end
  340. -- BagLogic.addItemList(human, tItemList, "abs_manghe")
  341. human.db.absAct[id].buyCnt = buyCnt + 1
  342. BagLogic.addItemList(human, config.reward, "abs_manghe")
  343. query(human, id)
  344. end
  345. -- 每日任务激活
  346. function mrActive(human, mrId, id)
  347. local state = AbsActLogic.isStarted(human, id)
  348. if not state then return end
  349. local absAct = human.db.absAct[id]
  350. if not absAct then return end
  351. initMrDb(human, id, mrId)
  352. --MANGHE_MR_1 = 1 -- 每日登陆奖励
  353. --MANGHE_MR_2 = 2 -- 每日活跃度奖励
  354. --MANGHE_MR_3 = 3 -- 每日充值奖励
  355. if mrId == MANGHE_MR_1 or mrId == MANGHE_MR_3 then
  356. if absAct.mrReward[mrId].status == 0 then
  357. absAct.mrReward[mrId].status = MANGHE_MR_STATUS_1
  358. absAct.mrReward[mrId].cur = 1
  359. end
  360. return
  361. end
  362. end
  363. function updateDaily(human, id)
  364. local state = AbsActLogic.isStarted(human, id)
  365. if not state then return end
  366. AbsActLogic.checkAbsActClean(human, id)
  367. local absAct = human.db.absAct[id]
  368. if not absAct then return end
  369. absAct.mrReward = nil
  370. mrActive(human, MANGHE_MR_1, id)
  371. end
  372. function onDailyTask(human, id)
  373. local state = AbsActLogic.isStarted(human, id)
  374. if not state then return end
  375. AbsActLogic.checkAbsActClean(human, id)
  376. local absAct = human.db.absAct[id]
  377. if not absAct then return end
  378. local nowHuoYue = human.db.dailyTask and human.db.dailyTask.nowHuoYue or 0
  379. initMrDb(human, id, MANGHE_MR_2)
  380. absAct.mrReward[MANGHE_MR_2].cur = nowHuoYue
  381. if nowHuoYue >= 100 then
  382. if absAct.mrReward[MANGHE_MR_2].status == 0 then
  383. absAct.mrReward[MANGHE_MR_2].status = MANGHE_MR_STATUS_1
  384. YunYingLogic.updateIcon(YYInfo[id], human)
  385. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3702)
  386. end
  387. end
  388. end
  389. function onLogin(human,funcID)
  390. -- 因为玩家在活动未开启前完成了活跃度任务,活动开启后没法完成活跃度任务,所以在玩家上线时,通过onDailyTask()做一次更新活跃度数据操作
  391. onDailyTask(human, funcID)
  392. -- 因为玩家在活动未开启前进行充值,活动开启后没法完成充值任务,所以在玩家上线时,通过onCharge()做一次更新活跃度数据操作
  393. local topupAcountDaily = human.db.topupAcountDaily
  394. if topupAcountDaily and topupAcountDaily > 0 then
  395. onCharge(human, topupAcountDaily, funcID)
  396. end
  397. end
  398. function onCharge(human, price, id)
  399. local state = AbsActLogic.isStarted(human, id)
  400. if not state then return end
  401. AbsActLogic.checkAbsActClean(human, id)
  402. mrActive(human, MANGHE_MR_3, id)
  403. end
  404. function isRed(human, YYInfo, funcConfig)
  405. local state = AbsActLogic.isStarted(human, funcConfig.funcID)
  406. if not state then return end
  407. local absAct = human.db.absAct[funcConfig.funcID]
  408. if not absAct then return end
  409. if absAct.mrReward then
  410. for k, v in pairs(absAct.mrReward) do
  411. if v.status == MANGHE_MR_STATUS_1 then
  412. return true
  413. end
  414. end
  415. end
  416. local getID = absAct.getID or 0
  417. local config = AbsActExcel.mangHeCj[getID + 1]
  418. if not config then return end
  419. local now = absAct.drawCnt or 0
  420. if now >= config.need then
  421. return true
  422. end
  423. end
  424. function isActive(human, YYInfo, funcConfig)
  425. return not isOpen(human, YYInfo, funcConfig)
  426. end
  427. function isOpen(human, YYInfo, funcConfig)
  428. return AbsActLogic.isStarted(human, funcConfig.funcID)
  429. end
  430. -- function GetRemainNum(human, nBuyID)
  431. -- local config = AbsActExcel.mangHeGift[1]
  432. -- if config.buyID ~= nBuyID then
  433. -- return 0
  434. -- end
  435. -- AbsActLogic.checkAbsActClean(human, MANGHE_ABS_ID)
  436. -- local buyCnt = human.db.absAct[MANGHE_ABS_ID].buyCnt and human.db.absAct[MANGHE_ABS_ID].buyCnt or 0
  437. -- return buyCnt < config.cnt and (config.cnt - buyCnt) or 0
  438. -- end