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

1027 lines
36 KiB
Lua
Raw Normal View History

2020-08-25 15:46:38 +08:00
BattleManager = {}
2020-05-09 13:31:21 +08:00
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)
2020-11-01 15:46:48 +08:00
local SpiritAnimalSkill = ConfigManager.GetConfig(ConfigName.SpiritAnimalSkill)
local FakeBattleNew = ConfigManager.GetConfig(ConfigName.FakeBattleNew)
2020-11-01 15:46:48 +08:00
local FEAConfig = require("Modules/Battle/Config/FightEffectAudioConfig")
2021-01-06 16:12:54 +08:00
local lastFightData = nil
2020-05-09 13:31:21 +08:00
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)
2020-06-28 17:48:49 +08:00
local indent_str = "{"
2020-05-09 13:31:21 +08:00
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)
2020-06-12 18:04:22 +08:00
elseif type(v) == "string" then
indent_str = indent_str .. "\""..tostring(v) .. "\""
2020-05-09 13:31:21 +08:00
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))
2020-06-12 18:04:22 +08:00
elseif type(v) == "string" then
indent_str = string.format("%s%s=\"%s\"", indent_str, tostring(k), tostring(v))
2020-05-09 13:31:21 +08:00
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
2020-06-28 17:48:49 +08:00
indent_str = indent_str .. "}"
2020-05-09 13:31:21 +08:00
return indent_str
end
function this.Initialize()
--加载相关模块
local files = ReloadFile("Modules/Battle/Config/LuaFileConfig")
LoadLuaFiles(files)
2020-11-01 15:46:48 +08:00
this._delayRecycleList = {}
2020-05-09 13:31:21 +08:00
end
--获取技能数据(战斗用)
2020-11-06 10:12:24 +08:00
function this.GetSkillData(skillId,skinId)
2020-05-09 13:31:21 +08:00
if not skillId or not SkillLogicConfig[skillId] then
return
end
local skill = {skillId}
2020-07-08 21:19:34 +08:00
--skill = {skillId, 命中时间, 持续时间, 伤害次数, {目标id1, 效果1, 效果2, ...},{目标id2, 效果3, 效果4, ...}, ...}
2020-05-09 13:31:21 +08:00
--效果 = {效果类型id, 效果参数1, 效果参数2, ...}
local target = SkillLogicConfig[skillId].Target
local effectList = SkillLogicConfig[skillId].Effect
local effectArgsList = SkillLogicConfig[skillId].EffectValue
2020-11-06 13:00:04 +08:00
local eid = BattleManager.GetCombatIdBySkin(skillId, skinId or 0)
2020-11-06 10:51:41 +08:00
local EffectCombat = CombatControl[eid]
2020-07-08 21:19:34 +08:00
skill[1] = skillId
skill[2] = EffectCombat.KeyFrame/1000
skill[3] = EffectCombat.SkillDuration/1000
skill[4] = EffectCombat.SkillNumber
local index = 1
2020-05-09 13:31:21 +08:00
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
2020-07-08 21:19:34 +08:00
effectGroup[j + 1] = effect
2020-05-09 13:31:21 +08:00
index = index + 1
end
2020-07-08 21:19:34 +08:00
skill[i + 4] = effectGroup
2020-05-09 13:31:21 +08:00
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])
2020-05-09 13:31:21 +08:00
local cfg = PassiveSkillLogicConfig[passiveId]
-- 判断技能是否在战斗中生效
if cfg and cfg.EffectiveRange == 1 then
2020-05-09 13:31:21 +08:00
-- 判断是否有需要覆盖的被动技能
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
2020-05-09 13:31:21 +08:00
for j = 1, #cfg.Value do
pass[j + 3] = cfg.Value[j]
2020-05-09 13:31:21 +08:00
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,
2020-11-06 10:12:24 +08:00
skinId=monsterConfig.SkinId,
star=monsterConfig.Star,
2020-11-06 10:12:24 +08:00
skill = this.GetSkillData(monsterConfig.SkillList[1],monsterConfig.SkinId),
superSkill = this.GetSkillData(monsterConfig.SkillList[2],monsterConfig.SkinId),
2020-05-09 13:31:21 +08:00
element = monsterConfig.PropertyName,
job=HeroConfig[monsterConfig.MonsterId].Job,
2020-05-09 13:31:21 +08:00
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
2020-11-01 15:46:48 +08:00
--
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
2020-06-03 19:09:01 +08:00
---获取服务端传过来的战斗数据和随机数种子
---参数2 isFightPlayer 0和怪物对战 1和玩家对战
function this.GetBattleServerData(msg, isFightPlayer)
2020-05-09 13:31:21 +08:00
local fightData = {
2020-07-22 21:24:42 +08:00
playerData = { teamSkill = {}, teamPassive = {}, firstCamp = 0, },
enemyData = { },
2020-05-09 13:31:21 +08:00
}
2020-06-03 19:09:01 +08:00
isFightPlayer = isFightPlayer == 1
2020-07-22 21:24:42 +08:00
-- 判断是否先手
fightData.playerData.firstCamp = msg.fightData.heroFightInfos.firstCamp or 0
--
2020-05-09 13:31:21 +08:00
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)
2020-06-03 19:09:01 +08:00
local star = tonumber(data.fightUnitList[i].star)
2020-11-06 10:12:24 +08:00
local skin=tonumber(data.fightUnitList[i].skinId)
2020-05-09 13:31:21 +08:00
local skills = string.split(data.fightUnitList[i].unitSkillIds, "#")
local propertys = string.split(data.fightUnitList[i].property, "#")
local role = {
roleId = rid,
position = position,
2020-06-03 19:09:01 +08:00
star = star,
2020-11-06 10:12:24 +08:00
skinId=skin,
2020-05-09 13:31:21 +08:00
camp = 0,
type = 1,
quality = 0,
job=HeroConfig[rid].Job,
2020-05-09 13:31:21 +08:00
element = HeroConfig[rid].PropertyName,
professionId = HeroConfig[rid].Profession,
passivity = { },
property = { },
}
if skills[1] then
2020-11-06 10:12:24 +08:00
role.skill = this.GetSkillData(tonumber(skills[1]),skin)
2020-05-09 13:31:21 +08:00
end
if skills[2] and skills[2] ~= "0" then
2020-11-06 10:12:24 +08:00
role.superSkill = this.GetSkillData(tonumber(skills[2]),skin)
2020-05-09 13:31:21 +08:00
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], "#")
2020-11-06 10:53:41 +08:00
fightData.playerData.teamSkill[i] = this.GetSkillData(tonumber(s[2]))
2020-05-09 13:31:21 +08:00
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
2020-05-25 19:16:23 +08:00
-- 一些战斗外数据
fightData.playerData.outData = data.specialPassive
2020-12-17 18:36:08 +08:00
-- LogRed(Language[10221]..data.specialPassive)
2020-11-01 15:46:48 +08:00
-- 灵兽数据
fightData.playerData.monsterList ={}
2020-12-17 18:36:08 +08:00
if data.pokemonUnitList then
for i = 1, #data.pokemonUnitList do
fightData.playerData.monsterList[i] = this.PokemonUnitAdapter(data.pokemonUnitList[i],0)
end
2020-11-01 15:46:48 +08:00
end
2020-05-25 19:16:23 +08:00
2020-07-22 21:24:42 +08:00
-- 敌方
--
2020-05-09 13:31:21 +08:00
for i = 1, #msg.fightData.monsterList do
local data2 = msg.fightData.monsterList[i]
2020-07-22 21:24:42 +08:00
fightData.enemyData[i] = { teamSkill = {}, teamPassive = {} , firstCamp = 0, }
-- 判断是否先手
fightData.enemyData[i].firstCamp = data2.firstCamp or 0
2020-05-09 13:31:21 +08:00
2020-07-22 21:24:42 +08:00
--
2020-05-09 13:31:21 +08:00
for j = 1, #data2.fightUnitList do
local skills, propertys, role
2020-06-03 19:09:01 +08:00
if not isFightPlayer then
2020-05-09 13:31:21 +08:00
local monsterConfig = ConfigManager.GetConfigData(ConfigName.MonsterConfig, tonumber(data2.fightUnitList[j].unitId))
local position = tonumber(data2.fightUnitList[j].position)
2020-06-03 19:09:01 +08:00
local star = tonumber(data2.fightUnitList[j].star)
2020-11-06 10:12:24 +08:00
local skin=tonumber(data2.fightUnitList[j].skinId)
2020-05-09 13:31:21 +08:00
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,
2020-06-03 19:09:01 +08:00
star = star,
2020-11-06 10:12:24 +08:00
skinId=skin,
job=HeroConfig[monsterConfig.MonsterId].Job,
2020-05-09 13:31:21 +08:00
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)
2020-06-03 19:09:01 +08:00
local star = tonumber(data2.fightUnitList[j].star)
2020-11-06 10:12:24 +08:00
local skin=tonumber(data2.fightUnitList[j].skinId)
2020-05-09 13:31:21 +08:00
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
2020-05-09 13:31:21 +08:00
role = {
roleId = rid,
position = position,
2020-06-03 19:09:01 +08:00
star = star,
2020-11-06 10:12:24 +08:00
skinId=skin,
job=HeroConfig[rid].Job,
2020-05-09 13:31:21 +08:00
camp = 1,
type = 1,
quality = 0,
element = HeroConfig[rid].PropertyName,
professionId = HeroConfig[rid].Profession,
passivity = { },
property = { },
2020-05-09 13:31:21 +08:00
}
end
if skills[1] then
2020-11-06 10:12:24 +08:00
role.skill = this.GetSkillData(tonumber(skills[1]),role.skinId)
2020-05-09 13:31:21 +08:00
end
if skills[2] and skills[2] ~= "0" then
2020-11-06 10:12:24 +08:00
role.superSkill = this.GetSkillData(tonumber(skills[2]),role.skinId)
2020-05-09 13:31:21 +08:00
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], "#")
2020-11-06 10:53:41 +08:00
fightData.enemyData[i].teamSkill[j] = this.GetSkillData(tonumber(s[2]))
2020-05-09 13:31:21 +08:00
end
2020-05-25 19:16:23 +08:00
-- 一些战斗外数据
fightData.enemyData[i].outData = data2.specialPassive
2020-11-01 15:46:48 +08:00
-- 灵兽数据
fightData.enemyData[i].monsterList ={}
2020-12-17 18:36:08 +08:00
if data.pokemonUnitList then
for k = 1, #data2.pokemonUnitList do
fightData.enemyData[i].monsterList[k] = this.PokemonUnitAdapter(data2.pokemonUnitList[k],1)
end
2020-11-01 15:46:48 +08:00
end
2020-05-09 13:31:21 +08:00
end
2020-06-03 19:09:01 +08:00
local data = {
fightData = fightData,
fightSeed = msg.fightData.fightSeed,
fightType = msg.fightData.fightType,
maxRound = msg.fightData.fightMaxTime,
2020-12-17 18:36:08 +08:00
fightId = msg.fightData.fightId,
2020-06-03 19:09:01 +08:00
}
2020-12-17 18:36:08 +08:00
LogYellow("收到的战斗ID = "..msg.fightData.fightId)
2021-01-06 16:12:54 +08:00
this.SetLastBattleResult(nil,nil)
lastFightData = data
2020-06-03 19:09:01 +08:00
return data
2020-05-09 13:31:21 +08:00
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))
2020-11-06 10:53:41 +08:00
fightData.playerData.teamSkill[i] = this.GetSkillData(DiffMonsterManager.GetSinglePokemonSkillIdData(pokemonInfos[i].pokemonId))
2020-05-09 13:31:21 +08:00
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,
2020-06-03 19:09:01 +08:00
star = heroData.star,
2020-05-09 13:31:21 +08:00
camp = 0,
type = 1,
quality = 0,
job=HeroConfig[heroData.id].Job,
2020-05-09 13:31:21 +08:00
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) --等级
table.insert(allProVal, 2, proList[HeroProType.Hp]) --生命
table.insert(allProVal, 3, proList[HeroProType.Hp]) --最大生命
table.insert(allProVal, 4, proList[HeroProType.Attack]) --攻击力
table.insert(allProVal, 5, proList[HeroProType.PhysicalDefence]) --护甲
table.insert(allProVal, 6, proList[HeroProType.MagicDefence]) --魔抗
table.insert(allProVal, 7, proList[HeroProType.Speed]) --速度
table.insert(allProVal, 8, proList[HeroProType.DamageBocusFactor]) --伤害加成系数(%
table.insert(allProVal, 9, proList[HeroProType.DamageReduceFactor]) --伤害减免系数(%
table.insert(allProVal, 10, proList[HeroProType.Hit]) --命中率(%
table.insert(allProVal, 11, proList[HeroProType.Dodge]) --闪避率(%
table.insert(allProVal, 12, proList[HeroProType.CritFactor]) --暴击率(%
table.insert(allProVal, 13, proList[HeroProType.CritDamageFactor]) --暴击伤害系数(%
table.insert(allProVal, 14, proList[HeroProType.AntiCritDamageFactor]) --抗暴率(%
table.insert(allProVal, 15, proList[HeroProType.TreatFacter]) --治疗加成系数(%
table.insert(allProVal, 16, proList[HeroProType.CureFacter]) --受到治疗系数(%
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
2020-11-13 17:07:32 +08:00
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.propertys = 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
2020-05-09 13:31:21 +08:00
-- 根据怪物组数据
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)
2020-05-09 13:31:21 +08:00
end
2020-05-09 13:31:21 +08:00
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
2020-05-09 13:31:21 +08:00
--获取单个英雄装备被动技能list
--function this.GetSingHeroAllEquipSkillListData(_heroId)
-- local allEquipSkillList = {}
-- local curHeroData = HeroManager.GetSingleHeroData(_heroId)
-- if curHeroData then
-- for i = 1, #curHeroData.equipIdList do
2020-07-06 20:35:39 +08:00
-- local curEquip = EquipManager.GetSingleEquipData(curHeroData.equipIdList[i])
2020-05-09 13:31:21 +08:00
-- 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,
2020-07-08 21:19:34 +08:00
BeforeBullet = combat.BeforeBullet,
SkillNumber = combat.SkillNumber,
SkillDuration = combat.SkillDuration,
2020-07-22 14:49:32 +08:00
BeforeOrientation = combat.BeforeOrientation,
2020-07-08 21:19:34 +08:00
Orientation = combat.Orientation,
2020-07-23 13:44:03 +08:00
HitOrientation = combat.HitOrientation,
2020-07-21 21:34:47 +08:00
BeforeEffectType = combat.BeforeEffectType ,
2020-07-08 21:19:34 +08:00
EffectType = combat.EffectType ,
HitEffectType = combat.HitEffectType,
BeforeOffset = combat.BeforeOffset,
HitOffset = combat.HitOffset,
2020-07-11 15:42:56 +08:00
SkillNameVoice = combat.SkillNameVoice,
2020-07-08 21:19:34 +08:00
2020-05-09 13:31:21 +08:00
}
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()
2020-07-15 16:35:51 +08:00
-- return false
return PrivilegeManager.GetPrivilegeOpenStatus(PRIVILEGE_TYPE.SkipFight)
2020-05-09 13:31:21 +08:00
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
2020-05-15 16:52:35 +08:00
function this.IsCanOperate()
return this.IsPlay ~= 0
end
2020-05-09 13:31:21 +08:00
-- 战斗加速控制
BATTLE_TIME_SCALE_ZERO = 0
BATTLE_TIME_SCALE_ONE= 1.1
BATTLE_TIME_SCALE_TWO = 2
this.TimeScale = 0
function this.InitTimeScale()
2020-05-25 19:16:23 +08:00
this.TimeScale = 0
2020-05-09 13:31:21 +08:00
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
2020-05-25 19:16:23 +08:00
PlayerPrefs.SetFloat("battleTimeScaleKey", this.TimeScale)
2020-05-09 13:31:21 +08:00
-- 刷新前端显示
Game.GlobalEvent:DispatchEvent(GameEvent.Battle.OnTimeScaleChanged)
-- 真正生效的敌方
Time.timeScale = TimeScale
-- 设置音效播放的速度
SoundManager.SetAudioSpeed(TimeScale)
2020-05-09 13:31:21 +08:00
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
2020-11-01 15:46:48 +08:00
if UIManager.IsOpen(UIName.GuideBattlePanel) then
return GuideBattlePanel.sortingOrder
end
return 0
2020-05-09 13:31:21 +08:00
end
-- 判断是否是战斗测试
function this.IsBattleTestPanel()
if UIManager.IsOpen(UIName.BattleTestPanel) then
return true
end
end
2020-06-18 20:39:29 +08:00
-- 获取战斗背景
function this.GetBattleBg(fightType)
2020-08-24 17:17:21 +08:00
local index = 1
2020-06-18 20:39:29 +08:00
if fightType == BATTLE_TYPE.STORY_FIGHT then
local curChapter = FightPointPassManager.GetCurChapterIndex()
2020-09-27 18:27:20 +08:00
index = math.floor((curChapter - 1) % 5 + 1)
elseif fightType == BATTLE_TYPE.BACK or fightType == BATTLE_TYPE.ARENA then
2020-08-24 17:17:21 +08:00
index = 1001
2020-06-19 21:44:27 +08:00
elseif fightType == BATTLE_TYPE.EXECUTE_FIGHT then
2020-08-24 17:17:21 +08:00
index = 1002
elseif fightType == BATTLE_TYPE.Xuanyuan then
index = 1003
elseif fightType == BATTLE_TYPE.DEATH_POS then
index = 1004
2020-06-18 20:39:29 +08:00
end
2020-08-24 18:20:54 +08:00
return "r_zhandou_changjing_"..tostring(index)
2020-06-18 20:39:29 +08:00
end
2020-05-09 13:31:21 +08:00
-- 引导战斗暂停控制
this.isGuidePause = false
function this.IsGuidePause()
return this.isGuidePause
end
function this.SetGuidePause(isPause)
this.isGuidePause = isPause
end
2020-11-01 15:46:48 +08:00
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)
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
2020-11-01 15:46:48 +08:00
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})
2020-11-01 15:46:48 +08:00
end
function this.RecycleAllDelayRes()
--立即回收延迟列表上的资源
for _, v in pairs(this._delayRecycleList) do
2020-11-01 15:46:48 +08:00
for i=1, #v do
Util.SetGray(v[i].go, false)
poolManager:UnLoadAsset(v[i].path, v[i].go, PoolManager.AssetType.GameObject)
2020-11-01 15:46:48 +08:00
end
end
this._delayRecycleList = {}
2020-11-01 15:46:48 +08:00
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[12391]}
end
end
--++++++++++++++++++++++++++++++++++++++++++
-- 通过接口获取战斗数据
2020-12-17 18:36:08 +08:00
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)
2020-12-17 18:36:08 +08:00
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)
2020-12-17 18:36:08 +08:00
if func then
func(fightData)
end
end, nil, nil, nil)
end
2021-01-06 16:12:54 +08:00
--新回放功能
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
2020-12-30 18:08:44 +08:00
if UIManager.GetOpenPanel(UIName.BattlePanel) then
UIManager.ClosePanel(UIName.BattlePanel)
end
2021-01-06 16:12:54 +08:00
UIManager.OpenPanel(UIName.BattlePanel, lastFightData, BATTLE_TYPE.BACK_BATTLE)
2020-12-30 18:08:44 +08:00
end
end
2020-12-17 18:36:08 +08:00
2020-06-23 18:36:24 +08:00
return this