Abs365CardLogic.lua 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. -- ABS 周卡
  2. local Config = require("Config")
  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 AbsActDefine = require("absAct.AbsActDefine")
  8. local ObjHuman = require("core.ObjHuman")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local MangHeLogic = require("absAct.MangHeLogic")
  11. local MailExcel = require("excel.mail")
  12. local MailManager = require("mail.MailManager")
  13. local CommonDB = require("common.CommonDB")
  14. local AbsActLogic = require("absAct.AbsActLogic")
  15. local HeroGrid = require("hero.HeroGrid")
  16. local DrawCardLogic = require("drawCard.DrawCardLogic")
  17. local Log = require("common.Log")
  18. local HeroBook = require("hero.HeroBook")
  19. local HeroExcel = require("excel.hero")
  20. local HeroLogic = require("hero.HeroLogic")
  21. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  22. local Grid = require("bag.Grid")
  23. local BuyLogic = require("topup.BuyLogic")
  24. local BuyExcel = require("excel.buy")
  25. local TopupLogic = require("topup.TopupLogic")
  26. local BagLogic = require("bag.BagLogic")
  27. local YunYingLogic = require("yunying.YunYingLogic")
  28. DAY_CNT = 365
  29. local function initDB(human, id)
  30. if not human.db.absAct[id] then return end
  31. human.db.absAct[id].dayCnt = human.db.absAct[id].dayCnt or DAY_CNT
  32. human.db.absAct[id].item = human.db.absAct[id].item or { }
  33. human.db.absAct[id].draw = human.db.absAct[id].draw or 1
  34. end
  35. function isOpen(human, YYInfo, funcConfig)
  36. local state, endTime, startTime = AbsActLogic.isStarted(human, funcConfig.funcID)
  37. if not state then return end
  38. local absAct = human.db.absAct[funcConfig.funcID]
  39. if absAct and absAct.dayCnt and absAct.dayCnt <= 0 and #absAct.item <= 0 then
  40. return false
  41. end
  42. return true, endTime, startTime
  43. end
  44. function isActive(human, YYInfo, funcConfig)
  45. return not isOpen(human, YYInfo, funcConfig)
  46. end
  47. function isRed(human, YYInfo, funcConfig)
  48. local absAct = human.db.absAct[funcConfig.funcID]
  49. if not absAct then return true end
  50. if not absAct.dayCnt or absAct.dayCnt <= 0 then return end
  51. if absAct.draw == 1 then
  52. return true
  53. end
  54. if absAct.active then
  55. if #absAct.item > 0 then
  56. return true
  57. end
  58. end
  59. return false
  60. end
  61. function getAndSendMsg(human, id, config)
  62. local msgRet = Msg.gc.GC_ABS_365CARD_QUERY
  63. msgRet.leftTime = 0
  64. msgRet.actId = id
  65. local actId = config.actId
  66. local abs365CardConfig = AbsActExcel.abs365Card[actId]
  67. if not abs365CardConfig then return end
  68. local buyItemConfig = BuyExcel.libao[TopupLogic.TOPUP_LIBAO_ID3]
  69. if not buyItemConfig then return end
  70. msgRet.items[0] = #abs365CardConfig.item
  71. for i = 1, #abs365CardConfig.item do
  72. Grid.makeItem(msgRet.items[i], abs365CardConfig.item[i][1], abs365CardConfig.item[i][2])
  73. end
  74. -- 获得的道具
  75. local absAct = human.db.absAct[id]
  76. initDB(human, id)
  77. msgRet.getItems[0] = 0
  78. if absAct.item then
  79. msgRet.getItems[0] = #absAct.item
  80. for i = 1, #absAct.item do
  81. Grid.makeItem(msgRet.getItems[i], absAct.item[i][1], absAct.item[i][2])
  82. end
  83. end
  84. msgRet.newItem[0] = 0
  85. if absAct.newItem then
  86. Grid.makeItem(msgRet.newItem[1], absAct.newItem[1], absAct.newItem[2])
  87. msgRet.newItem[0] = 1
  88. absAct.newItem = nil
  89. end
  90. msgRet.leftDay = absAct and absAct.dayCnt or DAY_CNT
  91. msgRet.draw = absAct and absAct.draw or 0
  92. msgRet.active = absAct.active or 0
  93. msgRet.buyItem.item[0] = #buyItemConfig.reward
  94. for i = 1, #buyItemConfig.reward do
  95. Grid.makeItem(msgRet.buyItem.item[i], buyItemConfig.reward[i][1], buyItemConfig.reward[i][2])
  96. end
  97. msgRet.buyItem.cnt = 1
  98. msgRet.buyItem.id = TopupLogic.TOPUP_LIBAO_ID3
  99. msgRet.buyItem.maxCnt = buyItemConfig.cnt
  100. msgRet.buyItem.icon = buyItemConfig.icon or 0
  101. msgRet.buyItem.name = ""
  102. BuyLogic.fontBuyItem(human, msgRet.buyItem.buyMsg[1], buyItemConfig.buyID)
  103. msgRet.buyItem.buyMsg[0] = 1
  104. msgRet.buyItem.needItem[0] = 0
  105. Msg.send(msgRet, human.fd)
  106. end
  107. -- 领取道具
  108. function get(human, id)
  109. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  110. if not state then return end
  111. local config = AbsActExcel.absActivity[id]
  112. if not config then return end
  113. local absAct = human.db.absAct[id]
  114. if not absAct then return end
  115. if not absAct.active then return end
  116. if #absAct.item <= 0 then return end
  117. BagLogic.addItemList(human, absAct.item, "abs_365Card")
  118. absAct.item = {}
  119. YunYingLogic.updateIcon(YYInfo[id], human)
  120. YunYingLogic.sendGroupUpdate(YYInfo[id], human, config.panelID)
  121. getAndSendMsg(human, id, config)
  122. end
  123. -- 积分购买
  124. function abs365Card(human, id, buyConf, isFirst, cnt)
  125. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  126. if not state then return end
  127. local config = AbsActExcel.absActivity[id]
  128. if not config then return end
  129. local buyItemConfig = BuyExcel.libao[TopupLogic.TOPUP_LIBAO_ID3]
  130. if not buyItemConfig then return end
  131. AbsActLogic.checkAbsActClean(human, id)
  132. human.db.absAct[id].active = 1
  133. BagLogic.addItemList(human, buyItemConfig.reward, "abs_365Card")
  134. end
  135. -- 根据权重算索引
  136. local function randomItemIndex(itemTable)
  137. local totalWeight = 0
  138. for i = 1, #itemTable do
  139. local item = itemTable[i]
  140. totalWeight = totalWeight + item[3]
  141. end
  142. if totalWeight <= 0 then
  143. return
  144. end
  145. local len = 0
  146. local index = nil
  147. local random = math.random(1, totalWeight)
  148. for i = 1, #itemTable do
  149. local item = itemTable[i]
  150. local weight = item[3]
  151. if random <= weight then
  152. index = i
  153. break
  154. else
  155. random = random - weight
  156. end
  157. end
  158. return index
  159. end
  160. function updateDaily(human, id)
  161. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  162. if not state then return end
  163. local config = AbsActExcel.absActivity[id]
  164. if not config then return end
  165. local actId = config.actId
  166. local abs365CardConfig = AbsActExcel.abs365Card[actId]
  167. if not abs365CardConfig then return end
  168. local absAct = human.db.absAct[id]
  169. if not absAct then return end
  170. if not absAct.dayCnt or absAct.dayCnt <= 0 then return end
  171. absAct.draw = 1
  172. end
  173. function draw(human, id)
  174. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  175. if not state then return end
  176. local config = AbsActExcel.absActivity[id]
  177. if not config then return end
  178. local actId = config.actId
  179. local abs365CardConfig = AbsActExcel.abs365Card[actId]
  180. if not abs365CardConfig then return end
  181. local absAct = human.db.absAct[id]
  182. if not absAct then return end
  183. if not absAct.dayCnt or absAct.dayCnt <= 0 then return end
  184. if not absAct.draw or absAct.draw ~= 1 then return end
  185. -- 随机道具1 奖池道具
  186. local index = randomItemIndex(abs365CardConfig.item)
  187. if not index or not abs365CardConfig.item[index] then return end
  188. local index2 = randomItemIndex(abs365CardConfig.item2)
  189. if not index2 or not abs365CardConfig.item2[index2] then return end
  190. absAct.dayCnt = absAct.dayCnt - 1
  191. absAct.draw = 0
  192. -- 加入到已有的道具中
  193. local itemReward = { [1] = { abs365CardConfig.item2[index2][1], abs365CardConfig.item2[index2][2] } }
  194. BagLogic.addItemList(human, itemReward, "abs_365Card")
  195. absAct.newItem = { abs365CardConfig.item[index][1], abs365CardConfig.item[index][2] }
  196. local bAdd = false
  197. for i = 1, #absAct.item do
  198. local item = absAct.item[i]
  199. if item[1] == abs365CardConfig.item[index][1] then
  200. item[2] = item[2] + abs365CardConfig.item[index][2]
  201. bAdd = true
  202. break
  203. end
  204. end
  205. if not bAdd then
  206. absAct.item[#absAct.item + 1] = { abs365CardConfig.item[index][1], abs365CardConfig.item[index][2] }
  207. end
  208. YunYingLogic.updateIcon(YYInfo[id], human)
  209. YunYingLogic.sendGroupUpdate(YYInfo[id], human, config.panelID)
  210. -- 刷新
  211. getAndSendMsg(human, id, config)
  212. end