|
|
@@ -12,29 +12,40 @@ local CommonDB = require("common.CommonDB")
|
|
|
local Msg = require("core.Msg")
|
|
|
local CombatPosLogic = require("combat.CombatPosLogic")
|
|
|
local CombatDefine = require("combat.CombatDefine")
|
|
|
+local HeroExcel = require("excel.hero")
|
|
|
|
|
|
|
|
|
local nRecommendLineupLen = 30 -- 阵容记录推荐数量
|
|
|
local tRecommendLineupData = nil
|
|
|
+local nSendLen = 15 -- 一次性发送数据长度
|
|
|
|
|
|
---------------------------------------- 内部函数 ------------------------------------
|
|
|
local function RecommendLineup_GetData()
|
|
|
if not tRecommendLineupData then
|
|
|
tRecommendLineupData = CommonDB.getRecommendLineUp()
|
|
|
+ table.sort(tRecommendLineupData, function (l, r)
|
|
|
+ return l.nPower > r.nPower
|
|
|
+ end
|
|
|
+ )
|
|
|
end
|
|
|
|
|
|
return tRecommendLineupData
|
|
|
end
|
|
|
|
|
|
local function RecommendLineup_SetData(tData)
|
|
|
+ table.sort(tData, function (l, r)
|
|
|
+ return l.nPower > r.nPower
|
|
|
+ end
|
|
|
+ )
|
|
|
tRecommendLineupData = tData
|
|
|
CommonDB.SetRecommendLineUp(tRecommendLineupData)
|
|
|
end
|
|
|
|
|
|
-- 获取小于该战力的下表
|
|
|
-local function RecommendLineup_GetIndex(nNewPower)
|
|
|
+local function RecommendLineup_GetIndex(nNewPower, human)
|
|
|
local nIndex = -1
|
|
|
local tDBData = RecommendLineup_GetData()
|
|
|
+ local nKey = human.db._id
|
|
|
|
|
|
if nil == _G.next(tDBData) then
|
|
|
nIndex = 1
|
|
|
@@ -43,8 +54,24 @@ local function RecommendLineup_GetIndex(nNewPower)
|
|
|
|
|
|
local nNowLen = #tDBData
|
|
|
if nNowLen < nRecommendLineupLen then
|
|
|
- nIndex = nNowLen + 1
|
|
|
- return nIndex
|
|
|
+ for i, value in ipairs(tDBData) do
|
|
|
+ -- 更新阵容
|
|
|
+ if value.key and value.key == nKey then
|
|
|
+ -- 大于等于才更新
|
|
|
+ if nNewPower >= value.nPower then
|
|
|
+ print("[RecommendLineup_GetIndex] 已存在 nIndex = "..i)
|
|
|
+ nIndex = i
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 直接返回
|
|
|
+ return nIndex
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ if -1 == nIndex then
|
|
|
+ nIndex = nNowLen + 1
|
|
|
+ return nIndex
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
for i, value in ipairs(tDBData) do
|
|
|
@@ -70,6 +97,15 @@ local function RecommendLineup_UpDateData(human, nIndex, tHeroData)
|
|
|
return
|
|
|
end
|
|
|
|
|
|
+ -- 已经存在
|
|
|
+ if nIndex <= nOldLen then
|
|
|
+ tNewData = tOldData
|
|
|
+ tNewData[nIndex] = tHeroData
|
|
|
+ RecommendLineup_SetData(tNewData)
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ -- 长度还不够
|
|
|
if nOldLen < nRecommendLineupLen then
|
|
|
tNewData = tOldData
|
|
|
table.insert(tNewData, tHeroData)
|
|
|
@@ -101,6 +137,48 @@ local function RecommendLineup_UpDateData(human, nIndex, tHeroData)
|
|
|
RecommendLineup_SetData(tNewData)
|
|
|
end
|
|
|
|
|
|
+-- 封装信息
|
|
|
+local function RecommendLineup_MakeSimpleData(net, tSaveData)
|
|
|
+ local cf = HeroExcel.hero[tSaveData.id]
|
|
|
+ if not cf then
|
|
|
+ print("[RecommendLineup_MakeSimpleData] 不存在对应英雄配置 nHeroID = "..tSaveData.id)
|
|
|
+ return
|
|
|
+ end
|
|
|
+ net.id = tSaveData.id
|
|
|
+ net.index = tSaveData.index or 0
|
|
|
+ net.uuid = tSaveData.uuid or ""
|
|
|
+ net.gl = tSaveData.gl or 0
|
|
|
+ net.camp = tSaveData.camp or 0
|
|
|
+ net.job = tSaveData.job or 0
|
|
|
+ net.star = tSaveData.star or 0 --cf and cf.star or 0 星级调整 dxzeng
|
|
|
+ net.icon = tSaveData.head or (cf.head or 0)
|
|
|
+ net.body = tSaveData.body or 0
|
|
|
+ net.up = tSaveData.up or 0 --是否能够升星
|
|
|
+
|
|
|
+ net.lv = tSaveData.lv or 1
|
|
|
+ net.xLv = tSaveData.xLv or 0
|
|
|
+ net.zhandouli = tSaveData.zhandouli or 0
|
|
|
+ net.quality = tSaveData.quality or 0
|
|
|
+ net.isLock = tSaveData.isLock and 1 or 0
|
|
|
+ net.hp = tSaveData.hp or 0
|
|
|
+ net.hpMax = tSaveData.hpMax or 0
|
|
|
+ net.cnt = tSaveData.cnt or 1
|
|
|
+ net.isget = tSaveData.isget or 0
|
|
|
+ net.weightLv = tSaveData.grade or 0
|
|
|
+ net.name = tSaveData.name or ""
|
|
|
+ net.grade = tSaveData.grade or 0
|
|
|
+ net.jobDesc = tSaveData.desc or ""
|
|
|
+ net.label = tSaveData.label or ""
|
|
|
+ net.order = tSaveData.order or 0
|
|
|
+ net.isGongMing = tSaveData.isGongMing or 0
|
|
|
+
|
|
|
+
|
|
|
+ --是否发送图鉴信息
|
|
|
+ net.general = tSaveData.general
|
|
|
+
|
|
|
+ --宝石
|
|
|
+ net.gemData = tSaveData.gemData
|
|
|
+end
|
|
|
|
|
|
---------------------------------------- 客户端请求 ------------------------------------
|
|
|
function GetRecommendLineUp(human)
|
|
|
@@ -108,64 +186,88 @@ function GetRecommendLineUp(human)
|
|
|
|
|
|
local tMsgData = Msg.gc.GC_DRAWCARD_GET_RECOMMEND_LINEUP
|
|
|
tMsgData.list[0] = 0
|
|
|
+ tMsgData.bIsEnd = 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
|
|
|
+ print("[GetRecommendLineUp] nPower = "..value.nPower.." i = "..i)
|
|
|
for _, v in pairs(value.data) do
|
|
|
+
|
|
|
tHeroData.data[0] = tHeroData.data[0] + 1
|
|
|
- tHeroData[tHeroData.data[0]] = v
|
|
|
+ RecommendLineup_MakeSimpleData(tHeroData.data[tHeroData.data[0]], v)
|
|
|
+ end
|
|
|
+
|
|
|
+ if i >= nSendLen then
|
|
|
+ Msg.send(tMsgData, human.fd)
|
|
|
+ tMsgData.list[0] = 0
|
|
|
end
|
|
|
end
|
|
|
-
|
|
|
+
|
|
|
+ tMsgData.bIsEnd = 1
|
|
|
Msg.send(tMsgData, human.fd)
|
|
|
+ print("[GetRecommendLineUp] 发送成功 ")
|
|
|
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
|
|
|
+ if 5 >= human.db.lv then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ 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, human)
|
|
|
+ if -1 >= nIndex then
|
|
|
+ return
|
|
|
+ end
|
|
|
+
|
|
|
+ print("[RecommendLineup_UpDate] 获取到的下表 nIndex = "..nIndex)
|
|
|
+
|
|
|
+ local tHeroData = {
|
|
|
+ key = human.db._id,
|
|
|
+ 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)
|
|
|
+ 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
|
|
|
+
|
|
|
+function RecommendLineup_GMClear()
|
|
|
+ local tData = {}
|
|
|
+ tRecommendLineupData = tData
|
|
|
+ CommonDB.SetRecommendLineUp(tRecommendLineupData)
|
|
|
+ print("[RecommendLineup_GMClear] 重置成功")
|
|
|
end
|