OpenServerActAddUpCharge.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. --------------------------------
  2. -- 文件名 : OpenServerActAddUpCharge.lua
  3. -- 文件说明 : 开服7天活动 - 累积充值
  4. -- 创建时间 : 2025/1/14
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Util = require("common.Util")
  8. local Lang = require("common.Lang")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local OpenAct = require("present.OpenAct")
  11. local PresentExcel = require("excel.present")
  12. local OpenActExcel = require("excel.openAct")
  13. local MailExcel = require("excel.mail")
  14. local Msg = require("core.Msg")
  15. local ObjHuman = require("core.ObjHuman")
  16. local MailManager = require("mail.MailManager")
  17. local BagLogic = require("bag.BagLogic")
  18. local Grid = require("bag.Grid")
  19. local KingWorldLogic = require("present.KingWorldLogic")
  20. local YunYingLogic = require("yunying.YunYingLogic")
  21. local PanelDefine = require("broadcast.PanelDefine")
  22. local SevenDayGiftLogic = require("present.SevenDayGiftLogic")
  23. local CommonDB = require("common.CommonDB")
  24. local BuyLogic = require("topup.BuyLogic")
  25. local GuideLogic = require("guide.GuideLogic")
  26. local Log = require("common.Log")
  27. local tPrizeByID = nil
  28. local nShowAllMoney = nil -- 展示所有的奖励的充值数
  29. local nMailID = 7011 -- 邮件ID
  30. ADDUPCHARGEGIFT_STATE_NONE = 0 -- 不可领取
  31. ADDUPCHARG_STATE_CANGET = 1 -- 可领取
  32. ADDUPCHARG_STATE_FINISH = 2 -- 已领取
  33. ----------------------------------------- DB数据操作 -------------------------------------
  34. -- 初始化DB数据
  35. local function ActAddUpCharge_InitDB(human)
  36. if not human then
  37. return false
  38. end
  39. human.db.AddUpChargeGift = {}
  40. return true
  41. end
  42. -- 获取DB数据
  43. local function ActAddUpCharge_GetDB(human)
  44. if not human or not human.db.AddUpChargeGift then
  45. return nil
  46. end
  47. return human.db.AddUpChargeGift
  48. end
  49. -- 获取累充金额
  50. local function ActAddUpCharge_GetDBCharge(human)
  51. if not human.db.AddUpCharge then
  52. human.db.AddUpCharge = 0
  53. end
  54. return human.db.AddUpCharge
  55. end
  56. -- 设置累充金额
  57. local function ActAddUpCharge_SetDBCharge(human, nValue)
  58. if not human.db.AddUpCharge then
  59. human.db.AddUpCharge = 0
  60. end
  61. human.db.AddUpCharge = nValue
  62. end
  63. -- 创建DB数据
  64. local function ActAddUpCharge_CreateDB(human)
  65. if not human then
  66. return false
  67. end
  68. if not human.db.AddUpChargeGift then
  69. local bRet = ActAddUpCharge_InitDB(human)
  70. if false == bRet then
  71. print("[ActAddUpCharge_CreateDB] 初始化BD数据失败")
  72. return false
  73. end
  74. if tPrizeByID then
  75. for nID, value in pairs(tPrizeByID) do
  76. human.db.AddUpChargeGift[nID] = ADDUPCHARGEGIFT_STATE_NONE
  77. end
  78. else
  79. print("[ActAddUpCharge_CreateDB] 不存在对应的ID对应配置")
  80. return false
  81. end
  82. end
  83. if not human.db.AddUpCharge then
  84. human.db.AddUpCharge = 0
  85. end
  86. human.db.AddUpChargeSendMail = 0
  87. return true
  88. end
  89. -- 获取某个数据状态
  90. local function ActAddUpCharge_GetDBIDState(human, nID)
  91. if not human or 0 >= nID then
  92. return ADDUPCHARGEGIFT_STATE_NONE
  93. end
  94. local tDBPrize = ActAddUpCharge_GetDB(human)
  95. if nil == tDBPrize then
  96. return ADDUPCHARGEGIFT_STATE_NONE
  97. end
  98. return tDBPrize[nID]
  99. end
  100. -- 设置某个数据状态
  101. local function ActAddUpCharge_SetDBIDState(human, nID, nState)
  102. if not human or 0 >= nID then
  103. return false
  104. end
  105. local tDBPrize = ActAddUpCharge_GetDB(human)
  106. if nil == tDBPrize then
  107. return false
  108. end
  109. tDBPrize[nID] = nState
  110. return true
  111. end
  112. ----------------------------------------- 内部函数判断 -------------------------------------
  113. -- 获取配置
  114. local function ActAddUpCharge_GetConfig()
  115. return OpenActExcel.AddUpChargeGift
  116. end
  117. -- 日志写入
  118. local function ActAddUpCharge_WriteLog(szText)
  119. Log.write(Log.LOGID_OSS_OPENSERVER_ACT, szText)
  120. end
  121. -- 报错打印
  122. local function ActAddUpCharge_PrintInfo(szFuncName,szText)
  123. print(szFuncName.." "..szText)
  124. end
  125. -- 客户端回包
  126. local function ActAddUpCharge_SendClient(fd, data)
  127. Msg.send(data, fd)
  128. ActAddUpCharge_PrintInfo("[ActAddUpCharge_SendClient]", "发送给客户端结束")
  129. end
  130. -- 活动是否开启
  131. local function ActAddUpCharge_IsOpen(human)
  132. local szFuncName = "ActAddUpCharge_IsOpen"
  133. local szText = ""
  134. if not human then
  135. szText = "参数不正确 "
  136. ActAddUpCharge_PrintInfo(szFuncName, szText)
  137. return false
  138. end
  139. local nOpenLv = YunYingLogic.getOpenLvByPanelID(PanelDefine.PANEL_ID_3609)
  140. if human.db.lv < nOpenLv then
  141. return false
  142. end
  143. local flag = OpenAct.getOpenActTime(OpenAct.OPEN_ACT_SERVER_GIFT)
  144. if not flag then
  145. return false
  146. end
  147. return true
  148. end
  149. -- 活动剩余时间
  150. local function ActAddUpCharge_GetLeftTime()
  151. local openDay = CommonDB.getServerOpenDay()
  152. if openDay == nil then
  153. return 0
  154. end
  155. local OpenActConfig = OpenActExcel.openAct[1]
  156. if not OpenActConfig then return 0 end
  157. local sDay = OpenActConfig.sDay
  158. local eDay = OpenActConfig.eDay
  159. if openDay >= sDay and openDay <= eDay then
  160. local time = os.time()
  161. local openTime = CommonDB.getServerOpenTime()
  162. if openTime == 0 then
  163. return 0
  164. end
  165. local endTime = Util.getDayStartTime(openTime) + eDay * 86400
  166. return endTime - time
  167. end
  168. return 0
  169. end
  170. -- 红点
  171. local function ActAddUpCharge_CheckRed(human)
  172. local szFuncName = "ActAddUpCharge_CheckRed"
  173. local szText = ""
  174. if not human then
  175. szText = "参数不正确"
  176. ActAddUpCharge_PrintInfo(szFuncName, szText)
  177. return false
  178. end
  179. ActAddUpCharge_CreateDB(human)
  180. local tDBData = ActAddUpCharge_GetDB(human)
  181. if not tDBData then
  182. szText = "获取玩家DB奖励数据状态表失败"
  183. ActAddUpCharge_PrintInfo(szFuncName, szText)
  184. return false
  185. end
  186. for k, v in pairs(tDBData) do
  187. if ADDUPCHARG_STATE_CANGET == v then
  188. print("[ActAddUpCharge_CheckRed] 存在红点")
  189. return true
  190. end
  191. end
  192. return false
  193. end
  194. -- 是否显示隐藏
  195. local function ActAddUpCharge_Show(human)
  196. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  197. if not nNowMoney or not nShowAllMoney then
  198. return false
  199. end
  200. return nNowMoney >= nShowAllMoney
  201. end
  202. ----------------------------------------- 活动模板调用 -------------------------------------
  203. -- 是否开启
  204. function isOpen(human, YYInfo, funcConfig)
  205. print("[ActAddUpCharge_isOpen] 进入了判断")
  206. return ActAddUpCharge_IsOpen(human)
  207. end
  208. -- 活动剩余时间
  209. function getLeftTime()
  210. print("[ActAddUpCharge_getLeftTime] 获取剩余时间")
  211. return ActAddUpCharge_GetLeftTime()
  212. end
  213. -- 是否存在红点
  214. function isRed(human)
  215. print("[ActAddUpCharge_isRed] 获取红点")
  216. return ActAddUpCharge_CheckRed(human)
  217. end
  218. function isActive(human, YYInfo, funcConfig)
  219. return not isOpen(human, YYInfo, funcConfig)
  220. end
  221. ----------------------------------------- 客户端协议请求 -------------------------------------
  222. -- 请求活动协议
  223. function ActAddUpCharge_Query(human)
  224. if not human then
  225. return
  226. end
  227. local nCreatRet = ActAddUpCharge_CreateDB(human)
  228. if false == nCreatRet then
  229. ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "初始化DB数据失败")
  230. return
  231. end
  232. local tPrize = tPrizeByID
  233. if not tPrize then
  234. return
  235. end
  236. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  237. local bShowAll = ActAddUpCharge_Show(human)
  238. local tMsgData = Msg.gc.GC_PRESEN_OPEN_ADDUP_CHARGE_QUERY
  239. tMsgData.nNowMoney = nNowMoney
  240. tMsgData.leftTime = ActAddUpCharge_GetLeftTime()
  241. tMsgData.list[0] = 0
  242. for nID, v in pairs(tPrize) do
  243. if 1 == v.nShow or (0 == v.nShow and true == bShowAll ) then
  244. tMsgData.list[0] = tMsgData.list[0] + 1
  245. local tPrizeData = tMsgData.list[tMsgData.list[0]]
  246. tPrizeData.nID = nID
  247. tPrizeData.nNeedMoney = v.nMoney
  248. tPrizeData.nState = ActAddUpCharge_GetDBIDState(human, nID)
  249. local nPrizeLne = #v.tPrize
  250. tPrizeData.item[0] = nPrizeLne
  251. -- ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "遍历的奖励信息 nID = "
  252. -- .. nID .. " nState = ".. tPrizeData.nState.." nPrizeLne = "..nPrizeLne)
  253. for j = 1, nPrizeLne do
  254. local nGoodsID = v.tPrize[j][1]
  255. local nGoodsNum = v.tPrize[j][2]
  256. -- ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "物品信息 nGoodsID = "..nGoodsID .. " nGoodsNum = "..nGoodsNum)
  257. Grid.makeItem(tPrizeData.item[j], nGoodsID, nGoodsNum)
  258. end
  259. end
  260. end
  261. Msg.send(tMsgData, human.fd)
  262. --ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "获取到的奖励长度为 nIndex = "..tMsgData.list[0])
  263. end
  264. -- 请求领取奖励
  265. function ActAddUpCharge_GetPrize(human, nID)
  266. if not human or 0 >= nID then
  267. return
  268. end
  269. if not tPrizeByID or not tPrizeByID[nID] then
  270. return
  271. end
  272. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  273. local nNowState = ActAddUpCharge_GetDBIDState(human, nID)
  274. if ADDUPCHARG_STATE_CANGET ~= nNowState then
  275. ActAddUpCharge_PrintInfo("ActAddUpCharge_GetPrize", "请求领取的奖励状态不正确 nID = "..nID)
  276. return
  277. end
  278. local tGoodsInfo = tPrizeByID[nID].tPrize
  279. -- 设置状态
  280. if false == ActAddUpCharge_SetDBIDState(human, nID, ADDUPCHARG_STATE_FINISH) then
  281. ActAddUpCharge_PrintInfo("ActAddUpCharge_GetPrize", "设置数据状态失败 nID = "..nID)
  282. return
  283. end
  284. -- 发奖励
  285. for i = 1, #tGoodsInfo do
  286. local nGoodsID = tGoodsInfo[i][1]
  287. local nGoodsNum = tGoodsInfo[i][2]
  288. BagLogic.addItem(human, nGoodsID, nGoodsNum,"open_server_PowerUpPrize")
  289. end
  290. BagLogic.sendItemGetList(human, tGoodsInfo, "open_server_PowerUpPrize")
  291. YunYingLogic.sendBanner(human)
  292. for k, v in pairs(funcID) do
  293. YunYingLogic.updateIcon(YYInfo[k], human)
  294. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3605)
  295. break
  296. end
  297. ActAddUpCharge_Query(human)
  298. end
  299. ----------------------------------------- 其他模块调用 -------------------------------------
  300. -- 用于起服时映射奖励ID对应配置
  301. function Init()
  302. local tPrize = ActAddUpCharge_GetConfig()
  303. if not tPrize then
  304. ActAddUpCharge_PrintInfo("Init", "起服获取不到配置")
  305. return
  306. end
  307. tPrizeByID = {}
  308. nShowAllMoney = 0
  309. for nID, v in pairs(tPrize) do
  310. if tPrizeByID[nID] then
  311. ActAddUpCharge_PrintInfo("Init", "配置了重复的奖励ID")
  312. return
  313. end
  314. tPrizeByID[nID] = v
  315. if 1 == v.nShow then
  316. nShowAllMoney = math.max(nShowAllMoney, v.nMoney)
  317. end
  318. end
  319. end
  320. -- 充值回调
  321. function onCharge(human, price, funcID, buyID)
  322. if not human or 0 >= price then
  323. return
  324. end
  325. if false == ActAddUpCharge_IsOpen(human) then
  326. return
  327. end
  328. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  329. nNowMoney = nNowMoney + price
  330. ActAddUpCharge_SetDBCharge(human, nNowMoney)
  331. if not tPrizeByID then
  332. return
  333. end
  334. local nSendClient = false
  335. for nID, v in pairs(tPrizeByID) do
  336. local nState = ActAddUpCharge_GetDBIDState(human, nID)
  337. if ADDUPCHARGEGIFT_STATE_NONE == nState then
  338. if nNowMoney >= v.nMoney then
  339. ActAddUpCharge_SetDBIDState(human, nID, ADDUPCHARG_STATE_CANGET)
  340. nSendClient = true
  341. end
  342. end
  343. end
  344. if true == nSendClient then
  345. YunYingLogic.sendBanner(human)
  346. end
  347. end
  348. -- 登录回调
  349. function onLogin(human, funcID)
  350. -- 在活动期间
  351. local bOpen = ActAddUpCharge_IsOpen(human)
  352. if true == ActAddUpCharge_IsOpen(human) then
  353. if not human.db.AddUpChargeSendMail then
  354. human.db.AddUpChargeSendMail = 1
  355. end
  356. return
  357. end
  358. if true == bOpen then
  359. print("[onLogin] 累充登录判断开启中")
  360. end
  361. if not tPrizeByID then
  362. return
  363. end
  364. if not human.db.AddUpChargeSendMail then
  365. return
  366. -- human.db.AddUpChargeSendMail = 0
  367. end
  368. if human.db.AddUpChargeSendMail ~= 1 then
  369. return
  370. end
  371. human.db.AddUpChargeSendMail = 2
  372. local tMailConfig = MailExcel.mail[nMailID]
  373. if not tMailConfig then
  374. return
  375. end
  376. local items = { }
  377. for nID, v in pairs(tPrizeByID) do
  378. local nState = ActAddUpCharge_GetDBIDState(human, nID)
  379. if nState == ADDUPCHARG_STATE_CANGET then
  380. for _, data in pairs(v.tPrize) do
  381. items[#items + 1] = { data[1], data[2] }
  382. end
  383. ActAddUpCharge_SetDBIDState(human, nID, ADDUPCHARG_STATE_FINISH)
  384. end
  385. end
  386. if nil ~= _G.next(items) then
  387. local title = tMailConfig.title
  388. local content = tMailConfig.content
  389. local senderName = tMailConfig.senderName
  390. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, items, senderName)
  391. end
  392. end