TreasureChestLogic.lua 19 KB

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