QQBigShot.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. end
  61. -- 获取玩家大咖等级
  62. local function QQBigShot_GetLv(human)
  63. return human.db.qqBigShot.nQQLv
  64. end
  65. -- 获取首次礼包状态
  66. local function QQBigShot_GetPrizeFirst(human, nID)
  67. return human.db.qqBigShot.tPrizeInfo[nID][1]
  68. end
  69. -- 设置首次礼包状态
  70. local function QQBigShot_SetPrizeFirst(human, nID, nValue)
  71. human.db.qqBigShot.tPrizeInfo[nID][1] = nValue
  72. end
  73. -- 获取周礼包状态
  74. local function QQBigShot_GetPrizeWeek(human, nID)
  75. return human.db.qqBigShot.tPrizeInfo[nID][2]
  76. end
  77. -- 设置首次礼包状态
  78. local function QQBigShot_SetPrizeWeek(human, nID, nValue)
  79. human.db.qqBigShot.tPrizeInfo[nID][2] = nValue
  80. end
  81. local function QQBigShot_CheckCreate(human)
  82. if human.db.qqBigShot then
  83. return
  84. end
  85. QQBigShot_CreatDB(human)
  86. end
  87. -- 重置对应等级的周礼包
  88. local function QQBigShot_ResetWeekPrize(human, nID)
  89. QQBigShot_SetPrizeWeek(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  90. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_109)
  91. end
  92. ----------------------------------------- 客户端请求开始 -------------------------------------
  93. -- 请求数据
  94. function QQBigShot_Query(human)
  95. QQBigShot_CheckCreate(human)
  96. local tMsgData = Msg.gc.GC_QQ_BIGSHOT_QUERY
  97. tMsgData.tItemData[0] = 0
  98. for nID, v in ipairs(QQBigShouCong.Sheet1) do
  99. tMsgData.tItemData[0] = tMsgData.tItemData[0] + 1
  100. local tPrizeInfo = tMsgData.tItemData[tMsgData.tItemData[0]]
  101. tPrizeInfo.nID = v.nValue
  102. tPrizeInfo.nFirstStatus = QQBigShot_GetPrizeFirst(human, nID)
  103. tPrizeInfo.nWeekStatus = QQBigShot_GetPrizeWeek(human, nID)
  104. tPrizeInfo.tFirstlist[0] = #v.tFirstPrize
  105. for nIndex, tGoods in ipairs(v.tFirstPrize) do
  106. local itemId = tGoods[1]
  107. local itemCnt = tGoods[2]
  108. Grid.makeItem(tPrizeInfo.tFirstlist[nIndex], itemId, itemCnt)
  109. end
  110. tPrizeInfo.tWeeklist[0] = #v.tWeekPrize
  111. for nIndex, tGoods in ipairs(v.tWeekPrize) do
  112. local itemId = tGoods[1]
  113. local itemCnt = tGoods[2]
  114. Grid.makeItem(tPrizeInfo.tWeeklist[nIndex], itemId, itemCnt)
  115. end
  116. end
  117. Msg.send(tMsgData, human.fd)
  118. end
  119. -- 请求领取数据
  120. function QQBigShot_GetPrize(human, nLv)
  121. nID = tLvID2ConfID[nLv]
  122. if not QQBigShouCong.Sheet1[nID] then
  123. return
  124. end
  125. local nNowLv = QQBigShot_GetLv(human)
  126. if nLv ~= nNowLv then
  127. print("[QQBigShot_GetPrize] 当前大咖等级不匹配 nLv = "..nLv.." nNowLv = "..nNowLv)
  128. return
  129. end
  130. local tConfig = QQBigShouCong.Sheet1[nID]
  131. local nFirstStatus = QQBigShot_GetPrizeFirst(human, nID)
  132. local nWeekStatus = QQBigShot_GetPrizeWeek(human, nID)
  133. local tGoods = {}
  134. if nFirstStatus == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  135. QQBigShot_SetPrizeFirst(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET)
  136. for _, v in ipairs(tConfig.tFirstPrize) do
  137. if not tGoods[v[1]] then
  138. tGoods[v[1]] = 0
  139. end
  140. tGoods[v[1]] = tGoods[v[1]] + v[2]
  141. end
  142. end
  143. if nWeekStatus == CommonDefine.COMMON_PRIZE_STATE_CANGET then
  144. QQBigShot_SetPrizeWeek(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET)
  145. for _, v in ipairs(tConfig.tWeekPrize) do
  146. if not tGoods[v[1]] then
  147. tGoods[v[1]] = 0
  148. end
  149. tGoods[v[1]] = tGoods[v[1]] + v[2]
  150. end
  151. end
  152. if nil ~= _G.next(tGoods) then
  153. local tItem = {}
  154. for nGoodID, nGoodNum in pairs(tGoods) do
  155. table.insert(tItem, {nGoodID, nGoodNum})
  156. end
  157. BagLogic.addItemList(human, tItem, "qqbigshot")
  158. QQBigShot_Query(human)
  159. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_109)
  160. end
  161. end
  162. function QQBigShot_UpdateLv(human, nLv)
  163. QQBigShot_CheckCreate(human)
  164. local nOldLv = QQBigShot_GetLv(human)
  165. -- local nNextLv = tNextLv[nOldLv]
  166. -- if not nNextLv then
  167. -- print("[QQBigShot_UpdateLv] 不存在对应的下一等级的大咖等级 nOldLv = "..nOldLv)
  168. -- return
  169. -- end
  170. -- if nLv ~= nNextLv then
  171. -- print("[QQBigShot_UpdateLv] 要提升的等级和下一等级的配置不同 nOldLv = "..nOldLv.." nLv = "..nLv.." nNextLv = "..nNextLv)
  172. -- return
  173. -- end
  174. print("[QQBigShot_UpdateLv] 收到的nLv = "..nLv.." nOldLv = "..nOldLv)
  175. if nOldLv ~= nLv then
  176. local nID = tLvID2ConfID[nLv]
  177. if not nID then
  178. print("[QQBigShot_UpdateLv] 不正确的等级 nLv = "..nLv.." nOldLv = "..nOldLv)
  179. return
  180. end
  181. QQBigShot_SetLv(human, nLv)
  182. local nFirstStatus = QQBigShot_GetPrizeFirst(human, nID)
  183. if CommonDefine.COMMON_PRIZE_STATE_CANGET == nFirstStatus then
  184. QQBigShot_SetPrizeFirst(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  185. end
  186. QQBigShot_SetPrizeWeek(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  187. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_109)
  188. QQBigShot_Query(human)
  189. end
  190. end
  191. ----------------------------------------- 外部调用开始 -------------------------------------
  192. function onLogin(human)
  193. QQBigShot_CheckCreate(human)
  194. local nLv = QQBigShot_GetLv(human)
  195. if 0 == nLv then
  196. return
  197. end
  198. local bRet = Util.isSameWeek(human.db.qqBigShot.nResetTime, os.time())
  199. if false == bRet then
  200. local nID = tLvID2ConfID[nLv]
  201. QQBigShot_ResetWeekPrize(human, nID)
  202. end
  203. end
  204. function updateDaily(human)
  205. onLogin(human)
  206. end
  207. function isDot(human)
  208. QQBigShot_CheckCreate(human)
  209. local bRet = false
  210. for nID, v in ipairs(QQBigShouCong.Sheet1) do
  211. local nFirstStatus = QQBigShot_GetPrizeFirst(human, nID)
  212. local nWeekStatus = QQBigShot_GetPrizeWeek(human, nID)
  213. if CommonDefine.COMMON_PRIZE_STATE_CANGET == nFirstStatus or CommonDefine.COMMON_PRIZE_STATE_CANGET == nWeekStatus then
  214. bRet = true
  215. break
  216. end
  217. end
  218. return bRet
  219. end
  220. function QQBigShot_HumanLoginHandle(human, nLv)
  221. print("[QQBigShot_HumanLoginHandle] 收到数据进行处理")
  222. if not human then
  223. print("[QQBigShot_HumanLoginHandle] 不存在对应的人物")
  224. return
  225. end
  226. if not human.db then
  227. print("[QQBigShot_HumanLoginHandle] 不存在对应的人物DB数据")
  228. return
  229. end
  230. if not nLv then
  231. print("[QQBigShot_HumanLoginHandle] 不存在对应的等级")
  232. return
  233. end
  234. QQBigShot_CheckCreate(human)
  235. print("[QQBigShot_HumanLoginHandle] 获取到nLv = "..nLv)
  236. QQBigShot_UpdateLv(human, nLv)
  237. end
  238. function QQBigShot_GMReset(human)
  239. local nOldLv = QQBigShot_GetLv(human)
  240. QQBigShot_CreatDB(human)
  241. QQBigShot_UpdateLv(human, nOldLv)
  242. end