412 lines
14 KiB
Lua
412 lines
14 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)
|
|
oTeam.teamId = teamId
|
|
if teamId < FormationTypeDef.FORMATION_ARENA_DEFEND then
|
|
oTeam.teamName = Language[10674]--Language[10675] .. tostring(teamId)
|
|
elseif teamId == FormationTypeDef.FORMATION_ARENA_DEFEND then
|
|
oTeam.teamName = Language[10676]-- 101
|
|
elseif teamId == FormationTypeDef.FORMATION_ARENA_ATTACK then
|
|
oTeam.teamName = Language[10677]-- 201
|
|
elseif teamId == FormationTypeDef.FORMATION_DREAMLAND then
|
|
oTeam.teamName = Language[10678]-- 301
|
|
elseif teamId == FormationTypeDef.FORMATION_ENDLESS_MAP then
|
|
oTeam.teamName = Language[10679]-- 401
|
|
elseif teamId == FormationTypeDef.FORMATION_GUILD_FIGHT_DEFEND then
|
|
oTeam.teamName = Language[10680]-- 501
|
|
elseif teamId == FormationTypeDef.FORMATION_GUILD_FIGHT_ATTACK then
|
|
oTeam.teamName = Language[10681]-- 502
|
|
elseif teamId == FormationTypeDef.MONSTER_CAMP_ATTACK then
|
|
oTeam.teamName = Language[10675]-- 601
|
|
elseif teamId == FormationTypeDef.BLOODY_BATTLE_ATTACK then
|
|
oTeam.teamName = Language[10682]-- 701
|
|
-- elseif teamId == FormationTypeDef.GUILD_BOSS then
|
|
-- oTeam.teamName = " 公会Boss"-- 901
|
|
elseif teamId == FormationTypeDef.EXPEDITION then
|
|
oTeam.teamName = Language[10683]-- 1001
|
|
end
|
|
oTeam.teamHeroInfos = {}
|
|
oTeam.teamPokemonInfos = {}
|
|
return oTeam
|
|
end
|
|
|
|
-- 刷新编队信息
|
|
function this.RefreshFormationData(func)
|
|
NetManager.TeamInfoRequest(func)
|
|
end
|
|
|
|
--刷新编队数据
|
|
function this.UpdateFormation(msg)
|
|
Log("#msg.TeamPosInfo : " .. #msg.TeamPosInfo)
|
|
this.formationList = {}
|
|
this.curFormationIndex = this.SetCurFormationIndex()
|
|
|
|
for i, team in ipairs(msg.TeamPosInfo) do
|
|
local oTeam = this.MakeAEmptyTeam(team.teamId)
|
|
|
|
for j = 1, #team.teamHeroInfos do
|
|
local teamHeroInfo = team.teamHeroInfos[j]
|
|
table.insert(oTeam.teamHeroInfos, teamHeroInfo)
|
|
end
|
|
|
|
for j = 1, #team.teamPokemonInfos do
|
|
local teamPokemonInfo = team.teamPokemonInfos[j]
|
|
table.insert(oTeam.teamPokemonInfos, teamPokemonInfo)
|
|
end
|
|
this.formationList[team.teamId] = oTeam
|
|
end
|
|
|
|
if #msg.TeamPosInfo == 0 then
|
|
for i = 1, 3 do
|
|
local curFormation = {}
|
|
curFormation.teamId = i
|
|
curFormation.teamName = Language[10674]--Language[10675] .. i
|
|
curFormation.teamHeroInfos = {}
|
|
curFormation.teamPokemonInfos = {}
|
|
this.formationList[i] = curFormation
|
|
end
|
|
end
|
|
|
|
-- 获取数据时检测一下公会战防守数据
|
|
this.CheckGuildFightDefendFormation()
|
|
end
|
|
|
|
function this.SetCurFormationIndex()
|
|
local curIndex = 1
|
|
local curMapId = PlayerManager.curMapId
|
|
local carbonType = 1
|
|
if curMapId > 0 then
|
|
carbonType = ChallengeData[curMapId].Type
|
|
end
|
|
curIndex = carbonType == 4 and 401 or 1
|
|
return curIndex
|
|
end
|
|
|
|
function this.RefreshFormation(index, roleList, pokemonList,isDiffmonster)
|
|
local curFormation = this.formationList[index]
|
|
if not curFormation or #this.formationList == 0 then
|
|
return
|
|
end
|
|
curFormation.teamHeroInfos = {}
|
|
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)
|
|
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)
|
|
end)
|
|
|
|
this.UserPowerChanged()
|
|
|
|
end
|
|
|
|
-- 获取所有正在编队的英雄id
|
|
function this.GetAllFormationHeroId()
|
|
local list = {}
|
|
local index = 1
|
|
for i, team in pairs(this.formationList) do
|
|
for j = 1, #team.teamHeroInfos do
|
|
list[team.teamHeroInfos[j].heroId] = index
|
|
index = index + 1
|
|
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.GetFormationByID(teamId)
|
|
if not teamId then
|
|
return
|
|
end
|
|
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
|
|
for n = 1, #this.formationList[1].teamHeroInfos do
|
|
table.insert(this.formationList[teamId].teamHeroInfos, this.formationList[1].teamHeroInfos[n])
|
|
end
|
|
--
|
|
FormationManager.RefreshFormation(teamId, this.formationList[teamId].teamHeroInfos, {})
|
|
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)
|
|
local allHeroTeamAddProVal = HeroManager.GetAllHeroTeamAddProVal(formationList.teamHeroInfos)
|
|
--for i, v in pairs(allHeroTeamAddProVal) do
|
|
-- LogError("团队加成 "..i .." " .. v)
|
|
--end
|
|
local power = 0
|
|
for i = 1, 6 do
|
|
if formationList.teamHeroInfos[i] then
|
|
local heroData = HeroManager.GetSingleHeroData(formationList.teamHeroInfos[i].heroId)
|
|
--1, curHeroData.dynamicId, false,nil,nil,true,allHeroTeamAddProVal)
|
|
local allEquipAddProVal = HeroManager.CalculateHeroAllProValList(1, heroData.dynamicId,false,nil,nil,true,allHeroTeamAddProVal)
|
|
power = power + allEquipAddProVal[HeroProType.WarPower]
|
|
end
|
|
end
|
|
return power
|
|
end
|
|
|
|
--某个妖灵师战力发生变化检查是否在任何一个编队
|
|
function this.CheckHeroIdExist(heroId)
|
|
for _, formationData in pairs(this.formationList) do
|
|
table.walk(formationData.teamHeroInfos, function(teamInfo)
|
|
if heroId == teamInfo.heroId then
|
|
this.UserPowerChanged()
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
|
|
function this.UserPowerChanged()
|
|
local maxPower, targetTeamId = 0
|
|
for _, teamInfo in pairs(this.formationList) do
|
|
if #teamInfo.teamHeroInfos > 0 then
|
|
if this.GetFormationPower(teamInfo.teamId) > maxPower then
|
|
maxPower = this.GetFormationPower(teamInfo.teamId)
|
|
targetTeamId = teamInfo.teamId
|
|
end
|
|
end
|
|
end
|
|
if maxPower > PlayerManager.maxForce then
|
|
Log(Language[10684])
|
|
NetManager.RequestUserForceChange(targetTeamId)
|
|
PlayerManager.maxForce = maxPower
|
|
end
|
|
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.RefreshFormation(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.RefreshFormation(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 i = 1, #curFormation do--将所有元素信息存入列表
|
|
local heroPropertyType = HeroManager.GetSingleHeroData(curFormation[i].heroId).heroConfig.PropertyName
|
|
table.insert(elementPropertyList, heroPropertyType)
|
|
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
|
|
for j = 1, #team.teamHeroInfos do
|
|
if team.teamHeroInfos[j].heroId == heroDid then
|
|
team.teamHeroInfos[j] = nil
|
|
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
|
|
|
|
return this |