FirstChargeLogic.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. -----------------------------------------------------------------
  2. -- 超值首充
  3. -- db.firstCharge
  4. -- firstCharge[type].ts 激活时间
  5. -- firstCharge.getList 奖励领取次数 firstCharge.getList[id] = cnt
  6. -- firstCharge.freeTime 每日登陆奖励领取时间 firstCharge.freeTime[type] = time
  7. -----------------------------------------------------------
  8. local Msg = require("core.Msg")
  9. local Util = require("common.Util")
  10. local PresentExcel = require("excel.present")
  11. local Grid = require("bag.Grid")
  12. local BagLogic = require("bag.BagLogic")
  13. local Broadcast = require("broadcast.Broadcast")
  14. local PanelDefine = require("broadcast.PanelDefine")
  15. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  16. local YunYingLogic = require("yunying.YunYingLogic")
  17. local SceneHandler = require("scene.Handler")
  18. local ObjHuman = require("core.ObjHuman")
  19. local FIRST_CHARGE_TYPE1 = 1 -- 首充赠礼
  20. local FIRST_CHARGE_TYPE2 = 2 -- 100元赠礼
  21. -- 状态
  22. STATE_CANT_GET = 0 -- 不可领
  23. STATE_CAT_GET = 1 -- 可领
  24. STATE_HAD_GET = 2 -- 已领
  25. function isOpenByType(human,giftType)
  26. -- 老首充只有数据才显示true了
  27. if not human.db.firstCharge or not human.db.firstCharge[giftType] then
  28. --return true
  29. return
  30. end
  31. for id,config in ipairs(PresentExcel.firstCharge) do
  32. if giftType == config.type then
  33. if getState(human, id, true) ~= STATE_HAD_GET then
  34. return true
  35. end
  36. end
  37. end
  38. end
  39. function isRedByType(human,giftType)
  40. if not human.db.firstCharge or not human.db.firstCharge[giftType] then
  41. return
  42. end
  43. for id,config in ipairs(PresentExcel.firstCharge) do
  44. if giftType == config.type then
  45. if getState(human, id) == STATE_CAT_GET then
  46. return true
  47. end
  48. end
  49. end
  50. end
  51. function isOpen(human,YYInfo,funcConfig)
  52. if not SceneHandler.canCharge(human) then
  53. return
  54. end
  55. if isOpenByType(human,FIRST_CHARGE_TYPE1) or isOpenByType(human,FIRST_CHARGE_TYPE2) then
  56. return true
  57. end
  58. end
  59. function isRed(human,YYInfo,funcConfig)
  60. if isRedByType(human,FIRST_CHARGE_TYPE1) or isRedByType(human,FIRST_CHARGE_TYPE2) then
  61. return true
  62. end
  63. end
  64. -- 封装结构体
  65. local function fontNet(net, human, id, cf)
  66. if not net then return end
  67. net.id = id
  68. net.status = getState(human, id)
  69. net.items[0] = #cf.reward
  70. for i, item in ipairs(cf.reward) do
  71. Grid.makeItem(net.items[i], item[1], item[2])
  72. end
  73. end
  74. function sendQuery(human,giftType)
  75. ObjHuman.updateDaily(human)
  76. local msgRet = Msg.gc.GC_FIRST_CHARGE_GIFT_QUERY
  77. msgRet.value = human.db.topupAcount or 0
  78. msgRet.type = giftType
  79. msgRet.list[0] = 0
  80. msgRet.red[0] = 0
  81. for id, cf in ipairs(PresentExcel.firstCharge) do
  82. if cf.type == giftType then
  83. msgRet.list[0] = msgRet.list[0] + 1
  84. local index = msgRet.list[0]
  85. fontNet(msgRet.list[index], human, id, cf)
  86. end
  87. if id == 2 or id == 4 then
  88. msgRet.red[0] = msgRet.red[0] + 1
  89. msgRet.red[msgRet.red[0]] = getState(human, id)
  90. end
  91. end
  92. --Msg.trace(msgRet)
  93. Msg.send(msgRet, human.fd)
  94. end
  95. function getItems(human, type)
  96. ObjHuman.updateDaily(human)
  97. -- 领取奖励
  98. local items = {}
  99. local len = 0
  100. for id, cf in ipairs(PresentExcel.firstCharge) do
  101. if cf.type == type then
  102. local state = getState(human, id)
  103. if state == STATE_CAT_GET then
  104. local cf = PresentExcel.firstCharge[id]
  105. if cf then
  106. human.db.firstCharge.getList = human.db.firstCharge.getList or {}
  107. human.db.firstCharge.getList[id] = (human.db.firstCharge.getList[id] or 0) + 1
  108. if cf.day == 0 then
  109. human.db.firstCharge.freeTime = human.db.firstCharge.freeTime or {}
  110. human.db.firstCharge.freeTime[cf.type] = os.time()
  111. end
  112. for k,v in pairs(cf.reward) do
  113. local itemID = v[1]
  114. local itemCnt = v[2]
  115. items[itemID] = items[itemID] or 0
  116. items[itemID] = items[itemID] + itemCnt
  117. len = len + 1
  118. end
  119. end
  120. end
  121. end
  122. end
  123. if len > 0 then
  124. BagLogic.addItemList(human, items, "shouchong")
  125. for k, v in pairs(funcID) do
  126. YunYingLogic.updateIcon(YYInfo[k], human)
  127. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3302)
  128. break
  129. end
  130. sendQuery(human, type)
  131. end
  132. end
  133. local TYPE_2_NEED = nil
  134. function getNeedList()
  135. if not TYPE_2_NEED then
  136. TYPE_2_NEED = {}
  137. for id, cf in pairs(PresentExcel.firstCharge) do
  138. TYPE_2_NEED[cf.type] = cf.need
  139. end
  140. end
  141. return TYPE_2_NEED
  142. end
  143. -- 状态
  144. function getState(human, id, byMax)
  145. local cf = PresentExcel.firstCharge[id]
  146. if not cf then
  147. return STATE_CANT_GET
  148. end
  149. local data = human.db.firstCharge and human.db.firstCharge[cf.type]
  150. if not data or not data.ts then
  151. return STATE_CANT_GET
  152. end
  153. if cf.day == 0 and not byMax then
  154. local freeTime = human.db.firstCharge.freeTime and human.db.firstCharge.freeTime[cf.type] or 0
  155. if Util.isSameDay(freeTime) then
  156. return STATE_HAD_GET
  157. end
  158. end
  159. local getCnt = human.db.firstCharge.getList and human.db.firstCharge.getList[id] or 0
  160. if getCnt >= cf.getMax then
  161. return STATE_HAD_GET
  162. end
  163. local day = Util.diffDay(data.ts) + 1
  164. if cf.day > day then
  165. return STATE_CANT_GET
  166. end
  167. return STATE_CAT_GET
  168. end
  169. -- 激活首充
  170. function activateFirstCharge(human, ftype)
  171. human.db.firstCharge = human.db.firstCharge or {}
  172. if human.db.firstCharge[ftype] then return end
  173. human.db.firstCharge[ftype] = {}
  174. human.db.firstCharge[ftype].ts = os.time()
  175. if ftype == FIRST_CHARGE_TYPE1 then
  176. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE15, 0)
  177. end
  178. return true
  179. end
  180. -- 充值回调
  181. function onCharge(human)
  182. return
  183. -- local needList = getNeedList()
  184. -- local isChange = nil
  185. -- for ftype, need in pairs(needList) do
  186. -- if (human.db.topupAcount or 0) >= need and
  187. -- activateFirstCharge(human, ftype) then
  188. -- isChange = true
  189. -- sendQuery(human, ftype)
  190. -- end
  191. -- end
  192. -- if isChange then
  193. -- for k, v in pairs(funcID) do
  194. -- YunYingLogic.updateIcon(YYInfo[k], human)
  195. -- break
  196. -- end
  197. -- end
  198. end
  199. function updateDaily(human)
  200. if human.db.firstCharge then
  201. human.db.firstCharge.freeTime = nil
  202. end
  203. end
  204. -- 是否已激活首充
  205. function isActive(human, YYInfo, funcConfig)
  206. if not human.db.firstCharge or not human.db.firstCharge[FIRST_CHARGE_TYPE1] then
  207. return
  208. end
  209. return true
  210. end