MangHeLogic.lua 15 KB

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