SpecificLogic.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. --金币礼包/通用特殊购买。。。
  2. local Util = require("common.Util")
  3. local Log = require("common.Log")
  4. local Lang = require("common.Lang")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local PresentExcel = require("excel.present")
  8. local BuyExcel = require("excel.buy")
  9. local BuyLogic = require("topup.BuyLogic")
  10. local HeroLogic = require("hero.HeroLogic")
  11. local BagLogic = require("bag.BagLogic")
  12. local Grid = require("bag.Grid")
  13. local Broadcast = require("broadcast.Broadcast")
  14. local SceneHandler = require("scene.Handler")
  15. local function fontSpecificNet(net, human, id)
  16. local config = PresentExcel.specificShop[id]
  17. net.id = id
  18. net.order = config.order
  19. Grid.makeItem(net.item, config.itemId, config.cnt)
  20. BuyLogic.fontBuyItem(human, net.buyItem, config.buyID)
  21. net.vipexp = config.vipExp
  22. end
  23. function query(human, id)
  24. local specificConf = PresentExcel.specific[id]
  25. if specificConf == nil then
  26. return
  27. end
  28. local msgRet = Msg.gc.GC_SPECIFIC_QUERY
  29. local net = msgRet.data
  30. net.id = id
  31. net.needZuanshi = specificConf.needZhuanShi
  32. local itemID = specificConf.reward[1] or 0
  33. local itemCnt = specificConf.reward[2] or 0
  34. net.reward[0] = 0
  35. if itemID > 0 then
  36. net.reward[0] = 1
  37. Grid.makeItem(net.reward[1], itemID, itemCnt)
  38. end
  39. net.list[0] = 0
  40. for _, spid in pairs(specificConf.shopId) do
  41. net.list[0] = net.list[0] + 1
  42. fontSpecificNet(net.list[net.list[0]], human, spid)
  43. end
  44. --Msg.trace(msgRet)
  45. Msg.send(msgRet,human.fd)
  46. end
  47. function buy(human, id, buyCnt)
  48. if buyCnt > 30000 or buyCnt <= 0 then
  49. return
  50. end
  51. local specificConf = PresentExcel.specific[id]
  52. if specificConf == nil then
  53. return
  54. end
  55. if specificConf.reward[1] == nil then
  56. return -- 不卖东西哦
  57. end
  58. local needZs = specificConf.needZhuanShi
  59. -- 钻石判断
  60. local needZuanshi = buyCnt * needZs
  61. if human.db.zuanshi < needZuanshi then
  62. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  63. end
  64. -- 扣钻石
  65. ObjHuman.decZuanshi(human, -needZuanshi, "buySpecific")
  66. local itemID = specificConf.reward[1]
  67. local itemCnt = specificConf.reward[2] * buyCnt
  68. BagLogic.cleanMomentItemList()
  69. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, itemID, itemCnt)
  70. BagLogic.addMomentItemList(human, "buySpecific")
  71. query(human, id)
  72. end
  73. function isOpen(human)
  74. if not SceneHandler.canCharge(human) then
  75. return
  76. end
  77. return true
  78. end