MangHeLogic.lua 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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 getID = human.db.absAct[id].getID and human.db.absAct[id].getID or 0
  251. local config = AbsActExcel.mangHeCj[getID + 1]
  252. if not config then return end
  253. local now = human.db.absAct[id].drawCnt and human.db.absAct[id].drawCnt or 0
  254. if now < config.need then
  255. return
  256. end
  257. human.db.absAct[id].getID = getID + 1
  258. BagLogic.cleanMomentItemList()
  259. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, config.item[1], config.item[2])
  260. BagLogic.addMomentItemList(human, "abs_manghe")
  261. query(human, id)
  262. YunYingLogic.updateIcon(YYInfo[id], human)
  263. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3702)
  264. end
  265. -- 每日奖励 领取
  266. function mrGet(human, mrId)
  267. local state,id = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_2)
  268. if not state then return end
  269. local absConfig = AbsActExcel.absActivity[id]
  270. if not absConfig then return end
  271. if absConfig.actId == 0 then return end
  272. local absAct = human.db.absAct[id]
  273. if not absAct then return end
  274. local manheMrConfig = AbsActExcel.mangHeMr[mrId]
  275. if not manheMrConfig then return end
  276. absAct.mrReward = absAct.mrReward or {}
  277. absAct.mrReward[mrId] = absAct.mrReward[mrId] or {}
  278. absAct.mrReward[mrId].status = absAct.mrReward[mrId].status or 0
  279. if absAct.mrReward[mrId].status ~= MANGHE_MR_STATUS_1 then
  280. return
  281. end
  282. absAct.mrReward[mrId].status = MANGHE_MR_STATUS_2
  283. BagLogic.cleanMomentItemList()
  284. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, manheMrConfig.item[absConfig.actId][1], manheMrConfig.item[absConfig.actId][2])
  285. BagLogic.addMomentItemList(human, "abs_manghe")
  286. YunYingLogic.sendBanner(human)
  287. query(human, id)
  288. YunYingLogic.updateIcon(YYInfo[id], human)
  289. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3702)
  290. end
  291. -- 盲盒礼包 购买
  292. function mangHeGift(human, id, buyConf, isFirst, cnt, buyNum)
  293. local state = AbsActLogic.isStarted(human, id)
  294. if not state then return end
  295. AbsActLogic.checkAbsActClean(human, id)
  296. local config = AbsActExcel.mangHeGift[1]
  297. local buyCnt = human.db.absAct[id].buyCnt and human.db.absAct[id].buyCnt or 0
  298. if config.cnt <= buyCnt then
  299. return
  300. end
  301. -- if buyCnt + buyNum >= config.cnt then
  302. -- return
  303. -- end
  304. -- human.db.absAct[id].buyCnt = buyCnt + buyNum
  305. -- local tItemList = {}
  306. -- for index, v in ipairs(config.reward) do
  307. -- table.insert(tItemList, {v[1], v[2]*buyNum})
  308. -- end
  309. -- BagLogic.addItemList(human, tItemList, "abs_manghe")
  310. human.db.absAct[id].buyCnt = buyCnt + 1
  311. BagLogic.addItemList(human, config.reward, "abs_manghe")
  312. query(human, id)
  313. end
  314. -- 每日任务激活
  315. function mrActive(human, mrId, id)
  316. local state = AbsActLogic.isStarted(human, id)
  317. if not state then return end
  318. local absAct = human.db.absAct[id]
  319. if not absAct then return end
  320. initMrDb(human, id, mrId)
  321. --MANGHE_MR_1 = 1 -- 每日登陆奖励
  322. --MANGHE_MR_2 = 2 -- 每日活跃度奖励
  323. --MANGHE_MR_3 = 3 -- 每日充值奖励
  324. if mrId == MANGHE_MR_1 or mrId == MANGHE_MR_3 then
  325. if absAct.mrReward[mrId].status == 0 then
  326. absAct.mrReward[mrId].status = MANGHE_MR_STATUS_1
  327. absAct.mrReward[mrId].cur = 1
  328. end
  329. return
  330. end
  331. end
  332. function updateDaily(human, id)
  333. local state = AbsActLogic.isStarted(human, id)
  334. if not state then return end
  335. AbsActLogic.checkAbsActClean(human, id)
  336. local absAct = human.db.absAct[id]
  337. if not absAct then return end
  338. absAct.mrReward = nil
  339. mrActive(human, MANGHE_MR_1, id)
  340. end
  341. function onDailyTask(human, id)
  342. local state = AbsActLogic.isStarted(human, id)
  343. if not state then return end
  344. AbsActLogic.checkAbsActClean(human, id)
  345. local absAct = human.db.absAct[id]
  346. if not absAct then return end
  347. local nowHuoYue = human.db.dailyTask and human.db.dailyTask.nowHuoYue or 0
  348. initMrDb(human, id, MANGHE_MR_2)
  349. absAct.mrReward[MANGHE_MR_2].cur = nowHuoYue
  350. if nowHuoYue >= 100 then
  351. if absAct.mrReward[MANGHE_MR_2].status == 0 then
  352. absAct.mrReward[MANGHE_MR_2].status = MANGHE_MR_STATUS_1
  353. YunYingLogic.updateIcon(YYInfo[id], human)
  354. YunYingLogic.sendGroupUpdate(YYInfo[id], human, PanelDefine.PANEL_ID_3702)
  355. end
  356. end
  357. end
  358. function onLogin(human,funcID)
  359. -- 因为玩家在活动未开启前完成了活跃度任务,活动开启后没法完成活跃度任务,所以在玩家上线时,通过onDailyTask()做一次更新活跃度数据操作
  360. onDailyTask(human, funcID)
  361. -- 因为玩家在活动未开启前进行充值,活动开启后没法完成充值任务,所以在玩家上线时,通过onCharge()做一次更新活跃度数据操作
  362. local topupAcountDaily = human.db.topupAcountDaily
  363. if topupAcountDaily and topupAcountDaily > 0 then
  364. onCharge(human, topupAcountDaily, funcID)
  365. end
  366. end
  367. function onCharge(human, price, id)
  368. local state = AbsActLogic.isStarted(human, id)
  369. if not state then return end
  370. AbsActLogic.checkAbsActClean(human, id)
  371. mrActive(human, MANGHE_MR_3, id)
  372. end
  373. function isRed(human, YYInfo, funcConfig)
  374. local state = AbsActLogic.isStarted(human, funcConfig.funcID)
  375. if not state then return end
  376. local absAct = human.db.absAct[funcConfig.funcID]
  377. if not absAct then return end
  378. if absAct.mrReward then
  379. for k, v in pairs(absAct.mrReward) do
  380. if v.status == MANGHE_MR_STATUS_1 then
  381. return true
  382. end
  383. end
  384. end
  385. local getID = absAct.getID or 0
  386. local config = AbsActExcel.mangHeCj[getID + 1]
  387. if not config then return end
  388. local now = absAct.drawCnt or 0
  389. if now >= config.need then
  390. return true
  391. end
  392. end
  393. function isActive(human, YYInfo, funcConfig)
  394. return not isOpen(human, YYInfo, funcConfig)
  395. end
  396. function isOpen(human, YYInfo, funcConfig)
  397. return AbsActLogic.isStarted(human, funcConfig.funcID)
  398. end
  399. -- function GetRemainNum(human, nBuyID)
  400. -- local config = AbsActExcel.mangHeGift[1]
  401. -- if config.buyID ~= nBuyID then
  402. -- return 0
  403. -- end
  404. -- AbsActLogic.checkAbsActClean(human, MANGHE_ABS_ID)
  405. -- local buyCnt = human.db.absAct[MANGHE_ABS_ID].buyCnt and human.db.absAct[MANGHE_ABS_ID].buyCnt or 0
  406. -- return buyCnt < config.cnt and (config.cnt - buyCnt) or 0
  407. -- end