OpenServerGiftLogic.lua 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. ---------------------------------------------------
  2. -- 开服有礼
  3. ---------------------------------------------------
  4. local Util = require("common.Util")
  5. local Lang = require("common.Lang")
  6. local Broadcast = require("broadcast.Broadcast")
  7. local OpenAct = require("present.OpenAct")
  8. local PresentExcel = require("excel.present")
  9. local OpenActExcel = require("excel.openAct")
  10. local MailExcel = require("excel.mail")
  11. local Msg = require("core.Msg")
  12. local ObjHuman = require("core.ObjHuman")
  13. local MailManager = require("mail.MailManager")
  14. local BagLogic = require("bag.BagLogic")
  15. local Grid = require("bag.Grid")
  16. local KingWorldLogic = require("present.KingWorldLogic")
  17. local YunYingLogic = require("yunying.YunYingLogic")
  18. local PanelDefine = require("broadcast.PanelDefine")
  19. local SevenDayGiftLogic = require("present.SevenDayGiftLogic")
  20. local CommonDB = require("common.CommonDB")
  21. local BuyLogic = require("topup.BuyLogic")
  22. local GuideLogic = require("guide.GuideLogic")
  23. GIFT_STATE_NONE = 0 -- 不可领取
  24. GIFT_STATE_GET = 1 -- 可领取
  25. GIFT_STATE_BUY = 2 -- 可购买
  26. GIFT_STATE_HADBUY = 3 -- 已购买
  27. -- 初始db
  28. local function initDB(human)
  29. human.db.openServerGift = {}
  30. human.db.openServerGift.free = {}
  31. human.db.openServerGift.cost = {}
  32. end
  33. local function getDB(human)
  34. if not human.db.openServerGift then
  35. initDB(human)
  36. end
  37. return human.db.openServerGift
  38. end
  39. -- 免费礼包状态
  40. function getFreeState(human, day)
  41. if not human.db.openServerGift then
  42. return
  43. end
  44. local data = human.db.openServerGift
  45. return data.free[day]
  46. end
  47. -- 付费礼包状态
  48. function getCostState(human, day)
  49. if not human.db.openServerGift then
  50. return
  51. end
  52. local data = human.db.openServerGift
  53. local limitCnt = OpenActExcel.openServerGift[day].limitCnt
  54. if data.cost[day] == nil or data.cost[day] < limitCnt then
  55. return
  56. else
  57. return 0
  58. end
  59. end
  60. local function setFreeState(human, day)
  61. local data = getDB(human)
  62. data.free[day] = GIFT_STATE_HADBUY
  63. end
  64. local function setCostState(human, day)
  65. local data = getDB(human)
  66. data.cost[day] = data.cost[day] or 0
  67. data.cost[day] = data.cost[day] + 1
  68. end
  69. -- 获取礼包状态
  70. function getGiftState(human, day)
  71. local freeState = getFreeState(human, day)
  72. local costState = getCostState(human, day)
  73. local flag = OpenAct.getOpenActTime(OpenAct.OPEN_ACT_SERVER_GIFT)
  74. local openDay = CommonDB.getServerOpenDay()
  75. if flag == nil or openDay == nil or openDay < day then
  76. return GIFT_STATE_NONE
  77. end
  78. if freeState == nil then
  79. return GIFT_STATE_GET
  80. elseif costState == nil then
  81. return GIFT_STATE_BUY
  82. end
  83. return GIFT_STATE_HADBUY
  84. end
  85. -- 查询
  86. function query(human)
  87. local msgRet = Msg.gc.GC_PRESENT_OPEN_SERVER_QUERY
  88. msgRet.list[0] = #OpenActExcel.openServerGift
  89. for day = 1, msgRet.list[0] do
  90. local cf = OpenActExcel.openServerGift[day]
  91. local net = msgRet.list[day]
  92. net.day = day
  93. net.state = getGiftState(human, day)
  94. local itemConfig = nil
  95. net.nowCnt = 0
  96. net.limitCnt = 0
  97. if net.state == GIFT_STATE_BUY then
  98. itemConfig = cf.freeGift
  99. --itemConfig = cf.costGift
  100. net.nowCnt = human.db.openServerGift.cost[day] or 0
  101. net.limitCnt = cf.limitCnt
  102. else
  103. itemConfig = cf.freeGift
  104. end
  105. net.item[0] = #itemConfig
  106. for j = 1, net.item[0] do
  107. local itemID = itemConfig[j][1]
  108. local itemCnt = itemConfig[j][2]
  109. Grid.makeItem(net.item[j], itemID, itemCnt)
  110. end
  111. net.buyItem[0] = 0
  112. --BuyLogic.fontBuyItem(human, net.buyItem, cf.buyID)
  113. end
  114. Msg.send(msgRet, human.fd)
  115. end
  116. -- 领取奖励
  117. function gift(human, day)
  118. local cf = OpenActExcel.openServerGift[day]
  119. if not cf then
  120. return Broadcast.sendErr(human, Lang.ITEM_BUY_ERROR)
  121. end
  122. local state = getGiftState(human, day)
  123. if state ~= GIFT_STATE_GET then
  124. if state == GIFT_STATE_NONE then
  125. return Broadcast.sendErr(human, Lang.PRESENT_SEVENLOGINDAY_GET_DAYERR)
  126. end
  127. return Broadcast.sendErr(human, Lang.YUNYING_GET_ERR_HADGET)
  128. end
  129. setFreeState(human, day)
  130. --发放物品
  131. local itemConfig = OpenActExcel.openServerGift[day].freeGift
  132. local len = #itemConfig
  133. for i = 1,len do
  134. local itemID = itemConfig[i][1]
  135. local itemCnt = itemConfig[i][2]
  136. BagLogic.addItem(human,itemID,itemCnt,"open_server_gift")
  137. end
  138. BagLogic.sendItemGetList(human, itemConfig, "open_server_gift")
  139. for k, v in pairs(funcID) do
  140. YunYingLogic.updateIcon(YYInfo[k], human)
  141. YunYingLogic.sendGroupUpdate(YYInfo[k], human, PanelDefine.PANEL_ID_3602)
  142. break
  143. end
  144. if day == 2 then
  145. KingWorldLogic.setState(human,2)
  146. end
  147. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_OPEN_SERVER_GIFT)
  148. query(human)
  149. end
  150. -- 红点
  151. function isRed(human)
  152. for day in ipairs(OpenActExcel.openServerGift) do
  153. local state = getGiftState(human, day)
  154. if state == GIFT_STATE_NONE then
  155. break
  156. end
  157. if state == GIFT_STATE_GET then
  158. return true
  159. end
  160. end
  161. end
  162. function buyGift(human,day)
  163. -- 校验状态是否为能买
  164. local state = getGiftState(human, day)
  165. if state ~= GIFT_STATE_BUY then
  166. return
  167. end
  168. -- 设置购买数量
  169. setCostState(human,day)
  170. -- 发放道具
  171. local itemConfig = OpenActExcel.openServerGift[day].costGift
  172. local len = #itemConfig
  173. for i = 1,len do
  174. local itemID = itemConfig[i][1]
  175. local itemCnt = itemConfig[i][2]
  176. BagLogic.addItem(human,itemID,itemCnt,"open_server_gift")
  177. end
  178. BagLogic.sendItemGetList(human, itemConfig, "open_server_gift")
  179. query(human)
  180. end
  181. function isBaseOpen(human,noSend)
  182. local openLv = YunYingLogic.getOpenLvByPanelID(PanelDefine.PANEL_ID_3602)
  183. if human.db.lv < openLv then
  184. if not noSend then
  185. local str = Util.format(Lang.ROLE_LEV_ERROR,openLv)
  186. return Broadcast.sendErr(human,str)
  187. end
  188. end
  189. local flag = OpenAct.getOpenActTime(OpenAct.OPEN_ACT_SERVER_GIFT)
  190. if not flag then
  191. return
  192. end
  193. return true
  194. end
  195. function isOpen(human)
  196. if isBaseOpen(human,true) then
  197. return true
  198. end
  199. end
  200. function getLeftTime()
  201. local openDay = CommonDB.getServerOpenDay()
  202. if openDay == nil then
  203. return 0
  204. end
  205. local OpenActConfig = OpenActExcel.openAct[1]
  206. if not OpenActConfig then return 0 end
  207. local sDay = OpenActConfig.sDay;
  208. local eDay = OpenActConfig.eDay;
  209. if openDay >= sDay and openDay <= eDay then
  210. local time = os.time();
  211. local openTime = CommonDB.getServerOpenTime()
  212. if openTime == 0 then
  213. return 0
  214. end
  215. local endTime = Util.getDayStartTime(openTime) + eDay * 86400
  216. return endTime - time
  217. end
  218. return 0
  219. end