OverflowFundLogic.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. local BuyExcel = require("excel.buy")
  25. local Log = require("common.Log")
  26. -----------------------------------------
  27. -- 宏定义
  28. OVERFLOW_TYPE_1 = 1 -- 超值基金
  29. OVERFLOW_TYPE_2 = 2 -- 奢华基金
  30. -----------------------------------------
  31. -- 逻辑接口
  32. -- 是否开启
  33. function isOpen(human,YYInfo,funcConfig)
  34. if not human.db.nFirstBuy or 1 ~= human.db.nFirstBuy then
  35. return false
  36. end
  37. return true
  38. end
  39. -- 获取当前基金状态
  40. --return 状态,下次领取天数 状态 0 未购买 1 领取 2 已领取
  41. local function getState(human,type)
  42. -- 有数据
  43. if human.db.overflow and human.db.overflow.state and human.db.overflow.state[type] then
  44. local day = Util.diffDay(human.db.overflow.state[type]) + 1
  45. human.db.overflow.get = human.db.overflow.get or {}
  46. human.db.overflow.get[type] = human.db.overflow.get[type] or 0
  47. local nextDay = human.db.overflow.get[type]
  48. if nextDay < day then
  49. return 1,nextDay + 1
  50. else
  51. return 2,nextDay + 1
  52. end
  53. end
  54. return 0,0
  55. end
  56. -- 基金信息查询
  57. function overflowQuery(human,type)
  58. -- 根据类型获得配置
  59. local config = nil
  60. if type == OVERFLOW_TYPE_1 then
  61. config = PresentExcel.overflowFund
  62. elseif type == OVERFLOW_TYPE_2 then
  63. config = PresentExcel.luxuryFund
  64. end
  65. if not config then
  66. return
  67. end
  68. local msgRet = Msg.gc.GC_OVERFLOW_FUND_QUERY
  69. msgRet.type = type
  70. BuyLogic.fontBuyItem(human, msgRet.buyMsg, config[1].buyID)
  71. msgRet.state,msgRet.nextGet = getState(human,type)
  72. local len = #config
  73. local count = 0
  74. for i = 1,len do
  75. Grid.makeItem(msgRet.item[i],config[i].item[1][1],config[i].item[1][2])
  76. if config[i].part == 1 then
  77. count = count + 1
  78. msgRet.partItem[count] = i
  79. end
  80. end
  81. msgRet.partItem[0] = count
  82. msgRet.item[0] = len
  83. msgRet.worth[1] = PresentExcel.overflowFund[1].worth
  84. msgRet.worth[2] = PresentExcel.luxuryFund[1].worth
  85. msgRet.worth[0] = 2
  86. Msg.send(msgRet,human.fd)
  87. end
  88. function onBuy(human,type)
  89. Log.write(Log.LOGID_DEBUG, "[OverflowFundLogic.onBuy] 进入购买 type="..type)
  90. -- 已购买,不可重复购买
  91. if human.db.overflow and human.db.overflow.state and human.db.overflow.state[type] then
  92. Log.write(Log.LOGID_DEBUG, "[OverflowFundLogic.onBuy] 已购买,不可重复购买 type="..type)
  93. return
  94. end
  95. human.db.overflow = human.db.overflow or {}
  96. human.db.overflow.state = human.db.overflow.state or {}
  97. human.db.overflow.get = human.db.overflow.get or {}
  98. human.db.overflow.state[type] = os.time()
  99. human.db.overflow.get[type] = 0
  100. Log.write(Log.LOGID_DEBUG, "[OverflowFundLogic.onBuy] 设置基金状态 type="..type..", state="..human.db.overflow.state[type])
  101. overflowQuery(human,type)
  102. for k, v in pairs(funcID) do
  103. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3310)
  104. break
  105. end
  106. -- 如果购买的是奢华基金(OVERFLOW_TYPE_2),需要更新勇者试炼的一键扫荡状态
  107. if type == OVERFLOW_TYPE_2 then
  108. Log.write(Log.LOGID_DEBUG, "[OverflowFundLogic.onBuy] 购买奢华基金,更新勇者试炼状态")
  109. local DrillLogic = require("drill.DrillLogic")
  110. -- 只刷新数据,不打开界面(openPanel = false)
  111. DrillLogic.queryDrillId(human, nil, false)
  112. end
  113. end
  114. function getFundReward(human,type)
  115. -- 根据类型获得配置
  116. local config = nil
  117. if type == OVERFLOW_TYPE_1 then
  118. config = PresentExcel.overflowFund
  119. elseif type == OVERFLOW_TYPE_2 then
  120. config = PresentExcel.luxuryFund
  121. end
  122. if not config then
  123. return
  124. end
  125. local state = getState(human,type)
  126. if state == 0 then
  127. return
  128. end
  129. local day = Util.diffDay(human.db.overflow.state[type]) + 1
  130. human.db.overflow.get = human.db.overflow.get or {}
  131. human.db.overflow.get[type] = human.db.overflow.get[type] or 0
  132. local nextDay = human.db.overflow.get[type] + 1
  133. local item = {}
  134. local len = #config
  135. for i = nextDay,day do
  136. if not config[i] then
  137. break
  138. end
  139. human.db.overflow.get[type] = human.db.overflow.get[type] + 1
  140. item[#item + 1] = {config[i].item[1][1],config[i].item[1][2]}
  141. end
  142. BagLogic.addItemList(human, item, "overflow_fund")
  143. -- 领取完最后一天
  144. if day >= len then
  145. human.db.overflow.state[type] = nil
  146. human.db.overflow.get[type] = nil
  147. end
  148. overflowQuery(human,type)
  149. for k, v in pairs(funcID) do
  150. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3310)
  151. break
  152. end
  153. end
  154. function isRed(human)
  155. for i = 1,2 do
  156. local state = getState(human,i)
  157. -- 已购买
  158. if state ~= 0 then
  159. local day = Util.diffDay(human.db.overflow.state[i]) + 1
  160. human.db.overflow.get = human.db.overflow.get or {}
  161. human.db.overflow.get[i] = human.db.overflow.get[i] or 0
  162. local nextDay = human.db.overflow.get[i] + 1
  163. if day >= nextDay then
  164. return true
  165. end
  166. end
  167. end
  168. return false
  169. end
  170. -- function GetRemainNum(human, nBuyID)
  171. -- local tBuyConf = BuyExcel.buy[nBuyID]
  172. -- if not tBuyConf then
  173. -- return 0
  174. -- end
  175. -- local bType = tBuyConf.args[1]
  176. -- local state = getState(human, bType)
  177. -- return (0 == state) and 1 or 0
  178. -- end