ActCustomizeLogic.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. local Msg = require("core.Msg")
  2. local PresentExcel = require("excel.present")
  3. local Grid = require("bag.Grid")
  4. local BagLogic = require("bag.BagLogic")
  5. local BuyLogic = require("topup.BuyLogic")
  6. local ItemDefine = require("bag.ItemDefine")
  7. -- 登录推送
  8. function onLogin(human)
  9. local msgRet = Msg.gc.GC_ACT_CUSTOMIZE_OPEN
  10. msgRet.isOpen = checkActIsOpen(human)
  11. Msg.send(msgRet,human.fd)
  12. if checkActIsOpen(human) == 1 then
  13. initHeroRiseDB(human)
  14. end
  15. end
  16. -- 检查活动是否开启
  17. function checkActIsOpen(human)
  18. if human.db.lv < 15 then
  19. return 0
  20. end
  21. -- todo
  22. return 1
  23. end
  24. -- 初始化数据
  25. function initCustomizeDB(human)
  26. if human.db.customize ~= nil then
  27. return
  28. end
  29. local now = os.time()
  30. human.db.customize = {}
  31. local config = PresentExcel.customizeGift
  32. local len = #config
  33. for i = 1,len do
  34. human.db.customize[i] = human.db.customize[i] or {}
  35. human.db.customize[i].cnt = 0
  36. human.db.customize[i].item = {}
  37. human.db.customize[i].selectItem = {}
  38. end
  39. end
  40. function customizeQuery(human)
  41. local isOpen = checkActIsOpen(human)
  42. if isOpen == 0 then
  43. return
  44. end
  45. if human.db.customize == nil then
  46. return
  47. end
  48. local msgRet = Msg.gc.GC_ACT_CUSTOMIZE_QUERY
  49. local config = PresentExcel.customizeGift
  50. local len = #config
  51. for i = 1,len do
  52. local v = config[i]
  53. local net = msgRet.giftList[i]
  54. net.id = i
  55. net.name = v.name
  56. net.limitCnt = v.limitCnt
  57. net.nowCnt = human.db.customize[i].cnt
  58. BuyLogic.fontBuyItem(human, net.buyItem, v.buyID)
  59. Grid.makeItem(net.zuanshi,ItemDefine.ITEM_ZUANSHI_ID,v.zuanshi)
  60. local cnt = 0
  61. for itemID,itemCnt in pairs(human.db.customize[i].item) do
  62. cnt = cnt + 1
  63. Grid.makeItem(net.item[cnt],itemID,itemCnt)
  64. end
  65. net.item[0] = cnt
  66. local warehouseLen = #v.first
  67. for j = 1,warehouseLen do
  68. local itemID = v.first[j][1]
  69. local itemCnt = v.first[j][2]
  70. Grid.makeItem(net.first[j],itemID,itemCnt)
  71. end
  72. net.first[0] = warehouseLen
  73. warehouseLen = #v.second
  74. for j = 1,warehouseLen do
  75. local itemID = v.second[j][1]
  76. local itemCnt = v.second[j][2]
  77. Grid.makeItem(net.second[j],itemID,itemCnt)
  78. end
  79. net.second[0] = warehouseLen
  80. warehouseLen = #v.third
  81. for j = 1,warehouseLen do
  82. local itemID = v.third[j][1]
  83. local itemCnt = v.third[j][2]
  84. Grid.makeItem(net.third[j],itemID,itemCnt)
  85. end
  86. net.third[0] = warehouseLen
  87. end
  88. end
  89. function selectItem(human,id,first,second,third)
  90. local msgRet = Msg.gc.GC_ACT_CUSTOMIZE_SELECT
  91. msgRet.ret = 1
  92. local isOpen = checkActIsOpen(human)
  93. if isOpen == 0 then
  94. msgRet.ret = 0
  95. Msg.send(msgRet,human.fd)
  96. return
  97. end
  98. if human.db.customize == nil then
  99. msgRet.ret = 0
  100. Msg.send(msgRet,human.fd)
  101. return
  102. end
  103. local config = PresentExcel.customizeGift[id]
  104. if config == nil
  105. or config.first[first] == nil
  106. or config.second[second] == nil
  107. or config.third[third] == nil then
  108. msgRet.ret = 0
  109. Msg.send(msgRet,human.fd)
  110. return
  111. end
  112. human.db.customize[id].selectItem[1] = config.first[first]
  113. human.db.customize[id].selectItem[2] = config.second[second]
  114. human.db.customize[id].selectItem[3] = config.third[third]
  115. Msg.send(msgRet,human.fd)
  116. end
  117. function onBuyCustomize(human,id)
  118. local isOpen = checkActIsOpen(human)
  119. if isOpen == 0 then
  120. return
  121. end
  122. if human.db.customize == nil then
  123. return
  124. end
  125. if #human.db.customize[id].selectItem <= 0 then
  126. return
  127. end
  128. local config = PresentExcel.customizeGift[id]
  129. if human.db.customize[id].cnt >= config.limitCnt then
  130. return
  131. end
  132. human.db.customize[id].cnt = human.db.customize[id].cnt + 1
  133. if human.db.customize[id].cnt >= config.limitCnt then
  134. for i = 1,#human.db.customize[id].selectItem do
  135. local itemID = human.db.customize[id].selectItem[i][1]
  136. local itemCnt = human.db.customize[id].selectItem[i][2]
  137. human.db.customize[id].item[itemID] = itemCnt
  138. end
  139. end
  140. --[[ for i = 1,#human.db.customize[id].selectItem do
  141. local itemID = human.db.customize[id].selectItem[i][1]
  142. local itemCnt = human.db.customize[id].selectItem[i][2]
  143. BagLogic.addItem(human,itemID,itemCnt,"customize_gift")
  144. end
  145. ]]
  146. BagLogic.addItemList(human, human.db.customize[id].selectItem, "customize_gift")
  147. end