FirstChargeLogic.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. return
  56. -- if isOpenByType(human,FIRST_CHARGE_TYPE1) or isOpenByType(human,FIRST_CHARGE_TYPE2) then
  57. -- return true
  58. -- end
  59. end
  60. function isRed(human,YYInfo,funcConfig)
  61. if isRedByType(human,FIRST_CHARGE_TYPE1) or isRedByType(human,FIRST_CHARGE_TYPE2) then
  62. return true
  63. end
  64. end
  65. -- 封装结构体
  66. local function fontNet(net, human, id, cf)
  67. if not net then return end
  68. net.id = id
  69. net.status = getState(human, id)
  70. net.items[0] = #cf.reward
  71. for i, item in ipairs(cf.reward) do
  72. Grid.makeItem(net.items[i], item[1], item[2])
  73. end
  74. end
  75. function sendQuery(human,giftType)
  76. ObjHuman.updateDaily(human)
  77. local msgRet = Msg.gc.GC_FIRST_CHARGE_GIFT_QUERY
  78. msgRet.value = human.db.topupAcount or 0
  79. msgRet.type = giftType
  80. msgRet.list[0] = 0
  81. msgRet.red[0] = 0
  82. for id, cf in ipairs(PresentExcel.firstCharge) do
  83. if cf.type == giftType then
  84. msgRet.list[0] = msgRet.list[0] + 1
  85. local index = msgRet.list[0]
  86. fontNet(msgRet.list[index], human, id, cf)
  87. end
  88. if id == 2 or id == 4 then
  89. msgRet.red[0] = msgRet.red[0] + 1
  90. msgRet.red[msgRet.red[0]] = getState(human, id)
  91. end
  92. end
  93. --Msg.trace(msgRet)
  94. Msg.send(msgRet, human.fd)
  95. end
  96. function getItems(human, type)
  97. ObjHuman.updateDaily(human)
  98. -- 领取奖励
  99. local items = {}
  100. local len = 0
  101. for id, cf in ipairs(PresentExcel.firstCharge) do
  102. if cf.type == type then
  103. local state = getState(human, id)
  104. if state == STATE_CAT_GET then
  105. local cf = PresentExcel.firstCharge[id]
  106. if cf then
  107. human.db.firstCharge.getList = human.db.firstCharge.getList or {}
  108. human.db.firstCharge.getList[id] = (human.db.firstCharge.getList[id] or 0) + 1
  109. if cf.day == 0 then
  110. human.db.firstCharge.freeTime = human.db.firstCharge.freeTime or {}
  111. human.db.firstCharge.freeTime[cf.type] = os.time()
  112. end
  113. for k,v in pairs(cf.reward) do
  114. local itemID = v[1]
  115. local itemCnt = v[2]
  116. items[itemID] = items[itemID] or 0
  117. items[itemID] = items[itemID] + itemCnt
  118. len = len + 1
  119. end
  120. end
  121. end
  122. end
  123. end
  124. if len > 0 then
  125. BagLogic.addItemList(human, items, "shouchong")
  126. for k, v in pairs(funcID) do
  127. YunYingLogic.updateIcon(YYInfo[k], human)
  128. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3302)
  129. break
  130. end
  131. sendQuery(human, type)
  132. end
  133. end
  134. local TYPE_2_NEED = nil
  135. function getNeedList()
  136. if not TYPE_2_NEED then
  137. TYPE_2_NEED = {}
  138. for id, cf in pairs(PresentExcel.firstCharge) do
  139. TYPE_2_NEED[cf.type] = cf.need
  140. end
  141. end
  142. return TYPE_2_NEED
  143. end
  144. -- 状态
  145. function getState(human, id, byMax)
  146. local cf = PresentExcel.firstCharge[id]
  147. if not cf then
  148. return STATE_CANT_GET
  149. end
  150. local data = human.db.firstCharge and human.db.firstCharge[cf.type]
  151. if not data or not data.ts then
  152. return STATE_CANT_GET
  153. end
  154. if cf.day == 0 and not byMax then
  155. local freeTime = human.db.firstCharge.freeTime and human.db.firstCharge.freeTime[cf.type] or 0
  156. if Util.isSameDay(freeTime) then
  157. return STATE_HAD_GET
  158. end
  159. end
  160. local getCnt = human.db.firstCharge.getList and human.db.firstCharge.getList[id] or 0
  161. if getCnt >= cf.getMax then
  162. return STATE_HAD_GET
  163. end
  164. local day = Util.diffDay(data.ts) + 1
  165. if cf.day > day then
  166. return STATE_CANT_GET
  167. end
  168. return STATE_CAT_GET
  169. end
  170. -- 激活首充
  171. function activateFirstCharge(human, ftype)
  172. human.db.firstCharge = human.db.firstCharge or {}
  173. if human.db.firstCharge[ftype] then return end
  174. human.db.firstCharge[ftype] = {}
  175. human.db.firstCharge[ftype].ts = os.time()
  176. if ftype == FIRST_CHARGE_TYPE1 then
  177. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE15, 0)
  178. end
  179. return true
  180. end
  181. -- 充值回调
  182. function onCharge(human)
  183. return
  184. -- local needList = getNeedList()
  185. -- local isChange = nil
  186. -- for ftype, need in pairs(needList) do
  187. -- if (human.db.topupAcount or 0) >= need and
  188. -- activateFirstCharge(human, ftype) then
  189. -- isChange = true
  190. -- sendQuery(human, ftype)
  191. -- end
  192. -- end
  193. -- if isChange then
  194. -- for k, v in pairs(funcID) do
  195. -- YunYingLogic.updateIcon(YYInfo[k], human)
  196. -- break
  197. -- end
  198. -- end
  199. end
  200. function updateDaily(human)
  201. if human.db.firstCharge then
  202. human.db.firstCharge.freeTime = nil
  203. end
  204. end
  205. -- 是否已激活首充
  206. function isActive(human, YYInfo, funcConfig)
  207. -- if not human.db.firstCharge or not human.db.firstCharge[FIRST_CHARGE_TYPE1] then
  208. -- return
  209. -- end
  210. -- return true
  211. return
  212. end