HeroGrowLogic.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. -------------------------------------------------
  2. -- 成神之路-英雄成长(神将辅助)
  3. -- db.heroGrowTask[id]
  4. -------------------------------------------------
  5. local Util = require("common.Util")
  6. local MailExcel = require("excel.mail")
  7. local HeroExcel = require("excel.hero").hero
  8. local PresentExcel = require("excel.present")
  9. local OpenActExcel = require("excel.openAct")
  10. local Msg = require("core.Msg")
  11. local ObjHuman = require("core.ObjHuman")
  12. local Grid = require("bag.Grid")
  13. local MailManager = require("mail.MailManager")
  14. HEROGROW_OPENTIME = 7 * 86400
  15. --
  16. local function getActLeftTime(human)
  17. local diffTime = os.time() - human.db.createTime
  18. if diffTime < HEROGROW_OPENTIME then
  19. return HEROGROW_OPENTIME - diffTime
  20. end
  21. return 0
  22. end
  23. function isOpen(human)
  24. if true then
  25. return
  26. end
  27. -- 创角七天
  28. if getActLeftTime(human) > 0 then
  29. return true
  30. end
  31. end
  32. local function getCurCnt(human, id)
  33. if not human.db.heroGrowTask then
  34. return 0
  35. end
  36. return human.db.heroGrowTask[id] or 0
  37. end
  38. -- 填充活动任务数据
  39. function makeTaskData(net, config, id, human)
  40. net.id = id
  41. net.desc = config.desc
  42. net.cur = getCurCnt(human, id)
  43. net.max = config.taskCnt
  44. net.reward[0] = #config.reward
  45. for i = 1, net.reward[0] do
  46. local itemID = config.reward[i][1]
  47. local itemCnt = config.reward[i][2]
  48. Grid.makeItem(net.reward[i], itemID, itemCnt)
  49. end
  50. end
  51. function query(human)
  52. local msgRet = Msg.gc.GC_PRESENT_HERO_GROW_QUERY
  53. msgRet.leftTime = getActLeftTime(human)
  54. msgRet.list[0] = #OpenActExcel.heroGrow
  55. for id, config in ipairs(OpenActExcel.heroGrow) do
  56. makeTaskData(msgRet.list[id], config, id, human)
  57. end
  58. --Msg.trace(msgRet)
  59. Msg.send(msgRet, human.fd)
  60. end
  61. local function addOpenServerHeroCnt(human, id)
  62. local tableConfig = OpenActExcel.heroGrow[id]
  63. if not tableConfig then return end
  64. -- 已经达到完成上限
  65. if getCurCnt(human, id) >= tableConfig.taskCnt then
  66. return
  67. end
  68. human.db.heroGrowTask = human.db.heroGrowTask or {}
  69. human.db.heroGrowTask[id] = (human.db.heroGrowTask[id] or 0) + 1
  70. -- 存db
  71. ObjHuman.save(human)
  72. --完成一次 发放奖励一次
  73. local title = MailExcel.mail[71].title
  74. local content = Util.format(MailExcel.mail[71].content, tableConfig.special)
  75. local senderName = MailExcel.mail[71].senderName
  76. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, tableConfig.reward, senderName)
  77. end
  78. -- 回调
  79. function addOpenServerHeroCntEx(human, star, heroID)
  80. if not isOpen(human) then return end
  81. star = star or 0
  82. for id, tableData in ipairs(OpenActExcel.heroGrow) do
  83. if tableData and star == tableData.special then
  84. addOpenServerHeroCnt(human, id, heroID)
  85. end
  86. end
  87. end