BoxLogic.lua 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. ----------------------------------------------------------
  2. -- 宝箱
  3. ----------------------------------------------------------
  4. local Msg = require("core.Msg")
  5. local Util = require("common.Util")
  6. local Lang = require("common.Lang")
  7. local Grid = require("bag.Grid")
  8. local BagLogic = require("bag.BagLogic")
  9. local ItemLogic = require("bag.ItemLogic")
  10. local ItemDefine = require("bag.ItemDefine")
  11. local Broadcast = require("broadcast.Broadcast")
  12. -- 发送自选宝箱列表
  13. function sendBoxList(human, list)
  14. local msgRet = Msg.gc.GC_BOX_QUERY
  15. msgRet.item[0] = list and #list or 0
  16. for i = 1, msgRet.item[0] do
  17. local itemID = list[i][1]
  18. local itemCnt = list[i][2]
  19. local quality = list[i][3]
  20. Grid.makeItem(msgRet.item[i], itemID, itemCnt, nil, nil, nil, nil, quality)
  21. end
  22. --Msg.trace(msgRet)
  23. Msg.send(msgRet, human.fd)
  24. end
  25. -- 自选宝箱-选择道具
  26. function getBoxItem(human, itemID, sIndex, cnt)
  27. local itemConfig = ItemDefine.getConfig(itemID)
  28. if not itemConfig then
  29. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CONFIG)
  30. end
  31. local cmdstr = itemConfig.cmd and itemConfig.cmd[1]
  32. if cmdstr ~= "box" then return end
  33. -- 检测数量
  34. local haveCnt = BagLogic.getItemCnt(human, itemID)
  35. if haveCnt <= 0 or haveCnt < cnt or cnt <= 0 then
  36. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CONFIG)
  37. end
  38. local itemList = itemConfig.cmd[2]
  39. if not itemList[sIndex] then return end
  40. local sItemID = itemList[sIndex][1]
  41. local sItemCnt = itemList[sIndex][2]
  42. local quality = itemList[sIndex][3]
  43. if ItemDefine.getConfig(sItemID) == nil then
  44. return Broadcast.sendErr(human, Lang.ITEM_USE_ERR_CONFIG)
  45. end
  46. BagLogic.delItem(human, itemID, cnt, "item_use")
  47. local itemList = {}
  48. itemList[1] = {sItemID, sItemCnt * cnt, quality}
  49. BagLogic.addItemList(human, itemList, "useBox")
  50. ItemLogic.sendItemUse(human, itemID)
  51. end