DropExchangeLogic.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  99. if not state then return end
  100. local absActConfig = AbsActExcel.absActivity[id]
  101. local actId = absActConfig.actId
  102. local absAct = human.db.absAct[id]
  103. local config = AbsActExcel.dropShop[shopID]
  104. if not config then return end
  105. if config.actID ~= actId then return end
  106. local oldBuy = absAct.buyCnt and absAct.buyCnt[shopID] or 0
  107. if config.limit > 0 and oldBuy + buyCnt > config.limit then return end
  108. if getJifen(human, id) < config.need * buyCnt then
  109. Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, ItemDefine.getValue(config.needItem, "name")))
  110. return
  111. end
  112. delJifen(human, config.need * buyCnt)
  113. absAct.buyCnt = absAct.buyCnt or {}
  114. absAct.buyCnt[shopID] = absAct.buyCnt[shopID] or 0
  115. absAct.buyCnt[shopID] = absAct.buyCnt[shopID] + buyCnt
  116. BagLogic.addItem(human, config.item[1], config.item[2] * buyCnt,"abs_dropShop")
  117. local msgRet = Msg.gc.GC_ABS_ACT_DROP_SHOP_BUY
  118. msgRet.id = shopID
  119. if not ItemDefine.isEquip(config.item[1]) then
  120. Grid.makeItem(msgRet.item , config.item[1], config.item[2] * buyCnt)
  121. else
  122. EquipLogic.makeEquipItemOne(human, msgRet.item)
  123. end
  124. Msg.send(msgRet, human.fd)
  125. -- shopQuery(human)
  126. end
  127. function giftQuery(human)
  128. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  129. if not state then return end
  130. local absActConfig = AbsActExcel.absActivity[id]
  131. local actId = absActConfig.actId
  132. local msgRet = Msg.gc.GC_ABS_ACT_DROP_GIFT_QUERY
  133. local len = 0
  134. for k, config in pairs(AbsActExcel.premiumGift) do
  135. if config and config.actId == actId then
  136. len = len + 1
  137. local net = msgRet.list[len]
  138. net.id = k
  139. net.cnt = human.db.absAct[id].premiumCnt and human.db.absAct[id].premiumCnt[k] or 0
  140. net.maxCnt = config.cnt
  141. for j = 1, #config.reward do
  142. Grid.makeItem(net.item[j], config.reward[j][1], config.reward[j][2])
  143. end
  144. net.item[0] = #config.reward
  145. BuyLogic.fontBuyItem(human,net.buyMsg, config.buyID)
  146. end
  147. end
  148. msgRet.list[0] = len
  149. Msg.send(msgRet, human.fd)
  150. end
  151. function drawSSR(human, net, cnt)
  152. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  153. if not state then return end
  154. local absActConfig = AbsActExcel.absActivity[id]
  155. local actId = absActConfig.actId
  156. for k, config in pairs(AbsActExcel.drop) do
  157. if config and config.actID == actId then
  158. BagLogic.addItem(human, config.ssrDrop[1], config.ssrDrop[2] * cnt, "abs_dropSSR")
  159. net[config.ssrDrop[1]] = net[config.ssrDrop[1]] or 0
  160. net[config.ssrDrop[1]] = net[config.ssrDrop[1]] + config.ssrDrop[2] * cnt
  161. break
  162. end
  163. end
  164. end
  165. function getDropItem(human,outSec, time ,net)
  166. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  167. if not state then return end
  168. AbsActLogic.checkAbsActClean(human, id)
  169. local absActConfig = AbsActExcel.absActivity[id]
  170. local actId = absActConfig.actId
  171. local now = os.time()
  172. local thisStart = now - outSec
  173. for i, config in pairs(AbsActExcel.drop) do
  174. if config and config.actID == actId then
  175. local absAct = human.db.absAct[id]
  176. local outCnt = 0
  177. local thisSec = outSec
  178. if absAct.dropTime then
  179. thisSec = now - absAct.dropTime
  180. local maxHang = BattleLogic.getHangMaxTime(human)
  181. thisSec = thisSec < maxHang and thisSec or maxHang
  182. elseif thisStart < starTime then
  183. thisSec = outSec - (starTime - thisStart)
  184. end
  185. if thisSec > 0 then
  186. outCnt = math.floor(thisSec/config.dropTime)
  187. end
  188. if outCnt > 0 then
  189. for j = 1, outCnt do
  190. local itemID = config.dropItem[1]
  191. local itemCnt = config.dropItem[2]
  192. net.items = net.items or {}
  193. net.items[itemID] = net.items[itemID] or 0
  194. net.items[itemID] = net.items[itemID] + itemCnt
  195. absAct.dropTime = os.time()
  196. end
  197. end
  198. end
  199. end
  200. end
  201. function getDropItemSaoQuery(human, net, dropCnt)
  202. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  203. if not state then return dropCnt end
  204. AbsActLogic.checkAbsActClean(human, id)
  205. local absActConfig = AbsActExcel.absActivity[id]
  206. local actId = absActConfig.actId
  207. for i, config in pairs(AbsActExcel.drop) do
  208. if config and config.actID == actId then
  209. local itemID = config.dropItem[1]
  210. local itemCnt = config.dropItem[2]
  211. dropCnt = dropCnt + 1
  212. Grid.makeItem(net.item[dropCnt], itemID, 1)
  213. break
  214. end
  215. end
  216. return dropCnt
  217. end
  218. function getDropItemSao(human,time ,itemTable)
  219. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  220. if not state then return end
  221. AbsActLogic.checkAbsActClean(human, id)
  222. local absActConfig = AbsActExcel.absActivity[id]
  223. local actId = absActConfig.actId
  224. for i, config in pairs(AbsActExcel.drop) do
  225. if config and config.actID == actId then
  226. local outCnt = math.floor(time/config.dropTime)
  227. if outCnt > 0 then
  228. for j = 1, outCnt do
  229. local itemID = config.dropItem[1]
  230. local itemCnt = config.dropItem[2]
  231. itemTable[itemID] = itemTable[itemID] or 0
  232. itemTable[itemID] = itemTable[itemID] + itemCnt
  233. end
  234. end
  235. end
  236. end
  237. end
  238. function getAbsCanDrop(human)
  239. local state,id,endTime, starTime = AbsActLogic.isStartedByType(human, AbsActDefine.ABS_ACT_TYPE_6)
  240. if not state then return end
  241. local list
  242. local have = {}
  243. local absActConfig = AbsActExcel.absActivity[id]
  244. local actId = absActConfig.actId
  245. for i, config in pairs(AbsActExcel.drop) do
  246. if config and config.actID == actId then
  247. list = list or {}
  248. list[config.dropItem[1]] = config.dropItem[2]
  249. break
  250. end
  251. end
  252. return list
  253. end
  254. function isRed(human, YYInfo, funcConfig)
  255. -- if funcConfig.adIcon == 1 then return end
  256. -- local state,endTime, starTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  257. -- if not state then return end
  258. -- return true
  259. end
  260. function isActive(human, YYInfo, funcConfig)
  261. return not isOpen(human, YYInfo, funcConfig)
  262. end
  263. function isOpen(human, YYInfo, funcConfig)
  264. return AbsActLogic.isStarted(human, funcConfig.funcID)
  265. end