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 duoDuiTowerHero=ConfigManager.GetConfig(ConfigName.DuoDuiTowerHero) local CombatControl = ConfigManager.GetConfig(ConfigName.CombatControl) local SpiritAnimalSkill = ConfigManager.GetConfig(ConfigName.SpiritAnimalSkill) local ShenBingSkill=ConfigManager.GetConfig(ConfigName.ShenBingSkill) local playerSkill = ConfigManager.GetConfig(ConfigName.PlayerSkill) local FakeBattleNew = ConfigManager.GetConfig(ConfigName.FakeBattleNew) local cardPosition=ConfigManager.GetConfig(ConfigName.ChangingCardPosition) 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) -- LogError("op1=="..op1.." op2=="..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 skill[5] = EffectCombat.SkillNumbetTime skill[6] = EffectCombat.AttackDisplaceoffset==nil and {[1]=0.4,[2]=-0.2} or EffectCombat.AttackDisplaceoffset 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 + 6] = 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]) if passiveId then --LogError("passiveId======================"..passiveId) 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 end -- 构建数据 for _, passive in pairs(orderList) do table.insert(pList, passive) end return pList end --获取怪物数据(战斗用) function this.GetMonsterData(monsterId) LogRed("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.WeaponSkillAdapter(MSkillId) local skill = {} if MSkillId then LogError("mskillid======"..MSkillId) local monsterSkill = ShenBingSkill[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 end return skill end function this.PlayerSkillAdapter(pos,MSkillId) local skill = {} local monsterSkill = playerSkill[tonumber(MSkillId)] for index, skillId in ipairs(monsterSkill.SkillIDList) do skill[index] = {} skill[index].effect = this.GetSkillData(tonumber(skillId)) skill[index].triggerCondition = {0} if index==1 then skill[index].triggerId = cardPosition[pos].ReleasePoint[1] skill[index].triggerCondition = cardPosition[pos].ReleaseLimit[1] else skill[index].triggerId = monsterSkill.ReleasePoint[index] if monsterSkill.ReleaseLimit and monsterSkill.ReleaseLimit[index] then for k, v in ipairs(monsterSkill.ReleaseLimit[index]) do skill[index].triggerCondition[k] = v end end end skill[index].maxCount = monsterSkill.WarEffectCount[index] or 999 skill[index].maxRoundCount = monsterSkill.TurnEffectCount[index] or 999 end return skill end --老版主角技能 function this.PlayerSkillAdapter2(MSkillId) local skill = {} local monsterSkill = playerSkill[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,_teamDamage) -- 基础数据 --LogError("teamdamage=="..tonumber(pokemonUnit.forceScore)) local role = { id = tonumber(pokemonUnit.unitId), position = tonumber(pokemonUnit.position), star = tonumber(pokemonUnit.star), teamDamage = tonumber(pokemonUnit.forceScore), sex= tonumber(pokemonUnit.playerSex), camp = camp, skill = {}, property = {}, } if pokemonUnit.position==100 then LogError("主角技能 pokemonUnit.unitSkillIds=="..pokemonUnit.unitSkillIds) local skills2 = string.split(pokemonUnit.unitSkillIds, "|") if skills2 then for i = 1, #skills2 do local actives2=string.split(skills2[i], "#") if actives2 and #actives2>1 then local newSkill=this.PlayerSkillAdapter(tonumber(actives2[1]),tonumber(actives2[2])) role.skill[i] = newSkill end end end else --灵兽技能 LogError("灵兽技能 pokemonUnit.unitSkillIds=="..pokemonUnit.unitSkillIds) local skills = string.split(pokemonUnit.unitSkillIds, "|") if skills then if skills[1] then local actives=string.split(skills[1], "#") for i = 1, #actives do role.skill[i]= this.MonsterSkillAdapter(tonumber(actives[i])) end end if skills[2] then local passs=string.split(skills[2], "#") local passivityList = {} for j = 1, #passs do table.insert(passivityList, tonumber(passs[j])) end role.passivity = this.GetPassivityData(passivityList) end end end -- 属性 local propertys = string.split(pokemonUnit.property, "#") LogError("pokemon #propertys=="..#propertys) for j = 1, #propertys do role.property[j] = tonumber(propertys[j]) end return role end --老板灵兽技能解析 function this.PokemonUnitAdapter2(pokemonUnit,camp,_teamDamage) -- 基础数据 --LogError("teamdamage=="..tonumber(pokemonUnit.forceScore)) local role = { id = tonumber(pokemonUnit.unitId), position = tonumber(pokemonUnit.position), star = tonumber(pokemonUnit.star), teamDamage = tonumber(pokemonUnit.forceScore), sex= tonumber(pokemonUnit.playerSex), camp = camp, skill = {}, property = {}, } -- 技能 local skills = string.split(pokemonUnit.unitSkillIds, "|") if skills then if skills[1] then local actives=string.split(skills[1], "#") if pokemonUnit.position==100 then -- 特殊处理位置 100 是玩家技能数据 for i = 1, #actives do if actives[i] and actives[i]~="" then local newSkill=this.PlayerSkillAdapter2(tonumber(actives[i])) role.skill[i] = newSkill end end else for i = 1, #actives do role.skill[i]= this.MonsterSkillAdapter(tonumber(actives[i])) end end end if skills[2] then local passs=string.split(skills[2], "#") local passivityList = {} for j = 1, #passs do table.insert(passivityList, tonumber(passs[j])) end role.passivity = this.GetPassivityData(passivityList) end end -- 属性 local propertys = string.split(pokemonUnit.property, "#") for j = 1, #propertys do role.property[j] = tonumber(propertys[j]) end return role end function this.GodWeaponUnitAdapter(pokemonUnit,camp,_teamDamage) -- 基础数据 --LogError("teamdamage=="..tonumber(pokemonUnit.forceScore)) local role = { id = tonumber(pokemonUnit.unitId), position = tonumber(pokemonUnit.position), star = tonumber(pokemonUnit.star), teamDamage = tonumber(pokemonUnit.forceScore), sex= tonumber(pokemonUnit.playerSex), camp = camp, skill = {}, property = {}, passivity = {}, } -- 技能 LogError("pokemonUnit.unitSkillIds=="..pokemonUnit.unitSkillIds) if pokemonUnit.unitSkillIds~=nil and tonumber(pokemonUnit.unitSkillIds)~=0 then local skills = string.split(pokemonUnit.unitSkillIds, "|") if skills then if skills[1] then local actives=string.split(skills[1], "#") local passivityList1 = {} for i = 1, #actives do local skillId=tonumber(actives[i]) role.skill[i]= this.WeaponSkillAdapter(skillId) LogError("tonumber(actives[i])=="..skillId) local shenbing=ShenBingSkill[skillId] if shenbing and shenbing.PassiveSkill~=nil and #shenbing.PassiveSkill~=0 then --local passs=string.split(shenbing.PassiveSkill, "#") local passs=shenbing.PassiveSkill for j = 1, #passs do if passs[j]~=0 and passs[j]~=nil and tostring(passs[j])~=nil then --LogError("passs[j]==="..passs[j]) table.insert(passivityList1, passs[j]) end end end end role.passivity = this.GetPassivityData(passivityList1) end end 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 _godSoulLv=tonumber(data.fightUnitList[i].godSoulLv) local skills = string.split(data.fightUnitList[i].unitSkillIds, "#") local propertys = string.split(data.fightUnitList[i].property, "#") local proId= tonumber(data.fightUnitList[i].propertyId) local role = { roleId = rid, position = position, star = star, skinId=skin, godSoulLv=_godSoulLv, camp = 0, type = 1, quality = 0, job=HeroConfig[rid].Job, element = proId, 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 --LogError("pass id=="..tostring(skills[j])) table.insert(passivityList, tonumber(skills[j])) end role.passivity = this.GetPassivityData(passivityList) end LogError("#propertys=="..#propertys) 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], "#") --LogError("team skill id=="..tostring(s[2])) 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 --LogError("team pass id=="..tostring(s[j])) teamPassiveList[j] = tonumber(s[j]) end fightData.playerData.teamPassive[i] = this.GetPassivityData(teamPassiveList) end -- 一些战斗外数据 fightData.playerData.outData = data.specialPassive -- 灵兽数据 fightData.playerData.monsterList ={} if data.pokemonUnitList then for i = 1, #data.pokemonUnitList do local pokemonData=data.pokemonUnitList[i] fightData.playerData.monsterList[i] = this.PokemonUnitAdapter(pokemonData,0,data.forceScore) end end -- 神兵数据 fightData.playerData.weaponList ={} if data.MagicSoldierList then for i = 1, #data.MagicSoldierList do local weaponData=data.MagicSoldierList[i] fightData.playerData.weaponList[i] = this.GodWeaponUnitAdapter(weaponData,0,data.forceScore) 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) local _godSoulLv=tonumber(data2.fightUnitList[j].godSoulLv) local proId = tonumber(data2.fightUnitList[j].propertyId) 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, godSoulLv=_godSoulLv, job=HeroConfig[monsterConfig.MonsterId].Job, camp = 1, type = monsterConfig.Type, quality = monsterConfig.Quality, element = proId, ai = monsterConfig.MonsterAi, professionId = monsterConfig.Profession, passivity = { }, property = { }, } else local rid = tonumber(data2.fightUnitList[j].unitId) local position = tonumber(data2.fightUnitList[j].position) LogError("position======"..position) local star = tonumber(data2.fightUnitList[j].star) local skin=tonumber(data2.fightUnitList[j].skinId) local _godSoulLv=tonumber(data2.fightUnitList[j].godSoulLv) local proId2 = tonumber(data2.fightUnitList[j].propertyId) skills = string.split(data2.fightUnitList[j].unitSkillIds, "#") propertys = string.split(data2.fightUnitList[j].property, "#") -- 如果找不到去怪物里面找 LogError("rid=="..rid) if not MonsterConfig[rid] and not HeroConfig[rid] then rid = duoDuiTowerHero[rid].Hero end if not HeroConfig[rid] and not duoDuiTowerHero[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, godSoulLv=_godSoulLv, element = proId2, 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 -- LogError("em pass id=="..tostring(skills[k])) 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,data2.forceScore) end end --神兵数据 fightData.enemyData[i].weaponList ={} if data2.MagicSoldierList then for k = 1, #data2.MagicSoldierList do local weaponData=data2.MagicSoldierList[k] fightData.enemyData[i].weaponList[k] = this.GodWeaponUnitAdapter(weaponData,1,data.forceScore) end end end --精英副本关卡id fightData.nodeId = msg.fightData.nodeId 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.." 精英副本关卡id="..msg.fightData.nodeId) 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.AntiCritFactor] 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, proList[HeroProType.RenBonus] or 0) -- 灭人 table.insert(allProVal, 18, proList[HeroProType.FoBonus] or 0) -- 灭佛 table.insert(allProVal, 19, proList[HeroProType.YaoBonus] or 0) -- 灭妖 table.insert(allProVal, 20, proList[HeroProType.DaoBonus] or 0) -- 灭道 table.insert(allProVal, 21, proList[HeroProType.RenReduce] or 0) -- 抗人 table.insert(allProVal, 22, proList[HeroProType.FoReduce] or 0) -- 抗佛 table.insert(allProVal, 23, proList[HeroProType.YaoReduce] or 0) -- 抗妖 table.insert(allProVal, 24, proList[HeroProType.DaoReduce] or 0) -- 抗道 table.insert(allProVal, 25, proList[HeroProType.AntiCritDamageFactor] or 0) -- 爆伤减免 table.insert(allProVal, 26, proList[HeroProType.InitRage] or 0) -- 初始怒气 local pros = table.concat(allProVal, "#") return pros end -- 从monsterGroup中获取灵兽数据 function this.GetMonsterDataFromGroup(gId, camp) local list = {} -- 灵兽 local Monsters = MonsterGroup[gId].Animal if Monsters then 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, playerSex = 0, forceScore = 0 } 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 end -- 技能 local RoleSkills = MonsterGroup[gId].Role if RoleSkills and #RoleSkills > 0 then -- 主角ID local CharacterId = MonsterGroup[gId].CharacterId if not CharacterId or CharacterId == 0 then CharacterId = 20100 end local mUnit = { unitId = CharacterId, position = 100, star = 1, playerSex = NameManager.roleSex, forceScore = 0, property = {} } for _, id in ipairs(RoleSkills) do if not mUnit.unitSkillIds then mUnit.unitSkillIds = id else mUnit.unitSkillIds = mUnit.unitSkillIds .. "#" .. id end end list[#list+1] = this.PokemonUnitAdapter2(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 return end local battleData = {} battleData.enemyData = this.GetBattleEnemyData(fakeConfig.EnnemiId) battleData.playerData = this.GetPlayerDataFromMonsterGroup(fakeConfig.OwnId) if not fakeConfig.FirstCamp or fakeConfig.FirstCamp == 0 then battleData.enemyData[1].firstCamp = 0 battleData.playerData.firstCamp = 1 else battleData.enemyData[1].firstCamp = 1 battleData.playerData.firstCamp = 0 end battleData.enemyId=fakeId 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, SkillNumbetTime = combat.SkillNumbetTime, SkillDuration = combat.SkillDuration, ActionTime = combat.ActionTime, DamageDelay = combat.DamageDelay, 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, BeforeEffectDelay = combat.BeforeEffectDelay, AttackDisplacement = combat.AttackDisplacement, AttackDisplaceTime = combat.AttackDisplaceTime, AttackDisplaceBackTime = combat.AttackDisplaceBackTime, CloseRangeHit=combat.CloseRangeHit, AttackDisplaceoffset=combat.AttackDisplaceoffset, CloseRangeHitOffset=combat.CloseRangeHitOffset, CloseRangeHitScale=combat.CloseRangeHitScale, ShankTime=combat.ShankTime, HightLightTime=combat.HightLightTime, AttackMove=combat.AttackMove, HitScale=combat.HitScale, HitRecycleTime=combat.HitRecycleTime, HitTimeScale=combat.HitTimeScale, SkillTimeScale=combat.SkillTimeScale, } end return _CombatList[id] end function this.SetSkillCombat(id, combat) _CombatList[id] = combat end ----- 战斗控制相关 ------------------ -- 是否解锁二倍速 function this.IsUnlockBattleSpeed() return PrivilegeManager.GetPrivilegeOpenStatus(PRIVILEGE_TYPE.DoubleTimesFight) end -- 是否解锁3倍速 function this.IsUnlockBattleSpeedThree() return PrivilegeManager.GetPrivilegeOpenStatus(PRIVILEGE_TYPE.ThreeTimesFight) end -- 是否解锁跳过功能 function this.IsUnlockBattlePass() -- return false return PrivilegeManager.GetPrivilegeOpenStatus(PRIVILEGE_TYPE.SkipFight), "通关简单5-10或充值6元后解锁跳过" 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= 2 BATTLE_TIME_SCALE_TWO = 3 BATTLE_TIME_SCALE_THREE = 3 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_THREE then TimeScale = BATTLE_TIME_SCALE_THREE 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 or fightType == BATTLE_TYPE.MONSTER_CAMP then index = 1004 elseif fightType == BATTLE_TYPE.TASUILINGXIAO then index = 1006 elseif fightType == BATTLE_TYPE.EndlessMpaFight then -- 无尽副本 index = 5 elseif fightType == BATTLE_TYPE.DAILY_CHALLENGE -- 日常副本 or fightType == BATTLE_TYPE.FIGHTLEVEL -- 山河社稷图 or fightType == BATTLE_TYPE.FIGHT_ASSISTANT_LEVEL then index = 2 end --return "r_zhandou_changjing_"..tostring(index) return "UI_zhandoubeijing1" end -- 引导战斗暂停控制 this.isGuidePause = false function this.IsGuidePause() return this.isGuidePause end function this.SetGuidePause(isPause) this.isGuidePause = isPause end this.spLoader = nil function this.SetSpLoader(spLoader) this.spLoader = spLoader 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) -- LogError("path================"..path) UIManager.DoLanguageCheck(this.spLoader, 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.LoadSpineAsset(path, parent) --- 播放音效 -- local audioData = FEAConfig.GetAudioData(path) -- if audioData then -- SoundManager.PlaySound(audioData.name) -- end -- -- local go = poolManager:LoadLive(path, parent, Vector3.one, Vector3.zero) 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 "z_zhandou_mianyi_zh" elseif _ArtFontType == BattleArtFontType.Shield then return "z_zhandou_podun_zh" elseif _ArtFontType == BattleArtFontType.clear then return "z_zhandou_qingchu_zh" elseif _ArtFontType == BattleArtFontType.Blood then return "z_zhandou_jinjia_zh" end end --++++++++++++++++++++++++++++++++++++++++++ -- 通过接口获取战斗数据 function this.RequestBattleDataByFightId(serverUrl, fightId, func) local uid = string.split(fightId, "_")[1] local requestUrl = string.format("http://%s/req/getFightRecord?uid=%s&fightid=%s", serverUrl, uid, fightId) LogGreen(requestUrl) HttpManager: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