miduo_client/Assets/ManagedResources/~Lua/Modules/Formation/FormationManager.lua

656 lines
24 KiB
Lua

FormationManager = {}
local this = FormationManager
local ChallengeData = ConfigManager.GetConfig(ConfigName.ChallengeConfig)
local specialConfig=ConfigManager.GetConfig(ConfigName.SpecialConfig)
this.AllFormationFunIds = {[1] = JumpType.Level,[601] = JumpType.BeastIncomingTide,[101] = JumpType.Arena,[201] = JumpType.Arena,
[401] = JumpType.EndlessFight,[501] = JumpType.Guild,[502] = JumpType.Guild}
function this.Initialize()
this.currentFormationIndex=0
end
function this.MakeAEmptyTeam(teamId)
local oTeam = {}
-- Log("TeamId" .. teamId)
--LogError("创造一个空编队====="..teamId)
oTeam.teamId = teamId
if teamId < FormationTypeDef.FORMATION_ARENA_DEFEND then
oTeam.teamName = Language[10676]--Language[10677] .. tostring(teamId)
elseif teamId == FormationTypeDef.FORMATION_ARENA_DEFEND then
oTeam.teamName = Language[10678]-- 101
elseif teamId == FormationTypeDef.FORMATION_ARENA_ATTACK then
oTeam.teamName = Language[10679]-- 201
elseif teamId == FormationTypeDef.FORMATION_DREAMLAND then
oTeam.teamName = Language[10680]-- 301
elseif teamId == FormationTypeDef.FORMATION_ENDLESS_MAP then
oTeam.teamName = Language[10681]-- 401
elseif teamId == FormationTypeDef.FORMATION_GUILD_FIGHT_DEFEND then
oTeam.teamName = Language[10682]-- 501
elseif teamId == FormationTypeDef.FORMATION_GUILD_FIGHT_ATTACK then
oTeam.teamName = Language[10683]-- 502
elseif teamId == FormationTypeDef.MONSTER_CAMP_ATTACK then
oTeam.teamName = Language[10677]-- 601
elseif teamId == FormationTypeDef.BLOODY_BATTLE_ATTACK then
oTeam.teamName = Language[10684]-- 701
-- elseif teamId == FormationTypeDef.GUILD_BOSS then
-- oTeam.teamName = " 公会Boss"-- 901
elseif teamId == FormationTypeDef.EXPEDITION then
oTeam.teamName = Language[10685]-- 1001
elseif teamId == FormationTypeDef.ARENA_TOM_MATCH then
oTeam.teamName = Language[10678]-- 1301
elseif teamId == FormationTypeDef.JUMPSERVER_HIGHTLADDER then
oTeam.teamName = "罗浮争锋"-- 1601
elseif teamId == FormationTypeDef.FIGHT_LEVEL then
oTeam.teamName = "山河社稷图"-- 1701
elseif teamId == FormationTypeDef.FIGHT_ASSISTANTLEVEL then
oTeam.teamName = "山河社稷图"-- 1801
elseif teamId == FormationTypeDef.FORMATION_YUXUNLUNDAO1 then
oTeam.teamName = "玉虚论道1队"-- 2001
elseif teamId == FormationTypeDef.FORMATION_YUXUNLUNDAO2 then
oTeam.teamName = "玉虚论道2队"-- 2002
elseif teamId == FormationTypeDef.FORMATION_YUXUNLUNDAO3 then
oTeam.teamName = "玉虚论道3队"-- 2003
elseif teamId == FormationTypeDef.FourElement_PEOPLE then
oTeam.teamName = "四灵试炼人"-- 3001
elseif teamId == FormationTypeDef.FourElement_BUDDHIST then
oTeam.teamName = "四灵试炼佛"-- 3002
elseif teamId == FormationTypeDef.FourElement_MAGIC then
oTeam.teamName = "四灵试炼妖"-- 3003
elseif teamId == FormationTypeDef.FourElement_TAOIST then
oTeam.teamName = "四灵试炼道"-- 3004
elseif teamId == FormationTypeDef.FORMATION_QIJIESHILIAN then
oTeam.teamName = "七界试炼"-- 2101
elseif teamId == FormationTypeDef.GodsWayTower_Two_1 then
oTeam.teamName = "二队1"-- 2101
elseif teamId == FormationTypeDef.GodsWayTower_Two_2 then
oTeam.teamName = "二队2"-- 2101
end
oTeam.teamHeroInfos = {}
oTeam.teamPokemonInfos = {}
--LogError("return 新的编对")
return oTeam
end
-- 刷新编队信息
function this.RefreshFormationData(func)
NetManager.TeamInfoRequest(func)
end
--刷新编队数据
function this.UpdateFormation(msg)
this.formationList = {}
-- this.curFormationIndex = this.SetCurFormationIndex()
this.curFormationIndex = 1
for i, team in ipairs(msg.TeamPosInfo) do
local isRefresh = false
local oTeam = this.MakeAEmptyTeam(team.teamId)
for j = 1, #team.teamHeroInfos do
local teamHeroInfo = team.teamHeroInfos[j]
-- TODO: 四灵试炼编队特殊处理
if team.teamId == FormationTypeDef.FourElement_PEOPLE
or team.teamId == FormationTypeDef.FourElement_MAGIC
or team.teamId == FormationTypeDef.FourElement_BUDDHIST
or team.teamId == FormationTypeDef.FourElement_TAOIST then
if HeroManager.GetSingleHeroData(teamHeroInfo.heroId) then
table.insert(oTeam.teamHeroInfos, teamHeroInfo)
HeroManager.SetHeroFormationList(teamHeroInfo.heroId,team.teamId,1)
else
isRefresh = true
end
else
table.insert(oTeam.teamHeroInfos, teamHeroInfo)
HeroManager.SetHeroFormationList(teamHeroInfo.heroId,team.teamId,1)
end
end
oTeam.teamPokemonInfos = {}
this.formationList[team.teamId] = oTeam
if isRefresh then
FormationManager.SaveFormation(team.teamId, this.formationList[team.teamId].teamHeroInfos, {})
end
end
if #msg.TeamPosInfo == 0 then
for i = 1, 3 do
local curFormation = {}
curFormation.teamId = i
curFormation.teamName = Language[10676]--Language[10677] .. i
curFormation.teamHeroInfos = {}
curFormation.teamPokemonInfos = {}
this.formationList[i] = curFormation
end
end
-- 获取数据时检测一下公会战防守数据
-- this.CheckGuildFightDefendFormation()
end
--刷新临时编队数据
function this.UpdateTemporaryFormation(teamId, TeamPosInfo)
if teamId < FormationTypeDef.FORMATION_TEMPORARY then
LogError("临时编队ID错误")
return
end
local curFormation = {}
curFormation.teamId = teamId
curFormation.teamName = "临时"
curFormation.teamHeroInfos = {}
curFormation.teamPokemonInfos = {}
if #TeamPosInfo > 0 then
for j = 1, #TeamPosInfo do
table.insert(curFormation.teamHeroInfos, TeamPosInfo[j])
end
end
this.formationList[teamId] = curFormation
-- 设置临时编队为脏数据
HeroPropManager.SetFormationPropDirty(teamId)
end
-- function this.SetCurFormationIndex()
-- local curIndex = 1
-- local curMapId = PlayerManager.curMapId
-- local carbonType = 1
-- if curMapId and curMapId > 0 then
-- carbonType = ChallengeData[curMapId].Type
-- end
-- curIndex = carbonType == 4 and 401 or 1
-- return curIndex
-- end
function this.SaveFormation(index, roleList, pokemonList,isDiffmonster)
local curFormation = this.formationList[index]
if not curFormation or #this.formationList == 0 then
return
end
local newTeamheroInfos = {}
for i = 1, #roleList do
newTeamheroInfos[roleList[i].heroId] = roleList[i]
end
local oldTeamheroInfos = {}
for i = 1, #curFormation.teamHeroInfos do
if curFormation.teamHeroInfos[i] then
oldTeamheroInfos[curFormation.teamHeroInfos[i].heroId] = curFormation.teamHeroInfos[i]
if not newTeamheroInfos[curFormation.teamHeroInfos[i].heroId] then
HeroManager.SetHeroFormationList(curFormation.teamHeroInfos[i].heroId,this.formationList[index].teamId,nil)
end
end
end
curFormation.teamHeroInfos = {}
-- LogPink("#roleList"..#roleList)
for i = 1, #roleList do
local teamInfo = {}
teamInfo.heroId = roleList[i].heroId--roleList[i]
teamInfo.position = roleList[i].position--i
table.insert(curFormation.teamHeroInfos, teamInfo)
if not oldTeamheroInfos[teamInfo.heroId] then
--LogRed("roleList[i].heroId"..roleList[i].heroId.." this.formationList[index].teamId"..this.formationList[index].teamId)
HeroManager.SetHeroFormationList(roleList[i].heroId,this.formationList[index].teamId,1)
end
end
curFormation.teamPokemonInfos = {}
for j = 1, #pokemonList do
--#curFormation.teamPokemonInfos
local teamPokemonInfo = {}
teamPokemonInfo.pokemonId = pokemonList[j].pokemonId
teamPokemonInfo.position = pokemonList[j].position
table.insert(curFormation.teamPokemonInfos, teamPokemonInfo)
end
NetManager.TeamInfoSaveRequest(curFormation, function()
Game.GlobalEvent:DispatchEvent(GameEvent.Formation.OnFormationChange,isDiffmonster)
LogGreen("发送保存编队请求 ,长度:"..#curFormation.teamHeroInfos)
end)
this.CheckHeroIdExist()
--设置战斗力脏数据
HeroPropManager.SetFormationPropDirty(index)
end
-- 获取所有正在编队的英雄id
function this.GetAllFormationHeroId()
local list = {}
local index = 1
for i, team in pairs(this.formationList) do
if i ~= FormationTypeDef.FORMATION_ENDLESS_MAP then
for j = 1, #team.teamHeroInfos do
-- 加空判断避免不知名错误
if team and team.teamHeroInfos[j] then
list[team.teamHeroInfos[j].heroId] = index
index = index + 1
end
end
end
end
return list
end
-- 获取主线所有正在编队的英雄id
function this.GetAllMainFormationHeroId()
local list = {}
local index = 1
for i, team in pairs(this.formationList) do
if i == FormationTypeDef.FORMATION_NORMAL then
for j = 1, #team.teamHeroInfos do
-- 加空判断避免不知名错误
if team and team.teamHeroInfos[j] then
list[team.teamHeroInfos[j].heroId] = index
index = index + 1
end
end
end
end
return list
end
--获取单个编队所有上阵英雄
function this.GetWuJinFormationHeroIds(index)
local forMationData = this.GetFormationByID(index).teamHeroInfos
local index = 1
local list = {}
for j = 1, #forMationData do
list[forMationData[j].heroId] = index
index = index + 1
end
return list
end
function this.CopyStoryFormationToCurFormation(teamId)
if not this.formationList[teamId] then
this.formationList[teamId] = this.MakeAEmptyTeam(teamId)
end
if #this.formationList[teamId].teamHeroInfos<=0 then
for n = 1, #this.formationList[1].teamHeroInfos do
table.insert(this.formationList[teamId].teamHeroInfos, this.formationList[1].teamHeroInfos[n])
end
--
FormationManager.SaveFormation(teamId, this.formationList[teamId].teamHeroInfos, {})
end
end
-- 获取编队信息
function this.GetFormationByID(teamId)
if not teamId then
return
end
--LogError("teamid===="..teamId)
if not this.formationList then return nil end
if not this.formationList[teamId] then
this.formationList[teamId] = this.MakeAEmptyTeam(teamId)
end
--根据配置表 解锁功能时复制主线阵容 的配置
for i, v in ipairs(string.split(specialConfig[47].Value,"#")) do
local _v=tonumber(v)
if teamId ==_v and #this.formationList[teamId].teamHeroInfos<=0 then
this.CopyStoryFormationToCurFormation(teamId)
return this.formationList[teamId]
end
end
return this.formationList[teamId]
end
-- 获取编队总战斗力
function this.GetFormationPower(formationId)
if not formationId then
return
end
--获取当前编队数据
if formationId == FormationTypeDef.EXPEDITION then
ExpeditionManager.ExpeditionRrefreshFormation()--刷新编队
end
local formationList = this.GetFormationByID(formationId)
--for i, v in pairs(allHeroTeamAddProVal) do
-- LogError("团队加成 "..i .." " .. v)
--end
-- LogPink("计算编队战斗力: "..formationId)
local power = 0
-- for i = 1, 6 do
-- if formationList.teamHeroInfos[i] then
-- -- local heroData = HeroManager.GetSingleHeroData(formationList.teamHeroInfos[i].heroId)
-- -- power = power + HeroPowerManager.GetHeroPower(heroData.dynamicId, formationId)
-- local heroData = HeroManager.GetSingleHeroData(formationList.teamHeroInfos[i].heroId)
-- --1, curHeroData.dynamicId, false,nil,nil,true,allHeroTeamAddProVal)
-- local allHeroTeamAddProVal = HeroManager.GetAllHeroTeamAddProVal(formationList.teamHeroInfos,formationList.teamHeroInfos[i].heroId)
-- local allEquipAddProVal = HeroManager.CalculateHeroAllProValList(1, heroData.dynamicId,false,nil,nil,true,allHeroTeamAddProVal)
-- power = power + allEquipAddProVal[HeroProType.WarPower]
-- end
-- end
-- LogRed("原方式战斗力:"..power)
local power2 = 0
for i = 1, 6 do
if formationList.teamHeroInfos[i] then
power2 = power2 + HeroPowerManager.GetHeroPower(formationList.teamHeroInfos[i].heroId, formationId)
end
end
power2=power2+PracticeManager.GetPracticeAddPower()
-- LogGreen("新方式战斗力:"..power2)
-- 主线编队战斗力
ThinkingAnalyticsManager.SetSuperProperties({
fighting_capacity = power2,
})
-- 刷新后端战斗力
if power2 > PlayerManager.maxForce then
NetManager.RequestUserForceChange(FormationTypeDef.FORMATION_NORMAL)--targetTeamId
PlayerManager.maxForce = power2
end
-- 编队战斗力刷新
Game.GlobalEvent:DispatchEvent(GameEvent.Formation.OnFormationPowerChange, power2)
return power2
end
-- 刷新主线编队战斗力
function this.RefreshMainFormationPower()
this.GetFormationPower(this.curFormationIndex)
end
--某个妖灵师战力发生变化检查是否在任何一个编队
function this.CheckHeroIdExist(heroId)
if not heroId then
NetManager.RequestUserForceChange(FormationTypeDef.FORMATION_NORMAL)
return
end
-- for _, formationData in pairs(this.formationList) do
table.walk(this.formationList[FormationTypeDef.FORMATION_NORMAL].teamHeroInfos, function(teamInfo)
if heroId == teamInfo.heroId then
NetManager.RequestUserForceChange(FormationTypeDef.FORMATION_NORMAL)
end
end)
-- end
end
-- 判断编队中是否有这个人
function this.CheckFormationHasId(formationId, heroId)
local has = false
if this.formationList and this.formationList[formationId] then
table.walk(this.formationList[formationId].teamHeroInfos, function(teamInfo)
if heroId == teamInfo.heroId then
has = true
end
end)
end
return has
end
-- 重新算一遍战斗力
function this.UserPowerChanged()
this.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)
end
-- 获取相应编队的血量数据
function this.GetFormationHeroHp(formationIndex, dhId)
if formationIndex == FormationTypeDef.FORMATION_ENDLESS_MAP then
local data = EndLessMapManager.allHeroBlood[dhId]
if not data then return end
return data.percentHp
elseif formationIndex == FormationTypeDef.FORMATION_GUILD_FIGHT_ATTACK then
local dataList = GuildFightManager.GetMyHeroBloodData()
local data = dataList[dhId]
if not data then return end
return data
elseif formationIndex == FormationTypeDef.EXPEDITION then
local data = ExpeditionManager.heroInfo[dhId]
if not data then return end
return data.remainHp
end
end
-- 检测编队正确性
function this.CheckFormationHp(formationIndex)
local formation = this.GetFormationByID(formationIndex)
local newFormation = {}
local newIndex = 1
for index = 1, #formation.teamHeroInfos do
local teamInfo = formation.teamHeroInfos[index]
local hp = this.GetFormationHeroHp(formationIndex, teamInfo.heroId)
if hp > 0 then
local singleData = {}
singleData.heroId = teamInfo.heroId
singleData.position = newIndex
newIndex = newIndex + 1
table.insert(newFormation, singleData)
end
end
this.SaveFormation(formationIndex, newFormation, formation.teamPokemonInfos)
end
-- 检测编队是否有上阵人数
function this.CheckFormationValid(teamId)
local team = this.GetFormationByID(teamId)
local isValid = #team.teamHeroInfos > 0
return isValid
end
-- 检测公会战防守阶段玩家防守阵容正确性,防守阵容为空时将主线阵容复制到防守阵容
function FormationManager.CheckGuildFightDefendFormation()
if not ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.GUILD) then return end -- 公会未开启
if PlayerManager.familyId == 0 then return end -- 没有公会
local isInFight = GuildFightManager.IsInGuildFight()
local curStage = GuildFightManager.GetCurFightStage()
if not isInFight or curStage == GUILD_FIGHT_STAGE.DEFEND then
if not this.CheckFormationValid(FormationTypeDef.FORMATION_GUILD_FIGHT_DEFEND) then
local formation = this.GetFormationByID(FormationTypeDef.FORMATION_NORMAL)
local newFormation = {}
for index = 1, #formation.teamHeroInfos do
local teamInfo = formation.teamHeroInfos[index]
local singleData = {}
singleData.heroId = teamInfo.heroId
singleData.position = index
table.insert(newFormation, singleData)
end
this.SaveFormation(FormationTypeDef.FORMATION_GUILD_FIGHT_DEFEND, newFormation, formation.teamPokemonInfos)
end
end
end
--设置元素共鸣激活索引
function this.GetElementIndex(curFormation)
local elementPropertyList = {}
local fireElementNum = 0
local windyElementNum = 0
local waterElementNum = 0
local groundElementNum = 0
for _,go in pairs(curFormation) do--将所有元素信息存入列表
if go and go.heroId then
local temp = HeroManager.GetSingleHeroData(go.heroId)
if not temp then
--LogGreen(go.heroId.."这个英雄不存在")
else
local heroPropertyType = temp.changeProId
table.insert(elementPropertyList, heroPropertyType)
end
else
--LogGreen(_.."这个编队的这个英雄不存在")
end
end
for i, v in pairs(elementPropertyList) do--遍历该列表拿筛选出各元素
if (v == 1) then
fireElementNum = fireElementNum + 1
elseif (v == 2) then
windyElementNum = windyElementNum + 1
elseif (v == 3) then
waterElementNum = waterElementNum + 1
elseif (v == 4) then
groundElementNum = groundElementNum + 1
end
end
local list = {}
list[1] = fireElementNum
list[2] = windyElementNum
list[3] = waterElementNum
list[4] = groundElementNum
local indexChoose = 0
for i = 1, #list do
local v=list[i]
if v==4 then
indexChoose=4
end
if v==5 then
indexChoose=5
end
if v==6 then
indexChoose=6
end
end
local count=0
for i = 1, #list do
local v=list[i]
if v==3 then
count=count+1
end
end
if count==1 then
indexChoose=2
elseif count==2 then
indexChoose=3
end
local index=0
for i = 1, #list do
local v=list[i]
if v==2 then
index=index+1
end
end
if index==3 then
indexChoose=1
end
return indexChoose
end
-- 获取所有正在编队的英雄id
function this.AllFormationDeleCurHeroId(heroDid)
for i, team in pairs(this.formationList) do
local removeIndex
for j = 1, #team.teamHeroInfos do
if team.teamHeroInfos[j] and team.teamHeroInfos[j].heroId == heroDid then
removeIndex = j
end
end
if removeIndex then
table.remove( team.teamHeroInfos, removeIndex)
end
end
end
-- 归元时检测无尽 和 大闹天宫阵容是否需要下阵
function this.ResolvDownBattleCurHeroId(heroDid)
for i, team in pairs(this.formationList) do
local removeIndex
if i == FormationTypeDef.EXPEDITION or i == FormationTypeDef.FORMATION_ENDLESS_MAP then
for j = 1, #team.teamHeroInfos do
if team.teamHeroInfos[j] and team.teamHeroInfos[j].heroId == heroDid then
removeIndex = j
end
end
if removeIndex then
table.remove( team.teamHeroInfos, removeIndex)
end
end
end
end
-- 获取当前光环的加成数据 type 编队类型
function this.GetCurFormationElementAdd(teamHeroInfos)
local data={}
local index= this.GetElementIndex(teamHeroInfos)
if index==0 then return data end
local config=ConfigManager.GetConfig(ConfigName.ElementalResonanceConfig)
for i = 1, #config[index].Content do
table.insert(data,config[index].Content[i][1],config[index].Content[i][2])
end
return data
end
-- 获取当前光环的加成数据 type 编队类型
function this.GetCurFormationElementAddByType(type,heroDid)
local data={}
local curFormation = this.GetFormationByID(type)
local isAdd = false
if not curFormation then return {} end
for i = 1, #curFormation.teamHeroInfos do
if curFormation.teamHeroInfos[i].heroId == heroDid then
isAdd = true
end
end
if isAdd then
local index= this.GetElementIndex(curFormation.teamHeroInfos)
if index==0 then return data end
local config=ConfigManager.GetConfig(ConfigName.ElementalResonanceConfig)
for i = 1, #config[index].Content do
table.insert(data,config[index].Content[i][1],config[index].Content[i][2])
end
end
return data
end
--自动一键上阵没有前端显示
function this.SetOneKeyGoWithoutUI(formationType,limitLevel)
local heros = HeroManager.GetAllHeroDatas(limitLevel)
--按战力从大到小排序
table.sort(heros,function(a,b)
if a.warPower == b.warPower then
return a.id>b.id
else
return a.warPower > b.warPower
end
end)
--修改 upHeroSidTable 静态id 存储 有则跳过
local upHeroSidTable = {}
local choosedList = {}
for i = 1, 6 do
if heros[i] then
local curSingleherodata = HeroManager.GetSingleHeroData(heros[i].dynamicId)
if not upHeroSidTable[curSingleherodata.id] then
upHeroSidTable[curSingleherodata.id] = curSingleherodata.id
table.insert(choosedList, {heroId = heros[i].dynamicId, position=i})
end
end
end
--保存编队
FormationManager.SaveFormation(formationType, choosedList,FormationManager.formationList[formationType].teamPokemonInfos)
end
-- 获取编队元素加成
function this.GetFormationElementAdd(type)
local propList = {}
local curFormation = this.GetFormationByID(type)
if not curFormation then return propList end
local index= this.GetElementIndex(curFormation.teamHeroInfos)
if index==0 then return propList end
local config=ConfigManager.GetConfig(ConfigName.ElementalResonanceConfig)
for i = 1, #config[index].Content do
local propId = config[index].Content[i][1]
local value = config[index].Content[i][2]
if not propList[propId] then
propList[propId] = 0
end
propList[propId] = propList[propId] + value
end
LogPinkTable_Prop(propList)
return propList
end
function this.GetCurIndexForMationNum(formationId)
local index = 0
if formationId and this.formationList[formationId] then
local team = this.formationList[formationId]
for j = 1, #team.teamHeroInfos do
if team.teamHeroInfos[j] then
index = index + 1
end
end
end
return index
end
return this