Abs365CardLogic.lua 8.8 KB

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