DropExchangeLogic.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. -- 掉落兑换 活动
  2. local AbsActLogic = require("absAct.AbsActLogic")
  3. local AbsActExcel = require("excel.absAct")
  4. local Lang = require("common.Lang")
  5. local Util = require("common.Util")
  6. local Msg = require("core.Msg")
  7. local Broadcast = require("broadcast.Broadcast")
  8. local Grid = require("bag.Grid")
  9. local BagLogic = require("bag.BagLogic")
  10. local ItemDefine = require("bag.ItemDefine")
  11. local BuyLogic = require("topup.BuyLogic")
  12. local AbsActDefine = require("absAct.AbsActDefine")
  13. local BattleLogic = require("battle.BattleLogic")
  14. local EquipLogic = require("equip.EquipLogic")
  15. local PremiumGiftLogic = require("absAct.PremiumGiftLogic")
  16. function query(human, id , isHandler)
  17. local config = AbsActExcel.absActivity[id]
  18. if not config then return end
  19. local actId = config.actId
  20. local msgRet = Msg.gc.GC_ABS_ACT_DROP_QUERY
  21. local dropId = 0
  22. for k, v in pairs(AbsActExcel.drop) do
  23. if v and v.actID == actId then
  24. dropId = v.dropItem[1]
  25. break
  26. end
  27. end
  28. Grid.makeItem(msgRet.drop, dropId, getJifen(human, id))
  29. Msg.send(msgRet, human.fd)
  30. -- 客户端主动请求的时候 另外俩个活动也发送给客户端 因为客户端要做一个 极流畅的 特效切换 不能等主动请求返回
  31. if isHandler then
  32. shopQuery(human)
  33. for k, v in pairs(AbsActExcel.absActivity) do
  34. if v and v.absType == config.absType and
  35. v.type == AbsActDefine.ABS_ACT_TYPE_1 and
  36. AbsActLogic.isStarted(human, k) then
  37. AbsActLogic.checkAbsActClean(human, k)
  38. PremiumGiftLogic.getAndSendMsg(human, k, v.actId)
  39. break
  40. end
  41. end
  42. end
  43. end
  44. function addJifen(human, value)
  45. if not value or value <= 0 then return end
  46. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  47. if not state then return end
  48. AbsActLogic.checkAbsActClean(human, id)
  49. local absAct = human.db.absAct[id]
  50. absAct.jifen = absAct.jifen or 0
  51. absAct.jifen = absAct.jifen + value
  52. query(human, id)
  53. end
  54. function delJifen(human, value)
  55. if not value or value <= 0 then return end
  56. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  57. if not state then return end
  58. AbsActLogic.checkAbsActClean(human, id)
  59. local absAct = human.db.absAct[id]
  60. absAct.jifen = absAct.jifen or 0
  61. absAct.jifen = absAct.jifen - value
  62. absAct.jifen = absAct.jifen > 0 and absAct.jifen or 0
  63. query(human, id)
  64. end
  65. function getJifen(human, id)
  66. local absAct = human.db.absAct[id]
  67. return absAct and absAct.jifen or 0
  68. end
  69. function shopQuery(human)
  70. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  71. if not state then return end
  72. AbsActLogic.checkAbsActClean(human, id)
  73. local absActConfig = AbsActExcel.absActivity[id]
  74. if not absActConfig then return end
  75. local actId = absActConfig.actId
  76. local absAct = human.db.absAct[id]
  77. local msgRet = Msg.gc.GC_ABS_ACT_DROP_SHOP_QUERY
  78. msgRet.templateId = absActConfig.adIcon
  79. local len = 0
  80. local needItemID = 0
  81. for k, config in pairs(AbsActExcel.dropShop) do
  82. if config and config.actID == actId then
  83. needItemID = config.needItem
  84. len = len + 1
  85. local net = msgRet.list[len]
  86. net.id = k
  87. net.need = config.need
  88. net.buyCnt = absAct.buyCnt and absAct.buyCnt[k] or 0
  89. net.maxBuy = config.limit
  90. Grid.makeItem(net.item, config.item[1], config.item[2])
  91. end
  92. end
  93. msgRet.list[0] = len
  94. Grid.makeItem(msgRet.need, needItemID, 1)
  95. Msg.send(msgRet, human.fd)
  96. end
  97. function shopBuy(human, shopID, buyCnt)
  98. if buyCnt <= 0 then return end
  99. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  100. if not state then return end
  101. local absActConfig = AbsActExcel.absActivity[id]
  102. local actId = absActConfig.actId
  103. local absAct = human.db.absAct[id]
  104. local config = AbsActExcel.dropShop[shopID]
  105. if not config then return end
  106. if config.actID ~= actId then return end
  107. local oldBuy = absAct.buyCnt and absAct.buyCnt[shopID] or 0
  108. if config.limit > 0 and oldBuy + buyCnt > config.limit then return end
  109. if getJifen(human, id) < config.need * buyCnt then
  110. Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, ItemDefine.getValue(config.needItem, "name")))
  111. return
  112. end
  113. delJifen(human, config.need * buyCnt)
  114. absAct.buyCnt = absAct.buyCnt or {}
  115. absAct.buyCnt[shopID] = absAct.buyCnt[shopID] or 0
  116. absAct.buyCnt[shopID] = absAct.buyCnt[shopID] + buyCnt
  117. BagLogic.addItem(human, config.item[1], config.item[2] * buyCnt,"abs_dropShop")
  118. local msgRet = Msg.gc.GC_ABS_ACT_DROP_SHOP_BUY
  119. msgRet.id = shopID
  120. if not ItemDefine.isEquip(config.item[1]) then
  121. Grid.makeItem(msgRet.item , config.item[1], config.item[2] * buyCnt)
  122. else
  123. EquipLogic.makeEquipItemOne(human, msgRet.item)
  124. end
  125. Msg.send(msgRet, human.fd)
  126. -- shopQuery(human)
  127. end
  128. function giftQuery(human)
  129. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  130. if not state then return end
  131. local absActConfig = AbsActExcel.absActivity[id]
  132. local actId = absActConfig.actId
  133. local msgRet = Msg.gc.GC_ABS_ACT_DROP_GIFT_QUERY
  134. local len = 0
  135. for k, config in pairs(AbsActExcel.premiumGift) do
  136. if config and config.actId == actId then
  137. len = len + 1
  138. local net = msgRet.list[len]
  139. net.id = k
  140. net.cnt = human.db.absAct[id].premiumCnt and human.db.absAct[id].premiumCnt[k] or 0
  141. net.maxCnt = config.cnt
  142. for j = 1, #config.reward do
  143. Grid.makeItem(net.item[j], config.reward[j][1], config.reward[j][2])
  144. end
  145. net.item[0] = #config.reward
  146. BuyLogic.fontBuyItem(human,net.buyMsg, config.buyID)
  147. end
  148. end
  149. msgRet.list[0] = len
  150. Msg.send(msgRet, human.fd)
  151. end
  152. function drawSSR(human, net, cnt)
  153. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  154. if not state then return end
  155. local absActConfig = AbsActExcel.absActivity[id]
  156. local actId = absActConfig.actId
  157. for k, config in pairs(AbsActExcel.drop) do
  158. if config and config.actID == actId then
  159. BagLogic.addItem(human, config.ssrDrop[1], config.ssrDrop[2] * cnt, "abs_dropSSR")
  160. net[config.ssrDrop[1]] = net[config.ssrDrop[1]] or 0
  161. net[config.ssrDrop[1]] = net[config.ssrDrop[1]] + config.ssrDrop[2] * cnt
  162. break
  163. end
  164. end
  165. end
  166. function getDropItem(human,outSec, time ,net)
  167. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  168. if not state then return end
  169. AbsActLogic.checkAbsActClean(human, id)
  170. local absActConfig = AbsActExcel.absActivity[id]
  171. local actId = absActConfig.actId
  172. local now = os.time()
  173. local thisStart = now - outSec
  174. for i, config in pairs(AbsActExcel.drop) do
  175. if config and config.actID == actId then
  176. local absAct = human.db.absAct[id]
  177. local outCnt = 0
  178. local thisSec = outSec
  179. if absAct.dropTime then
  180. thisSec = now - absAct.dropTime
  181. local maxHang = BattleLogic.getHangMaxTime(human)
  182. thisSec = thisSec < maxHang and thisSec or maxHang
  183. elseif thisStart < starTime then
  184. thisSec = outSec - (starTime - thisStart)
  185. end
  186. if thisSec > 0 then
  187. outCnt = math.floor(thisSec/config.dropTime)
  188. end
  189. if outCnt > 0 then
  190. for j = 1, outCnt do
  191. local itemID = config.dropItem[1]
  192. local itemCnt = config.dropItem[2]
  193. net.items = net.items or {}
  194. net.items[itemID] = net.items[itemID] or 0
  195. net.items[itemID] = net.items[itemID] + itemCnt
  196. absAct.dropTime = os.time()
  197. end
  198. end
  199. end
  200. end
  201. end
  202. function getDropItemSaoQuery(human, net, dropCnt)
  203. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  204. if not state then return dropCnt end
  205. AbsActLogic.checkAbsActClean(human, id)
  206. local absActConfig = AbsActExcel.absActivity[id]
  207. local actId = absActConfig.actId
  208. for i, config in pairs(AbsActExcel.drop) do
  209. if config and config.actID == actId then
  210. local itemID = config.dropItem[1]
  211. local itemCnt = config.dropItem[2]
  212. dropCnt = dropCnt + 1
  213. Grid.makeItem(net.item[dropCnt], itemID, 1)
  214. break
  215. end
  216. end
  217. return dropCnt
  218. end
  219. function getDropItemSao(human,time ,itemTable)
  220. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  221. if not state then return end
  222. AbsActLogic.checkAbsActClean(human, id)
  223. local absActConfig = AbsActExcel.absActivity[id]
  224. local actId = absActConfig.actId
  225. for i, config in pairs(AbsActExcel.drop) do
  226. if config and config.actID == actId then
  227. local outCnt = math.floor(time/config.dropTime)
  228. if outCnt > 0 then
  229. for j = 1, outCnt do
  230. local itemID = config.dropItem[1]
  231. local itemCnt = config.dropItem[2]
  232. itemTable[itemID] = itemTable[itemID] or 0
  233. itemTable[itemID] = itemTable[itemID] + itemCnt
  234. end
  235. end
  236. end
  237. end
  238. end
  239. function getAbsCanDrop(human)
  240. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  241. if not state then return end
  242. local list
  243. local have = {}
  244. local absActConfig = AbsActExcel.absActivity[id]
  245. local actId = absActConfig.actId
  246. for i, config in pairs(AbsActExcel.drop) do
  247. if config and config.actID == actId then
  248. list = list or {}
  249. list[config.dropItem[1]] = config.dropItem[2]
  250. break
  251. end
  252. end
  253. return list
  254. end
  255. function isRed(human, YYInfo, funcConfig)
  256. -- if funcConfig.adIcon == 1 then return end
  257. -- local state,endTime, starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  258. -- if not state then return end
  259. -- return true
  260. end
  261. function isActive(human, YYInfo, funcConfig)
  262. return not isOpen(human, YYInfo, funcConfig)
  263. end
  264. function isOpen(human, YYInfo, funcConfig)
  265. return AbsActLogic.isStarted(human, funcConfig.funcID)
  266. end