OverflowFundLogic.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. --------------------------------------
  2. -- 数据库设计
  3. --[[
  4. 1 超值基金
  5. 2 奢华基金
  6. human.db.overflow = {}
  7. human.db.overflow.state = {}
  8. human.db.overflow.state[1] = time
  9. human.db.overflow.state[2] = time
  10. human.db.overflow.get = {}
  11. human.db.overflow.get[1] = val
  12. human.db.overflow.get[2] = val
  13. ]]
  14. -----------------------------------------
  15. -- 引用文件
  16. local PresentExcel = require("excel.present")
  17. local Msg = require("core.Msg")
  18. local Util = require("common.Util")
  19. local BuyLogic = require("topup.BuyLogic")
  20. local BagLogic = require("bag.BagLogic")
  21. local Grid = require("bag.Grid")
  22. local PanelDefine = require("broadcast.PanelDefine")
  23. local YunYingLogic = require("yunying.YunYingLogic")
  24. -----------------------------------------
  25. -- 宏定义
  26. OVERFLOW_TYPE_1 = 1 -- 超值基金
  27. OVERFLOW_TYPE_2 = 2 -- 奢华基金
  28. -----------------------------------------
  29. -- 逻辑接口
  30. -- 是否开启
  31. function isOpen()
  32. return true
  33. end
  34. -- 获取当前基金状态
  35. --return 状态,下次领取天数 状态 0 未购买 1 领取 2 已领取
  36. local function getState(human,type)
  37. -- 有数据
  38. if human.db.overflow and human.db.overflow.state and human.db.overflow.state[type] then
  39. local day = Util.diffDay(human.db.overflow.state[type]) + 1
  40. human.db.overflow.get = human.db.overflow.get or {}
  41. human.db.overflow.get[type] = human.db.overflow.get[type] or 0
  42. local nextDay = human.db.overflow.get[type]
  43. if nextDay < day then
  44. return 1,nextDay + 1
  45. else
  46. return 2,nextDay + 1
  47. end
  48. end
  49. return 0,0
  50. end
  51. -- 基金信息查询
  52. function overflowQuery(human,type)
  53. -- 根据类型获得配置
  54. local config = nil
  55. if type == OVERFLOW_TYPE_1 then
  56. config = PresentExcel.overflowFund
  57. elseif type == OVERFLOW_TYPE_2 then
  58. config = PresentExcel.luxuryFund
  59. end
  60. if not config then
  61. return
  62. end
  63. local msgRet = Msg.gc.GC_OVERFLOW_FUND_QUERY
  64. msgRet.type = type
  65. BuyLogic.fontBuyItem(human, msgRet.buyMsg, config[1].buyID)
  66. msgRet.state,msgRet.nextGet = getState(human,type)
  67. local len = #config
  68. local count = 0
  69. for i = 1,len do
  70. Grid.makeItem(msgRet.item[i],config[i].item[1][1],config[i].item[1][2])
  71. if config[i].part == 1 then
  72. count = count + 1
  73. msgRet.partItem[count] = i
  74. end
  75. end
  76. msgRet.partItem[0] = count
  77. msgRet.item[0] = len
  78. msgRet.worth[1] = PresentExcel.overflowFund[1].worth
  79. msgRet.worth[2] = PresentExcel.luxuryFund[1].worth
  80. msgRet.worth[0] = 2
  81. Msg.send(msgRet,human.fd)
  82. end
  83. function onBuy(human,type)
  84. -- 已购买,不可重复购买
  85. if human.db.overflow and human.db.overflow.state and human.db.overflow.state[type] then
  86. return
  87. end
  88. human.db.overflow = human.db.overflow or {}
  89. human.db.overflow.state = human.db.overflow.state or {}
  90. human.db.overflow.get = human.db.overflow.get or {}
  91. human.db.overflow.state[type] = os.time()
  92. human.db.overflow.get[type] = 0
  93. overflowQuery(human,type)
  94. for k, v in pairs(funcID) do
  95. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3310)
  96. break
  97. end
  98. end
  99. function getFundReward(human,type)
  100. -- 根据类型获得配置
  101. local config = nil
  102. if type == OVERFLOW_TYPE_1 then
  103. config = PresentExcel.overflowFund
  104. elseif type == OVERFLOW_TYPE_2 then
  105. config = PresentExcel.luxuryFund
  106. end
  107. if not config then
  108. return
  109. end
  110. local state = getState(human,type)
  111. if state == 0 then
  112. return
  113. end
  114. local day = Util.diffDay(human.db.overflow.state[type]) + 1
  115. human.db.overflow.get = human.db.overflow.get or {}
  116. human.db.overflow.get[type] = human.db.overflow.get[type] or 0
  117. local nextDay = human.db.overflow.get[type] + 1
  118. local item = {}
  119. local len = #config
  120. for i = nextDay,day do
  121. if not config[i] then
  122. break
  123. end
  124. human.db.overflow.get[type] = human.db.overflow.get[type] + 1
  125. item[#item + 1] = {config[i].item[1][1],config[i].item[1][2]}
  126. end
  127. BagLogic.addItemList(human, item, "overflow_fund")
  128. -- 领取完最后一天
  129. if day >= len then
  130. human.db.overflow.state[type] = nil
  131. human.db.overflow.get[type] = nil
  132. end
  133. overflowQuery(human,type)
  134. for k, v in pairs(funcID) do
  135. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3310)
  136. break
  137. end
  138. end
  139. function isRed(human)
  140. for i = 1,2 do
  141. local state = getState(human,i)
  142. -- 已购买
  143. if state ~= 0 then
  144. local day = Util.diffDay(human.db.overflow.state[i]) + 1
  145. human.db.overflow.get = human.db.overflow.get or {}
  146. human.db.overflow.get[i] = human.db.overflow.get[i] or 0
  147. local nextDay = human.db.overflow.get[i] + 1
  148. if day >= nextDay then
  149. return true
  150. end
  151. end
  152. end
  153. return false
  154. end