SpecialCustomLogic.lua 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. function isOpen(human, YYInfo, funcConfig)
  24. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  25. if not state then return end
  26. local absAct = human.db.absAct[funcConfig.funcID]
  27. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  28. return false
  29. end
  30. return true, endTime, startTime
  31. end
  32. function isActive(human, YYInfo, funcConfig)
  33. return not isOpen(human, YYInfo, funcConfig)
  34. end
  35. --���Ͷ����������
  36. -- id �id
  37. function getAndSendMsg(human,id,actID)
  38. -- �δ��������
  39. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  40. if not state then return end
  41. local absConfig = AbsActExcel.absActivity[id]
  42. if not absConfig then return end
  43. local absAct = human.db.absAct[id]
  44. if not absAct then
  45. return
  46. end
  47. -- ��ʼ��custom����
  48. absAct.custom = absAct.custom or {}
  49. -- ��������
  50. local msgRet = Msg.gc.GC_ABS_ND_CUSTOM_QUERY
  51. local config = AbsActExcel.custom
  52. local len = 0
  53. for k,v in pairs(config) do
  54. if len >= 3 then
  55. msgRet.giftList[0] =len
  56. msgRet.isEnd = 0
  57. Msg.send(msgRet,human.fd)
  58. len = 0
  59. msgRet = Msg.gc.GC_ABS_ND_CUSTOM_QUERY
  60. end
  61. if v.actId == absConfig.actId then
  62. len = len + 1
  63. local net = msgRet.giftList[len]
  64. net.id = k
  65. net.limitCnt = v.limitCnt
  66. net.price = v.price
  67. net.name = v.name
  68. net.nowCnt = absAct.custom[k] and absAct.custom[k].cnt or 0
  69. net.state = absAct.custom[k] and absAct.custom[k].state or 0
  70. net.buyItem[0] = 1
  71. if v.buyID ~= 0 then
  72. BuyLogic.fontBuyItem(human, net.buyItem[1], v.buyID)
  73. else
  74. net.buyItem[0] = 0
  75. end
  76. local warehouseLen = #v.fixed
  77. for j = 1,warehouseLen do
  78. local itemID = v.fixed[j][1]
  79. local itemCnt = v.fixed[j][2]
  80. Grid.makeItem(net.fixed[j],itemID,itemCnt)
  81. end
  82. net.fixed[0] = warehouseLen
  83. if net.nowCnt >= net.limitCnt then
  84. net.first[0] = 0
  85. net.second[0] = 0
  86. net.third[0] = 0
  87. else
  88. warehouseLen = #v.first
  89. for j = 1,warehouseLen do
  90. local itemID = v.first[j][1]
  91. local itemCnt = v.first[j][2]
  92. Grid.makeItem(net.first[j],itemID,itemCnt)
  93. end
  94. net.first[0] = warehouseLen
  95. warehouseLen = #v.second
  96. for j = 1,warehouseLen do
  97. local itemID = v.second[j][1]
  98. local itemCnt = v.second[j][2]
  99. Grid.makeItem(net.second[j],itemID,itemCnt)
  100. end
  101. net.second[0] = warehouseLen
  102. warehouseLen = #v.third
  103. for j = 1,warehouseLen do
  104. local itemID = v.third[j][1]
  105. local itemCnt = v.third[j][2]
  106. Grid.makeItem(net.third[j],itemID,itemCnt)
  107. end
  108. net.third[0] = warehouseLen
  109. end
  110. -- ״̬Ϊ0����ʾδѡ����Ʒ��������Ʒ��
  111. if net.state == 0 then
  112. net.one[0] = 0
  113. net.two[0] = 0
  114. net.three[0] = 0
  115. else
  116. -- ״̬��Ϊ0����ʾ���������ѡ����Ʒ��չʾ��ѡ����Ʒ
  117. Grid.makeItem(net.one[1],absAct.custom[k].selectItem[1][1],absAct.custom[k].selectItem[1][2])
  118. Grid.makeItem(net.two[1],absAct.custom[k].selectItem[2][1],absAct.custom[k].selectItem[2][2])
  119. net.one[0] = 1
  120. net.two[0] = 1
  121. net.three[0] = 0
  122. if absAct.custom[k].selectItem[3] then
  123. Grid.makeItem(net.three[1],absAct.custom[k].selectItem[3][1],absAct.custom[k].selectItem[3][2])
  124. net.three[0] = 1
  125. end
  126. end
  127. end
  128. end
  129. msgRet.giftList[0] = len
  130. msgRet.isEnd = 1
  131. Msg.send(msgRet,human.fd)
  132. end
  133. -- ѡ����Ʒ
  134. function selectItem(human,id,giftId,first,second,third)
  135. local msgRet = Msg.gc.GC_ABS_ND_CUSTOM_SELECT
  136. msgRet.ret = 1
  137. -- �δ�����޷�ѡ����Ʒ
  138. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  139. if not state then
  140. msgRet.ret = 0
  141. Msg.send(msgRet,human.fd)
  142. return
  143. end
  144. local absConfig = AbsActExcel.absActivity[id]
  145. if not absConfig then
  146. msgRet.ret = 0
  147. Msg.send(msgRet,human.fd)
  148. return
  149. end
  150. local absAct = human.db.absAct[id]
  151. if not absAct then
  152. msgRet.ret = 0
  153. Msg.send(msgRet,human.fd)
  154. return
  155. end
  156. -- ����������޷�ѡ����Ʒ
  157. if absAct.custom and absAct.custom[giftId] and absAct.custom[giftId].state == 2 then
  158. msgRet.ret = 0
  159. Msg.send(msgRet,human.fd)
  160. return
  161. end
  162. -- ��ʼ������
  163. absAct.custom = absAct.custom or {}
  164. absAct.custom[giftId] = absAct.custom[giftId] or {}
  165. absAct.custom[giftId].cnt = absAct.custom[giftId].cnt or 0
  166. absAct.custom[giftId].state = absAct.custom[giftId].state or 0
  167. absAct.custom[giftId].selectItem = absAct.custom[giftId].selectItem or {}
  168. -- У����Ʒ�Ƿ����
  169. local config = AbsActExcel.custom[giftId]
  170. if config == nil
  171. or config.first[first] == nil
  172. or config.second[second] == nil
  173. or (config.third[third] == nil and third ~= 0) then
  174. msgRet.ret = 0
  175. Msg.send(msgRet,human.fd)
  176. return
  177. end
  178. if (first == 0 and #config.first ~= 0) or
  179. (second == 0 and #config.second ~= 0) or
  180. (third == 0 and #config.third ~= 0) then
  181. return
  182. end
  183. -- ����ѡ����Ʒ�������ݿ�
  184. absAct.custom[giftId].selectItem[1] = {}
  185. absAct.custom[giftId].selectItem[1][1] = config.first[first][1]
  186. absAct.custom[giftId].selectItem[1][2] = config.first[first][2]
  187. absAct.custom[giftId].selectItem[2] = {}
  188. absAct.custom[giftId].selectItem[2][1] = config.second[second][1]
  189. absAct.custom[giftId].selectItem[2][2] = config.second[second][2]
  190. -- ���������������ѡ��3����Ʒ
  191. if third ~= 0 then
  192. absAct.custom[giftId].selectItem[3] = {}
  193. absAct.custom[giftId].selectItem[3][1] = config.third[third][1]
  194. absAct.custom[giftId].selectItem[3][2] = config.third[third][2]
  195. end
  196. Msg.send(msgRet,human.fd)
  197. absAct.custom[giftId].state = 1
  198. end
  199. -- �������
  200. function custom(human,funcID,conf)
  201. customBuy(human,conf.args[1],funcID)
  202. end
  203. function customBuy(human,args,id)
  204. -- �δ��������
  205. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  206. if not state then return end
  207. local absConfig = AbsActExcel.absActivity[id]
  208. if not absConfig then return end
  209. local absAct = human.db.absAct[id]
  210. if not absAct then
  211. return
  212. end
  213. -- ����״̬��Ϊ�ɹ��򣬷���
  214. if not absAct.custom or not absAct.custom[args] or absAct.custom[args].state ~= 1 then
  215. return
  216. end
  217. -- δѡ����Ʒ������
  218. if #absAct.custom[args].selectItem <= 0 then
  219. return
  220. end
  221. -- �Ѵﵽ�޹�����������
  222. local config = AbsActExcel.custom[args]
  223. if absAct.custom[args].cnt >= config.limitCnt then
  224. return
  225. end
  226. -- ��ʯ�۸�Ϊ0ʱ����ʾ��ʯ���������ж���ʯ�Ƿ��㹻
  227. if config.price ~= 0 then
  228. if not ObjHuman.checkRMB(human, config.price) then
  229. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  230. end
  231. ObjHuman.decZuanshi(human, -config.price, "abs_custom")
  232. end
  233. -- �����������һ��
  234. absAct.custom[args].cnt = absAct.custom[args].cnt + 1
  235. -- ״̬����Ϊ�����꣬��ʱ��Ϊ��ֹ�������������¿����޹��򣬹�������Ϊ�޷���������
  236. absAct.custom[args].state = 2
  237. -- ͳ����Ʒ��������
  238. local item = {}
  239. for i = 1, #config.fixed do
  240. item[#item+1] = {config.fixed[i][1],config.fixed[i][2]}
  241. end
  242. for i = 1,#absAct.custom[args].selectItem do
  243. item[#item+1] = {absAct.custom[args].selectItem[i][1],absAct.custom[args].selectItem[i][2]}
  244. end
  245. BagLogic.addItemList(human, item, "abs_custom")
  246. -- �ж��Ƿ�ﵽ�޹�������δ�ﵽ�򽫹���״̬��Ϊѡ����Ʒ
  247. if absAct.custom[args].cnt < config.limitCnt then
  248. --absAct.custom[args].selectItem = {}
  249. absAct.custom[args].state = 0
  250. else
  251. absAct.custom[args].state = 2
  252. end
  253. getAndSendMsg(human,id)
  254. end