QQBigShot.lua 8.7 KB

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