QQBigShot.lua 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. --------------------------------
  2. -- 文件名 : QQBigShot.lua
  3. -- 文件说明 : QQ大咖相关
  4. -- 创建时间 : 2025/05/19
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Msg = require("core.Msg")
  8. local Util = require("common.Util")
  9. local Grid = require("bag.Grid")
  10. local BagLogic = require("bag.BagLogic")
  11. local BuyLogic = require("topup.BuyLogic")
  12. local QQBigShouCong = require("excel.qqbigshot")
  13. local CommonDefine = require("common.CommonDefine")
  14. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  15. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  16. local tLvID2ConfID =
  17. {
  18. [1] = 3,
  19. [2] = 4,
  20. [3] = 1,
  21. [4] = 2,
  22. }
  23. local tNextLv =
  24. {
  25. [0] = 3,
  26. [3] = 4,
  27. [4] = 1,
  28. [1] = 2
  29. }
  30. ----------------------------------------- 内部处理开始 -------------------------------------
  31. -- 初始化玩家qq大咖数据
  32. local function QQBigShot_CreatDB(human)
  33. if not human.db.qqBigShot then
  34. human.db.qqBigShot = {}
  35. end
  36. human.db.qqBigShot = {
  37. nQQLv = 0,
  38. nResetTime = os.time(),
  39. tPrizeInfo = {
  40. --[[
  41. [nID] = { -- 可以用位运算,但是没必要
  42. [1] = 0/1/2 -- 首次
  43. [2] = 0/1/2 -- 免费
  44. }
  45. ]]
  46. }
  47. }
  48. local tPrize = human.db.qqBigShot.tPrizeInfo
  49. for nID, v in ipairs(QQBigShouCong.Sheet1) do
  50. if not tPrize[nID] then
  51. tPrize[nID] = {}
  52. end
  53. tPrize[nID][1] = CommonDefine.COMMON_PRIZE_STATE_NOGET
  54. tPrize[nID][2] = CommonDefine.COMMON_PRIZE_STATE_NOGET
  55. end
  56. end
  57. -- 设置玩家大咖等级
  58. local function QQBigShot_SetLv(human, nLv)
  59. human.db.qqBigShot.nQQLv = nLv
  60. if not human.db.yellow then
  61. human.db.yellow = {}
  62. end
  63. human.db.yellow.lv = nLv
  64. end
  65. -- 获取玩家大咖等级
  66. local function QQBigShot_GetLv(human)
  67. return human.db.qqBigShot.nQQLv
  68. end
  69. -- 获取首次礼包状态
  70. local function QQBigShot_GetPrizeFirst(human, nID)
  71. return human.db.qqBigShot.tPrizeInfo[nID][1]
  72. end
  73. -- 设置首次礼包状态
  74. local function QQBigShot_SetPrizeFirst(human, nID, nValue)
  75. human.db.qqBigShot.tPrizeInfo[nID][1] = nValue
  76. end
  77. -- 获取周礼包状态
  78. local function QQBigShot_GetPrizeWeek(human, nID)
  79. return human.db.qqBigShot.tPrizeInfo[nID][2]
  80. end
  81. -- 设置首次礼包状态
  82. local function QQBigShot_SetPrizeWeek(human, nID, nValue)
  83. human.db.qqBigShot.tPrizeInfo[nID][2] = nValue
  84. end
  85. local function QQBigShot_CheckCreate(human)
  86. if human.db.qqBigShot then
  87. return
  88. end
  89. QQBigShot_CreatDB(human)
  90. end
  91. local function QQBigShot_SetResetTime(human)
  92. human.db.qqBigShot.nResetTime = os.time()
  93. end
  94. -- 重置对应等级的周礼包
  95. local function QQBigShot_ResetWeekPrize(human, nID)
  96. QQBigShot_SetPrizeWeek(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  97. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_109)
  98. end
  99. ----------------------------------------- 客户端请求开始 -------------------------------------
  100. -- 请求数据
  101. function QQBigShot_Query(human)
  102. QQBigShot_CheckCreate(human)
  103. local tMsgData = Msg.gc.GC_QQ_BIGSHOT_QUERY
  104. tMsgData.tItemData[0] = 0
  105. for nID, v in ipairs(QQBigShouCong.Sheet1) do
  106. tMsgData.tItemData[0] = tMsgData.tItemData[0] + 1
  107. local tPrizeInfo = tMsgData.tItemData[tMsgData.tItemData[0]]
  108. tPrizeInfo.nID = v.nValue
  109. tPrizeInfo.nFirstStatus = QQBigShot_GetPrizeFirst(human, nID)
  110. tPrizeInfo.nWeekStatus = QQBigShot_GetPrizeWeek(human, nID)
  111. tPrizeInfo.tFirstlist[0] = #v.tFirstPrize
  112. for nIndex, tGoods in ipairs(v.tFirstPrize) do
  113. local itemId = tGoods[1]
  114. local itemCnt = tGoods[2]
  115. Grid.makeItem(tPrizeInfo.tFirstlist[nIndex], itemId, itemCnt)
  116. end
  117. tPrizeInfo.tWeeklist[0] = #v.tWeekPrize
  118. for nIndex, tGoods in ipairs(v.tWeekPrize) do
  119. local itemId = tGoods[1]
  120. local itemCnt = tGoods[2]
  121. Grid.makeItem(tPrizeInfo.tWeeklist[nIndex], itemId, itemCnt)
  122. end
  123. end
  124. Msg.send(tMsgData, human.fd)
  125. end
  126. -- 请求领取数据
  127. function QQBigShot_GetPrize(human, nLv)
  128. local nID = tLvID2ConfID[nLv]
  129. if not QQBigShouCong.Sheet1[nID] then
  130. return
  131. end
  132. local nNowLv = QQBigShot_GetLv(human)
  133. if nLv ~= nNowLv then
  134. print("[QQBigShot_GetPrize] 当前大咖等级不匹配 nLv = "..nLv.." nNowLv = "..nNowLv)
  135. return
  136. end
  137. local tConfig = QQBigShouCong.Sheet1[nID]
  138. local nFirstStatus = QQBigShot_GetPrizeFirst(human, nID)
  139. local nWeekStatus = QQBigShot_GetPrizeWeek(human, nID)
  140. local tGoods = {}
  141. if nFirstStatus == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  142. QQBigShot_SetPrizeFirst(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET)
  143. for _, v in ipairs(tConfig.tFirstPrize) do
  144. if not tGoods[v[1]] then
  145. tGoods[v[1]] = 0
  146. end
  147. tGoods[v[1]] = tGoods[v[1]] + v[2]
  148. end
  149. end
  150. if nWeekStatus == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  151. QQBigShot_SetPrizeWeek(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET)
  152. for _, v in ipairs(tConfig.tWeekPrize) do
  153. if not tGoods[v[1]] then
  154. tGoods[v[1]] = 0
  155. end
  156. tGoods[v[1]] = tGoods[v[1]] + v[2]
  157. end
  158. end
  159. if nil ~= _G.next(tGoods) then
  160. local tItem = {}
  161. for nGoodID, nGoodNum in pairs(tGoods) do
  162. table.insert(tItem, {nGoodID, nGoodNum})
  163. end
  164. BagLogic.addItemList(human, tItem, "qqbigshot")
  165. QQBigShot_Query(human)
  166. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_109)
  167. end
  168. end
  169. function QQBigShot_UpdateLv(human, nLv)
  170. QQBigShot_CheckCreate(human)
  171. local nOldLv = QQBigShot_GetLv(human)
  172. -- local nNextLv = tNextLv[nOldLv]
  173. -- if not nNextLv then
  174. -- print("[QQBigShot_UpdateLv] 不存在对应的下一等级的大咖等级 nOldLv = "..nOldLv)
  175. -- return
  176. -- end
  177. -- if nLv ~= nNextLv then
  178. -- print("[QQBigShot_UpdateLv] 要提升的等级和下一等级的配置不同 nOldLv = "..nOldLv.." nLv = "..nLv.." nNextLv = "..nNextLv)
  179. -- return
  180. -- end
  181. print("[QQBigShot_UpdateLv] 收到的nLv = "..nLv.." nOldLv = "..nOldLv)
  182. if nOldLv ~= nLv then
  183. local nID = tLvID2ConfID[nLv]
  184. if not nID then
  185. print("[QQBigShot_UpdateLv] 不正确的等级 nLv = "..nLv.." nOldLv = "..nOldLv)
  186. return
  187. end
  188. QQBigShot_SetLv(human, nLv)
  189. local nFirstStatus = QQBigShot_GetPrizeFirst(human, nID)
  190. if CommonDefine.COMMON_PRIZE_STATE_CANGET == nFirstStatus then
  191. QQBigShot_SetPrizeFirst(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  192. end
  193. QQBigShot_SetPrizeWeek(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  194. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_109)
  195. QQBigShot_Query(human)
  196. end
  197. end
  198. ----------------------------------------- 外部调用开始 -------------------------------------
  199. function onLogin(human)
  200. QQBigShot_CheckCreate(human)
  201. local nLv = QQBigShot_GetLv(human)
  202. if 0 == nLv then
  203. return
  204. end
  205. local bRet = Util.isSameWeek(human.db.qqBigShot.nResetTime, os.time())
  206. if false == bRet then
  207. local nID = tLvID2ConfID[nLv]
  208. QQBigShot_ResetWeekPrize(human, nID)
  209. QQBigShot_SetResetTime(human)
  210. end
  211. end
  212. function updateDaily(human)
  213. onLogin(human)
  214. end
  215. function isDot(human)
  216. QQBigShot_CheckCreate(human)
  217. local bRet = false
  218. for nID, v in ipairs(QQBigShouCong.Sheet1) do
  219. local nFirstStatus = QQBigShot_GetPrizeFirst(human, nID)
  220. local nWeekStatus = QQBigShot_GetPrizeWeek(human, nID)
  221. if CommonDefine.COMMON_PRIZE_STATE_CANGET == nFirstStatus or CommonDefine.COMMON_PRIZE_STATE_CANGET == nWeekStatus then
  222. bRet = true
  223. break
  224. end
  225. end
  226. return bRet
  227. end
  228. function QQBigShot_HumanLoginHandle(human, nLv)
  229. print("[QQBigShot_HumanLoginHandle] 收到数据进行处理")
  230. if not human then
  231. print("[QQBigShot_HumanLoginHandle] 不存在对应的人物")
  232. return
  233. end
  234. if not human.db then
  235. print("[QQBigShot_HumanLoginHandle] 不存在对应的人物DB数据")
  236. return
  237. end
  238. if not nLv then
  239. print("[QQBigShot_HumanLoginHandle] 不存在对应的等级")
  240. return
  241. end
  242. QQBigShot_CheckCreate(human)
  243. print("[QQBigShot_HumanLoginHandle] 获取到nLv = "..nLv)
  244. QQBigShot_UpdateLv(human, nLv)
  245. end
  246. function QQBigShot_GMReset(human)
  247. local nOldLv = QQBigShot_GetLv(human)
  248. QQBigShot_CreatDB(human)
  249. QQBigShot_UpdateLv(human, nOldLv)
  250. end