MonthSummon.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. -- 月度活动 转盘高抽 猛将如虎 招贤纳士
  2. -- human.db.actMonthTask.summonCnt 本轮完成次数
  3. -- human.db.actMonthTask.sumWinScoCnt 总完成轮数
  4. local Lang = require("common.Lang")
  5. local Util = require("common.Util")
  6. local Msg = require("core.Msg")
  7. local MailExcel = require("excel.mail")
  8. local MonthactExcel = require("excel.monthAct")
  9. local Grid = require("bag.Grid")
  10. local Broadcast = require("broadcast.Broadcast")
  11. local BagLogic = require("bag.BagLogic")
  12. local MailManager = require("mail.MailManager")
  13. local MonthActLogic = require("monthAct.MonthActLogic")
  14. local YunYingLogic = require("yunying.YunYingLogic")
  15. local function getRoundCnt(human)
  16. if not human.db.actMonthTask then
  17. return 0
  18. end
  19. return human.db.actMonthTask.sumWinScoCnt or 0
  20. end
  21. local function setRoundCnt(human, value)
  22. human.db.actMonthTask = human.db.actMonthTask or {}
  23. human.db.actMonthTask.sumWinScoCnt = value
  24. end
  25. local function getSummonCnt(human)
  26. if not human.db.actMonthTask then
  27. return 0
  28. end
  29. return human.db.actMonthTask.summonCnt or 0
  30. end
  31. local function setSummonCnt(human, value)
  32. human.db.actMonthTask = human.db.actMonthTask or {}
  33. human.db.actMonthTask.summonCnt = value
  34. end
  35. local MAX_SUMMON_CNT = nil
  36. local function getMaxSummonCnt()
  37. if not MAX_SUMMON_CNT then
  38. MAX_SUMMON_CNT = 0
  39. for _, cf in ipairs(MonthactExcel.sumWinScore) do
  40. MAX_SUMMON_CNT = math.max(MAX_SUMMON_CNT, cf.needCnt)
  41. end
  42. end
  43. return MAX_SUMMON_CNT
  44. end
  45. -- 查询召唤礼包信息
  46. function query(human)
  47. local msgRet = Msg.gc.GC_MONTHACT_SUMMON_WIN_SCORE_QUERY
  48. local roundCnt = getRoundCnt(human)
  49. local maxRoundCnt = MonthactExcel.sumWinScore[1].reCnt
  50. msgRet.curCnt = roundCnt
  51. msgRet.cnt = maxRoundCnt
  52. msgRet.leftTime = MonthActLogic.getActLeftTime(human)
  53. msgRet.sunWinScoreMsg[0] = #MonthactExcel.sumWinScore
  54. for id, cf in ipairs(MonthactExcel.sumWinScore) do
  55. local net = msgRet.sunWinScoreMsg[id]
  56. net.id = id
  57. if roundCnt >= maxRoundCnt then
  58. net.cur = cf.needCnt
  59. else
  60. net.cur = math.min(getSummonCnt(human), cf.needCnt)
  61. end
  62. net.max = cf.needCnt
  63. net.reward[0] = #cf.reward
  64. net.desc = ""
  65. for i = 1, net.reward[0] do
  66. Grid.makeItem(net.reward[i], cf.reward[i][1], cf.reward[i][2])
  67. end
  68. end
  69. --Msg.trace(msgRet)
  70. Msg.send(msgRet, human.fd)
  71. end
  72. -- 发送礼包物品
  73. function onSummon(human, cnt)
  74. -- 检查活动是否结束
  75. MonthActLogic.checkActEndTime(human)
  76. -- 满6轮了
  77. local roundCnt = getRoundCnt(human)
  78. local maxRoundCnt = MonthactExcel.sumWinScore[1].reCnt
  79. if roundCnt >= maxRoundCnt then
  80. return
  81. end
  82. local oldCnt = getSummonCnt(human)
  83. local newCnt = oldCnt + cnt
  84. local maxSummonCnt = getMaxSummonCnt()
  85. local summonCnt = newCnt % maxSummonCnt
  86. -- 判断是否达到兑换次数上限
  87. for round = roundCnt + 1, maxRoundCnt do
  88. for id, cf in ipairs(MonthactExcel.sumWinScore) do
  89. if newCnt < cf.needCnt then
  90. break
  91. end
  92. if oldCnt < cf.needCnt then
  93. local title = MailExcel.mail[26].title
  94. local content = Util.format(MailExcel.mail[26].content, cf.needCnt)
  95. local senderName = MailExcel.mail[26].senderName
  96. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, cf.reward, senderName)
  97. end
  98. end
  99. if newCnt < maxSummonCnt then
  100. break
  101. end
  102. oldCnt = 0
  103. newCnt = newCnt - maxSummonCnt
  104. roundCnt = round
  105. end
  106. setRoundCnt(human, roundCnt)
  107. setSummonCnt(human, summonCnt)
  108. for k, v in pairs(funcID) do
  109. YunYingLogic.updateIcon(YYInfo[k], human)
  110. break
  111. end
  112. end
  113. --[[
  114. function isRed(human)
  115. local roundCnt = getRoundCnt(human)
  116. local maxRoundCnt = MonthactExcel.sumWinScore[1].reCnt
  117. if roundCnt < maxRoundCnt then
  118. return true
  119. end
  120. end
  121. --]]