SpecialCustomLogic.lua 11 KB

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