AbsJifenDrawLogic.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. --英雄兑换ID
  23. ABS_ACT_ID_HERODRAW=10001
  24. function onZero(human,funcID)
  25. local state=AbsActLogic.isStarted(human, funcID)
  26. if not state then
  27. human.db.absAct[ABS_ACT_ID_HERODRAW] = nil
  28. end
  29. end
  30. function isOpen(human, YYInfo, funcConfig)
  31. return AbsActLogic.isStarted(human, funcConfig.funcID)
  32. end
  33. function isActive(human, YYInfo, funcConfig)
  34. return not isOpen(human, YYInfo, funcConfig)
  35. end
  36. function isRed(human, YYInfo, funcConfig)
  37. return false
  38. end
  39. function getAndSendMsg(human, id, config)
  40. local absAct = human.db.absAct[id]
  41. if not absAct then
  42. print("not found human.db.absAct")
  43. return
  44. end
  45. local actId = config.actId
  46. local msgRet = Msg.gc.GC_ABS_ACT_JIFEN_DRAW_QUERY
  47. local jifenDrawConfig = AbsActExcel.absJifenDraw[actId]
  48. if not jifenDrawConfig then
  49. print("not found jifenDrawConfig",actId)
  50. return
  51. end
  52. local len = 0
  53. for k, config in ipairs(jifenDrawConfig.heroList) do
  54. len = len + 1
  55. if len > #msgRet.list then
  56. break
  57. end
  58. local net = msgRet.list[len]
  59. if net then
  60. net.id = k
  61. net.cur = absAct[k] or 0
  62. net.max = config[3]
  63. net.cost = config[2]
  64. HeroGrid.makeHeroSimpleByID(net.hero, config[1])
  65. end
  66. end
  67. msgRet.list[0] = len
  68. msgRet.randomCost = DrawCardLogic.MAX_JIFEN
  69. msgRet.curJifen = DrawCardLogic.getJifen(human)
  70. Msg.send(msgRet, human.fd)
  71. end
  72. -- 积分购买
  73. function buy(human, id, actID)
  74. local state,endTime, starTime = AbsActLogic.isStarted(human, actID)
  75. if not state then return end
  76. local config = AbsActExcel.absActivity[actID]
  77. if not config then return end
  78. local jifenDrawConfig = AbsActExcel.absJifenDraw[config.actId]
  79. if not jifenDrawConfig then return end
  80. local absAct = human.db.absAct[actID]
  81. if not absAct then
  82. return
  83. end
  84. local heroConfig = jifenDrawConfig.heroList[id]
  85. if not heroConfig then return end
  86. -- 扣除积分
  87. if DrawCardLogic.getJifen(human) < heroConfig[2] then
  88. return Broadcast.sendErr(human, Lang.DRAWCARD_ERR_NOJIFEN)
  89. end
  90. absAct[id] = absAct[id] or 0
  91. if absAct[id] >= heroConfig[3] then
  92. return
  93. end
  94. DrawCardLogic.updateJifen(human, -heroConfig[2])
  95. absAct[id] = absAct[id] + 1
  96. local heroID = heroConfig[1]
  97. local drawConfig = HeroExcel.hero[heroID]
  98. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE4, drawConfig.grade, heroID)
  99. local isNew = not HeroBook.isGet(human, drawConfig.id, drawConfig.star)
  100. local heroIndex, fenjielist = HeroLogic.addHero(human, heroID, nil, 1, "abs_jifenDraw")
  101. Log.write(Log.LOGID_OSS_DRAWCARD, human.db._id, human.db.account, human.db.name, human.db.lv, DrawCardLogic.DRAWCARD_ID4, heroID, 0, 0, 0, DrawCardLogic.getJifen(human))
  102. DrawCardLogic.sendDrawOp(human, DrawCardLogic.DRAWCARD_ID4, 0, {heroID}, fenjielist, {isNew}, {heroIndex}, AbsActDefine.ABS_ACT_TYPE_7)
  103. end