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

523 lines
19 KiB
Lua
Raw Normal View History

2021-04-20 13:58:00 +08:00
FormationManager = {}
2020-05-09 13:31:21 +08:00
local this = FormationManager
local ChallengeData = ConfigManager.GetConfig(ConfigName.ChallengeConfig)
2020-05-15 16:52:35 +08:00
local specialConfig=ConfigManager.GetConfig(ConfigName.SpecialConfig)
2020-05-09 13:31:21 +08:00
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
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10676]--Language[10677] .. tostring(teamId)
2020-05-09 13:31:21 +08:00
elseif teamId == FormationTypeDef.FORMATION_ARENA_DEFEND then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10678]-- 101
2020-05-09 13:31:21 +08:00
elseif teamId == FormationTypeDef.FORMATION_ARENA_ATTACK then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10679]-- 201
2020-06-03 19:09:01 +08:00
elseif teamId == FormationTypeDef.FORMATION_DREAMLAND then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10680]-- 301
2020-05-09 13:31:21 +08:00
elseif teamId == FormationTypeDef.FORMATION_ENDLESS_MAP then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10681]-- 401
2020-05-09 13:31:21 +08:00
elseif teamId == FormationTypeDef.FORMATION_GUILD_FIGHT_DEFEND then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10682]-- 501
2020-05-09 13:31:21 +08:00
elseif teamId == FormationTypeDef.FORMATION_GUILD_FIGHT_ATTACK then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10683]-- 502
2020-05-09 13:31:21 +08:00
elseif teamId == FormationTypeDef.MONSTER_CAMP_ATTACK then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10677]-- 601
2020-05-09 13:31:21 +08:00
elseif teamId == FormationTypeDef.BLOODY_BATTLE_ATTACK then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10684]-- 701
2020-05-09 13:31:21 +08:00
-- elseif teamId == FormationTypeDef.GUILD_BOSS then
-- oTeam.teamName = " 公会Boss"-- 901
elseif teamId == FormationTypeDef.EXPEDITION then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10685]-- 1001
2020-07-23 14:36:28 +08:00
elseif teamId == FormationTypeDef.ARENA_TOM_MATCH then
2021-04-09 12:26:35 +08:00
oTeam.teamName = Language[10678]-- 1301
2021-05-17 17:54:21 +08:00
elseif teamId == FormationTypeDef.FIGHT_LEVEL then
oTeam.teamName = "山河社稷图"-- 1701
elseif teamId == FormationTypeDef.FIGHT_ASSISTANTLEVEL then
oTeam.teamName = "山河社稷图"-- 1701
2020-05-09 13:31:21 +08:00
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 = {}
2020-09-03 16:43:08 +08:00
-- this.curFormationIndex = this.SetCurFormationIndex()
2020-09-03 16:45:40 +08:00
this.curFormationIndex = 1
2020-05-09 13:31:21 +08:00
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)
2020-08-12 14:13:16 +08:00
HeroManager.SetHeroFormationList(teamHeroInfo.heroId,team.teamId,1)
2020-05-09 13:31:21 +08:00
end
oTeam.teamPokemonInfos = {}
2020-05-09 13:31:21 +08:00
this.formationList[team.teamId] = oTeam
end
if #msg.TeamPosInfo == 0 then
for i = 1, 3 do
local curFormation = {}
curFormation.teamId = i
2021-04-09 12:26:35 +08:00
curFormation.teamName = Language[10676]--Language[10677] .. i
2020-05-09 13:31:21 +08:00
curFormation.teamHeroInfos = {}
curFormation.teamPokemonInfos = {}
this.formationList[i] = curFormation
end
end
-- 获取数据时检测一下公会战防守数据
this.CheckGuildFightDefendFormation()
end
function this.RefreshFormation(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
2020-08-26 11:26:32 +08:00
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
2020-05-09 13:31:21 +08:00
curFormation.teamHeroInfos = {}
LogPink("#roleList"..#roleList)
2020-05-09 13:31:21 +08:00
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
2021-05-26 14:57:28 +08:00
--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
2020-05-09 13:31:21 +08:00
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)
2020-05-09 13:31:21 +08:00
end)
2020-08-03 15:36:29 +08:00
this.CheckHeroIdExist()
2020-05-09 13:31:21 +08:00
end
-- 获取所有正在编队的英雄id
function this.GetAllFormationHeroId()
local list = {}
local index = 1
for i, team in pairs(this.formationList) do
2021-05-14 19:11:40 +08:00
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
2021-05-14 19:11:40 +08:00
end
2020-05-09 13:31:21 +08:00
end
return list
end
2020-09-03 16:03:14 +08:00
-- 获取主线所有正在编队的英雄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
2020-05-09 13:31:21 +08:00
--获取单个编队所有上阵英雄
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
2020-05-15 16:52:35 +08:00
--根据配置表 解锁功能时复制主线阵容 的配置
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
2020-05-25 19:16:23 +08:00
table.insert(this.formationList[teamId].teamHeroInfos, this.formationList[1].teamHeroInfos[n])
2020-05-15 16:52:35 +08:00
end
2020-05-25 19:16:23 +08:00
--
FormationManager.RefreshFormation(teamId, this.formationList[teamId].teamHeroInfos, {})
2020-05-15 16:52:35 +08:00
return this.formationList[teamId]
end
end
2020-05-09 13:31:21 +08:00
return this.formationList[teamId]
end
-- 获取编队总战斗力
function this.GetFormationPower(formationId)
if not formationId then
return
end
--获取当前编队数据
if formationId == FormationTypeDef.EXPEDITION then
ExpeditionManager.ExpeditionRrefreshFormation()--刷新编队
end
2020-05-09 13:31:21 +08:00
local formationList = this.GetFormationByID(formationId)
--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)
2020-07-14 14:49:15 +08:00
local allHeroTeamAddProVal = HeroManager.GetAllHeroTeamAddProVal(formationList.teamHeroInfos,formationList.teamHeroInfos[i].heroId)
2020-05-09 13:31:21 +08:00
local allEquipAddProVal = HeroManager.CalculateHeroAllProValList(1, heroData.dynamicId,false,nil,nil,true,allHeroTeamAddProVal)
power = power + allEquipAddProVal[HeroProType.WarPower]
end
end
2020-07-17 17:50:05 +08:00
-- 主线编队战斗力
ThinkingAnalyticsManager.SetSuperProperties({
fighting_capacity = power,
})
-- 编队战斗力刷新
Game.GlobalEvent:DispatchEvent(GameEvent.Formation.OnFormationPowerChange, power)
2020-05-09 13:31:21 +08:00
return power
end
-- 刷新主线编队战斗力
function this.RefreshMainFormationPower()
this.GetFormationPower(this.curFormationIndex)
end
2020-05-09 13:31:21 +08:00
--某个妖灵师战力发生变化检查是否在任何一个编队
function this.CheckHeroIdExist(heroId)
2020-08-03 15:36:29 +08:00
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)
2020-05-09 13:31:21 +08:00
end
end)
2020-08-03 15:36:29 +08:00
-- end
2020-05-09 13:31:21 +08:00
end
function this.UserPowerChanged()
2020-05-09 13:31:21 +08:00
local maxPower, targetTeamId = 0
2020-08-18 17:32:26 +08:00
-- for _, teamInfo in pairs(this.formationList) do
-- if #teamInfo.teamHeroInfos > 0 then
local curFormationWarPower = this.GetFormationPower(FormationTypeDef.FORMATION_NORMAL)--teamInfo.teamId
if curFormationWarPower > maxPower then
maxPower = curFormationWarPower
-- targetTeamId = teamInfo.teamId
2020-05-15 16:52:35 +08:00
end
2020-08-18 17:32:26 +08:00
-- end
-- end
2020-05-09 13:31:21 +08:00
if maxPower > PlayerManager.maxForce then
Log("发送队伍战力改变 ~~~~~~~~~~~~~~ ")
NetManager.RequestUserForceChange(FormationTypeDef.FORMATION_NORMAL)--targetTeamId
2020-05-09 13:31:21 +08:00
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
2020-07-28 22:25:51 +08:00
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.."这个英雄不存在")
2020-07-28 22:25:51 +08:00
else
local heroPropertyType = temp.heroConfig.PropertyName
table.insert(elementPropertyList, heroPropertyType)
end
else
--LogGreen(_.."这个编队的这个英雄不存在")
2020-07-28 22:25:51 +08:00
end
2020-05-09 13:31:21 +08:00
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
2020-06-23 18:36:24 +08:00
indexChoose=2
2020-05-09 13:31:21 +08:00
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
2020-06-23 18:36:24 +08:00
indexChoose=1
2020-05-09 13:31:21 +08:00
end
return indexChoose
end
-- 获取所有正在编队的英雄id
function this.AllFormationDeleCurHeroId(heroDid)
for i, team in pairs(this.formationList) do
2020-08-26 15:00:13 +08:00
local removeIndex
2020-05-09 13:31:21 +08:00
for j = 1, #team.teamHeroInfos do
2020-08-24 23:38:17 +08:00
if team.teamHeroInfos[j] and team.teamHeroInfos[j].heroId == heroDid then
2020-08-26 15:00:13 +08:00
removeIndex = j
2020-05-09 13:31:21 +08:00
end
end
2020-08-26 15:00:13 +08:00
if removeIndex then
table.remove( team.teamHeroInfos, removeIndex)
end
2020-05-09 13:31:21 +08:00
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
2020-05-09 13:31:21 +08:00
-- 获取当前光环的加成数据 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.RefreshFormation(formationType, choosedList,FormationManager.formationList[formationType].teamPokemonInfos)
end
2020-06-23 18:36:24 +08:00
return this