NewFirstChargeLogic.lua 11 KB

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