NewFirstChargeLogic.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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. [6] = 1,
  34. [68] = 2,
  35. [98] = 3,
  36. }
  37. local NEWFIRST_DAY = 3 -- 奖励天数,策划也没配置,直接写死吧
  38. local OPENNEWLV = 9 -- 等级9开
  39. -- 状态
  40. NEWFIRST_STATE_CANT_GET = 0 -- 不可领
  41. NEWFIRST_STATE_CAT_GET = 1 -- 可领
  42. NEWFIRST_STATE_HAD_GET = 2 -- 已领
  43. -- local tNewFirstChargeCof = nil -- 配置 Key = nBuyID
  44. -- local tPrizeDataByTypeDay = nil -- 具体奖励配置 [nType] = {[nDay] = v}
  45. local itemID2Type = {
  46. [92001] = 1,
  47. [92002] = 2,
  48. [92003] = 3,
  49. [92004] = 4,
  50. [92005] = 5,
  51. [92006] = 6,
  52. }
  53. -- 是否是正确的渠道
  54. local function isCorrectChanel(human)
  55. if not human then
  56. return false
  57. end
  58. if human.phpChanelID == 1 then --暂时写死
  59. return true
  60. end
  61. return false
  62. end
  63. -- 是否使用新加的首充配置
  64. local function isUseNewCfg(human)
  65. if not isCorrectChanel(human) then
  66. return false
  67. end
  68. local newFirstChargeData = human.db.newFirstCharge
  69. -- 如果原来的首充礼包一个都没购买, 就只能购买新的首充礼包
  70. if not newFirstChargeData or not next(newFirstChargeData) then
  71. return true
  72. end
  73. local subNum = 0
  74. -- 如果购买了老的首充, 必须全部购买且领完, 才能开启下新夹首充礼包
  75. for i=NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3 do
  76. local data = newFirstChargeData[i]
  77. if data then
  78. for k = 1, NEWFIRST_DAY do
  79. if data.tDayStatus[k] ~= NEWFIRST_STATE_HAD_GET then
  80. return false
  81. end
  82. end
  83. subNum = subNum + 1
  84. end
  85. if i == NEWFIRST_CHARGE_TYPE3 and subNum > 0 and subNum < NEWFIRST_CHARGE_TYPE3 then
  86. return false
  87. end
  88. end
  89. return true
  90. end
  91. local function getFinalOffset(human)
  92. local startIdx, endIdx = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3
  93. if isUseNewCfg(human) then
  94. startIdx = 4
  95. endIdx = 6
  96. end
  97. return startIdx, endIdx
  98. end
  99. local function getFinalType(nType, isUseNew)
  100. if isUseNew then
  101. nType = nType + 3
  102. end
  103. return nType
  104. end
  105. local function getNeedList(isNew)
  106. local startIdx, endIdx = 1, 3
  107. if isNew then
  108. startIdx, endIdx = 11, 13
  109. end
  110. local tNewFirstChargeCof = {}
  111. local tPrizeDataByTypeDay = {}
  112. -- for nID, tPrize in pairs(PresentExcel.newfirstcharge) do
  113. -- if type(tPrize) == "table" then
  114. -- --table.print_lua_table(tPrize)
  115. -- local nBuyID = tPrize.nBuyID
  116. -- tNewFirstChargeCof[nBuyID] = tPrize
  117. -- if tMoneyToType[tPrize.nMoney] then
  118. -- tNewFirstChargeCof[nBuyID].nType = tMoneyToType[tPrize.nMoney]
  119. -- else
  120. -- print("[getNeedList] 配置了不正确的金额 nMoney = "..tPrize.nMoney.." nID = "..nID)
  121. -- end
  122. -- else
  123. -- print("[getNeedList] tType = \n"..type(tPrize))
  124. -- end
  125. -- end
  126. for i = startIdx, endIdx do
  127. local singleCfg = PresentExcel.newfirstcharge[i]
  128. local nBuyID = singleCfg.nBuyID
  129. tNewFirstChargeCof[nBuyID] = singleCfg
  130. tNewFirstChargeCof[nBuyID].nType = itemID2Type[singleCfg.nBuyID]
  131. end
  132. for nID, tPrize in pairs(tNewFirstChargeCof) do
  133. local nType = tPrize.nType
  134. tPrizeDataByTypeDay[nType] = {}
  135. for i = 1, NEWFIRST_DAY, 1 do
  136. local tItem = i == 1 and tPrize.tPrize1 or ( i == 2 and tPrize.tPrize2 or tPrize.tPrize3)
  137. tPrizeDataByTypeDay[nType][i] = tItem
  138. end
  139. end
  140. return tNewFirstChargeCof, tPrizeDataByTypeDay
  141. end
  142. -- 初始化对应类型的DB类型数据
  143. local function NewFirstCharge_InitDBByType(human, nType)
  144. if not human.db.newFirstCharge then
  145. human.db.newFirstCharge = {}
  146. end
  147. human.db.newFirstCharge[nType] =
  148. {
  149. nBuyTime = 0,
  150. nSatus = NEWFIRST_STATE_CANT_GET,
  151. tDayStatus = {},
  152. }
  153. for i = 1, NEWFIRST_DAY, 1 do
  154. human.db.newFirstCharge[nType].tDayStatus[i] = NEWFIRST_STATE_CANT_GET
  155. end
  156. end
  157. -- 创建DB数据
  158. local function NewFirstCharge_CreateDB(human)
  159. if not human then
  160. return
  161. end
  162. if not human.db.newFirstCharge then
  163. human.db.newFirstCharge = {}
  164. end
  165. -- for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  166. -- if not human.db.newFirstCharge[i] then
  167. -- NewFirstCharge_InitDBByType(human, i)
  168. -- end
  169. -- end
  170. local startIdx, endIdx = getFinalOffset(human)
  171. for i = startIdx, endIdx do
  172. if not human.db.newFirstCharge[i] then
  173. NewFirstCharge_InitDBByType(human, i)
  174. end
  175. end
  176. --table.print_lua_table(human.db.newFirstCharge)
  177. print("[NewFirstCharge_CreateDB] \n")
  178. end
  179. -- 设置对应天数领取了奖励
  180. local function NewFirstCharge_SetPrizeStauts(human, nType, nDay, nValue)
  181. if not human.db.newFirstCharge or not human.db.newFirstCharge[nType] then
  182. return
  183. end
  184. human.db.newFirstCharge[nType].tDayStatus[nDay] = nValue
  185. end
  186. -- 获取对应类型对应天数奖励状态
  187. local function NewFirstCharge_GetPrizeStauts(human, nType, nDay)
  188. if not human.db.newFirstCharge or not human.db.newFirstCharge[nType] then
  189. return NEWFIRST_STATE_CANT_GET
  190. end
  191. --table.print_lua_table(human.db.newFirstCharge[nType])
  192. --print("\n")
  193. return human.db.newFirstCharge[nType].tDayStatus[nDay]
  194. end
  195. -- 设置购买状态
  196. local function NewFirstCharge_SetBuyStatus(human, nType)
  197. if not human.db.newFirstCharge then
  198. NewFirstCharge_InitDBByType(human, nType)
  199. end
  200. human.db.newFirstCharge[nType].nBuyTime = os.time()
  201. human.db.newFirstCharge[nType].nSatus = NEWFIRST_STATE_HAD_GET
  202. NewFirstCharge_SetPrizeStauts(human, nType, 1, NEWFIRST_STATE_CAT_GET)
  203. end
  204. -- 获取购买状态
  205. local function NewFirstCharge_GetBuyStatus(human, nType)
  206. if not human.db.newFirstCharge then
  207. NewFirstCharge_InitDBByType(human, nType)
  208. end
  209. return human.db.newFirstCharge[nType].nSatus
  210. end
  211. -- 设置时间
  212. local function NewFirstCharge_SetTime(human, nType, nTime)
  213. if not human.db.newFirstCharge then
  214. NewFirstCharge_InitDBByType(human, nType)
  215. end
  216. human.db.newFirstCharge[nType].nBuyTime = nTime
  217. end
  218. -- 获取时间
  219. local function NewFirstCharge_GetTime(human, nType)
  220. if not human.db.newFirstCharge then
  221. NewFirstCharge_InitDBByType(human, nType)
  222. end
  223. return human.db.newFirstCharge[nType].nBuyTime
  224. end
  225. local function isOpenByType(human,giftType)
  226. if not human.db.newFirstCharge or not human.db.newFirstCharge[giftType] then
  227. return true
  228. end
  229. -- 未购买,显示
  230. if NEWFIRST_STATE_CANT_GET == human.db.newFirstCharge[giftType].nSatus then
  231. return true
  232. end
  233. -- 购买了
  234. for nDay = 1, NEWFIRST_DAY, 1 do
  235. local nDayStatus = NewFirstCharge_GetPrizeStauts(human, giftType, nDay)
  236. -- 只要没领取,都是开启的
  237. if NEWFIRST_STATE_HAD_GET ~= nDayStatus then
  238. return true
  239. end
  240. end
  241. return false
  242. end
  243. -- 根据类型判断是否有红点
  244. local function isRedByType(human, giftType)
  245. if not human.db.newFirstCharge or not human.db.newFirstCharge[giftType] then
  246. return false
  247. end
  248. -- 未购买
  249. if NEWFIRST_STATE_CANT_GET == human.db.newFirstCharge[giftType].nSatus then
  250. return false
  251. end
  252. for i = 1, NEWFIRST_DAY, 1 do
  253. local nDayStatus = NewFirstCharge_GetPrizeStauts(human, giftType, i)
  254. if NEWFIRST_STATE_CAT_GET == nDayStatus then
  255. return true
  256. end
  257. end
  258. return false
  259. end
  260. function isOpen(human,YYInfo,funcConfig)
  261. if not SceneHandler.canCharge(human) then
  262. print("[NewFirstCharge- isOpen] 不能充值返回")
  263. return false
  264. end
  265. if OPENNEWLV > human.db.lv then
  266. print("[NewFirstCharge- isOpen] 等级不足 不够 lv = "..human.db.lv)
  267. return false
  268. end
  269. -- for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  270. -- if true == isOpenByType(human,i) then
  271. -- print("[NewFirstCharge- isOpen] 满足条件 ")
  272. -- return true
  273. -- end
  274. -- end
  275. local startIdx, endIdx = getFinalOffset(human)
  276. for i = startIdx, endIdx, 1 do
  277. if true == isOpenByType(human,i) then
  278. print("[NewFirstCharge- isOpen] 满足条件 ")
  279. return true
  280. end
  281. end
  282. print("[NewFirstCharge- isOpen] 不满足条件 ")
  283. return false
  284. end
  285. function isRed(human,YYInfo,funcConfig)
  286. -- for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  287. -- if true == isRedByType(human,i) then
  288. -- return true
  289. -- end
  290. -- end
  291. local startIdx, endIdx = getFinalOffset(human)
  292. for i = startIdx, endIdx, 1 do
  293. if true == isRedByType(human,i) then
  294. return true
  295. end
  296. end
  297. return false
  298. end
  299. function NewFirstCharge_Query(human, nType)
  300. local bl = isUseNewCfg(human)
  301. local tAllConf, tItemConfByType = getNeedList(bl)
  302. local tTypeConf = nil
  303. local finalType = getFinalType(nType, bl)
  304. for _, v in pairs(tAllConf) do
  305. if v.nType == finalType then
  306. tTypeConf = v
  307. break
  308. end
  309. end
  310. if not tTypeConf then
  311. print("[NewFirstCharge_Query] 不存在对应类型的配置 nType = "..finalType)
  312. return
  313. end
  314. if not human.db.newFirstCharge then
  315. NewFirstCharge_CreateDB(human)
  316. end
  317. local tMsgData = Msg.gc.GC_NEW_FIRST_CHARGE_QUERY
  318. tMsgData.nType = nType
  319. tMsgData.nState = NewFirstCharge_GetBuyStatus(human, finalType)
  320. print("[NewFirstCharge_Query] 购买状态 nSatus = "..tMsgData.nState)
  321. tMsgData.nMoney = tTypeConf.nMoney
  322. tMsgData.tRed[0] = NEWFIRST_CHARGE_TYPE3
  323. local len = 0
  324. local startIdx, endIdx = getFinalOffset(human)
  325. for i = startIdx, endIdx, 1 do
  326. len = len + 1
  327. tMsgData.tRed[len] = 0
  328. if true == isRedByType(human, i) then
  329. tMsgData.tRed[len] = 1
  330. end
  331. end
  332. BuyLogic.fontBuyItem(human, tMsgData.buyItem, tTypeConf.nBuyID)
  333. tMsgData.list[0] = 0
  334. for i = 1, NEWFIRST_DAY, 1 do
  335. tMsgData.list[0] = tMsgData.list[0] + 1
  336. local tNodeData = tMsgData.list[tMsgData.list[0]]
  337. tNodeData.nState = NewFirstCharge_GetPrizeStauts(human, finalType, i)
  338. print("[NewFirstCharge_Query] 奖励天数状态 nSatus = "..tNodeData.nState.." i = "..i)
  339. tNodeData.nDay = i
  340. tNodeData.item[0] = 0
  341. local tItemConf = tItemConfByType[finalType][i]
  342. if not tItemConf then
  343. print("[NewFirstCharge_Query] 居然不存在对应的奖励配置")
  344. else
  345. for _, v in ipairs(tItemConf) do
  346. tNodeData.item[0] = tNodeData.item[0] + 1
  347. Grid.makeItem(tNodeData.item[tNodeData.item[0]], v[1], v[2])
  348. if v[3] then
  349. tNodeData.item[tNodeData.item[0]].rare = v[3]
  350. end
  351. end
  352. end
  353. end
  354. Msg.send(tMsgData, human.fd)
  355. -- print("[NewFirstCharge_Query] 发送数据成功\n")
  356. -- if human.db.nSpeed and _G.next(human.db.nSpeed) then
  357. -- table.print_lua_table(human.db.nSpeed)
  358. -- end
  359. end
  360. function NewFirstCharge_Get(human, nType)
  361. local bl = isUseNewCfg(human)
  362. local tAllConf, tItemConfByType = getNeedList(bl)
  363. local tTypeConf = nil
  364. local finalType = getFinalType(nType, bl)
  365. for _, v in pairs(tAllConf) do
  366. if v.nType == finalType then
  367. tTypeConf = v
  368. break
  369. end
  370. end
  371. if not tTypeConf or not tItemConfByType[finalType] then
  372. print("[NewFirstCharge_Get] 不存在对应类型的配置 nType = "..finalType)
  373. return
  374. end
  375. local nMoney = tTypeConf.nMoney
  376. local bChange = false
  377. local tItems = {}
  378. for nDay, value in pairs(tItemConfByType[finalType]) do
  379. local nStatus = NewFirstCharge_GetPrizeStauts(human, finalType, nDay)
  380. if NEWFIRST_STATE_CAT_GET == nStatus then
  381. for _, v in pairs(value) do
  382. table.insert(tItems, v)
  383. end
  384. if nDay == 1 then
  385. bChange = true
  386. local nIndex = tBuyID2Speed[nMoney]
  387. if not human.db.nSpeed then
  388. human.db.nSpeed = {}
  389. end
  390. human.db.nSpeed[nIndex] = 1
  391. end
  392. NewFirstCharge_SetPrizeStauts(human, finalType, nDay, NEWFIRST_STATE_HAD_GET)
  393. end
  394. end
  395. if nil ~= _G.next(tItems) then
  396. BagLogic.addItemList(human, tItems, "shouchong")
  397. for k, v in pairs(funcID) do
  398. YunYingLogic.updateIcon(YYInfo[k], human)
  399. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3302)
  400. break
  401. end
  402. -- 如果购买了老的首充且全部领完, 开启新加的首充
  403. if isUseNewCfg(human) then
  404. NewFirstCharge_CreateDB(human)
  405. NewFirstCharge_GetPrice(human)
  406. end
  407. NewFirstCharge_Query(human, nType)
  408. if true == bChange then
  409. ObjHuman.sendHumanInfo(human)
  410. end
  411. end
  412. end
  413. -- 获取所有礼包价格
  414. function NewFirstCharge_GetPrice(human)
  415. local bl = isUseNewCfg(human)
  416. local tAllConf = getNeedList(bl)
  417. local len = 0
  418. local tMsgData = Msg.gc.GC_NEW_FIRST_PRIZE_QUERY
  419. local tbl = {}
  420. for _,v in pairs(tAllConf) do
  421. len = len + 1
  422. tbl[len] = v.nMoney
  423. end
  424. tMsgData.priceList[0] = len
  425. table.sort(tbl)
  426. for k, v in ipairs(tbl) do
  427. tMsgData.priceList[k] = v
  428. end
  429. Msg.send(tMsgData, human.fd)
  430. end
  431. -- 充值回调
  432. function onCharge(human, nBuyID)
  433. -- print("[NewFirstChargeLogic-onCharge] nBuyID = "..nBuyID)
  434. local bl = isUseNewCfg(human)
  435. local tConfByBuyid = getNeedList(bl)
  436. local isChange = false
  437. if tConfByBuyid[nBuyID] then
  438. --print("[onCharge] nType = ".. tConfByBuyid[nBuyID].nType.." nBuyID = "..nBuyID)
  439. NewFirstCharge_SetBuyStatus(human, tConfByBuyid[nBuyID].nType)
  440. isChange = true
  441. -- 客户端只传1 ~3
  442. local targetType = tConfByBuyid[nBuyID].nType
  443. if bl then
  444. targetType = targetType - 3
  445. end
  446. -- NewFirstCharge_Query(human, tConfByBuyid[nBuyID].nType)
  447. NewFirstCharge_Query(human, targetType)
  448. else
  449. print("[NewFirstChargeLogic-onCharge] 不存在对应的礼包id nBuyID = "..nBuyID)
  450. return
  451. end
  452. if isChange then
  453. for k, v in pairs(funcID) do
  454. print("[NewFirstChargeLogic - onCharge], k = "..k)
  455. YunYingLogic.updateIcon(YYInfo[k], human)
  456. break
  457. end
  458. end
  459. end
  460. function updateDaily(human, funcID)
  461. if human.db.newFirstCharge then
  462. local nNowTime = os.time()
  463. -- for i = NEWFIRST_CHARGE_TYPE1, NEWFIRST_CHARGE_TYPE3, 1 do
  464. -- local nBuyStatus = NewFirstCharge_GetBuyStatus(human, i)
  465. -- local nLastTime = NewFirstCharge_GetTime(human, i)
  466. -- local bIsDay = Util.isSameDayByTimes(nNowTime, nLastTime)
  467. -- -- 遍历该类型全部天数
  468. -- if NEWFIRST_STATE_HAD_GET == nBuyStatus and true ~= bIsDay then
  469. -- for nDay = 1, NEWFIRST_DAY, 1 do
  470. -- local nDayStatus = NewFirstCharge_GetPrizeStauts(human, i, nDay)
  471. -- -- 当天奖励未领取
  472. -- if NEWFIRST_STATE_CANT_GET == nDayStatus then
  473. -- NewFirstCharge_SetPrizeStauts(human, i, nDay, NEWFIRST_STATE_CAT_GET)
  474. -- NewFirstCharge_SetTime(human, i, nNowTime)
  475. -- print("[NewFirstChargeLogic - updateDaily] 隔天刷新 奖励 nType = "..i.." nDay = "..nDay)
  476. -- break
  477. -- end
  478. -- end
  479. -- end
  480. -- end
  481. local startIdx, endIdx = getFinalOffset(human)
  482. for i = startIdx, endIdx do
  483. local nBuyStatus = NewFirstCharge_GetBuyStatus(human, i)
  484. local nLastTime = NewFirstCharge_GetTime(human, i)
  485. local bIsDay = Util.isSameDayByTimes(nNowTime, nLastTime)
  486. -- 遍历该类型全部天数
  487. if NEWFIRST_STATE_HAD_GET == nBuyStatus and true ~= bIsDay then
  488. for nDay = 1, NEWFIRST_DAY, 1 do
  489. local nDayStatus = NewFirstCharge_GetPrizeStauts(human, i, nDay)
  490. -- 当天奖励未领取
  491. if NEWFIRST_STATE_CANT_GET == nDayStatus then
  492. NewFirstCharge_SetPrizeStauts(human, i, nDay, NEWFIRST_STATE_CAT_GET)
  493. NewFirstCharge_SetTime(human, i, nNowTime)
  494. print("[NewFirstChargeLogic - updateDaily] 隔天刷新 奖励 nType = "..i.." nDay = "..nDay)
  495. break
  496. end
  497. end
  498. end
  499. end
  500. end
  501. end
  502. -- 是否已激活首充
  503. function isActive(human, YYInfo, funcConfig)
  504. return not isOpen(human, YYInfo, funcConfig)
  505. end
  506. -- 玩家整点
  507. function onZero(human, funcID)
  508. updateDaily(human, funcID)
  509. end
  510. -- GM 命令
  511. function NewFirstCharge_GMClear(human)
  512. human.db.newFirstCharge = nil
  513. print("[NewFirstCharge_GMClear] 清空完成")
  514. end