| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- --------------------------------
- -- 文件名 : RecommendLineup.lua
- -- 文件说明 : 推荐阵容
- -- 创建时间 : 2025/1/15
- -- 创建人 : FC
- --------------------------------
- local HeroLogic = require("hero.HeroLogic")
- local BagLogic = require("bag.BagLogic")
- local HeroGrid = require("hero.HeroGrid")
- local CommonDB = require("common.CommonDB")
- local Msg = require("core.Msg")
- local CombatPosLogic = require("combat.CombatPosLogic")
- local CombatDefine = require("combat.CombatDefine")
- local nRecommendLineupLen = 30 -- 阵容记录推荐数量
- local tRecommendLineupData = nil
- ---------------------------------------- 内部函数 ------------------------------------
- local function RecommendLineup_GetData()
- if not tRecommendLineupData then
- tRecommendLineupData = CommonDB.getRecommendLineUp()
- end
- return tRecommendLineupData
- end
- local function RecommendLineup_SetData(tData)
- tRecommendLineupData = tData
- CommonDB.SetRecommendLineUp(tRecommendLineupData)
- end
- -- 获取小于该战力的下表
- local function RecommendLineup_GetIndex(nNewPower)
- local nIndex = -1
- local tDBData = RecommendLineup_GetData()
- if nil == _G.next(tDBData) then
- nIndex = 1
- return nIndex
- end
- local nNowLen = #tDBData
- if nNowLen < nRecommendLineupLen then
- nIndex = nNowLen + 1
- return nIndex
- end
- for i, value in ipairs(tDBData) do
- local nPower = value.nPower
- if nNewPower > nPower then
- nIndex = i
- break
- end
- end
- return nIndex
- end
- -- 插入最新的表
- local function RecommendLineup_UpDateData(human, nIndex, tHeroData)
- local tOldData = RecommendLineup_GetData()
- local nOldLen = #tOldData
- local tNewData = {}
- if nil == _G.next(tOldData) then
- table.insert(tNewData, tHeroData)
- RecommendLineup_SetData(tNewData)
- return
- end
- if nOldLen < nRecommendLineupLen then
- tNewData = tOldData
- table.insert(tNewData, tHeroData)
- RecommendLineup_SetData(tNewData)
- return
- end
-
- -- 只有30个直接遍历
- local nLen = 0
- local tLastData = nil
- for i, value in ipairs(tOldData) do
- if nLen >= nRecommendLineupLen then
- break
- end
- if i == nIndex then
- table.insert(tNewData, tHeroData)
- tLastData = value
- elseif i < nIndex then
- table.insert(tNewData, value)
- elseif i > nIndex then
- table.insert(tNewData, tLastData)
- tLastData = value
- end
-
- nLen = nLen + 1
- end
- RecommendLineup_SetData(tNewData)
- end
- ---------------------------------------- 客户端请求 ------------------------------------
- function GetRecommendLineUp(human)
- local tData = RecommendLineup_GetData()
- local tMsgData = Msg.gc.GC_DRAWCARD_GET_RECOMMEND_LINEUP
- tMsgData.list[0] = 0
- for i, value in ipairs(tData) do
- tMsgData.list[0] = tMsgData.list[0] + 1
- local tHeroData = tMsgData.list[tMsgData.list[0]]
- tHeroData.data[0] = 0
- tHeroData.nPower = value.nPower
- for _, v in pairs(value.data) do
- tHeroData.data[0] = tHeroData.data[0] + 1
- tHeroData[tHeroData.data[0]] = v
- end
- end
- Msg.send(tMsgData, human.fd)
- end
- function RecommendLineup_UpDate(human)
- local combatHero,helpList = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
- if not combatHero then
- return
- end
- local nNewPower = CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE1, true)
- local nIndex = RecommendLineup_GetIndex(nNewPower)
- if -1 >= nIndex then
- return
- end
- local tHeroData = {
- nPower = nNewPower,
- data = {},
- }
- local nLen = 1
- for _, v in pairs(combatHero) do
- local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
- if heroGrid then
- tHeroData.data[nLen] = {
- general = {},
- gemData = {},
- }
- HeroGrid.makeHeroSimple(tHeroData.data[nLen], heroGrid, heroGrid.bagIndex, human)
- nLen = nLen + 1
- end
- end
-
- for _,v in pairs(helpList) do
- local heroGrid = HeroLogic.getHeroGridByUuid(human, v)
- if heroGrid then
- tHeroData.data[nLen] = {
- general = {},
- gemData = {},
- }
- HeroGrid.makeHeroSimple(tHeroData.data[nLen], heroGrid, heroGrid.bagIndex, human)
- nLen = nLen + 1
- end
- end
- -- RecommendLineup_UpDateData(human, nIndex, tHeroData)
- end
|