miduo_client/Assets/ManagedResources/~Lua/Modules/Battle/BattleManager.lua

1032 lines
37 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

BattleManager = {}
local this = BattleManager
local PassiveSkillLogicConfig = ConfigManager.GetConfig(ConfigName.PassiveSkillLogicConfig)
local SkillLogicConfig = ConfigManager.GetConfig(ConfigName.SkillLogicConfig)
local HeroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
local MonsterGroup = ConfigManager.GetConfig(ConfigName.MonsterGroup)
local MonsterConfig = ConfigManager.GetConfig(ConfigName.MonsterConfig)
local CombatControl = ConfigManager.GetConfig(ConfigName.CombatControl)
local SpiritAnimalSkill = ConfigManager.GetConfig(ConfigName.SpiritAnimalSkill)
local FakeBattleNew = ConfigManager.GetConfig(ConfigName.FakeBattleNew)
local FEAConfig = require("Modules/Battle/Config/FightEffectAudioConfig")
local lastFightData = nil
local function pairsByKeys(t)
local a = {}
for n in pairs(t) do
if n then
a[#a+1] = n
end
end
table.sort(a, function( op1, op2 )
local type1, type2 = type(op1), type(op2)
local num1, num2 = tonumber(op1), tonumber(op2)
if ( num1 ~= nil) and (num2 ~= nil) then
return num1 < num2
elseif type1 ~= type2 then
return type1 < type2
elseif type1 == "string" then
return op1 < op2
elseif type1 == "boolean" then
return op1
-- 以上处理: number, string, boolean
else -- 处理剩下的: function, table, thread, userdata
return tostring(op1) < tostring(op2) -- tostring后比较字符串
end
end)
local i = 0
return function()
i = i + 1
return a[i], t[a[i]]
end
end
function this.PrintBattleTable(tb)
local indent_str = "{"
local count = 0
for k,v in pairs(tb) do
count = count + 1
end
for k=1, #tb do
local v = tb[k]
if type(v) == "table" then
indent_str = indent_str .. this.PrintBattleTable(v)
elseif type(v) == "string" then
indent_str = indent_str .. "\""..tostring(v) .. "\""
else
indent_str = indent_str .. tostring(v)
end
if k < count then
indent_str = indent_str..","
end
end
local index = 0
for k,v in pairsByKeys(tb) do
index = index + 1
if type(k) ~= "number" then
if type(v) == "table" then
indent_str = string.format("%s%s=%s", indent_str, tostring(k), this.PrintBattleTable(v))
elseif type(v) == "string" then
indent_str = string.format("%s%s=\"%s\"", indent_str, tostring(k), tostring(v))
else
indent_str = string.format("%s%s=%s", indent_str, tostring(k), tostring(v))
end
if index < count then
indent_str = indent_str .. ","
end
end
end
indent_str = indent_str .. "}"
return indent_str
end
function this.Initialize()
--加载相关模块
local files = ReloadFile("Modules/Battle/Config/LuaFileConfig")
LoadLuaFiles(files)
this._delayRecycleList = {}
end
--获取技能数据(战斗用)
function this.GetSkillData(skillId,skinId)
if not skillId or not SkillLogicConfig[skillId] then
return
end
local skill = {skillId}
--skill = {skillId, 命中时间, 持续时间, 伤害次数, {目标id1, 效果1, 效果2, ...},{目标id2, 效果3, 效果4, ...}, ...}
--效果 = {效果类型id, 效果参数1, 效果参数2, ...}
local target = SkillLogicConfig[skillId].Target
local effectList = SkillLogicConfig[skillId].Effect
local effectArgsList = SkillLogicConfig[skillId].EffectValue
local eid = BattleManager.GetCombatIdBySkin(skillId, skinId or 0)
local EffectCombat = CombatControl[eid]
skill[1] = skillId
skill[2] = EffectCombat.KeyFrame/1000
skill[3] = EffectCombat.SkillDuration/1000
skill[4] = EffectCombat.SkillNumber
local index = 1
for i = 1, #effectList do
local effectGroup = { target[i][1] } -- 效果目标
for j = 1, #effectList[i] do
local effect = { effectList[i][j] } -- 效果Id
for k = 1, #effectArgsList[index] do
effect[k + 1] = effectArgsList[index][k] -- 效果参数
end
effectGroup[j + 1] = effect
index = index + 1
end
skill[i + 4] = effectGroup
end
return skill
end
function this.GetPassivityData(passivityList)
local pList = {}
if not passivityList then
return pList
end
-- 遍历被动,检查是否有要覆盖的被动技能
local orderList = {}
local coverList = {}
for i = 1, #passivityList do
local passiveId = tonumber(passivityList[i])
local cfg = PassiveSkillLogicConfig[passiveId]
-- 判断技能是否在战斗中生效
if cfg and cfg.EffectiveRange == 1 then
-- 判断是否有需要覆盖的被动技能
local coverId = cfg.CoverID
if coverId and coverId ~= 0 then
if orderList[coverId] then
orderList[coverId] = nil
end
coverList[coverId] = 1
end
-- 判断该被动技能是否已经被覆盖
if not coverList[passiveId] then
-- 没有被覆盖,数据加入
local pass = {}
if cfg and cfg.Type ~= 0 then
pass[1]=passiveId
pass[2]=cfg.Judge
pass[3] = cfg.Type
for j = 1, #cfg.Value do
pass[j + 3] = cfg.Value[j]
end
orderList[passiveId] = pass
end
end
end
end
-- 构建数据
for _, passive in pairs(orderList) do
table.insert(pList, passive)
end
return pList
end
--获取怪物数据(战斗用)
function this.GetMonsterData(monsterId)
local monsterConfig = MonsterConfig[monsterId]
return {
roleId = monsterConfig.MonsterId,
monsterId = monsterId, --非战斗数据,仅用于显示怪物名称
professionId = monsterConfig.Profession,
camp = 1,
type = 1,
quality = 0,
skinId=monsterConfig.SkinId,
star=monsterConfig.Star,
skill = this.GetSkillData(monsterConfig.SkillList[1],monsterConfig.SkinId),
superSkill = this.GetSkillData(monsterConfig.SkillList[2],monsterConfig.SkinId),
element = monsterConfig.PropertyName,
job=HeroConfig[monsterConfig.MonsterId].Job,
passivity = this.GetPassivityData(monsterConfig.PassiveSkillList),
property = {
monsterConfig.Level,
monsterConfig.Hp,
monsterConfig.Hp,
monsterConfig.Attack,
monsterConfig.PhysicalDefence,
monsterConfig.MagicDefence,
monsterConfig.Speed,
monsterConfig.DamageBocusFactor,
monsterConfig.DamageReduceFactor,
monsterConfig.Hit,
monsterConfig.Dodge,
monsterConfig.CritFactor,
monsterConfig.CritDamageFactor,
monsterConfig.AntiCritDamageFactor,
monsterConfig.TreatFacter,
monsterConfig.CureFacter,
monsterConfig.DifferDemonsBocusFactor,
monsterConfig.DifferDemonsReduceFactor,
monsterConfig.ElementDamageReduceFactor[1],
monsterConfig.ElementDamageReduceFactor[2],
monsterConfig.ElementDamageReduceFactor[3],
monsterConfig.ElementDamageReduceFactor[4],
monsterConfig.ElementDamageReduceFactor[5],
monsterConfig.ElementDamageReduceFactor[6],
monsterConfig.ElementDamageBonusFactor,
},
ai = monsterConfig.MonsterAi,
}
end
--
function this.MonsterSkillAdapter(MSkillId)
local skill = {}
local monsterSkill = SpiritAnimalSkill[tonumber(MSkillId)]
for index, skillId in ipairs(monsterSkill.SkillIDList) do
skill[index] = {}
skill[index].effect = this.GetSkillData(tonumber(skillId))
skill[index].triggerId = monsterSkill.ReleasePoint[index]
skill[index].triggerCondition = {0}
if monsterSkill.ReleaseLimit and monsterSkill.ReleaseLimit[index] then
for k, v in ipairs(monsterSkill.ReleaseLimit[index]) do
skill[index].triggerCondition[k] = v
end
end
skill[index].maxCount = monsterSkill.WarEffectCount[index] or 999
skill[index].maxRoundCount = monsterSkill.TurnEffectCount[index] or 999
end
return skill
end
function this.PokemonUnitAdapter(pokemonUnit,camp)
-- 基础数据
local role = {
id = tonumber(pokemonUnit.unitId),
position = tonumber(pokemonUnit.position),
star = tonumber(pokemonUnit.star),
camp = camp,
skill = {},
property = {},
}
-- 技能
local skills = string.split(pokemonUnit.unitSkillIds, "#")
for i = 1, #skills do
role.skill = this.MonsterSkillAdapter(tonumber(skills[i]))
end
-- 属性
local propertys = string.split(pokemonUnit.property, "#")
for j = 1, #propertys do
role.property[j] = tonumber(propertys[j])
end
return role
end
---获取服务端传过来的战斗数据和随机数种子
---参数2 isFightPlayer 0和怪物对战 1和玩家对战
function this.GetBattleServerData(msg, isFightPlayer)
local fightData = {
playerData = { teamSkill = {}, teamPassive = {}, firstCamp = 0, },
enemyData = { },
}
isFightPlayer = isFightPlayer == 1
-- 判断是否先手
fightData.playerData.firstCamp = msg.fightData.heroFightInfos.firstCamp or 0
--
local data = msg.fightData.heroFightInfos
for i = 1, #data.fightUnitList do
local rid = tonumber(data.fightUnitList[i].unitId)
local position = tonumber(data.fightUnitList[i].position)
local star = tonumber(data.fightUnitList[i].star)
local skin=tonumber(data.fightUnitList[i].skinId)
local skills = string.split(data.fightUnitList[i].unitSkillIds, "#")
local propertys = string.split(data.fightUnitList[i].property, "#")
local role = {
roleId = rid,
position = position,
star = star,
skinId=skin,
camp = 0,
type = 1,
quality = 0,
job=HeroConfig[rid].Job,
element = HeroConfig[rid].PropertyName,
professionId = HeroConfig[rid].Profession,
passivity = { },
property = { },
}
if skills[1] then
role.skill = this.GetSkillData(tonumber(skills[1]),skin)
end
if skills[2] and skills[2] ~= "0" then
role.superSkill = this.GetSkillData(tonumber(skills[2]),skin)
end
if #skills > 2 then
local passivityList = {}
for j = 3, #skills do
table.insert(passivityList, tonumber(skills[j]))
end
role.passivity = this.GetPassivityData(passivityList)
end
for j = 1, #propertys do
role.property[j] = tonumber(propertys[j])
end
fightData.playerData[i] = role
end
--Log("teamSkills:"..data.teamSkillList)
local teamSkills = string.split(data.teamSkillList, "|") --异妖位置1#技能id1|异妖位置2#技能id2|..
for i = 1, #teamSkills do
local s = string.split(teamSkills[i], "#")
fightData.playerData.teamSkill[i] = this.GetSkillData(tonumber(s[2]))
end
--Log("data.teamPassiveList:"..data.teamPassiveList)
local teamPassives = string.split(data.teamPassiveList, "|")
for i = 1, #teamPassives do
local s = string.split(teamPassives[i], "#")
local teamPassiveList = {}
for j = 1, #s do
teamPassiveList[j] = tonumber(s[j])
end
fightData.playerData.teamPassive[i] = this.GetPassivityData(teamPassiveList)
end
-- 一些战斗外数据
fightData.playerData.outData = data.specialPassive
-- LogRed("战斗外数据 ==================== "..data.specialPassive)
-- 灵兽数据
fightData.playerData.monsterList ={}
if data.pokemonUnitList then
for i = 1, #data.pokemonUnitList do
fightData.playerData.monsterList[i] = this.PokemonUnitAdapter(data.pokemonUnitList[i],0)
end
end
-- 敌方
--
for i = 1, #msg.fightData.monsterList do
local data2 = msg.fightData.monsterList[i]
fightData.enemyData[i] = { teamSkill = {}, teamPassive = {} , firstCamp = 0, }
-- 判断是否先手
fightData.enemyData[i].firstCamp = data2.firstCamp or 0
--
for j = 1, #data2.fightUnitList do
local skills, propertys, role
if not isFightPlayer then
local monsterConfig = ConfigManager.GetConfigData(ConfigName.MonsterConfig, tonumber(data2.fightUnitList[j].unitId))
local position = tonumber(data2.fightUnitList[j].position)
local star = tonumber(data2.fightUnitList[j].star)
local skin=tonumber(data2.fightUnitList[j].skinId)
skills = string.split(data2.fightUnitList[j].unitSkillIds, "#")
propertys = string.split(data2.fightUnitList[j].property, "#")
role = {
roleId = monsterConfig.MonsterId,
monsterId = tonumber(data2.fightUnitList[j].unitId), --非战斗数据,仅用于显示怪物名称
position = position,
star = star,
skinId=skin,
job=HeroConfig[monsterConfig.MonsterId].Job,
camp = 1,
type = monsterConfig.Type,
quality = monsterConfig.Quality,
element = monsterConfig.PropertyName,
ai = monsterConfig.MonsterAi,
professionId = monsterConfig.Profession,
passivity = { },
property = { },
}
else
local rid = tonumber(data2.fightUnitList[j].unitId)
local position = tonumber(data2.fightUnitList[j].position)
local star = tonumber(data2.fightUnitList[j].star)
local skin=tonumber(data2.fightUnitList[j].skinId)
skills = string.split(data2.fightUnitList[j].unitSkillIds, "#")
propertys = string.split(data2.fightUnitList[j].property, "#")
-- 如果找不到去怪物里面找
if not HeroConfig[rid] then
rid = MonsterConfig[rid].MonsterId
end
if not rid then
LogRed("怪物数据错误")
end
role = {
roleId = rid,
position = position,
star = star,
skinId=skin,
job=HeroConfig[rid].Job,
camp = 1,
type = 1,
quality = 0,
element = HeroConfig[rid].PropertyName,
professionId = HeroConfig[rid].Profession,
passivity = { },
property = { },
}
end
if skills[1] then
role.skill = this.GetSkillData(tonumber(skills[1]),role.skinId)
end
if skills[2] and skills[2] ~= "0" then
role.superSkill = this.GetSkillData(tonumber(skills[2]),role.skinId)
end
if #skills > 2 then
local passivityList = {}
for k = 3, #skills do
table.insert(passivityList, tonumber(skills[k]))
end
role.passivity = this.GetPassivityData(passivityList)
end
for k = 1, #propertys do
role.property[k] = tonumber(propertys[k])
end
fightData.enemyData[i][j] = role
end
--Log("teamSkills2:"..data2.teamSkillList)
local teamSkills2 = string.split(data2.teamSkillList, "|") --异妖位置1#技能id1|异妖位置2#技能id2|..
for j = 1, #teamSkills2 do
local s = string.split(teamSkills2[j], "#")
fightData.enemyData[i].teamSkill[j] = this.GetSkillData(tonumber(s[2]))
end
-- 一些战斗外数据
fightData.enemyData[i].outData = data2.specialPassive
-- 灵兽数据
fightData.enemyData[i].monsterList ={}
if data2.pokemonUnitList then
for k = 1, #data2.pokemonUnitList do
fightData.enemyData[i].monsterList[k] = this.PokemonUnitAdapter(data2.pokemonUnitList[k],1)
end
end
end
local data = {
fightData = fightData,
fightSeed = msg.fightData.fightSeed,
fightType = msg.fightData.fightType,
maxRound = msg.fightData.fightMaxTime,
fightId = msg.fightData.fightId,
}
LogYellow("收到的战斗ID = "..msg.fightData.fightId)
this.SetLastBattleResult(nil,nil)
lastFightData = data
return data
end
--获取战斗数据(战斗用)
function this.GetBattleData(formationId, monsterGroupId)
local fightData = {
playerData = { teamSkill = {}, teamPassive = {} },
enemyData = {},
}
local pokemonInfos = FormationManager.formationList[formationId].teamPokemonInfos
local teamHeroInfos = FormationManager.formationList[formationId].teamHeroInfos
for i = 1, #pokemonInfos do
Log(DiffMonsterManager.GetSinglePokemonSkillIdData(pokemonInfos[i].pokemonId))
fightData.playerData.teamSkill[i] = this.GetSkillData(DiffMonsterManager.GetSinglePokemonSkillIdData(pokemonInfos[i].pokemonId))
fightData.playerData.teamPassive[i] = this.GetPassivityData(DiffMonsterManager.GetSinglePokemonPassiveSkillIdData(pokemonInfos[i].pokemonId))
end
for i = 1, #teamHeroInfos do
local heroData = HeroManager.GetSingleHeroData(teamHeroInfos[i].heroId)
if heroData then
local role = {
roleId = heroData.id,
camp = 0,
type = 1,
quality = 0,
element = HeroConfig[heroData.id].PropertyName,
professionId = heroData.profession,
--skill = this.GetSkillData(1000112),
--superSkill = nil,
passivity = this.GetPassivityData(this.GetTalismanSkillData(heroData.dynamicId)),
}
if heroData.skillIdList[1] then
Log("skillId1" .. heroData.skillIdList[1].skillId)
role.skill = this.GetSkillData(heroData.skillIdList[1].skillId)
end
if heroData.skillIdList[2] then
Log("skillId2" .. heroData.skillIdList[2].skillId)
role.superSkill = this.GetSkillData(heroData.skillIdList[2].skillId)
end
local allPassiveSkillIds = HeroManager.GetHeroAllPassiveSkillIds(heroData)
if allPassiveSkillIds then
role.passivity = this.GetPassivityData(allPassiveSkillIds)
end
-- if heroData.passiveSkillList[2] then
-- Log("skillIdPassive2" .. heroData.passiveSkillList[2].skillId)
-- local skillPL = this.GetPassivityData({heroData.passiveSkillList[2].skillId})
-- for i=1, #skillPL do
-- table.insert(role.passivity, skillPL[i])
-- end
-- end
role.property = HeroManager.CalculateWarAllProVal(heroData.dynamicId)
fightData.playerData[i] = role
end
end
local Contents = MonsterGroup[monsterGroupId].Contents
for i = 1, #Contents do
local enemyList = { teamSkill = {}, teamPassive = {} }
for j = 1, #Contents[i] do
enemyList[j] = this.GetMonsterData(Contents[i][j])
end
fightData.enemyData[i] = enemyList
end
return fightData
end
-- 获取我数据
function this.GetBattlePlayerData(fId)
fId = fId or 1 -- 默认主线编队
local playerData = { teamSkill = {}, teamPassive = {} }
-- local pokemonInfos = FormationManager.formationList[formationId].teamPokemonInfos
-- for i = 1, #pokemonInfos do
-- Log(DiffMonsterManager.GetSinglePokemonSkillIdData(pokemonInfos[i].pokemonId))
-- fightData.playerData.teamSkill[i] = this.GetSkillData(DiffMonsterManager.GetSinglePokemonSkillIdData(pokemonInfos[i].pokemonId), pokemonInfos[i].position)
-- fightData.playerData.teamPassive[i] = this.GetPassivityData(DiffMonsterManager.GetSinglePokemonPassiveSkillIdData(pokemonInfos[i].pokemonId))
-- end
local teamHeroInfos = FormationManager.formationList[fId].teamHeroInfos
for i = 1, #teamHeroInfos do
local teamData = teamHeroInfos[i]
local heroData = HeroManager.GetSingleHeroData(teamData.heroId)
if heroData then
local role = {
roleId = heroData.id,
position = teamData.position,
star = heroData.star,
camp = 0,
type = 1,
quality = 0,
job=HeroConfig[heroData.id].Job,
element = HeroConfig[heroData.id].PropertyName,
professionId = heroData.profession,
}
if heroData.skillIdList[1] then
role.skill = this.GetSkillData(heroData.skillIdList[1].skillId)
end
if heroData.skillIdList[2] then
role.superSkill = this.GetSkillData(heroData.skillIdList[2].skillId)
end
local allPassiveSkillIds = HeroManager.GetHeroAllPassiveSkillIds(heroData)
if allPassiveSkillIds then
role.passivity = this.GetPassivityData(allPassiveSkillIds)
end
role.property = HeroManager.CalculateWarAllProVal(heroData.dynamicId)
--
table.insert(playerData, role)
end
end
return playerData
end
function this.GetMonsterPros(id, lv, star)
local proList = PokemonManager.GetSinglePokemonAddProDataByLvAndStar(id, lv, star)
local allProVal = {}
table.insert(allProVal, 1, lv or 0) --等级
table.insert(allProVal, 2, proList[HeroProType.Hp] or 0) --生命
table.insert(allProVal, 3, proList[HeroProType.Hp] or 0) --最大生命
table.insert(allProVal, 4, proList[HeroProType.Attack] or 0) --攻击力
table.insert(allProVal, 5, proList[HeroProType.PhysicalDefence] or 0) --护甲
table.insert(allProVal, 6, proList[HeroProType.MagicDefence] or 0) --魔抗
table.insert(allProVal, 7, proList[HeroProType.Speed] or 0) --速度
table.insert(allProVal, 8, proList[HeroProType.DamageBocusFactor] or 0) --伤害加成系数(%
table.insert(allProVal, 9, proList[HeroProType.DamageReduceFactor] or 0) --伤害减免系数(%
table.insert(allProVal, 10, proList[HeroProType.Hit] or 1) --命中率(% 默认为1
table.insert(allProVal, 11, proList[HeroProType.Dodge] or 0) --闪避率(%
table.insert(allProVal, 12, proList[HeroProType.CritFactor] or 0) --暴击率(%
table.insert(allProVal, 13, proList[HeroProType.CritDamageFactor] or 0) --暴击伤害系数(%
table.insert(allProVal, 14, proList[HeroProType.AntiCritDamageFactor] or 0) --抗暴率(%
table.insert(allProVal, 15, proList[HeroProType.TreatFacter] or 1) --治疗加成系数(% 默认为1
table.insert(allProVal, 16, proList[HeroProType.CureFacter] or 1) --受到治疗系数(%默认为1
table.insert(allProVal, 17, 0) --异妖伤害加成系数(%
table.insert(allProVal, 18, 0) --异妖减伤率(%
table.insert(allProVal, 19, 0) --火系伤害减免系数(%
table.insert(allProVal, 20, 0) --风系伤害减免系数(%
table.insert(allProVal, 21, 0) --冰系伤害减免系数(%
table.insert(allProVal, 22, 0) --地系伤害减免系数(%
table.insert(allProVal, 23, 0) --光系伤害减免系数(%
table.insert(allProVal, 24, 0) --暗系伤害减免系数(%
table.insert(allProVal, 25, 0)
local pros = table.concat(allProVal, "#")
return pros
end
-- 从monsterGroup中获取灵兽数据
function this.GetMonsterDataFromGroup(gId, camp)
local list = {}
local Monsters = MonsterGroup[gId].Animal
if not Monsters then
return list
end
for i = 1, #Monsters do
local monster = Monsters[i]
local id = monster[1]
local star = monster[2]
local level = monster[3]
local mUnit = {
unitId = id,
position = i,
star = star
}
local pros = this.GetMonsterPros(id, level, star)
mUnit.property = pros
local mSkill = ConfigManager.GetConfigDataByDoubleKey(ConfigName.SpiritAnimalSkill, "SpiritAnimalMatch", id, "StarMatch", star)
mUnit.unitSkillIds = mSkill.Id
list[i] = this.PokemonUnitAdapter(mUnit, camp)
end
return list
end
-- 根据怪物组数据
function this.GetBattleEnemyData(gId)
-- body
local enemyData = {}
local Contents = MonsterGroup[gId].Contents
for i = 1, #Contents do
local enemyList = { teamSkill = {}, teamPassive = {} }
for j = 1, #Contents[i] do
if Contents[i][j] ~= 0 then
local data = this.GetMonsterData(Contents[i][j])
data.position = j
table.insert(enemyList, data)
end
end
enemyData[i] = enemyList
-- 构建灵兽数据
enemyData[i].monsterList = this.GetMonsterDataFromGroup(gId, 1)
end
return enemyData
end
function this.GetPlayerDataFromMonsterGroup(gId)
local playerData = { teamSkill = {}, teamPassive = {} }
local Contents = MonsterGroup[gId].Contents
if Contents and Contents[1] then
for j = 1, #Contents[1] do
if Contents[1][j] ~= 0 then
local data = this.GetMonsterData(Contents[1][j])
data.camp = 0
data.position = j
table.insert(playerData, data)
end
end
end
-- 构建灵兽数据
playerData.monsterList = this.GetMonsterDataFromGroup(gId, 0)
return playerData
end
function this.GetFakeBattleData(fakeId)
local fakeConfig = FakeBattleNew[fakeId]
if not fakeConfig then
LogError("未找到假战斗数据:"..tostring(fakeId))
return
end
local battleData = {}
battleData.enemyData = this.GetBattleEnemyData(fakeConfig.EnnemiId)
battleData.playerData = this.GetPlayerDataFromMonsterGroup(fakeConfig.OwnId)
return battleData, fakeConfig.TimeSeed
end
--获取单个英雄装备被动技能list
--function this.GetSingHeroAllEquipSkillListData(_heroId)
-- local allEquipSkillList = {}
-- local curHeroData = HeroManager.GetSingleHeroData(_heroId)
-- if curHeroData then
-- for i = 1, #curHeroData.equipIdList do
-- local curEquip = EquipManager.GetSingleEquipData(curHeroData.equipIdList[i])
-- if curEquip then
-- if curEquip.skillId and curEquip.skillId > 0 then
-- table.insert(allEquipSkillList, curEquip.skillId)
-- end
-- end
-- end
-- end
-- return allEquipSkillList
--end
--获取单个英雄法宝被动技能list
function this.GetTalismanSkillData(_heroId)
local allTalismanSkillList = {}
local curHeroData = HeroManager.GetSingleHeroData(_heroId)
if curHeroData then
for i = 1, #curHeroData.talismanList do
local curTalisman = TalismanManager.GetSingleTalismanData(curHeroData.talismanList[i])
if curTalisman then
local talismanConFig = ConfigManager.GetConfigDataByDoubleKey(ConfigName.EquipTalismana, "TalismanaId", curTalisman.backData.equipId,"Level",curTalisman.star)
if talismanConFig then
for j = 1, #talismanConFig.OpenSkillRules do
table.insert(allTalismanSkillList, talismanConFig.OpenSkillRules[j])
end
end
end
end
end
return allTalismanSkillList
end
-- 获取技能表现
local _CombatList = {}
function this.GetSkillCombat(id)
if not _CombatList[id] then
local combat = CombatControl[id]
if not combat then return end
_CombatList[id] = {
Id = combat.Id,
SkillType = combat.SkillType,
VerticalDrawing = combat.VerticalDrawing,
KeyFrame = combat.KeyFrame,
Eterm = combat.Eterm,
ShockScreen = combat.ShockScreen,
Bullet = combat.Bullet,
BulletTime = combat.BulletTime,
Hit = combat.Hit,
Offset = combat.Offset,
skillname = combat.skillname,
BeforeBullet = combat.BeforeBullet,
SkillNumber = combat.SkillNumber,
SkillDuration = combat.SkillDuration,
BeforeOrientation = combat.BeforeOrientation,
Orientation = combat.Orientation,
HitOrientation = combat.HitOrientation,
BeforeEffectType = combat.BeforeEffectType ,
EffectType = combat.EffectType ,
HitEffectType = combat.HitEffectType,
BeforeOffset = combat.BeforeOffset,
HitOffset = combat.HitOffset,
SkillNameVoice = combat.SkillNameVoice,
}
end
return _CombatList[id]
end
function this.SetSkillCombat(id, combat)
_CombatList[id] = combat
end
----- 战斗控制相关 ------------------
-- 是否解锁二倍速
function this.IsUnlockBattleSpeed()
return PrivilegeManager.GetPrivilegeOpenStatus(PRIVILEGE_TYPE.DoubleTimesFight)
end
-- 是否解锁跳过功能
function this.IsUnlockBattlePass()
-- return false
return PrivilegeManager.GetPrivilegeOpenStatus(PRIVILEGE_TYPE.SkipFight)
end
-- 战斗暂停控制
this.IsPlay = 0
function this.StartBattle()
if this.IsPlay == 0 then
this.IsPlay = 1
end
end
function this.IsBattlePlaying()
return this.IsPlay == 1
end
function this.PauseBattle()
if this.IsPlay == 1 then
this.IsPlay = 2
end
end
function this.ResumeBattle()
if this.IsPlay == 2 then
this.IsPlay = 1
end
end
function this.StopBattle()
this.IsPlay = 0
end
function this.IsCanOperate()
return this.IsPlay ~= 0
end
-- 战斗加速控制
BATTLE_TIME_SCALE_ZERO = 0
BATTLE_TIME_SCALE_ONE= 1.1
BATTLE_TIME_SCALE_TWO = 2
this.TimeScale = 0
function this.InitTimeScale()
this.TimeScale = 0
local _TimeScale = PlayerPrefs.GetFloat("battleTimeScaleKey", BATTLE_TIME_SCALE_ONE)
this.SetTimeScale(_TimeScale)
end
function this.GetTimeScale()
return this.TimeScale
end
function this.SetTimeScale(TimeScale)
--
if TimeScale < 0 or not this.IsUnlockBattleSpeed() then--or this.IsFirstBattle()then
TimeScale = BATTLE_TIME_SCALE_ONE
end
--
if TimeScale > BATTLE_TIME_SCALE_TWO then
TimeScale = BATTLE_TIME_SCALE_TWO
end
if this.TimeScale ~= TimeScale then
this.TimeScale = TimeScale
PlayerPrefs.SetFloat("battleTimeScaleKey", this.TimeScale)
-- 刷新前端显示
Game.GlobalEvent:DispatchEvent(GameEvent.Battle.OnTimeScaleChanged)
-- 真正生效的敌方
Time.timeScale = TimeScale
-- 设置音效播放的速度
SoundManager.SetAudioSpeed(TimeScale)
end
end
-- 获取战斗界面层级
function this.GetBattleSorting()
if UIManager.IsOpen(UIName.BattlePanel) then
return BattlePanel.sortingOrder
end
if UIManager.IsOpen(UIName.BattleTestPanel) then
return BattleTestPanel.sortingOrder
end
if UIManager.IsOpen(UIName.GuideBattlePanel) then
return GuideBattlePanel.sortingOrder
end
return 0
end
-- 判断是否是战斗测试
function this.IsBattleTestPanel()
if UIManager.IsOpen(UIName.BattleTestPanel) then
return true
end
end
-- 获取战斗背景
function this.GetBattleBg(fightType)
local index = 1
if fightType == BATTLE_TYPE.STORY_FIGHT then
local curChapter = FightPointPassManager.GetCurChapterIndex()
index = math.floor((curChapter - 1) % 5 + 1)
elseif fightType == BATTLE_TYPE.BACK or fightType == BATTLE_TYPE.ARENA then
index = 1001
elseif fightType == BATTLE_TYPE.EXECUTE_FIGHT then
index = 1002
elseif fightType == BATTLE_TYPE.Xuanyuan then
index = 1003
elseif fightType == BATTLE_TYPE.DEATH_POS then
index = 1004
end
return "r_zhandou_changjing_"..tostring(index)
end
-- 引导战斗暂停控制
this.isGuidePause = false
function this.IsGuidePause()
return this.isGuidePause
end
function this.SetGuidePause(isPause)
this.isGuidePause = isPause
end
function this.LoadAsset(path, battleSorting)
--- 播放音效
local audioData = FEAConfig.GetAudioData(path)
if audioData then
SoundManager.PlaySound(audioData.name)
end
--
local go = poolManager:LoadAsset(path, PoolManager.AssetType.GameObject)
UIManager.DoLanguageCheck(go)
local layer = tonumber(go.name) or 0
battleSorting = battleSorting or BattleManager.GetBattleSorting()
Util.AddParticleSortLayer(go, battleSorting - layer)
go.name = tostring(battleSorting)
return go
end
--++++++++++++++所有需要延迟回收的资源走该接口,当回调执行前界面已被销毁时,不会报错
--
function this.LateUpdate()
if not this._delayRecycleList then return end
for _, list in pairs(this._delayRecycleList) do
local i = 1
while i <= #list do
-- 没有下一个
if not list[i] then
i = i + 1
end
--
list[i].delayTime = list[i].delayTime - Time.deltaTime
if list[i].delayTime <= 0 then
Util.SetGray(list[i].go, false)
poolManager:UnLoadAsset(list[i].path, list[i].go, PoolManager.AssetType.GameObject)
if list[i].delayFunc then
list[i].delayFunc()
end
table.remove(list, i)
else
i = i + 1
end
end
end
end
function this.AddDelayRecycleRes(path, go, delayTime, delayFunc)
if not this._delayRecycleList[path] then
this._delayRecycleList[path] = {}
end
table.insert(this._delayRecycleList[path], {path = path, go = go, delayTime = delayTime, delayFunc = delayFunc})
end
function this.RecycleAllDelayRes()
--立即回收延迟列表上的资源
for _, v in pairs(this._delayRecycleList) do
for i=1, #v do
Util.SetGray(v[i].go, false)
poolManager:UnLoadAsset(v[i].path, v[i].go, PoolManager.AssetType.GameObject)
end
end
this._delayRecycleList = {}
end
--++++++++++++++
-- 获取技能表现id
function this.GetCombatIdBySkin(skillId, skinId)
skillId = tonumber(skillId)
local effectIds = SkillLogicConfig[skillId].SkillDisplay
local eid=0
local skin = skinId or 0
if effectIds then
for i = 1, #effectIds do
if effectIds[i][1] == skin then
eid=effectIds[i][2]
end
end
end
if eid==0 then
eid=effectIds[1][2]
end
return eid
end
--+++++++++++++++++++++++++++++++++++++++++++
function this.GetArtFontConfig(_ArtFontType)
if _ArtFontType == BattleArtFontType.Immune then
return {type = 2, content = Language[10203]}
elseif _ArtFontType == BattleArtFontType.Shield then
return {type = 2, content = Language[12236]}
elseif _ArtFontType == BattleArtFontType.clear then
return {type = 2, content = Language[12237]}
end
end
--++++++++++++++++++++++++++++++++++++++++++
-- 通过接口获取战斗数据
function this.RequestBattleDataByFightId(fightId, func)
local uid = string.split(fightId, "_")[1]
local requestUrl = string.format("http://60.1.1.244:8888/req/getFightRecord?uid=%s&fightid=%s", uid, fightId)
LogGreen(requestUrl)
networkMgr:SendGetHttp(requestUrl, function(str)
LogGreen(str)
local json = require 'cjson'
local data = json.decode(str)
local fightData = this.GetBattleServerData({fightData = data}, 1)
if func then
func(fightData)
end
end, nil, nil, nil)
end
--新回放功能
local lastBattleResult = nil
local lastBattleType = nil
--设置上次战斗回放数据和类型
function this.SetLastBattleResult(_lastBattleResult,_lastBattleType)
lastBattleResult = _lastBattleResult
lastBattleType = _lastBattleType
end
function this.GetLastBattleResult()
return lastBattleResult
end
function this.GetLastBattleType()
return lastBattleType
end
--新回放功能
function this.BattleBackFun()
if lastFightData then
if UIManager.GetOpenPanel(UIName.BattlePanel) then
UIManager.ClosePanel(UIName.BattlePanel)
end
UIManager.OpenPanel(UIName.BattlePanel, lastFightData, BATTLE_TYPE.BACK_BATTLE)
end
end
return this