OpenServerActAddUpCharge.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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. if human.db.topupAcount and human.db.topupAcount > 0 then
  87. if not human.db.AddUpChargeFlag then
  88. human.db.AddUpChargeFlag = 1
  89. onCharge(human, human.db.topupAcount)
  90. end
  91. end
  92. human.db.AddUpChargeSendMail = 0
  93. return true
  94. end
  95. -- 获取某个数据状态
  96. local function ActAddUpCharge_GetDBIDState(human, nID)
  97. if not human or 0 >= nID then
  98. return ADDUPCHARGEGIFT_STATE_NONE
  99. end
  100. local tDBPrize = ActAddUpCharge_GetDB(human)
  101. if nil == tDBPrize then
  102. return ADDUPCHARGEGIFT_STATE_NONE
  103. end
  104. return tDBPrize[nID]
  105. end
  106. -- 设置某个数据状态
  107. local function ActAddUpCharge_SetDBIDState(human, nID, nState)
  108. if not human or 0 >= nID then
  109. return false
  110. end
  111. local tDBPrize = ActAddUpCharge_GetDB(human)
  112. if nil == tDBPrize then
  113. return false
  114. end
  115. tDBPrize[nID] = nState
  116. return true
  117. end
  118. ----------------------------------------- 内部函数判断 -------------------------------------
  119. -- 获取配置
  120. local function ActAddUpCharge_GetConfig()
  121. return OpenActExcel.AddUpChargeGift
  122. end
  123. -- 日志写入
  124. local function ActAddUpCharge_WriteLog(szText)
  125. Log.write(Log.LOGID_OSS_OPENSERVER_ACT, szText)
  126. end
  127. -- 报错打印
  128. local function ActAddUpCharge_PrintInfo(szFuncName,szText)
  129. print(szFuncName.." "..szText)
  130. end
  131. -- 客户端回包
  132. local function ActAddUpCharge_SendClient(fd, data)
  133. Msg.send(data, fd)
  134. ActAddUpCharge_PrintInfo("[ActAddUpCharge_SendClient]", "发送给客户端结束")
  135. end
  136. -- 活动是否开启
  137. local function ActAddUpCharge_IsOpen(human)
  138. local szFuncName = "ActAddUpCharge_IsOpen"
  139. local szText = ""
  140. if not human then
  141. szText = "参数不正确 "
  142. ActAddUpCharge_PrintInfo(szFuncName, szText)
  143. return false
  144. end
  145. local nOpenLv = YunYingLogic.getOpenLvByPanelID(PanelDefine.PANEL_ID_3609)
  146. if human.db.lv < nOpenLv then
  147. return false
  148. end
  149. local flag = OpenAct.getOpenActTime(OpenAct.OPEN_ACT_SERVER_GIFT)
  150. if not flag then
  151. return false
  152. end
  153. return true
  154. end
  155. -- 活动剩余时间
  156. local function ActAddUpCharge_GetLeftTime()
  157. local openDay = CommonDB.getServerOpenDay()
  158. if openDay == nil then
  159. return 0
  160. end
  161. local OpenActConfig = OpenActExcel.openAct[1]
  162. if not OpenActConfig then return 0 end
  163. local sDay = OpenActConfig.sDay
  164. local eDay = OpenActConfig.eDay
  165. if openDay >= sDay and openDay <= eDay then
  166. local time = os.time()
  167. local openTime = CommonDB.getServerOpenTime()
  168. if openTime == 0 then
  169. return 0
  170. end
  171. local endTime = Util.getDayStartTime(openTime) + eDay * 86400
  172. return endTime - time
  173. end
  174. return 0
  175. end
  176. -- 红点
  177. local function ActAddUpCharge_CheckRed(human)
  178. local szFuncName = "ActAddUpCharge_CheckRed"
  179. local szText = ""
  180. if not human then
  181. szText = "参数不正确"
  182. ActAddUpCharge_PrintInfo(szFuncName, szText)
  183. return false
  184. end
  185. ActAddUpCharge_CreateDB(human)
  186. local tDBData = ActAddUpCharge_GetDB(human)
  187. if not tDBData then
  188. szText = "获取玩家DB奖励数据状态表失败"
  189. ActAddUpCharge_PrintInfo(szFuncName, szText)
  190. return false
  191. end
  192. for k, v in pairs(tDBData) do
  193. if ADDUPCHARG_STATE_CANGET == v then
  194. return true
  195. end
  196. end
  197. return false
  198. end
  199. -- 是否显示隐藏
  200. local function ActAddUpCharge_Show(human)
  201. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  202. if not nNowMoney or not nShowAllMoney then
  203. return false
  204. end
  205. return nNowMoney >= nShowAllMoney
  206. end
  207. ----------------------------------------- 活动模板调用 -------------------------------------
  208. -- 是否开启
  209. function isOpen(human, YYInfo, funcConfig)
  210. print("[ActAddUpCharge_isOpen] 进入了判断")
  211. return ActAddUpCharge_IsOpen(human)
  212. end
  213. -- 活动剩余时间
  214. function getLeftTime()
  215. print("[ActAddUpCharge_getLeftTime] 获取剩余时间")
  216. return ActAddUpCharge_GetLeftTime()
  217. end
  218. -- 是否存在红点
  219. function isRed(human)
  220. print("[ActAddUpCharge_isRed] 获取红点")
  221. return ActAddUpCharge_CheckRed(human)
  222. end
  223. function isActive(human, YYInfo, funcConfig)
  224. return not isOpen(human, YYInfo, funcConfig)
  225. end
  226. ----------------------------------------- 客户端协议请求 -------------------------------------
  227. -- 请求活动协议
  228. function ActAddUpCharge_Query(human)
  229. if not human then
  230. return
  231. end
  232. local nCreatRet = ActAddUpCharge_CreateDB(human)
  233. if false == nCreatRet then
  234. ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "初始化DB数据失败")
  235. return
  236. end
  237. local tPrize = tPrizeByID
  238. if not tPrize then
  239. return
  240. end
  241. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  242. local bShowAll = ActAddUpCharge_Show(human)
  243. local tMsgData = Msg.gc.GC_PRESEN_OPEN_ADDUP_CHARGE_QUERY
  244. tMsgData.nNowMoney = nNowMoney
  245. tMsgData.leftTime = ActAddUpCharge_GetLeftTime()
  246. tMsgData.list[0] = 0
  247. for nID, v in pairs(tPrize) do
  248. if 1 == v.nShow or (0 == v.nShow and true == bShowAll ) then
  249. tMsgData.list[0] = tMsgData.list[0] + 1
  250. local tPrizeData = tMsgData.list[tMsgData.list[0]]
  251. tPrizeData.nID = nID
  252. tPrizeData.nNeedMoney = v.nMoney
  253. tPrizeData.nState = ActAddUpCharge_GetDBIDState(human, nID)
  254. local nPrizeLne = #v.tPrize
  255. tPrizeData.item[0] = nPrizeLne
  256. -- ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "遍历的奖励信息 nID = "
  257. -- .. nID .. " nState = ".. tPrizeData.nState.." nPrizeLne = "..nPrizeLne)
  258. for j = 1, nPrizeLne do
  259. local nGoodsID = v.tPrize[j][1]
  260. local nGoodsNum = v.tPrize[j][2]
  261. -- ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "物品信息 nGoodsID = "..nGoodsID .. " nGoodsNum = "..nGoodsNum)
  262. Grid.makeItem(tPrizeData.item[j], nGoodsID, nGoodsNum)
  263. end
  264. end
  265. end
  266. Msg.send(tMsgData, human.fd)
  267. --ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "获取到的奖励长度为 nIndex = "..tMsgData.list[0])
  268. end
  269. -- 请求领取奖励
  270. function ActAddUpCharge_GetPrize(human, nID)
  271. if not human or 0 >= nID then
  272. return
  273. end
  274. if not tPrizeByID or not tPrizeByID[nID] then
  275. return
  276. end
  277. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  278. -- local tMsgData = Msg.gc.GC_PRESENT_OPEN_ADDUP_CHARGE_GETPRIZE
  279. -- tMsgData.nID = nID
  280. local nNowState = ActAddUpCharge_GetDBIDState(human, nID)
  281. if ADDUPCHARG_STATE_CANGET ~= nNowState then
  282. ActAddUpCharge_PrintInfo("ActAddUpCharge_GetPrize", "请求领取的奖励状态不正确 nID = "..nID)
  283. -- tMsgData.nState = 0
  284. --ActAddUpCharge_SendClient(human.fd, tMsgData)
  285. return
  286. end
  287. local tGoodsInfo = tPrizeByID[nID].tPrize
  288. -- if nNowPower < tGoodsInfo.nPower then
  289. -- ActAddUpCharge_PrintInfo("ActAddUpCharge_GetPrize", "战斗力不足不应该领取 nID = "..nID)
  290. -- return
  291. -- end
  292. --tMsgData.nState = 1
  293. -- 设置状态
  294. if false == ActAddUpCharge_SetDBIDState(human, nID, ADDUPCHARG_STATE_FINISH) then
  295. ActAddUpCharge_PrintInfo("ActAddUpCharge_GetPrize", "设置数据状态失败 nID = "..nID)
  296. --tMsgData.nState = 0
  297. -- ActAddUpCharge_SendClient(human.fd, tMsgData)
  298. return
  299. end
  300. -- 发奖励
  301. for i = 1, #tGoodsInfo do
  302. local nGoodsID = tGoodsInfo[i][1]
  303. local nGoodsNum = tGoodsInfo[i][2]
  304. BagLogic.addItem(human, nGoodsID, nGoodsNum,"open_server_PowerUpPrize")
  305. end
  306. BagLogic.sendItemGetList(human, tGoodsInfo, "open_server_PowerUpPrize")
  307. YunYingLogic.sendBanner(human)
  308. for k, v in pairs(funcID) do
  309. YunYingLogic.updateIcon(YYInfo[k], human)
  310. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3605)
  311. break
  312. end
  313. ActAddUpCharge_Query(human)
  314. end
  315. ----------------------------------------- 其他模块调用 -------------------------------------
  316. -- 用于起服时映射奖励ID对应配置
  317. function Init()
  318. local tPrize = ActAddUpCharge_GetConfig()
  319. if not tPrize then
  320. ActAddUpCharge_PrintInfo("Init", "起服获取不到配置")
  321. return
  322. end
  323. tPrizeByID = {}
  324. -- Util.printTable(tPrize)
  325. nShowAllMoney = 0
  326. for nID, v in pairs(tPrize) do
  327. if tPrizeByID[nID] then
  328. ActAddUpCharge_PrintInfo("Init", "配置了重复的奖励ID")
  329. return
  330. end
  331. tPrizeByID[nID] = v
  332. if 1 == v.nShow then
  333. nShowAllMoney = math.max(nShowAllMoney, v.nMoney)
  334. end
  335. end
  336. end
  337. -- 充值回调
  338. function onCharge(human, price, funcID, buyID)
  339. if not human or 0 >= price then
  340. return
  341. end
  342. if false == ActAddUpCharge_IsOpen(human) then
  343. return
  344. end
  345. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  346. nNowMoney = nNowMoney + price
  347. ActAddUpCharge_SetDBCharge(human, nNowMoney)
  348. if not tPrizeByID then
  349. return
  350. end
  351. local nSendClient = false
  352. for nID, v in pairs(tPrizeByID) do
  353. local nState = ActAddUpCharge_GetDBIDState(human, nID)
  354. if ADDUPCHARGEGIFT_STATE_NONE == nState then
  355. if nNowMoney >= v.nMoney then
  356. ActAddUpCharge_SetDBIDState(human, nID, ADDUPCHARG_STATE_CANGET)
  357. nSendClient = true
  358. end
  359. end
  360. end
  361. if true == nSendClient then
  362. YunYingLogic.sendBanner(human)
  363. end
  364. end
  365. -- 登录回调
  366. function onLogin(human, funcID)
  367. -- 在活动期间
  368. local bOpen = ActAddUpCharge_IsOpen(human)
  369. if true == ActAddUpCharge_IsOpen(human) then
  370. if not human.db.AddUpChargeSendMail then
  371. human.db.AddUpChargeSendMail = 1
  372. end
  373. return
  374. end
  375. if true == bOpen then
  376. print("[onLogin] 累充登录判断开启中")
  377. end
  378. if not tPrizeByID then
  379. return
  380. end
  381. if not human.db.AddUpChargeSendMail then
  382. return
  383. -- human.db.AddUpChargeSendMail = 0
  384. end
  385. if human.db.AddUpChargeSendMail ~= 1 then
  386. return
  387. end
  388. human.db.AddUpChargeSendMail = 2
  389. local tMailConfig = MailExcel.mail[nMailID]
  390. if not tMailConfig then
  391. return
  392. end
  393. local items = { }
  394. for nID, v in pairs(tPrizeByID) do
  395. local nState = ActAddUpCharge_GetDBIDState(human, nID)
  396. if nState == ADDUPCHARG_STATE_CANGET then
  397. for _, data in pairs(v.tPrize) do
  398. items[#items + 1] = { data[1], data[2] }
  399. end
  400. ActAddUpCharge_SetDBIDState(human, nID, ADDUPCHARG_STATE_FINISH)
  401. end
  402. end
  403. if nil ~= _G.next(items) then
  404. local title = tMailConfig.title
  405. local content = tMailConfig.content
  406. local senderName = tMailConfig.senderName
  407. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, items, senderName)
  408. end
  409. end