RecommendLineup.lua 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. --------------------------------
  2. -- 文件名 : RecommendLineup.lua
  3. -- 文件说明 : 推荐阵容
  4. -- 创建时间 : 2025/1/15
  5. -- 创建人 : FC
  6. --------------------------------
  7. local HeroLogic = require("hero.HeroLogic")
  8. local BagLogic = require("bag.BagLogic")
  9. local HeroGrid = require("hero.HeroGrid")
  10. local CommonDB = require("common.CommonDB")
  11. local Msg = require("core.Msg")
  12. local CombatPosLogic = require("combat.CombatPosLogic")
  13. local CombatDefine = require("combat.CombatDefine")
  14. local nRecommendLineupLen = 30 -- 阵容记录推荐数量
  15. local tRecommendLineupData = nil
  16. ---------------------------------------- 内部函数 ------------------------------------
  17. local function RecommendLineup_GetData()
  18. if not tRecommendLineupData then
  19. tRecommendLineupData = CommonDB.getRecommendLineUp()
  20. end
  21. return tRecommendLineupData
  22. end
  23. local function RecommendLineup_SetData(tData)
  24. tRecommendLineupData = tData
  25. CommonDB.SetRecommendLineUp(tRecommendLineupData)
  26. end
  27. -- 获取小于该战力的下表
  28. local function RecommendLineup_GetIndex(nNewPower)
  29. local nIndex = -1
  30. local tDBData = RecommendLineup_GetData()
  31. if nil == _G.next(tDBData) then
  32. nIndex = 1
  33. return nIndex
  34. end
  35. local nNowLen = #tDBData
  36. if nNowLen < nRecommendLineupLen then
  37. nIndex = nNowLen + 1
  38. return nIndex
  39. end
  40. for i, value in ipairs(tDBData) do
  41. local nPower = value.nPower
  42. if nNewPower > nPower then
  43. nIndex = i
  44. break
  45. end
  46. end
  47. return nIndex
  48. end
  49. -- 插入最新的表
  50. local function RecommendLineup_UpDateData(human, nIndex, tHeroData)
  51. local tOldData = RecommendLineup_GetData()
  52. local nOldLen = #tOldData
  53. local tNewData = {}
  54. if nil == _G.next(tOldData) then
  55. table.insert(tNewData, tHeroData)
  56. RecommendLineup_SetData(tNewData)
  57. return
  58. end
  59. if nOldLen < nRecommendLineupLen then
  60. tNewData = tOldData
  61. table.insert(tNewData, tHeroData)
  62. RecommendLineup_SetData(tNewData)
  63. return
  64. end
  65. -- 只有30个直接遍历
  66. local nLen = 0
  67. local tLastData = nil
  68. for i, value in ipairs(tOldData) do
  69. if nLen >= nRecommendLineupLen then
  70. break
  71. end
  72. if i == nIndex then
  73. table.insert(tNewData, tHeroData)
  74. tLastData = value
  75. elseif i < nIndex then
  76. table.insert(tNewData, value)
  77. elseif i > nIndex then
  78. table.insert(tNewData, tLastData)
  79. tLastData = value
  80. end
  81. nLen = nLen + 1
  82. end
  83. RecommendLineup_SetData(tNewData)
  84. end
  85. ---------------------------------------- 客户端请求 ------------------------------------
  86. function GetRecommendLineUp(human)
  87. local tData = RecommendLineup_GetData()
  88. local tMsgData = Msg.gc.GC_DRAWCARD_GET_RECOMMEND_LINEUP
  89. tMsgData.list[0] = 0
  90. for i, value in ipairs(tData) do
  91. tMsgData.list[0] = tMsgData.list[0] + 1
  92. local tHeroData = tMsgData.list[tMsgData.list[0]]
  93. tHeroData.data[0] = 0
  94. tHeroData.nPower = value.nPower
  95. for _, v in pairs(value.data) do
  96. tHeroData.data[0] = tHeroData.data[0] + 1
  97. tHeroData[tHeroData.data[0]] = v
  98. end
  99. end
  100. Msg.send(tMsgData, human.fd)
  101. end
  102. function RecommendLineup_UpDate(human)
  103. -- local combatHero,helpList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  104. -- if not combatHero then
  105. -- return
  106. -- end
  107. -- local nNewPower = CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE1, true)
  108. -- local nIndex = RecommendLineup_GetIndex(nNewPower)
  109. -- if -1 >= nIndex then
  110. -- return
  111. -- end
  112. -- local tHeroData = {
  113. -- nPower = nNewPower,
  114. -- data = {},
  115. -- }
  116. -- local nLen = 1
  117. -- for _, v in pairs(combatHero) do
  118. -- local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
  119. -- if heroGrid then
  120. -- tHeroData.data[nLen] = {
  121. -- general = {},
  122. -- gemData = {},
  123. -- }
  124. -- HeroGrid.makeHeroSimple(tHeroData.data[nLen], heroGrid, heroGrid.bagIndex, human)
  125. -- nLen = nLen + 1
  126. -- end
  127. -- end
  128. -- for _,v in pairs(helpList) do
  129. -- local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
  130. -- if heroGrid then
  131. -- tHeroData.data[nLen] = {
  132. -- general = {},
  133. -- gemData = {},
  134. -- }
  135. -- HeroGrid.makeHeroSimple(tHeroData.data[nLen], heroGrid, heroGrid.bagIndex, human)
  136. -- nLen = nLen + 1
  137. -- end
  138. -- end
  139. -- RecommendLineup_UpDateData(human, nIndex, tHeroData)
  140. end