Abs365CardLogic.lua 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. -- 刷新
  135. getAndSendMsg(human, id, config)
  136. end
  137. -- 根据权重算索引
  138. local function randomItemIndex(itemTable)
  139. local totalWeight = 0
  140. for i = 1, #itemTable do
  141. local item = itemTable[i]
  142. totalWeight = totalWeight + item[3]
  143. end
  144. if totalWeight <= 0 then
  145. return
  146. end
  147. local len = 0
  148. local index = nil
  149. local random = math.random(1, totalWeight)
  150. for i = 1, #itemTable do
  151. local item = itemTable[i]
  152. local weight = item[3]
  153. if random <= weight then
  154. index = i
  155. break
  156. else
  157. random = random - weight
  158. end
  159. end
  160. return index
  161. end
  162. function updateDaily(human, id)
  163. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  164. if not state then return end
  165. local config = AbsActExcel.absActivity[id]
  166. if not config then return end
  167. local actId = config.actId
  168. local abs365CardConfig = AbsActExcel.abs365Card[actId]
  169. if not abs365CardConfig then return end
  170. local absAct = human.db.absAct[id]
  171. if not absAct then return end
  172. if not absAct.dayCnt or absAct.dayCnt <= 0 then return end
  173. absAct.draw = 1
  174. end
  175. function draw(human, id)
  176. local state, endTime, starTime = AbsActLogic.isStarted(human, id)
  177. if not state then return end
  178. local config = AbsActExcel.absActivity[id]
  179. if not config then return end
  180. local actId = config.actId
  181. local abs365CardConfig = AbsActExcel.abs365Card[actId]
  182. if not abs365CardConfig then return end
  183. local absAct = human.db.absAct[id]
  184. if not absAct then return end
  185. if not absAct.dayCnt or absAct.dayCnt <= 0 then return end
  186. if not absAct.draw or absAct.draw ~= 1 then return end
  187. -- 随机道具1 奖池道具
  188. local index = randomItemIndex(abs365CardConfig.item)
  189. if not index or not abs365CardConfig.item[index] then return end
  190. local index2 = randomItemIndex(abs365CardConfig.item2)
  191. if not index2 or not abs365CardConfig.item2[index2] then return end
  192. absAct.dayCnt = absAct.dayCnt - 1
  193. absAct.draw = 0
  194. -- 加入到已有的道具中
  195. local itemReward = { [1] = { abs365CardConfig.item2[index2][1], abs365CardConfig.item2[index2][2] } }
  196. BagLogic.addItemList(human, itemReward, "abs_365Card")
  197. absAct.newItem = { abs365CardConfig.item[index][1], abs365CardConfig.item[index][2] }
  198. local bAdd = false
  199. for i = 1, #absAct.item do
  200. local item = absAct.item[i]
  201. if item[1] == abs365CardConfig.item[index][1] then
  202. item[2] = item[2] + abs365CardConfig.item[index][2]
  203. bAdd = true
  204. break
  205. end
  206. end
  207. if not bAdd then
  208. absAct.item[#absAct.item + 1] = { abs365CardConfig.item[index][1], abs365CardConfig.item[index][2] }
  209. end
  210. YunYingLogic.updateIcon(YYInfo[id], human)
  211. YunYingLogic.sendGroupUpdate(YYInfo[id], human, config.panelID)
  212. -- 刷新
  213. getAndSendMsg(human, id, config)
  214. end