OpenServerActAddUpCharge.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. print("[ActAddUpCharge_CheckRed] 存在红点")
  195. return true
  196. end
  197. end
  198. return false
  199. end
  200. -- 是否显示隐藏
  201. local function ActAddUpCharge_Show(human)
  202. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  203. if not nNowMoney or not nShowAllMoney then
  204. return false
  205. end
  206. return nNowMoney >= nShowAllMoney
  207. end
  208. ----------------------------------------- 活动模板调用 -------------------------------------
  209. -- 是否开启
  210. function isOpen(human, YYInfo, funcConfig)
  211. print("[ActAddUpCharge_isOpen] 进入了判断")
  212. return ActAddUpCharge_IsOpen(human)
  213. end
  214. -- 活动剩余时间
  215. function getLeftTime()
  216. print("[ActAddUpCharge_getLeftTime] 获取剩余时间")
  217. return ActAddUpCharge_GetLeftTime()
  218. end
  219. -- 是否存在红点
  220. function isRed(human)
  221. print("[ActAddUpCharge_isRed] 获取红点")
  222. return ActAddUpCharge_CheckRed(human)
  223. end
  224. function isActive(human, YYInfo, funcConfig)
  225. return not isOpen(human, YYInfo, funcConfig)
  226. end
  227. ----------------------------------------- 客户端协议请求 -------------------------------------
  228. -- 请求活动协议
  229. function ActAddUpCharge_Query(human)
  230. if not human then
  231. return
  232. end
  233. local nCreatRet = ActAddUpCharge_CreateDB(human)
  234. if false == nCreatRet then
  235. ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "初始化DB数据失败")
  236. return
  237. end
  238. local tPrize = tPrizeByID
  239. if not tPrize then
  240. return
  241. end
  242. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  243. local bShowAll = ActAddUpCharge_Show(human)
  244. local tMsgData = Msg.gc.GC_PRESEN_OPEN_ADDUP_CHARGE_QUERY
  245. tMsgData.nNowMoney = nNowMoney
  246. tMsgData.leftTime = ActAddUpCharge_GetLeftTime()
  247. tMsgData.list[0] = 0
  248. for nID, v in pairs(tPrize) do
  249. if 1 == v.nShow or (0 == v.nShow and true == bShowAll ) then
  250. tMsgData.list[0] = tMsgData.list[0] + 1
  251. local tPrizeData = tMsgData.list[tMsgData.list[0]]
  252. tPrizeData.nID = nID
  253. tPrizeData.nNeedMoney = v.nMoney
  254. tPrizeData.nState = ActAddUpCharge_GetDBIDState(human, nID)
  255. local nPrizeLne = #v.tPrize
  256. tPrizeData.item[0] = nPrizeLne
  257. -- ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "遍历的奖励信息 nID = "
  258. -- .. nID .. " nState = ".. tPrizeData.nState.." nPrizeLne = "..nPrizeLne)
  259. for j = 1, nPrizeLne do
  260. local nGoodsID = v.tPrize[j][1]
  261. local nGoodsNum = v.tPrize[j][2]
  262. -- ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "物品信息 nGoodsID = "..nGoodsID .. " nGoodsNum = "..nGoodsNum)
  263. Grid.makeItem(tPrizeData.item[j], nGoodsID, nGoodsNum)
  264. end
  265. end
  266. end
  267. Msg.send(tMsgData, human.fd)
  268. --ActAddUpCharge_PrintInfo("[ActAddUpCharge_Query]", "获取到的奖励长度为 nIndex = "..tMsgData.list[0])
  269. end
  270. -- 请求领取奖励
  271. function ActAddUpCharge_GetPrize(human, nID)
  272. if not human or 0 >= nID then
  273. return
  274. end
  275. if not tPrizeByID or not tPrizeByID[nID] then
  276. return
  277. end
  278. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  279. local nNowState = ActAddUpCharge_GetDBIDState(human, nID)
  280. if ADDUPCHARG_STATE_CANGET ~= nNowState then
  281. ActAddUpCharge_PrintInfo("ActAddUpCharge_GetPrize", "请求领取的奖励状态不正确 nID = "..nID)
  282. return
  283. end
  284. local tGoodsInfo = tPrizeByID[nID].tPrize
  285. -- 设置状态
  286. if false == ActAddUpCharge_SetDBIDState(human, nID, ADDUPCHARG_STATE_FINISH) then
  287. ActAddUpCharge_PrintInfo("ActAddUpCharge_GetPrize", "设置数据状态失败 nID = "..nID)
  288. return
  289. end
  290. -- 发奖励
  291. for i = 1, #tGoodsInfo do
  292. local nGoodsID = tGoodsInfo[i][1]
  293. local nGoodsNum = tGoodsInfo[i][2]
  294. BagLogic.addItem(human, nGoodsID, nGoodsNum,"open_server_PowerUpPrize")
  295. end
  296. BagLogic.sendItemGetList(human, tGoodsInfo, "open_server_PowerUpPrize")
  297. YunYingLogic.sendBanner(human)
  298. for k, v in pairs(funcID) do
  299. YunYingLogic.updateIcon(YYInfo[k], human)
  300. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3605)
  301. break
  302. end
  303. ActAddUpCharge_Query(human)
  304. end
  305. ----------------------------------------- 其他模块调用 -------------------------------------
  306. -- 用于起服时映射奖励ID对应配置
  307. function Init()
  308. local tPrize = ActAddUpCharge_GetConfig()
  309. if not tPrize then
  310. ActAddUpCharge_PrintInfo("Init", "起服获取不到配置")
  311. return
  312. end
  313. tPrizeByID = {}
  314. nShowAllMoney = 0
  315. for nID, v in pairs(tPrize) do
  316. if tPrizeByID[nID] then
  317. ActAddUpCharge_PrintInfo("Init", "配置了重复的奖励ID")
  318. return
  319. end
  320. tPrizeByID[nID] = v
  321. if 1 == v.nShow then
  322. nShowAllMoney = math.max(nShowAllMoney, v.nMoney)
  323. end
  324. end
  325. end
  326. -- 充值回调
  327. function onCharge(human, price, funcID, buyID)
  328. if not human or 0 >= price then
  329. return
  330. end
  331. if false == ActAddUpCharge_IsOpen(human) then
  332. return
  333. end
  334. local nNowMoney = ActAddUpCharge_GetDBCharge(human)
  335. nNowMoney = nNowMoney + price
  336. ActAddUpCharge_SetDBCharge(human, nNowMoney)
  337. if not tPrizeByID then
  338. return
  339. end
  340. local nSendClient = false
  341. for nID, v in pairs(tPrizeByID) do
  342. local nState = ActAddUpCharge_GetDBIDState(human, nID)
  343. if ADDUPCHARGEGIFT_STATE_NONE == nState then
  344. if nNowMoney >= v.nMoney then
  345. ActAddUpCharge_SetDBIDState(human, nID, ADDUPCHARG_STATE_CANGET)
  346. nSendClient = true
  347. end
  348. end
  349. end
  350. if true == nSendClient then
  351. YunYingLogic.sendBanner(human)
  352. end
  353. end
  354. -- 登录回调
  355. function onLogin(human, funcID)
  356. -- 在活动期间
  357. if true == ActAddUpCharge_IsOpen(human) then
  358. return
  359. end
  360. if not tPrizeByID then
  361. return
  362. end
  363. if not human.db.AddUpChargeSendMail then
  364. human.db.AddUpChargeSendMail = 0
  365. end
  366. if human.db.AddUpChargeSendMail == 1 then
  367. return
  368. end
  369. human.db.AddUpChargeSendMail = 1
  370. local tMailConfig = MailExcel.mail[nMailID]
  371. if not tMailConfig then
  372. return
  373. end
  374. local items = { }
  375. for nID, v in pairs(tPrizeByID) do
  376. local nState = ActAddUpCharge_GetDBIDState(human, nID)
  377. if nState == ADDUPCHARG_STATE_CANGET then
  378. for _, data in pairs(v.tPrize) do
  379. items[#items + 1] = { data[1], data[2] }
  380. end
  381. ActAddUpCharge_SetDBIDState(human, nID, ADDUPCHARG_STATE_FINISH)
  382. end
  383. end
  384. local title = tMailConfig.title
  385. local content = tMailConfig.content
  386. local senderName = tMailConfig.senderName
  387. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, items, senderName)
  388. end