SpecialCustomLogic.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. --[[
  2. absAct[od] = {
  3. coustom[id] = {
  4. selectItem[1] =
  5. selectItem[2] =
  6. selectItem[3] =
  7. state =
  8. cnt =
  9. }
  10. }
  11. ]]
  12. local AbsActLogic = require("absAct.AbsActLogic")
  13. local AbsActExcel = require("excel.absAct")
  14. local BuyExcel = require("excel.buy")
  15. local Util = require("common.Util")
  16. local Msg = require("core.Msg")
  17. local Grid = require("bag.Grid")
  18. local BagLogic = require("bag.BagLogic")
  19. local BuyLogic = require("topup.BuyLogic")
  20. local ObjHuman = require("core.ObjHuman")
  21. local Lang = require("common.Lang")
  22. local Broadcast = require("broadcast.Broadcast")
  23. local Log = require("common.Log")
  24. local SPECIALCISTOMACTID = 31004 -- 活动ID
  25. local SPECIALCISTOMNOBUYID = 20001 -- 不使用的投放ID
  26. function isOpen(human, YYInfo, funcConfig)
  27. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  28. if not state then return end
  29. local absAct = human.db.absAct[funcConfig.funcID]
  30. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  31. return false
  32. end
  33. return true, endTime, startTime
  34. end
  35. function isActive(human, YYInfo, funcConfig)
  36. return not isOpen(human, YYInfo, funcConfig)
  37. end
  38. --发送定制礼包数据
  39. -- id 活动id
  40. function getAndSendMsg(human,id,actID)
  41. -- 活动未开,返回
  42. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  43. if not state then return end
  44. local absConfig = AbsActExcel.absActivity[id]
  45. if not absConfig then return end
  46. local absAct = human.db.absAct[id]
  47. if not absAct then
  48. return
  49. end
  50. -- 初始化custom数据
  51. absAct.custom = absAct.custom or {}
  52. -- 构造数据
  53. local msgRet = Msg.gc.GC_ABS_ND_CUSTOM_QUERY
  54. local config = AbsActExcel.custom
  55. local len = 0
  56. for k,v in pairs(config) do
  57. if len >= 3 then
  58. msgRet.giftList[0] =len
  59. msgRet.isEnd = 0
  60. Msg.send(msgRet,human.fd)
  61. len = 0
  62. msgRet = Msg.gc.GC_ABS_ND_CUSTOM_QUERY
  63. end
  64. if v.actId == absConfig.actId then
  65. len = len + 1
  66. local net = msgRet.giftList[len]
  67. net.id = k
  68. net.limitCnt = v.limitCnt
  69. net.price = v.price
  70. net.name = v.name
  71. net.nowCnt = absAct.custom[k] and absAct.custom[k].cnt or 0
  72. net.state = absAct.custom[k] and absAct.custom[k].state or 0
  73. net.buyItem[0] = 1
  74. if v.buyID ~= 0 then
  75. BuyLogic.fontBuyItem(human, net.buyItem[1], v.buyID)
  76. else
  77. net.buyItem[0] = 0
  78. end
  79. local warehouseLen = #v.fixed
  80. for j = 1,warehouseLen do
  81. local itemID = v.fixed[j][1]
  82. local itemCnt = v.fixed[j][2]
  83. Grid.makeItem(net.fixed[j],itemID,itemCnt)
  84. end
  85. net.fixed[0] = warehouseLen
  86. if net.nowCnt >= net.limitCnt then
  87. net.first[0] = 0
  88. net.second[0] = 0
  89. net.third[0] = 0
  90. else
  91. warehouseLen = #v.first
  92. for j = 1,warehouseLen do
  93. local itemID = v.first[j][1]
  94. local itemCnt = v.first[j][2]
  95. Grid.makeItem(net.first[j],itemID,itemCnt)
  96. end
  97. net.first[0] = warehouseLen
  98. warehouseLen = #v.second
  99. for j = 1,warehouseLen do
  100. local itemID = v.second[j][1]
  101. local itemCnt = v.second[j][2]
  102. Grid.makeItem(net.second[j],itemID,itemCnt)
  103. end
  104. net.second[0] = warehouseLen
  105. warehouseLen = #v.third
  106. for j = 1,warehouseLen do
  107. local itemID = v.third[j][1]
  108. local itemCnt = v.third[j][2]
  109. Grid.makeItem(net.third[j],itemID,itemCnt)
  110. end
  111. net.third[0] = warehouseLen
  112. end
  113. -- 状态为0,表示未选择物品,发送物品库
  114. if net.state == 0 then
  115. net.one[0] = 0
  116. net.two[0] = 0
  117. net.three[0] = 0
  118. else
  119. -- 状态不为0,表示已卖完或已选择物品,展示已选择物品
  120. Grid.makeItem(net.one[1],absAct.custom[k].selectItem[1][1],absAct.custom[k].selectItem[1][2])
  121. Grid.makeItem(net.two[1],absAct.custom[k].selectItem[2][1],absAct.custom[k].selectItem[2][2])
  122. net.one[0] = 1
  123. net.two[0] = 1
  124. net.three[0] = 0
  125. if absAct.custom[k].selectItem[3] then
  126. Grid.makeItem(net.three[1],absAct.custom[k].selectItem[3][1],absAct.custom[k].selectItem[3][2])
  127. net.three[0] = 1
  128. end
  129. end
  130. end
  131. end
  132. msgRet.giftList[0] = len
  133. msgRet.isEnd = 1
  134. Msg.send(msgRet,human.fd)
  135. end
  136. -- 选择物品
  137. function selectItem(human,id,giftId,first,second,third)
  138. local msgRet = Msg.gc.GC_ABS_ND_CUSTOM_SELECT
  139. msgRet.ret = 1
  140. -- 活动未开,无法选择物品
  141. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  142. if not state then
  143. msgRet.ret = 0
  144. Msg.send(msgRet,human.fd)
  145. return
  146. end
  147. local absConfig = AbsActExcel.absActivity[id]
  148. if not absConfig then
  149. msgRet.ret = 0
  150. Msg.send(msgRet,human.fd)
  151. return
  152. end
  153. local absAct = human.db.absAct[id]
  154. if not absAct then
  155. msgRet.ret = 0
  156. Msg.send(msgRet,human.fd)
  157. return
  158. end
  159. -- 礼包已卖完无法选择物品
  160. if absAct.custom and absAct.custom[giftId] and absAct.custom[giftId].state == 2 then
  161. msgRet.ret = 0
  162. Msg.send(msgRet,human.fd)
  163. return
  164. end
  165. -- 校验物品是否存在
  166. absAct.custom = absAct.custom or {}
  167. absAct.custom[giftId] = absAct.custom[giftId] or {}
  168. absAct.custom[giftId].cnt = absAct.custom[giftId].cnt or 0
  169. absAct.custom[giftId].state = absAct.custom[giftId].state or 0
  170. absAct.custom[giftId].selectItem = absAct.custom[giftId].selectItem or {}
  171. -- 将已选择物品存入数据库
  172. local config = AbsActExcel.custom[giftId]
  173. if config == nil
  174. or config.first[first] == nil
  175. or config.second[second] == nil
  176. or (config.third[third] == nil and third ~= 0) then
  177. msgRet.ret = 0
  178. Msg.send(msgRet,human.fd)
  179. return
  180. end
  181. if (first == 0 and #config.first ~= 0) or
  182. (second == 0 and #config.second ~= 0) or
  183. (third == 0 and #config.third ~= 0) then
  184. return
  185. end
  186. -- 并非所有礼包都能选择3个物品
  187. absAct.custom[giftId].selectItem[1] = {}
  188. absAct.custom[giftId].selectItem[1][1] = config.first[first][1]
  189. absAct.custom[giftId].selectItem[1][2] = config.first[first][2]
  190. absAct.custom[giftId].selectItem[2] = {}
  191. absAct.custom[giftId].selectItem[2][1] = config.second[second][1]
  192. absAct.custom[giftId].selectItem[2][2] = config.second[second][2]
  193. -- 并非所有礼包都能选择3个物品
  194. if third ~= 0 then
  195. absAct.custom[giftId].selectItem[3] = {}
  196. absAct.custom[giftId].selectItem[3][1] = config.third[third][1]
  197. absAct.custom[giftId].selectItem[3][2] = config.third[third][2]
  198. end
  199. Msg.send(msgRet,human.fd)
  200. absAct.custom[giftId].state = 1
  201. end
  202. -- 购买礼包
  203. function custom(human,funcID,conf)
  204. customBuy(human,conf.args[1],funcID, true)
  205. end
  206. function customBuy(human,args,id, bFromPay)
  207. -- 活动未开,返回
  208. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  209. if not state then return end
  210. local absConfig = AbsActExcel.absActivity[id]
  211. if not absConfig then return end
  212. local absAct = human.db.absAct[id]
  213. if not absAct then
  214. return
  215. end
  216. -- 检查来源
  217. local tConfig = AbsActExcel.custom[args]
  218. if not tConfig then
  219. return
  220. end
  221. -- 付费奖励
  222. if tConfig.buyID ~= 0 then
  223. if not bFromPay or true ~= bFromPay then
  224. local szText = "[SpecialCustonLogic_customBuy] 付费奖励, 协议请求领取 来源不正确 name = "..human.db.name.." _id = "..human.db._id.." 礼包ID = "..args
  225. Log.write(Log.LOGID_OSS_BT, szText)
  226. return
  227. end
  228. end
  229. -- 购买状态不为可购买,返回
  230. if not absAct.custom or not absAct.custom[args] or absAct.custom[args].state ~= 1 then
  231. return
  232. end
  233. -- 未选择物品,返回
  234. if #absAct.custom[args].selectItem <= 0 then
  235. return
  236. end
  237. -- 已达到限购次数,返回
  238. local config = AbsActExcel.custom[args]
  239. if absAct.custom[args].cnt >= config.limitCnt then
  240. return
  241. end
  242. -- 钻石价格不为0时,表示钻石购买,则需判断钻石是否足够
  243. if config.price ~= 0 then
  244. if not ObjHuman.checkRMB(human, config.price) then
  245. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  246. end
  247. ObjHuman.decZuanshi(human, -config.price, "abs_custom")
  248. end
  249. -- 购买次数增加一次
  250. absAct.custom[args].cnt = absAct.custom[args].cnt + 1
  251. -- 状态设置为已卖完,此时,为防止后续报错,导致可无限购买,故先设置为无法继续购买
  252. absAct.custom[args].state = 2
  253. -- 统计物品,并发放
  254. local item = {}
  255. for i = 1, #config.fixed do
  256. item[#item+1] = {config.fixed[i][1],config.fixed[i][2]}
  257. end
  258. for i = 1,#absAct.custom[args].selectItem do
  259. item[#item+1] = {absAct.custom[args].selectItem[i][1],absAct.custom[args].selectItem[i][2]}
  260. end
  261. BagLogic.addItemList(human, item, "abs_custom")
  262. -- 判断是否达到限购次数,未达到则将购买状态设为选择物品
  263. if absAct.custom[args].cnt < config.limitCnt then
  264. --absAct.custom[args].selectItem = {}
  265. absAct.custom[args].state = 0
  266. else
  267. absAct.custom[args].state = 2
  268. end
  269. getAndSendMsg(human,id)
  270. end
  271. -- 是否有红点
  272. function isRed(human, YYInfo, funcConfig)
  273. local tConfig = AbsActExcel.custom
  274. if not isRed then
  275. return false
  276. end
  277. local tActDBData = human.db.absAct[SPECIALCISTOMACTID]
  278. if not tActDBData then
  279. return false
  280. end
  281. local bRed = false
  282. for k, v in pairs(tConfig) do
  283. if 0 == v.buyID and k < SPECIALCISTOMNOBUYID then
  284. if not tActDBData.custom or not tActDBData.custom[k] then
  285. bRed = true
  286. else
  287. if tActDBData.custom[k].state then
  288. bRed = tActDBData.custom[k].state ~= 2 and true or false
  289. else
  290. bRed = true
  291. end
  292. end
  293. if bRed == true then
  294. break
  295. end
  296. end
  297. end
  298. return bRed
  299. end