NewFirstChargeLogic.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 NEWFIRST_DAY = 3 -- 奖励天数,策划也没配置,直接写死吧
  29. local OPENBATTLEID = 12 -- 主线12关
  30. -- 状态
  31. NEWFIRST_STATE_CANT_GET = 0 -- 不可领
  32. NEWFIRST_STATE_CAT_GET = 1 -- 可领
  33. NEWFIRST_STATE_HAD_GET = 2 -- 已领
  34. local tNewFirstChargeCof = nil -- 配置 Key = nBuyID
  35. local tPrizeDataByTypeDay = nil -- 具体奖励配置 [nType] = {[nDay] = v}
  36. local function getNeedList()
  37. if not tNewFirstChargeCof then
  38. tNewFirstChargeCof = {}
  39. for nID, tPrize in pairs(PresentExcel.newfirstcharge) do
  40. print("[getNeedList] tType = \n"..type(tPrize))
  41. if type(tPrize) == "table" then
  42. table.print_lua_table(tPrize)
  43. print("\n")
  44. end
  45. local nBuyID = tPrize.nBuyID
  46. tNewFirstChargeCof[nBuyID] = tPrize
  47. if tMoneyToType[tPrize.nMoney] then
  48. tNewFirstChargeCof.nType = tMoneyToType[tPrize.nMoney]
  49. else
  50. print("[getNeedList] 配置了不正确的金额 nMoney = "..tPrize.nMoney.." nID = "..nID)
  51. end
  52. end
  53. end
  54. if not tPrizeDataByTypeDay then
  55. tPrizeDataByTypeDay = {}
  56. for nID, tPrize in pairs(tNewFirstChargeCof) do
  57. local nType = tPrize.nType
  58. tPrizeDataByTypeDay[nType] = {}
  59. for i = 1, NEWFIRST_DAY, 1 do
  60. local tItem = i == 1 and tPrize.tPrize1 or ( i == 2 and tPrize.tPrize2 or tPrize.tPrize3)
  61. tPrizeDataByTypeDay[nType][i] = tItem
  62. end
  63. end
  64. end
  65. return tNewFirstChargeCof, tPrizeDataByTypeDay
  66. end
  67. -- 初始化对应类型的DB类型数据
  68. local function NewFirstCharge_InitDBByType(human, nType)
  69. if not human.db.newFirstCharge then
  70. human.db.newFirstCharge = {}
  71. end
  72. human.db.newFirstCharge[nType] =
  73. {
  74. nBuyTime = 0,
  75. nSatus = NEWFIRST_STATE_CANT_GET,
  76. tDayStatus = {},
  77. }
  78. for i = 1, NEWFIRST_DAY, 1 do
  79. human.db.newFirstCharge[nType].tDayStatus[i] = NEWFIRST_STATE_CANT_GET
  80. end
  81. end
  82. -- 创建DB数据
  83. local function NewFirstCharge_CreateDB(human)
  84. if not human then
  85. return
  86. end
  87. if not human.db.newFirstCharge then
  88. human.db.newFirstCharge = {}
  89. end
  90. for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  91. if not human.db.newFirstCharge[i] then
  92. NewFirstCharge_InitDBByType(human, i)
  93. end
  94. end
  95. end
  96. -- 设置对应天数领取了奖励
  97. local function NewFirstCharge_SetPrizeStauts(human, nType, nDay, nValue)
  98. if not human.db.newFirstCharge or not human.db.newFirstCharge[nType] then
  99. return
  100. end
  101. human.db.newFirstCharge[nType].tDayStatus[nDay] = nValue
  102. end
  103. -- 获取对应类型对应天数奖励状态
  104. local function NewFirstCharge_GetPrizeStauts(human, nType, nDay)
  105. if not human.db.newFirstCharge or not human.db.newFirstCharge[nType] then
  106. return NEWFIRST_STATE_CANT_GET
  107. end
  108. return human.db.newFirstCharge[nType].tDayStatus[nDay]
  109. end
  110. -- 设置购买状态
  111. local function NewFirstCharge_SetBuyStatus(human, nType)
  112. if not human.db.newFirstCharge then
  113. NewFirstCharge_InitDBByType(human, nType)
  114. end
  115. human.db.newFirstCharge[nType].nBuyTime = os.time()
  116. human.db.newFirstCharge[nType].nSatus = NEWFIRST_STATE_HAD_GET
  117. NewFirstCharge_SetPrizeStauts(human, 1, NEWFIRST_STATE_CAT_GET)
  118. end
  119. -- 获取购买状态
  120. local function NewFirstCharge_GetBuyStatus(human, nType)
  121. if not human.db.newFirstCharge then
  122. NewFirstCharge_InitDBByType(human, nType)
  123. end
  124. return human.db.newFirstCharge[nType].nSatus
  125. end
  126. -- 设置时间
  127. local function NewFirstCharge_SetTime(human, nType, nTime)
  128. if not human.db.newFirstCharge then
  129. NewFirstCharge_InitDBByType(human, nType)
  130. end
  131. human.db.newFirstCharge[nType].nBuyTime = nTime
  132. end
  133. -- 获取时间
  134. local function NewFirstCharge_GetTime(human, nType)
  135. if not human.db.newFirstCharge then
  136. NewFirstCharge_InitDBByType(human, nType)
  137. end
  138. return human.db.newFirstCharge[nType].nBuyTime
  139. end
  140. local function isOpenByType(human,giftType)
  141. if not human.db.newfirstCharge or not human.db.newfirstCharge[giftType] then
  142. return true
  143. end
  144. -- 未购买,显示
  145. if NEWFIRST_STATE_CANT_GET == human.db.newfirstCharge[giftType].nSatus then
  146. return true
  147. end
  148. -- 购买了
  149. for nDay = 1, NEWFIRST_DAY, 1 do
  150. local nDayStatus = NewFirstCharge_GetPrizeStauts(human, giftType, nDay)
  151. -- 只要没领取,都是开启的
  152. if NEWFIRST_STATE_HAD_GET ~= nDayStatus then
  153. return true
  154. end
  155. end
  156. return false
  157. end
  158. -- 根据类型判断是否有红点
  159. local function isRedByType(human, giftType)
  160. if not human.db.newfirstCharge or not human.db.newfirstCharge[giftType] then
  161. return false
  162. end
  163. -- 未购买
  164. if NEWFIRST_STATE_CANT_GET == human.db.newfirstCharge[giftType].nSatus then
  165. return false
  166. end
  167. for i = 1, NEWFIRST_DAY, 1 do
  168. local nDayStatus = NewFirstCharge_GetPrizeStauts(human, giftType, i)
  169. if NEWFIRST_STATE_CAT_GET == nDayStatus then
  170. return true
  171. end
  172. end
  173. return false
  174. end
  175. function isOpen(human,YYInfo,funcConfig)
  176. if not SceneHandler.canCharge(human) then
  177. return false
  178. end
  179. if not human.db.battleID then
  180. return false
  181. end
  182. if OPENBATTLEID < human.db.battleID then
  183. return false
  184. end
  185. for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  186. if true == isOpenByType(human,i) then
  187. return true
  188. end
  189. end
  190. return false
  191. end
  192. function isRed(human,YYInfo,funcConfig)
  193. for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  194. if true == isRedByType(human,i) then
  195. return true
  196. end
  197. end
  198. return false
  199. end
  200. function NewFirstCharge_Query(human, nType)
  201. local tAllConf, tItemConfByType = getNeedList()
  202. local tTypeConf = nil
  203. for _, v in pairs(tAllConf) do
  204. if v.nType == nType then
  205. tTypeConf = v
  206. break
  207. end
  208. end
  209. if not tTypeConf then
  210. print("[NewFirstCharge_Query] 不存在对应类型的配置 nType = "..nType)
  211. return
  212. end
  213. if not human.db.newFirstCharge then
  214. NewFirstCharge_CreateDB(human)
  215. end
  216. local tMsgData = Msg.gc.GC_NEW_FIRST_CHARGE_QUERY
  217. tMsgData.nType = nType
  218. tMsgData.nState = NewFirstCharge_GetBuyStatus(human, nType)
  219. tMsgData.nMoney = tTypeConf.nMoney
  220. BuyLogic.fontBuyItem(human, tMsgData.buyItem, tTypeConf.nBuyID)
  221. tMsgData.list[0] = 0
  222. for i = 1, NEWFIRST_DAY, 1 do
  223. tMsgData.list[0] = tMsgData.list[0] + 1
  224. local tNodeData = tMsgData.list[tMsgData.list[0]]
  225. tNodeData.nState = NewFirstCharge_GetPrizeStauts(human, nType, i)
  226. tNodeData.nDay = i
  227. tNodeData.item[0] = 0
  228. local tItemConf = tItemConfByType[nType][i]
  229. if not tItemConf then
  230. print("[NewFirstCharge_Query] 居然不存在对应的奖励配置")
  231. else
  232. for _, v in ipairs(tItemConf) do
  233. tNodeData.item[0] = tNodeData.item[0] + 1
  234. Grid.makeItem(tNodeData.item[tNodeData.item[0]], v[1], v[2])
  235. if v[3] then
  236. tNodeData.item[tNodeData.item[0]].rare = v[3]
  237. end
  238. end
  239. end
  240. end
  241. Msg.send(tMsgData, human.fd)
  242. end
  243. function NewFirstCharge_Get(human, nType)
  244. local tAllConf, tItemConfByType = getNeedList()
  245. local tTypeConf = nil
  246. for _, v in pairs(tAllConf) do
  247. if v.nType == nType then
  248. tTypeConf = v
  249. break
  250. end
  251. end
  252. if not tTypeConf or not tItemConfByType[nType] then
  253. print("[NewFirstCharge_Get] 不存在对应类型的配置 nType = "..nType)
  254. return
  255. end
  256. local tItems = {}
  257. for nDay, value in pairs(tItemConfByType[nType]) do
  258. local nStatus = NewFirstCharge_GetPrizeStauts(human, nType, nDay)
  259. if NEWFIRST_STATE_CAT_GET == nStatus then
  260. for _, v in pairs(value) do
  261. table.insert(tItems, v)
  262. end
  263. NewFirstCharge_SetPrizeStauts(human, nType, nDay, NEWFIRST_STATE_HAD_GET)
  264. end
  265. end
  266. if nil ~= _G.next(tItems) then
  267. BagLogic.addItemList(human, tItems, "shouchong")
  268. for k, v in pairs(funcID) do
  269. YunYingLogic.updateIcon(YYInfo[k], human)
  270. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3302)
  271. break
  272. end
  273. NewFirstCharge_Query(human, type)
  274. end
  275. end
  276. -- 充值回调
  277. function onCharge(human, nBuyID)
  278. local tConfByBuyid = getNeedList()
  279. local isChange = false
  280. if tConfByBuyid[nBuyID] then
  281. NewFirstCharge_SetBuyStatus(human, tConfByBuyid[nBuyID].nType)
  282. else
  283. print("[onCharge] 不存在对应的礼包id nBuyID = "..nBuyID)
  284. return
  285. end
  286. if isChange then
  287. for k, v in pairs(funcID) do
  288. print("[NewFirstChargeLogic - onCharge], k = "..k)
  289. YunYingLogic.updateIcon(YYInfo[k], human)
  290. break
  291. end
  292. end
  293. end
  294. function updateDaily(human, funcID)
  295. if human.db.newfirstCharge then
  296. local nNowTime = os.time()
  297. for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  298. local nBuyStatus = NewFirstCharge_GetBuyStatus(human, i)
  299. local nLastTime = NewFirstCharge_GetTime(human)
  300. local bIsDay = Util.isSameDayByTimes(nNowTime, nLastTime)
  301. -- 遍历该类型全部天数
  302. if NEWFIRST_STATE_HAD_GET == nBuyStatus and true ~= bIsDay then
  303. for nDay = 1, NEWFIRST_DAY, 1 do
  304. local nDayStatus = NewFirstCharge_GetPrizeStauts(human, i, nDay)
  305. -- 当天奖励未领取
  306. if NEWFIRST_STATE_CANT_GET == nDayStatus then
  307. NewFirstCharge_SetPrizeStauts(human, i, nDay, NEWFIRST_STATE_CAT_GET)
  308. NewFirstCharge_SetTime(human, i, nNowTime)
  309. print("[NewFirstChargeLogic - updateDaily] 隔天刷新 奖励 nType = "..i.." nDay = "..nDay)
  310. break
  311. end
  312. end
  313. end
  314. end
  315. end
  316. end
  317. -- 是否已激活首充
  318. function isActive(human, YYInfo, funcConfig)
  319. return not isOpen(human, YYInfo, funcConfig)
  320. end