TreasureChestLogic.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. --------------------------------
  2. -- 文件名 : TreasureChestLogic.lua
  3. -- 文件说明 : 宝箱系统
  4. -- 创建时间 : 2025/03/10
  5. -- 创建人 : FC
  6. --------------------------------
  7. ---
  8. local Util = require("common.Util")
  9. local Msg = require("core.Msg")
  10. local BagLogic = require("bag.BagLogic")
  11. local Log = require("common.Log")
  12. local TreasureConf = require("excel.treasurechest")
  13. local CommonDefine = require("common.CommonDefine")
  14. local Grid = require("bag.Grid")
  15. local MainDianLogic = require("MaiDian.MaiDianLogic")
  16. local MaiDianDefine = require("MaiDian.MaiDianDefine")
  17. local TriggerDefine = require("trigger.TriggerDefine")
  18. local TriggerLogic = require("trigger.TriggerLogic")
  19. local WeekTaskLogic = require("dailyTask.WeekTaskLogic")
  20. -- 奖励缓存有序 key为宝箱类型
  21. local tCacheBoxPrize = nil
  22. -- 一次性最多打开宝箱数量
  23. local TREASURECHEST_OPEN_NUM = 9999
  24. -- 自动开宝箱解锁条件
  25. local TREASURECHEST_OPEN_AUTO_TYPE = 5 -- 钻石
  26. local TREASURECHEST_OPEN_AUTO_NUM = 2 -- 开两次
  27. local TREASURECHEST_OPEN_ONETOUCH_NUM = 10 -- 激活一键开启宝箱功能, 需要开启钻石宝箱数量
  28. ----------------------------------------- 内部处理开始 -------------------------------------
  29. -- 写日志
  30. local function TreasureChestLogic_WriteLog(human, szText)
  31. Log.write(Log.LOGID_OSS_COMMON, "name = "..human.db.name.." id = "..human.db._id..szText)
  32. end
  33. -- 获取宝箱配置
  34. local function TreasureChestLogic_GetBoxTypeConf()
  35. return TreasureConf.boxtype
  36. end
  37. -- 获取宝箱积分配置
  38. local function TreasureChestLogic_GetPointConf()
  39. return TreasureConf.boxpoint
  40. end
  41. -- 重置积分奖励数据
  42. local function TreasureChestLogic_ResetDBPointPrize(human)
  43. local tBoxPoint = TreasureChestLogic_GetPointConf()
  44. for key, v in pairs(tBoxPoint) do
  45. human.db.TreasureChest.tPointPrize[key] = CommonDefine.COMMON_PRIZE_STATE_NOGET
  46. end
  47. end
  48. -- 创建DB数据
  49. local function TreasureChestLogic_CreateDB(human)
  50. human.db.TreasureChest = {
  51. nPoint = 0,
  52. nOpenNum = 0,
  53. tPointPrize = {},
  54. tItem = {}, -- 宝箱数量
  55. openBoxSumNum = 0, -- 开启宝箱总数量
  56. }
  57. TreasureChestLogic_ResetDBPointPrize(human)
  58. end
  59. -- 获取开启总宝箱数量
  60. local function TreasureChestLogic_GetDBOpenBoxSumNum(human)
  61. if not human.db.TreasureChest then
  62. TreasureChestLogic_CreateDB(human)
  63. end
  64. return human.db.TreasureChest.openBoxSumNum
  65. end
  66. -- 增加宝箱开启数量
  67. local function TreasureChestLogic_AddDBOpenBoxSumNum(human, nValue)
  68. if not human.db.TreasureChest then
  69. TreasureChestLogic_CreateDB(human)
  70. end
  71. human.db.TreasureChest.openBoxSumNum = (human.db.TreasureChest.openBoxSumNum or 0) + nValue
  72. end
  73. -- 获取宝箱奖励配置
  74. local function TreasureChestLogic_GetPointPrizeConf(human)
  75. local openBoxSumNum = TreasureChestLogic_GetDBOpenBoxSumNum(human)
  76. --if not tCacheBoxPrize then
  77. tCacheBoxPrize = {}
  78. for _, v in pairs(TreasureConf.boxprize) do
  79. local nType = v.nType
  80. if not tCacheBoxPrize[nType] then
  81. tCacheBoxPrize[nType] = {}
  82. end
  83. -- table.insert(tCacheBoxPrize[nType], v)
  84. if openBoxSumNum >= v.count then
  85. table.insert(tCacheBoxPrize[nType], v)
  86. end
  87. end
  88. -- 变成有序
  89. for _, v in pairs(tCacheBoxPrize) do
  90. table.sort(v, function (l, r)
  91. return l.nPro < r.nPro
  92. end)
  93. end
  94. -- 整合权重
  95. for _, data in ipairs(tCacheBoxPrize) do
  96. local nAllWeight = 0
  97. for _, v in ipairs(data) do
  98. if nAllWeight == 0 then
  99. nAllWeight = v.nPro
  100. else
  101. nAllWeight = nAllWeight + v.nPro
  102. end
  103. v.nAllPro = nAllWeight
  104. end
  105. end
  106. --end
  107. return tCacheBoxPrize
  108. end
  109. -- 获取当前积分
  110. local function TreasureChestLogic_GetDBPoint(human)
  111. if not human.db.TreasureChest then
  112. TreasureChestLogic_CreateDB(human)
  113. end
  114. return human.db.TreasureChest.nPoint
  115. end
  116. -- 设置当前积分
  117. local function TreasureChestLogic_SetDBPoint(human, nValue)
  118. if not human.db.TreasureChest then
  119. TreasureChestLogic_CreateDB(human)
  120. end
  121. human.db.TreasureChest.nPoint = nValue
  122. end
  123. -- 获取当前积分奖励状态
  124. local function TreasureChestLogic_GetDBPointPrize(human, nID)
  125. if not human.db.TreasureChest then
  126. TreasureChestLogic_CreateDB(human)
  127. end
  128. return human.db.TreasureChest.tPointPrize[nID]
  129. end
  130. -- 设置当前积分奖励状态
  131. local function TreasureChestLogic_SetDBPointPrize(human, nID, nState)
  132. if not human.db.TreasureChest then
  133. TreasureChestLogic_CreateDB(human)
  134. end
  135. human.db.TreasureChest.tPointPrize[nID] = nState
  136. end
  137. -- 更新积分奖励状态
  138. local function TreasureChestLogic_UpdatePointPrize(human)
  139. local nNowPoint = TreasureChestLogic_GetDBPoint(human)
  140. local tBoxPointCof = TreasureChestLogic_GetPointConf()
  141. for nID, v in ipairs(tBoxPointCof) do
  142. local nState = TreasureChestLogic_GetDBPointPrize(human, nID)
  143. if nNowPoint >= v.nPoint then
  144. --print("[TreasureChestLogic_UpdatePointPrize] nID = "..nID.." nNowPoint "..nNowPoint.." nPoint "..v.nPoint.." nState "..nState)
  145. if CommonDefine.COMMON_PRIZE_STATE_NOGET == nState then
  146. TreasureChestLogic_SetDBPointPrize(human, nID, CommonDefine.COMMON_PRIZE_STATE_CANGET)
  147. nNowPoint = nNowPoint - v.nPoint
  148. elseif CommonDefine.COMMON_PRIZE_STATE_CANGET == nState then
  149. nNowPoint = nNowPoint - v.nPoint
  150. end
  151. else
  152. if CommonDefine.COMMON_PRIZE_STATE_NOGET == nState then
  153. break
  154. end
  155. end
  156. end
  157. end
  158. -- 打开宝箱操作
  159. local function TreasureChestLogic_OpenBox(human, nType, nBoxNum)
  160. local tBoxTypeConf = TreasureChestLogic_GetBoxTypeConf()
  161. local tBoxPrize = TreasureChestLogic_GetPointPrizeConf(human)
  162. if not tBoxTypeConf[nType] or not tBoxPrize[nType] then
  163. return nil
  164. end
  165. local nOpenNum = tBoxTypeConf[nType].nOpenNum
  166. -- 获取的表是有序的
  167. local tBoxTypePrize = tBoxPrize[nType]
  168. local nLen = #tBoxTypePrize
  169. local nAllWeight = tBoxTypePrize[nLen].nAllPro
  170. --print("[TreasureChestLogic_OpenBox] nAllWeight = "..nAllWeight)
  171. local tOpenPrize = {}
  172. for i = 1, nBoxNum, 1 do
  173. for j = 1, nOpenNum, 1 do
  174. -- 随机权重
  175. local nRandNum = math.random(1, nAllWeight)
  176. --print("[TreasureChestLogic_OpenBox] j = "..j.." nRandNum = "..nRandNum)
  177. for _, v in pairs(tBoxTypePrize) do
  178. --print("[TreasureChestLogic_OpenBox] nAllPro = "..v.nAllPro.." ID = "..v.tPrize[1].." num = "..v.tPrize[2].."\n")
  179. if nRandNum <= v.nAllPro then
  180. table.insert(tOpenPrize, v.tPrize)
  181. --print("[TreasureChestLogic_OpenBox] 获得的道具 nID = "..v.tPrize[1].." nNum = "..v.tPrize[2].." nKey "..v.nAllPro)
  182. TreasureChestLogic_AddDBOpenBoxSumNum(human, 1)
  183. break
  184. end
  185. end
  186. tBoxPrize = TreasureChestLogic_GetPointPrizeConf(human)
  187. tBoxTypePrize = tBoxPrize[nType]
  188. nLen = #tBoxTypePrize
  189. nAllWeight = tBoxTypePrize[nLen].nAllPro
  190. end
  191. end
  192. return tOpenPrize
  193. end
  194. -- 获取宝箱数量
  195. local function TreasureChestLogic_GetGoodsNum(human, nGoodsID)
  196. if not human.db.TreasureChest.tItem[nGoodsID] then
  197. human.db.TreasureChest.tItem[nGoodsID] = 0
  198. end
  199. return human.db.TreasureChest.tItem[nGoodsID]
  200. end
  201. -- 添加宝箱物品
  202. local function TreasureChestLogic_AddGoods(human, nGoodsID, nGoodsNum)
  203. if not human.db.TreasureChest.tItem[nGoodsID] then
  204. human.db.TreasureChest.tItem[nGoodsID] = 0
  205. end
  206. human.db.TreasureChest.tItem[nGoodsID] = human.db.TreasureChest.tItem[nGoodsID] + nGoodsNum
  207. end
  208. -- 删除物品
  209. local function TreasureChestLogic_DelGoods(human, nGoodsID, nGoodsNum)
  210. human.db.TreasureChest.tItem[nGoodsID] = human.db.TreasureChest.tItem[nGoodsID] - nGoodsNum
  211. if 0 > human.db.TreasureChest.tItem[nGoodsID] then
  212. human.db.TreasureChest.tItem[nGoodsID] = 0
  213. end
  214. TreasureChestLogic_WriteLog(human, "减少了宝箱道具 nItemID "..nGoodsID.." nDelNum "..nGoodsNum)
  215. end
  216. -- 获取当前打开的钻石宝箱数量
  217. local function TreasureChestLogic_GetAutoOpenNum(human)
  218. if not human.db.TreasureChest then
  219. TreasureChestLogic_CreateDB(human)
  220. end
  221. return human.db.TreasureChest.nOpenNum
  222. end
  223. -- 记录打开钻石宝箱数量
  224. local function TreasureChestLogic_AddAutoNum(human, nType, nNum)
  225. if TREASURECHEST_OPEN_AUTO_TYPE ~= nType then
  226. print("[TreasureChestLogic_AddAutoNum] 类型不正确返回")
  227. return
  228. end
  229. -- local nNowNum = TreasureChestLogic_GetAutoOpenNum(human)
  230. -- if TREASURECHEST_OPEN_AUTO_NUM <= nNowNum then
  231. -- print("[TreasureChestLogic_AddAutoNum] 数量已经足够 nNowNum = "..nNowNum)
  232. -- return
  233. -- end
  234. local nNowNum = TreasureChestLogic_GetAutoOpenNum(human)
  235. if TREASURECHEST_OPEN_ONETOUCH_NUM <= nNowNum then
  236. print("[TreasureChestLogic_AddAutoNum] 数量已经足够 nNowNum = "..nNowNum)
  237. return
  238. end
  239. human.db.TreasureChest.nOpenNum = human.db.TreasureChest.nOpenNum + nNum
  240. if human.db.TreasureChest.nOpenNum >= TREASURECHEST_OPEN_ONETOUCH_NUM then
  241. TreasureChestLogic_Query(human)
  242. end
  243. end
  244. -- 处理老数据
  245. local function openBoxSumNumCheck(human)
  246. local num = TreasureChestLogic_GetDBOpenBoxSumNum(human)
  247. if not num then
  248. TreasureChestLogic_AddDBOpenBoxSumNum(human, 2300)
  249. end
  250. end
  251. ----------------------------------------- 客户端请求 -------------------------------------
  252. -- 请求宝箱界面信息
  253. function TreasureChestLogic_Query(human)
  254. if not human then
  255. return
  256. end
  257. if not human.db.TreasureChest then
  258. TreasureChestLogic_CreateDB(human)
  259. end
  260. TreasureChestLogic_UpdatePointPrize(human)
  261. -- table.print_lua_table(human.db.TreasureChest)
  262. -- print("\n")
  263. --local nOpenNum = TreasureChestLogic_GetAutoOpenNum(human)
  264. local tMsgData = Msg.gc.GC_TEEASURECHEST_QUERY
  265. tMsgData.nNowPoint = TreasureChestLogic_GetDBPoint(human)
  266. -- tMsgData.nAuto = TreasureChestLogic_GetAutoOpenNum(human) >= TREASURECHEST_OPEN_AUTO_NUM and 1 or 0
  267. tMsgData.nAuto = 1 --改为默认开启
  268. tMsgData.nOneTouch = TreasureChestLogic_GetAutoOpenNum(human) >= TREASURECHEST_OPEN_ONETOUCH_NUM and 1 or 0
  269. tMsgData.nID = 0
  270. tMsgData.nNextPoint = 0
  271. tMsgData.nState = 0
  272. local tBoxPointConf = TreasureChestLogic_GetPointConf()
  273. local tBoxTypeConf = TreasureChestLogic_GetBoxTypeConf()
  274. --print("[TreasureChestLogic_Query] nAuto = "..tMsgData.nAuto.." num = "..nOpenNum)
  275. -- 下一阶段需要的积分信息
  276. for nID, v in ipairs(tBoxPointConf) do
  277. local nState = TreasureChestLogic_GetDBPointPrize(human, nID)
  278. if CommonDefine.COMMON_PRIZE_STATE_NOGET == nState or CommonDefine.COMMON_PRIZE_STATE_CANGET == nState then
  279. tMsgData.nID = nID
  280. tMsgData.nNextPoint = v.nPoint
  281. tMsgData.nState = nState
  282. Grid.makeItem(tMsgData.tPointPirze, v.tPrize[1], v.tPrize[2])
  283. break
  284. end
  285. end
  286. -- 奖励信息
  287. local nLen = 0
  288. for nType, v in pairs(tBoxTypeConf) do
  289. nLen = nLen + 1
  290. tMsgData.tList[0] = nLen
  291. local tData = tMsgData.tList[nLen]
  292. tData.nType = nType
  293. local nGoodsID = v.nItemID
  294. local nGoodsNum = TreasureChestLogic_GetGoodsNum(human, nGoodsID)
  295. Grid.makeItem(tData.tItemData, nGoodsID, nGoodsNum)
  296. end
  297. Msg.send(tMsgData, human.fd)
  298. end
  299. -- 请求宝箱内奖励信息
  300. function TreasureChestLogic_QueryPrize(human, nBoxType)
  301. local tBoxPrize = TreasureChestLogic_GetPointPrizeConf()
  302. if not tBoxPrize[nBoxType] then
  303. print("[TreasureChestLogic_QueryPrize] 不存在对应的奖励配置 nBoxType = "..nBoxType)
  304. return
  305. end
  306. local tBoxTypePrize = tBoxPrize[nBoxType]
  307. local tMsgData = Msg.gc.GC_TEEASURECHEST_PRIZE_QUERY
  308. local nLen = 0
  309. tMsgData.tItemData[0] = nLen
  310. for _, v in pairs(tBoxTypePrize) do
  311. nLen = nLen + 1
  312. tMsgData.tItemData[0] = nLen
  313. local tData = tMsgData.tItemData[nLen]
  314. local nGoodsID = v.prize[1]
  315. local nGoodsNum = v.prize[2]
  316. local quality = v.prize[3]
  317. Grid.makeItem(tData, nGoodsID, nGoodsNum, nil, nil, nil, nil, quality)
  318. end
  319. Msg.send(tMsgData, human.fd)
  320. end
  321. -- 请求打开宝箱
  322. function TreasureChestLogic_Open(human, nBoxType, nBoxNum)
  323. openBoxSumNumCheck(human)
  324. print("[TreasureChestLogic_Open]玩家当前请求打开的宝箱类型 ntyepe = "..nBoxType)
  325. local szText = "[TreasureChestLogic_Open] 玩家请求打开宝箱 nBoxType = "..nBoxType.." nBoxNum = "..nBoxNum
  326. TreasureChestLogic_WriteLog(human, szText)
  327. if nBoxNum >= TREASURECHEST_OPEN_NUM or 0 >= nBoxNum then
  328. szText = szText .. " 失败不正确的打开数量 nBoxNum "..nBoxNum
  329. TreasureChestLogic_WriteLog(human, szText)
  330. return
  331. end
  332. -- 检测配置
  333. local tBoxTypeConf = TreasureChestLogic_GetBoxTypeConf()
  334. if not tBoxTypeConf[nBoxType] then
  335. print("[TreasureChestLogic_Open] 不存在对应的宝箱类型 nBoxType = "..nBoxType)
  336. szText = szText.." 失败不存在对应宝箱类型"
  337. TreasureChestLogic_WriteLog(human, szText)
  338. return
  339. end
  340. local nGoodsID = tBoxTypeConf[nBoxType].nItemID
  341. local nGoodsNum = TreasureChestLogic_GetGoodsNum(human, nGoodsID)
  342. if nBoxNum > nGoodsNum or 0 >= nGoodsNum then
  343. print("[TreasureChestLogic_Open] 玩家拥有宝箱数量不足 nBoxType = "
  344. ..nBoxType.." nBoxNum = "..nBoxNum.." nGoodsNum = "..nGoodsNum)
  345. szText = szText.." 数量不正确 nGoodsNum = "..nGoodsNum
  346. TreasureChestLogic_WriteLog(human, szText)
  347. return
  348. end
  349. local tPrize = TreasureChestLogic_OpenBox(human, nBoxType, nBoxNum)
  350. -- 发送奖励
  351. BagLogic.addItemList(human, tPrize, "treasurechest")
  352. --BagLogic.sendItemGetList(human, tPrize, "treasurechest")
  353. szText = szText .." 发送奖励成功"
  354. TreasureChestLogic_WriteLog(human, szText)
  355. -- 加积分
  356. local nAddPoint = nBoxNum * tBoxTypeConf[nBoxType].nPoint
  357. local nNowPoint = TreasureChestLogic_GetDBPoint(human)
  358. nNowPoint = nAddPoint + nNowPoint
  359. TreasureChestLogic_SetDBPoint(human, nNowPoint)
  360. szText = szText.." 增加积分 nAddPoint = "..nAddPoint.." nNowPoint = "..nNowPoint
  361. TreasureChestLogic_WriteLog(human, szText)
  362. -- 删除使用了的物品
  363. TreasureChestLogic_DelGoods(human, nGoodsID, nBoxNum)
  364. -- 更新积分奖励状态
  365. TreasureChestLogic_UpdatePointPrize(human)
  366. MainDianLogic.MaiDian_Begin(human, MaiDianDefine.MAIDIAN_TYPE_CHEST_OPEN,{nValue = nBoxNum})
  367. if TREASURECHEST_OPEN_AUTO_TYPE == nBoxType then
  368. TreasureChestLogic_AddAutoNum(human, nBoxType, nBoxNum)
  369. end
  370. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_OPENBOX, human.db._id, nBoxNum,nBoxType)
  371. print("TreasureChestLogic..当前已经进入商业活动注册事件",nBoxType)
  372. --周任务开启宝箱
  373. WeekTaskLogic.recordWeekTaskFinishCnt(human, WeekTaskLogic.WEEK_TASK_ID_5, nBoxNum)
  374. TreasureChestLogic_Query(human)
  375. TreasureChestLogic_GetAllBoxNum(human)
  376. end
  377. -- 请求自动打开宝箱
  378. function TreasureChestLogic_AutoOpen(human, nBoxType)
  379. local szText = "[TreasureChestLogic_AutoOpen] 玩家请求打开宝箱开始 nBoxType = "..nBoxType
  380. local tBoxTypeConf = TreasureChestLogic_GetBoxTypeConf()
  381. if not tBoxTypeConf[nBoxType] then
  382. print("[TreasureChestLogic_AutoOpen] 不存在对应的宝箱类型 nBoxType = "..nBoxType)
  383. szText = szText.." 失败不存在对应宝箱类型"
  384. TreasureChestLogic_WriteLog(human, szText)
  385. return
  386. end
  387. local nGoodsID = tBoxTypeConf[nBoxType].nItemID
  388. local nGoodsNum = TreasureChestLogic_GetGoodsNum(human, nGoodsID)
  389. if 0 >= nGoodsNum then
  390. return
  391. end
  392. -- 改为默认开启
  393. -- if TreasureChestLogic_GetAutoOpenNum(human) < TREASURECHEST_OPEN_AUTO_NUM then
  394. -- return
  395. -- end
  396. TreasureChestLogic_WriteLog(human, szText)
  397. TreasureChestLogic_Open(human, nBoxType, 1)
  398. TreasureChestLogic_GetAllBoxNum(human)
  399. end
  400. -- 请求领取积分奖励
  401. function TreasureChestLogic_GetPointPrize(human, nID)
  402. local szText = "[TreasureChestLogic_GetPointPrize] 玩家请求领取积分奖励 nID = "..nID
  403. local tPointPrize = TreasureChestLogic_GetPointConf()
  404. if not tPointPrize[nID] then
  405. print("[TreasureChestLogic_GetPointPrize] 不存在对应的积分ID nID = "..nID)
  406. return
  407. end
  408. -- 积分检测
  409. local nNowPoint = TreasureChestLogic_GetDBPoint(human)
  410. if nNowPoint < tPointPrize[nID].nPoint then
  411. print("[TreasureChestLogic_GetPointPrize] 玩家当前积分不足 nNowPoint = "
  412. ..nNowPoint.." nNeedPoint = "..tPointPrize[nID].nPoint)
  413. return
  414. end
  415. local nState = TreasureChestLogic_GetDBPointPrize(human, nID)
  416. if CommonDefine.COMMON_PRIZE_STATE_CANGET ~= nState then
  417. print("[TreasureChestLogic_GetPointPrize] 玩家奖励状态不正确 nNowPoint = "
  418. ..nNowPoint.." nState = "..nState.."nID = "..nID)
  419. return
  420. end
  421. local tGoodsInfo =
  422. {
  423. [tPointPrize[nID].tPrize[1]] = tPointPrize[nID].tPrize[2]
  424. }
  425. -- 添加奖励
  426. BagLogic.addItemList(human, tGoodsInfo, "treasurechest")
  427. -- BagLogic.sendItemGetList(human, tGoodsInfo, "treasurechest")
  428. TreasureChestLogic_SetDBPointPrize(human, nID, CommonDefine.COMMON_PRIZE_STATE_GET)
  429. local szSendPrize = szText .. " 发送奖励成功 nGoodsID = "..tPointPrize[nID].tPrize[1]
  430. .." nGoodsNum = "..tPointPrize[nID].tPrize[2]
  431. TreasureChestLogic_WriteLog(human, szSendPrize)
  432. -- 改变积分
  433. local nNewPoint = nNowPoint - tPointPrize[nID].nPoint
  434. TreasureChestLogic_SetDBPoint(human, nNewPoint)
  435. local szPointPrize = szText.." nNowPoint = "..nNowPoint.." nDelPoint = "
  436. ..tPointPrize[nID].nPoint.." nNewPoint = "..nNewPoint
  437. TreasureChestLogic_WriteLog(human, szPointPrize)
  438. if 0 == tPointPrize[nID].nNextID then
  439. TreasureChestLogic_ResetDBPointPrize(human)
  440. local szResetText = szText.." 玩家领取完最后的奖励进行重置"
  441. TreasureChestLogic_WriteLog(human, szResetText)
  442. end
  443. -- 更新积分奖励状态
  444. TreasureChestLogic_UpdatePointPrize(human)
  445. TreasureChestLogic_Query(human)
  446. TreasureChestLogic_GetAllBoxNum(human)
  447. end
  448. --请求一件开启宝箱
  449. function TreasureChestLogic_OneTouchOpen(human)
  450. local boxCfg = TreasureChestLogic_GetBoxTypeConf()
  451. for boxType, boxInfo in ipairs(boxCfg) do
  452. local nGoodsID = boxInfo.nItemID
  453. local nGoodsNum = TreasureChestLogic_GetGoodsNum(human, nGoodsID)
  454. if nGoodsNum > 0 then
  455. TreasureChestLogic_Open(human, boxType, nGoodsNum)
  456. end
  457. end
  458. TreasureChestLogic_GetAllBoxNum(human)
  459. end
  460. function TreasureChestLogic_GmClear(human)
  461. TreasureChestLogic_CreateDB(human)
  462. end
  463. -- 增加道具
  464. function TreasureChestLogic_AddItem(human, nItemID, nAddNum)
  465. if not human.db.TreasureChest then
  466. TreasureChestLogic_CreateDB(human)
  467. end
  468. if 0 >= nAddNum then
  469. return
  470. end
  471. TreasureChestLogic_AddGoods(human, nItemID, nAddNum)
  472. TreasureChestLogic_WriteLog(human, "增加了宝箱道具 nItemID "..nItemID.." nAddNum "..nAddNum)
  473. end
  474. -- 购买终身月卡解锁自动开宝箱
  475. function TreasureChestLogic_BuyOpenAuto(human)
  476. --local nOpenNum = TreasureChestLogic_GetAutoOpenNum(human)
  477. --print("[TreasureChestLogic_BuyOpenAuto] nOpenNum = "..nOpenNum)
  478. -- TreasureChestLogic_AddAutoNum(human, TREASURECHEST_OPEN_AUTO_TYPE, TREASURECHEST_OPEN_AUTO_NUM)
  479. TreasureChestLogic_AddAutoNum(human, TREASURECHEST_OPEN_AUTO_TYPE, TREASURECHEST_OPEN_ONETOUCH_NUM)
  480. end
  481. function TreasureChestLogic_GetAllBoxNum(human)
  482. if not human.db.TreasureChest then
  483. TreasureChestLogic_CreateDB(human)
  484. end
  485. local tBoxTypeConf = TreasureChestLogic_GetBoxTypeConf()
  486. local tMsgData = Msg.gc.GC_GET_ALL_GJBOX_NUM
  487. local nAllNum = 0
  488. for nType, v in pairs(tBoxTypeConf) do
  489. local nGoodsID = v.nItemID
  490. local nGoodsNum = TreasureChestLogic_GetGoodsNum(human, nGoodsID)
  491. nAllNum = nAllNum + nGoodsNum
  492. end
  493. tMsgData.nAllNum = nAllNum
  494. Msg.send(tMsgData, human.fd)
  495. end