NewFirstChargeLogic.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. -----------------------------------------------------------------
  2. -- 文件名 : NewFirstChargeLogic.lua
  3. -- 文件说明 : 新首充
  4. -- 创建时间 : 2025/1/22
  5. -- 创建人 : FC
  6. -----------------------------------------------------------
  7. local Msg = require("core.Msg")
  8. local Util = require("common.Util")
  9. local PresentExcel = require("excel.present")
  10. local Grid = require("bag.Grid")
  11. local BagLogic = require("bag.BagLogic")
  12. local Broadcast = require("broadcast.Broadcast")
  13. local PanelDefine = require("broadcast.PanelDefine")
  14. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  15. local YunYingLogic = require("yunying.YunYingLogic")
  16. local SceneHandler = require("scene.Handler")
  17. local ObjHuman = require("core.ObjHuman")
  18. local BuyLogic = require("topup.BuyLogic")
  19. local NEWFIRST_CHARGE_TYPE1 = 1 -- 1元
  20. local NEWFIRST_CHARGE_TYPE2 = 2 -- 8元
  21. local NEWFIRST_CHARGE_TYPE3 = 3 -- 18元
  22. local tMoneyToType =
  23. {
  24. [1] = NEWFIRST_CHARGE_TYPE1,
  25. [8] = NEWFIRST_CHARGE_TYPE2,
  26. [18] = NEWFIRST_CHARGE_TYPE3,
  27. }
  28. local tBuyID2Speed =
  29. {
  30. [1] = 1,
  31. [8] = 2,
  32. [18] = 3,
  33. }
  34. local NEWFIRST_DAY = 3 -- 奖励天数,策划也没配置,直接写死吧
  35. local OPENNEWLV = 9 -- 等级9开
  36. -- 状态
  37. NEWFIRST_STATE_CANT_GET = 0 -- 不可领
  38. NEWFIRST_STATE_CAT_GET = 1 -- 可领
  39. NEWFIRST_STATE_HAD_GET = 2 -- 已领
  40. local tNewFirstChargeCof = nil -- 配置 Key = nBuyID
  41. local tPrizeDataByTypeDay = nil -- 具体奖励配置 [nType] = {[nDay] = v}
  42. local function getNeedList()
  43. if not tNewFirstChargeCof then
  44. tNewFirstChargeCof = {}
  45. for nID, tPrize in pairs(PresentExcel.newfirstcharge) do
  46. if type(tPrize) == "table" then
  47. --table.print_lua_table(tPrize)
  48. local nBuyID = tPrize.nBuyID
  49. tNewFirstChargeCof[nBuyID] = tPrize
  50. if tMoneyToType[tPrize.nMoney] then
  51. tNewFirstChargeCof[nBuyID].nType = tMoneyToType[tPrize.nMoney]
  52. else
  53. print("[getNeedList] 配置了不正确的金额 nMoney = "..tPrize.nMoney.." nID = "..nID)
  54. end
  55. else
  56. print("[getNeedList] tType = \n"..type(tPrize))
  57. end
  58. end
  59. end
  60. if not tPrizeDataByTypeDay then
  61. tPrizeDataByTypeDay = {}
  62. for nID, tPrize in pairs(tNewFirstChargeCof) do
  63. local nType = tPrize.nType
  64. tPrizeDataByTypeDay[nType] = {}
  65. for i = 1, NEWFIRST_DAY, 1 do
  66. local tItem = i == 1 and tPrize.tPrize1 or ( i == 2 and tPrize.tPrize2 or tPrize.tPrize3)
  67. tPrizeDataByTypeDay[nType][i] = tItem
  68. end
  69. end
  70. end
  71. return tNewFirstChargeCof, tPrizeDataByTypeDay
  72. end
  73. -- 初始化对应类型的DB类型数据
  74. local function NewFirstCharge_InitDBByType(human, nType)
  75. if not human.db.newFirstCharge then
  76. human.db.newFirstCharge = {}
  77. end
  78. human.db.newFirstCharge[nType] =
  79. {
  80. nBuyTime = 0,
  81. nSatus = NEWFIRST_STATE_CANT_GET,
  82. tDayStatus = {},
  83. }
  84. for i = 1, NEWFIRST_DAY, 1 do
  85. human.db.newFirstCharge[nType].tDayStatus[i] = NEWFIRST_STATE_CANT_GET
  86. end
  87. end
  88. -- 创建DB数据
  89. local function NewFirstCharge_CreateDB(human)
  90. if not human then
  91. return
  92. end
  93. if not human.db.newFirstCharge then
  94. human.db.newFirstCharge = {}
  95. end
  96. for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  97. if not human.db.newFirstCharge[i] then
  98. NewFirstCharge_InitDBByType(human, i)
  99. end
  100. end
  101. table.print_lua_table(human.db.newFirstCharge)
  102. print("[NewFirstCharge_CreateDB] \n")
  103. end
  104. -- 设置对应天数领取了奖励
  105. local function NewFirstCharge_SetPrizeStauts(human, nType, nDay, nValue)
  106. if not human.db.newFirstCharge or not human.db.newFirstCharge[nType] then
  107. return
  108. end
  109. human.db.newFirstCharge[nType].tDayStatus[nDay] = nValue
  110. end
  111. -- 获取对应类型对应天数奖励状态
  112. local function NewFirstCharge_GetPrizeStauts(human, nType, nDay)
  113. if not human.db.newFirstCharge or not human.db.newFirstCharge[nType] then
  114. return NEWFIRST_STATE_CANT_GET
  115. end
  116. table.print_lua_table(human.db.newFirstCharge[nType])
  117. print("\n")
  118. return human.db.newFirstCharge[nType].tDayStatus[nDay]
  119. end
  120. -- 设置购买状态
  121. local function NewFirstCharge_SetBuyStatus(human, nType)
  122. if not human.db.newFirstCharge then
  123. NewFirstCharge_InitDBByType(human, nType)
  124. end
  125. human.db.newFirstCharge[nType].nBuyTime = os.time()
  126. human.db.newFirstCharge[nType].nSatus = NEWFIRST_STATE_HAD_GET
  127. NewFirstCharge_SetPrizeStauts(human, nType, 1, NEWFIRST_STATE_CAT_GET)
  128. end
  129. -- 获取购买状态
  130. local function NewFirstCharge_GetBuyStatus(human, nType)
  131. if not human.db.newFirstCharge then
  132. NewFirstCharge_InitDBByType(human, nType)
  133. end
  134. return human.db.newFirstCharge[nType].nSatus
  135. end
  136. -- 设置时间
  137. local function NewFirstCharge_SetTime(human, nType, nTime)
  138. if not human.db.newFirstCharge then
  139. NewFirstCharge_InitDBByType(human, nType)
  140. end
  141. human.db.newFirstCharge[nType].nBuyTime = nTime
  142. end
  143. -- 获取时间
  144. local function NewFirstCharge_GetTime(human, nType)
  145. if not human.db.newFirstCharge then
  146. NewFirstCharge_InitDBByType(human, nType)
  147. end
  148. return human.db.newFirstCharge[nType].nBuyTime
  149. end
  150. local function isOpenByType(human,giftType)
  151. if not human.db.newFirstCharge or not human.db.newFirstCharge[giftType] then
  152. return true
  153. end
  154. -- 未购买,显示
  155. if NEWFIRST_STATE_CANT_GET == human.db.newFirstCharge[giftType].nSatus then
  156. return true
  157. end
  158. -- 购买了
  159. for nDay = 1, NEWFIRST_DAY, 1 do
  160. local nDayStatus = NewFirstCharge_GetPrizeStauts(human, giftType, nDay)
  161. -- 只要没领取,都是开启的
  162. if NEWFIRST_STATE_HAD_GET ~= nDayStatus then
  163. return true
  164. end
  165. end
  166. return false
  167. end
  168. -- 根据类型判断是否有红点
  169. local function isRedByType(human, giftType)
  170. if not human.db.newFirstCharge or not human.db.newFirstCharge[giftType] then
  171. return false
  172. end
  173. -- 未购买
  174. if NEWFIRST_STATE_CANT_GET == human.db.newFirstCharge[giftType].nSatus then
  175. return false
  176. end
  177. for i = 1, NEWFIRST_DAY, 1 do
  178. local nDayStatus = NewFirstCharge_GetPrizeStauts(human, giftType, i)
  179. if NEWFIRST_STATE_CAT_GET == nDayStatus then
  180. return true
  181. end
  182. end
  183. return false
  184. end
  185. function isOpen(human,YYInfo,funcConfig)
  186. if not SceneHandler.canCharge(human) then
  187. print("[NewFirstCharge- isOpen] 不能充值返回")
  188. return false
  189. end
  190. if OPENNEWLV > human.db.lv then
  191. print("[NewFirstCharge- isOpen] 等级不足 不够 lv = "..human.db.lv)
  192. return false
  193. end
  194. for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  195. if true == isOpenByType(human,i) then
  196. print("[NewFirstCharge- isOpen] 满足条件 ")
  197. return true
  198. end
  199. end
  200. print("[NewFirstCharge- isOpen] 不满足条件 ")
  201. return false
  202. end
  203. function isRed(human,YYInfo,funcConfig)
  204. for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  205. if true == isRedByType(human,i) then
  206. return true
  207. end
  208. end
  209. return false
  210. end
  211. function NewFirstCharge_Query(human, nType)
  212. local tAllConf, tItemConfByType = getNeedList()
  213. local tTypeConf = nil
  214. for _, v in pairs(tAllConf) do
  215. if v.nType == nType then
  216. tTypeConf = v
  217. break
  218. end
  219. end
  220. if not tTypeConf then
  221. print("[NewFirstCharge_Query] 不存在对应类型的配置 nType = "..nType)
  222. return
  223. end
  224. if not human.db.newFirstCharge then
  225. NewFirstCharge_CreateDB(human)
  226. end
  227. local tMsgData = Msg.gc.GC_NEW_FIRST_CHARGE_QUERY
  228. tMsgData.nType = nType
  229. tMsgData.nState = NewFirstCharge_GetBuyStatus(human, nType)
  230. print("[NewFirstCharge_Query] 购买状态 nSatus = "..tMsgData.nState)
  231. tMsgData.nMoney = tTypeConf.nMoney
  232. tMsgData.tRed[0] = NEWFIRST_CHARGE_TYPE3
  233. for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  234. tMsgData.tRed[i] = 0
  235. if true == isRedByType(human, i) then
  236. tMsgData.tRed[i] = 1
  237. end
  238. end
  239. BuyLogic.fontBuyItem(human, tMsgData.buyItem, tTypeConf.nBuyID)
  240. tMsgData.list[0] = 0
  241. for i = 1, NEWFIRST_DAY, 1 do
  242. tMsgData.list[0] = tMsgData.list[0] + 1
  243. local tNodeData = tMsgData.list[tMsgData.list[0]]
  244. tNodeData.nState = NewFirstCharge_GetPrizeStauts(human, nType, i)
  245. print("[NewFirstCharge_Query] 奖励天数状态 nSatus = "..tNodeData.nState.." i = "..i)
  246. tNodeData.nDay = i
  247. tNodeData.item[0] = 0
  248. local tItemConf = tItemConfByType[nType][i]
  249. if not tItemConf then
  250. print("[NewFirstCharge_Query] 居然不存在对应的奖励配置")
  251. else
  252. for _, v in ipairs(tItemConf) do
  253. tNodeData.item[0] = tNodeData.item[0] + 1
  254. Grid.makeItem(tNodeData.item[tNodeData.item[0]], v[1], v[2])
  255. if v[3] then
  256. tNodeData.item[tNodeData.item[0]].rare = v[3]
  257. end
  258. end
  259. end
  260. end
  261. Msg.send(tMsgData, human.fd)
  262. print("[NewFirstCharge_Query] 发送数据成功\n")
  263. if human.db.nSpeed and _G.next(human.db.nSpeed) then
  264. table.print_lua_table(human.db.nSpeed)
  265. end
  266. end
  267. function NewFirstCharge_Get(human, nType)
  268. local tAllConf, tItemConfByType = getNeedList()
  269. local tTypeConf = nil
  270. for _, v in pairs(tAllConf) do
  271. if v.nType == nType then
  272. tTypeConf = v
  273. break
  274. end
  275. end
  276. if not tTypeConf or not tItemConfByType[nType] then
  277. print("[NewFirstCharge_Get] 不存在对应类型的配置 nType = "..nType)
  278. return
  279. end
  280. local nMoney = tTypeConf.nMoney
  281. local bChange = false
  282. local tItems = {}
  283. for nDay, value in pairs(tItemConfByType[nType]) do
  284. local nStatus = NewFirstCharge_GetPrizeStauts(human, nType, nDay)
  285. if NEWFIRST_STATE_CAT_GET == nStatus then
  286. for _, v in pairs(value) do
  287. table.insert(tItems, v)
  288. end
  289. if nDay == 1 then
  290. bChange = true
  291. local nIndex = tBuyID2Speed[nMoney]
  292. if not human.db.nSpeed then
  293. human.db.nSpeed = {}
  294. end
  295. human.db.nSpeed[nIndex] = 1
  296. end
  297. NewFirstCharge_SetPrizeStauts(human, nType, nDay, NEWFIRST_STATE_HAD_GET)
  298. end
  299. end
  300. if nil ~= _G.next(tItems) then
  301. BagLogic.addItemList(human, tItems, "shouchong")
  302. for k, v in pairs(funcID) do
  303. YunYingLogic.updateIcon(YYInfo[k], human)
  304. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3302)
  305. break
  306. end
  307. NewFirstCharge_Query(human, nType)
  308. if true == bChange then
  309. ObjHuman.sendHumanInfo(human)
  310. end
  311. end
  312. end
  313. -- 充值回调
  314. function onCharge(human, nBuyID)
  315. --print("[NewFirstChargeLogic-onCharge] nBuyID = "..nBuyID)
  316. local tConfByBuyid = getNeedList()
  317. local isChange = false
  318. if tConfByBuyid[nBuyID] then
  319. --print("[onCharge] nType = ".. tConfByBuyid[nBuyID].nType.." nBuyID = "..nBuyID)
  320. NewFirstCharge_SetBuyStatus(human, tConfByBuyid[nBuyID].nType)
  321. isChange = true
  322. else
  323. print("[NewFirstChargeLogic-onCharge] 不存在对应的礼包id nBuyID = "..nBuyID)
  324. return
  325. end
  326. if isChange then
  327. for k, v in pairs(funcID) do
  328. print("[NewFirstChargeLogic - onCharge], k = "..k)
  329. YunYingLogic.updateIcon(YYInfo[k], human)
  330. break
  331. end
  332. NewFirstCharge_Query(human)
  333. end
  334. end
  335. function updateDaily(human, funcID)
  336. if human.db.newFirstCharge then
  337. local nNowTime = os.time()
  338. for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  339. local nBuyStatus = NewFirstCharge_GetBuyStatus(human, i)
  340. local nLastTime = NewFirstCharge_GetTime(human, i)
  341. local bIsDay = Util.isSameDayByTimes(nNowTime, nLastTime)
  342. -- 遍历该类型全部天数
  343. if NEWFIRST_STATE_HAD_GET == nBuyStatus and true ~= bIsDay then
  344. for nDay = 1, NEWFIRST_DAY, 1 do
  345. local nDayStatus = NewFirstCharge_GetPrizeStauts(human, i, nDay)
  346. -- 当天奖励未领取
  347. if NEWFIRST_STATE_CANT_GET == nDayStatus then
  348. NewFirstCharge_SetPrizeStauts(human, i, nDay, NEWFIRST_STATE_CAT_GET)
  349. NewFirstCharge_SetTime(human, i, nNowTime)
  350. print("[NewFirstChargeLogic - updateDaily] 隔天刷新 奖励 nType = "..i.." nDay = "..nDay)
  351. break
  352. end
  353. end
  354. end
  355. end
  356. end
  357. end
  358. -- 是否已激活首充
  359. function isActive(human, YYInfo, funcConfig)
  360. return not isOpen(human, YYInfo, funcConfig)
  361. end
  362. -- 玩家整点
  363. function onZero(human, funcID)
  364. updateDaily(human, funcID)
  365. end
  366. -- GM 命令
  367. function NewFirstCharge_GMClear(human)
  368. human.db.newFirstCharge = nil
  369. print("[NewFirstCharge_GMClear] 清空完成")
  370. end