OpenServerGiftPackage.lua 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. local Msg = require("core.Msg")
  2. local Util = require("common.Util")
  3. local Lang = require("common.Lang")
  4. local BagLogic = require("bag.BagLogic")
  5. local YunYingLogic = require("yunying.YunYingLogic")
  6. local OpenActExcel = require("excel.openAct")
  7. local BuyLogic = require("topup.BuyLogic")
  8. local Grid = require("bag.Grid")
  9. local OpenAct = require("present.OpenAct")
  10. local Broadcast = require("broadcast.Broadcast")
  11. local function OpenServerGiftPackage_CreatDB(human)
  12. human.db.OpenServerGiftPackage = {}
  13. for nID, v in ipairs(OpenActExcel.OpenGiftPackage) do
  14. human.db.OpenServerGiftPackage[nID] = v.amount
  15. end
  16. end
  17. local function OpenServerGiftPackage_CheckDB(human)
  18. if not human.db.OpenServerGiftPackage then
  19. OpenServerGiftPackage_CreatDB(human)
  20. end
  21. end
  22. local function OpenServerGiftPackage_GetNum(human, nID)
  23. if not human.db.OpenServerGiftPackage[nID] then
  24. if OpenActExcel.OpenGiftPackage[nID] then
  25. human.db.OpenServerGiftPackage[nID] = OpenActExcel.OpenGiftPackage[nID].amount
  26. end
  27. else
  28. return 0
  29. end
  30. return human.db.OpenServerGiftPackage[nID]
  31. end
  32. local function OpenServerGiftPackage_SetNum(human, nID, nNum)
  33. human.db.OpenServerGiftPackage[nID] = human.db.OpenServerGiftPackage[nID] + nNum
  34. end
  35. function OpenServerGiftPackage_Query(human)
  36. OpenServerGiftPackage_CheckDB(human)
  37. local tMsgData = Msg.gc.GC_OPENSERVER_GIFTPACKAGE_QUERY
  38. tMsgData.tList[0] = #OpenActExcel.OpenGiftPackage
  39. for nID, v in ipairs(OpenActExcel.OpenGiftPackage) do
  40. local tData = tMsgData.tList[nID]
  41. tData.nID = nID
  42. tData.nMaxCnt = v.amount
  43. tData.nNowCnt = OpenServerGiftPackage_GetNum(human)
  44. BuyLogic.fontBuyItem(human, tData.tBuyInfo, v.buyID)
  45. tData.tItemList[0] = #v.rewards
  46. for i, tItem in ipairs(v.rewards) do
  47. Grid.makeItem(tData.tItemList[i], tItem[1], tItem[2])
  48. end
  49. end
  50. Msg.send(tMsgData, human.fd)
  51. end
  52. function onCharge(human, nBuyID)
  53. local tItem, nChoseID = nil, nil
  54. for nID, v in ipairs(OpenActExcel.OpenGiftPackage) do
  55. if v.buyID == nBuyID then
  56. nChoseID = nID
  57. tItem = v.rewards
  58. end
  59. end
  60. if nChoseID and tItem then
  61. local nNowCnt = OpenServerGiftPackage_GetNum(human, nChoseID)
  62. if nNowCnt > 0 then
  63. OpenServerGiftPackage_SetNum(human, nChoseID, -1)
  64. BagLogic.addItemList(human, tItem, "OpenServerGiftPackage")
  65. end
  66. end
  67. end
  68. function isRed(human)
  69. return false
  70. end
  71. function isActive(human, YYInfo, funcConfig)
  72. return not isOpen(human, YYInfo, funcConfig)
  73. end
  74. function isBaseOpen(human, YYInfo, funcConfig, noSend)
  75. if human.db.lv < funcConfig.openLv then
  76. if not noSend then
  77. local str = Util.format(Lang.ROLE_LEV_ERROR, funcConfig.openLv)
  78. return Broadcast.sendErr(human, str)
  79. end
  80. end
  81. local flag = OpenAct.getOpenActTime(funcConfig.param)
  82. if not flag then return end
  83. return true
  84. end
  85. function isOpen(human, YYInfo, funcConfig)
  86. if isBaseOpen(human, YYInfo, funcConfig, true) then return true end
  87. end