OpenServerActAddUpCharge.lua 12 KB

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