Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local HeroInfoHelper = require("app.DataManager.HeroInfoHelper")
- local HeroModel = require("app.fighting.HeroModel")
- local FightLogic = {}
- FightLogic._ReduceDamageLimit = string.split(WDConfig.Common.getItem(113, "Content"), ',')
- FightLogic.showType = 0 --0 nothing 1 召唤英雄 2 升级英雄 3 强化装备
- FightLogic._statisticInfo = {}
- FightLogic._statisticPlaybackInfo = {}
- FightLogic._statisticResult = {}
- FightLogic._statisticHeros = {}
- FightLogic._statisticEnemys = {}
- --LLH添加多人战斗支持
- --------------------------------
- FightLogic.battleData=nil --战斗缓存数据
- --多人服务器战斗数据
- FightLogic.serverMulitePlayData = {} --玩家数据
- FightLogic.serverMuliteFightAllResult = false --最后总结果胜负
- --这一段数据多人与单人服务器战斗通用
- FightLogic.serverMuliteFightDataList = {} --战斗完成的物品
- FightLogic.serverMuliteFightResult = {} --单场结果的胜负
- FightLogic.serverMuliteFightMD5 = nil --MD5数据
- FightLogic.serverMuliteFightLen = nil --数据总长度
- FightLogic.serverMuliteFightPoint = nil --双方得分
- --好友boss,工会bosss,非通用数据
- FightLogic.serverEnemyId = nil
- ---讨伐战伤害统计
- FightLogic.worldBossHurtValue = 0
- -------服务端战斗
- FightLogic.serverFightJsonData = "" --服务器下发的字符串
- FightLogic.serverMuliteFightIndex = 0 --多人战斗进行到第几场
- FightLogic.startFightType = -1 --0单人,1回放,2多人
- FightLogic.backIndex = nil --回放下标
- FightLogic.muliteIndex = nil --多人里面的回放下标
- FightLogic.backSightId = nil --单人回放的id
- ------兼容分享或者其他的战斗
- FightLogic.backIndex1 = nil
- FightLogic.backIndex2 = nil
- --初始化服务器战斗数据
- function FightLogic.initServerFightData()
- FightLogic.serverMuliteFightDataList = {}
- FightLogic.serverMuliteFightResult = {}
- FightLogic.serverMulitePlayData = {}
- FightLogic.serverMuliteFightAllResult = false
- FightLogic.serverMuliteFightMD5 = nil
- FightLogic.serverMuliteFightLen = nil
- FightLogic.serverMuliteFightPoint = nil
- FightLogic.serverJsonData = ""
- FightLogic.serverMuliteFightIndex = 0
- FightLogic.serverFightJsonData = ""
- FightLogic.worldBossHurtValue = 0
- FightLogic.serverEnemyId = nil
- end
- --服务端多人战斗处理
- function FightLogic.fightServerMultiplayerCallBack(__battleData,_index)
- --单场数据设置
- FightLogic.startFightType = 2
- FightLogic.battleData = __battleData
- FightLogic._statisticInfo._enemyTeam = {} -- 防守方队形
- FightLogic._statisticInfo._enemyTeam.pet = __battleData.embattle[_index].petId
- FightLogic._statisticInfo._enemyTeam.petBaseData= __battleData.embattle[_index].petBaseData --宠物id
- FightLogic._statisticInfo._enemyTeam.heros = Utils:table_deepcopy( __battleData.embattle[_index].heroes ) --英雄列表
- FightLogic._statisticInfo._enemyTeam.playerInfo = Utils:table_deepcopy( __battleData.embattle[_index].player ) --防守方信息列表
- --攻击方
- FightLogic._statisticInfo._heroTeam = {} -- 攻击方队形
- FightLogic._statisticInfo._heroTeam.pet = __battleData.battle[_index].petId
- FightLogic._statisticInfo._heroTeam.petBaseData = __battleData.battle[_index].petBaseData --宠物id
- FightLogic._statisticInfo._heroTeam.heros = Utils:table_deepcopy(__battleData.battle[_index].heroes) --英雄列表
- FightLogic._statisticInfo._heroTeam.playerInfo = Utils:table_deepcopy( __battleData.battle[_index].player ) --攻击方信息列表
- --设置宠物数据
- if(FightLogic._statisticInfo._enemyTeam.pet~=0)then
- local __enamyPetData={id = FightLogic._statisticInfo._enemyTeam.pet,l = __battleData.embattle[_index].petLv }
- FightingServerDataConfig.setEnamyPetData(__enamyPetData)
- else
- FightingServerDataConfig.setNilEnamyPetData()
- end
- if(FightLogic._statisticInfo._heroTeam.pet~=0 )then
- local __heroPetData ={id = FightLogic._statisticInfo._heroTeam.pet,l = __battleData.battle[_index].petLv}
- FightingServerDataConfig.setHeroPetData(__heroPetData)
- else
- FightingServerDataConfig.setNilHeroPetData()
- end
- end
- --多人战斗响应按钮回调
- function FightLogic.fightMultiplayerCallBack(__battleData,__playback,_index,isMulte)
- if(globalManager._userMulitServer )then
- FightLogic.startFightType = 2
- end
- FightLogic.battleData = __battleData
- if sceneManager:isIdleScene() then
- local idleScene = sceneManager:getRunningScene()
- idleScene.bossGoblinTip:hideTip()
- if __battleData.attackType == globalConfig.BattleTag.HANG_BOSS then
- idleScene._fighting_Layer._battle_layer.btn_boss:setTouchEnabled(false)
- end
- end
- --战斗基本信息
- FightLogic._statisticInfo = {}
- FightLogic._statisticInfo._type = __battleData.attackType -- 战斗类型
- FightLogic._statisticInfo._beAttackId = __battleData.attackId -- 副本id
- FightLogic._statisticInfo._randseed = __battleData.randseed -- 随机种子
- FightLogic._statisticInfo._lineupindex = __battleData.idx -- 我的阵营索引
- FightLogic._statisticInfo._playback = __battleData.playback or false -- 回放模式
- --兼容原来的数据
- local index = 1
- if(_index)then
- index = _index
- end
- -- 即将进行的战斗的背景
- FightLogic._statisticInfo._bgspine = __battleData.embattle[index].bgspine
- FightLogic._statisticInfo._background = __battleData.embattle[index].background
- if not FightLogic._statisticInfo._background then
- FightLogic._statisticInfo._background = WDConfig.BattlePVPBg.getItem(math.random(WDConfig.BattlePVPBg._length),"Background")
- end
- --防守方
- FightLogic._statisticInfo._enemyTeam = {} -- 防守方队形
- FightLogic._statisticInfo._enemyTeam.circleId = __battleData.embattle[index].circleId --阵营光环
- FightLogic._statisticInfo._enemyTeam.pet = __battleData.embattle[index].petId
- FightLogic._statisticInfo._enemyTeam.petData = Utils:table_deepcopy( __battleData.embattle[index].petData ) --宠物数据
- FightLogic._statisticInfo._enemyTeam.petBaseData = __battleData.embattle[index].petBaseData --宠物id
- FightLogic._statisticInfo._enemyTeam.heros = Utils:table_deepcopy( __battleData.embattle[index].heroes ) --英雄列表
- FightLogic._statisticInfo._enemyTeam.playerInfo = Utils:table_deepcopy( __battleData.embattle[index].player ) --防守方信息列表
- --判断是否是多人
- if(FightLogic._statisticInfo._type ~= globalConfig.BattleTag.ARENA_CHAMPION)then
- index = __battleData.idx
- end
- --攻击方
- FightLogic._statisticInfo._heroTeam = {} -- 攻击方队形
- FightLogic._statisticInfo._heroTeam.circleId = __battleData.battle[index].circleId --阵营光环
- FightLogic._statisticInfo._heroTeam.pet = __battleData.battle[index].petId
- FightLogic._statisticInfo._heroTeam.petData = Utils:table_deepcopy( __battleData.battle[index].petData ) --宠物数据
- FightLogic._statisticInfo._heroTeam.petBaseData = __battleData.battle[index].petBaseData --宠物id
- FightLogic._statisticInfo._heroTeam.heros = Utils:table_deepcopy(__battleData.battle[index].heroes) --英雄列表
- FightLogic._statisticInfo._heroTeam.playerInfo = Utils:table_deepcopy( __battleData.battle[index].player ) --攻击方信息列表
- --talkingdata记录
- --开始loading
- if(isMulte)then
- sceneManager:GotoScene("LoadingScene")
- else
- sceneManager:PushScene("LoadingScene",{true})
- end
- end
- --单人服务器战斗回调
- function FightLogic.fightServerCallBack(__battleData,__playback, isSkip)
- isSkip = isSkip or false
- FightLogic.battleData = __battleData
- FightLogic.startFightType = 0
- if sceneManager:isIdleScene() then
- local idleScene = sceneManager:getRunningScene()
- idleScene.bossGoblinTip:hideTip()
- if __battleData.attackType == globalConfig.BattleTag.HANG_BOSS then
- idleScene._fighting_Layer._battle_layer:hideWidgetWithStatus(2,true)
- end
- end
- --战斗基本信息
- FightLogic._statisticInfo = {}
- FightLogic._statisticInfo._type = __battleData.attackType -- 战斗类型
- FightLogic._statisticInfo._beAttackId = __battleData.attackId -- 副本id
- FightLogic._statisticInfo._randseed = __battleData.randseed -- 随机种子
- FightLogic._statisticInfo._lineupindex = __battleData.idx -- 我的阵营索引
- FightLogic._statisticInfo._playback = __battleData.playback or false -- 回放模式
- -- 即将进行的战斗的背景
- FightLogic._statisticInfo._bgspine = __battleData.embattle[1].bgspine
- FightLogic._statisticInfo._background = __battleData.embattle[1].background
- if not FightLogic._statisticInfo._background then
- FightLogic._statisticInfo._background = WDConfig.BattlePVPBg.getItem(math.random(WDConfig.BattlePVPBg._length),"Background")
- end
- --战斗数据双方的数据
- FightLogic._statisticInfo._enemyTeam = {} -- 防守方队形
- FightLogic._statisticInfo._enemyTeam.pet = __battleData.embattle[1].petId
- FightLogic._statisticInfo._bgspine = __battleData.embattle[1].bgspine
- FightLogic._statisticInfo._enemyTeam.petBaseData= Utils:table_deepcopy( __battleData.embattle[1].petBaseData )
- FightLogic._statisticInfo._enemyTeam.heros = Utils:table_deepcopy( __battleData.embattle[1].heroes )
- FightLogic._statisticInfo._enemyTeam.playerInfo = Utils:table_deepcopy( __battleData.embattle[1].player ) --防守方信息列表
- --攻击方
- FightLogic._statisticInfo._heroTeam = {} -- 攻击方队形
- FightLogic._statisticInfo._heroTeam.pet = __battleData.battle[__battleData.idx].petId
- FightLogic._statisticInfo._heroTeam.petBaseData = Utils:table_deepcopy(__battleData.battle[__battleData.idx].petBaseData )
- FightLogic._statisticInfo._heroTeam.heros = Utils:table_deepcopy(__battleData.battle[__battleData.idx].heroes) --英雄列表
- FightLogic._statisticInfo._heroTeam.playerInfo = Utils:table_deepcopy( __battleData.battle[__battleData.idx].player )--攻击方信息列表
- if(FightLogic._statisticInfo._enemyTeam.pet~=0)then
- local __enamyPetData={id = FightLogic._statisticInfo._enemyTeam.pet,l = __battleData.embattle[1].petLv }
- FightingServerDataConfig.setEnamyPetData(__enamyPetData)
- end
- if(FightLogic._statisticInfo._heroTeam.pet~=0 )then
- local __heroPetData ={id = FightLogic._statisticInfo._heroTeam.pet,l = __battleData.battle[__battleData.idx].petLv }
- FightingServerDataConfig.setHeroPetData(__heroPetData)
- end
- --talkingdata记录
- if __battleData.attackType == globalConfig.BattleTag.HANG_BOSS then -- 挂机战斗boss
- nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
- elseif __battleData.attackType == globalConfig.BattleTag.ACTIVITY_MAP then -- 活动副本
- nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
- elseif __battleData.attackType == globalConfig.BattleTag.PASS_TOWER then -- 地下秘境
- Utils:sendTDEvent("event_tower_"..__battleData.attackId) --talkingdata
- nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
- elseif __battleData.attackType == globalConfig.BattleTag.PASS_TOWER then -- 星之试炼
- nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
- elseif __battleData.attackType == globalConfig.BattleTag.GUILD_BOSS then -- 公会boss
- Utils:sendTDEvent("event_guild_boss_battle") --talkingdata
- elseif __battleData.attackType == globalConfig.BattleTag.FREIND_BOSS then -- 好友boss
- elseif __battleData.attackType == globalConfig.BattleTag.GUILD_MILL then -- 矿脉掠夺(__carbonId 被掠夺工会id)
- elseif __battleData.attackType == globalConfig.BattleTag.GUILD_MILL_REVENGE then -- 矿脉复仇(__carbonId 矿脉复仇界面传递过来的数据)
- elseif __battleData.attackType == globalConfig.BattleTag.TRIALS_BRAVE then -- 远征(__carbonId 试炼界面传递过来的数据)
- Utils:sendTDEvent("event_expedition_fight") --talkingdata
- nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
- elseif __battleData.attackType == globalConfig.BattleTag.ARENA_NORMAL then -- 单人竞技
- Utils:sendTDEvent("event_arena_battle") --talkingdata
- elseif __battleData.attackType == globalConfig.BattleTag.ARENA_CHAMPION then -- 军团之争(多人竞技)
- elseif __battleData.attackType == globalConfig.BattleTag.FREIND_BOSS then -- 好友boss
- elseif __battleData.attackType == globalConfig.BattleTag.FREIND_PK then -- 好友PK
- end
- --开始loading
- if isSkip then
- if __battleData.attackType == globalConfig.BattleTag.FREIND_BOSS then
- require("app.layers.friend.FriendFightSettlement"):create()
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnCloseCallBack(function()
- Request:sendFBossEnterRequest()
- end)
- end
- else
- sceneManager:PushScene("LoadingScene")
- end
- end
- --开始战斗
- --__battleType 战斗类型
- --__carbonId PVE副本id
- function FightLogic.startPVEFight(__battleType,__carbonId, isSkip)
- if __battleType == globalConfig.BattleTag.HANG_BOSS then --挂机战斗boss
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.HANG_BOSS, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.ACTIVITY_MAP then --活动副本
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.ACTIVITY_MAP, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.PASS_TOWER then --地下秘境
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.PASS_TOWER, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.DUNGEON then --星之试炼
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.DUNGEON, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.GUILD_BOSS then --公会boss
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.GUILD_BOSS, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.FREIND_BOSS then --好友boss
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.FREIND_BOSS, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.GUILD_MILL then --公会矿脉掠夺(__carbonId 被掠夺工会id)
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.GUILD_MILL, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.GUILD_MILL_REVENGE then --公会矿脉复仇(__carbonId 公会矿脉复仇界面传递过来的数据)
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.GUILD_MILL_REVENGE, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.TRIALS_BRAVE then --远征(__carbonId 试炼界面传递过来的数据)
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.TRIALS_BRAVE, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.ARENA_NORMAL then --勇士联赛
- --单人战斗切换
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.ARENA_NORMAL, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.ARENA_CHAMPION then -- 冠军竞技
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.ARENA_CHAMPION, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightMultiplayerCallBack)
- --:setOnClickAttackCallback(function()
- -- print("战斗结束...........")
- --end)
- elseif __battleType == globalConfig.BattleTag.ARENA_TEAM then -- 组队竞技
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.ARENA_TEAM, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightMultiplayerCallBack)
- --:setOnClickAttackCallback(function()
- -- print("战斗结束...........")
- --end)
- elseif __battleType == globalConfig.BattleTag.FREIND_BOSS then --好友boss
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.FREIND_BOSS, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.FREIND_PK then --好友PK
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.FREIND_PK, __carbonId)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightServerCallBack)
- elseif __battleType == globalConfig.BattleTag.WORLD_BOSS then -- 讨伐战
- require("app.layers.formatModule.FormatInfo")
- :create(globalConfig.BattleTag.WORLD_BOSS, __carbonId, isSkip)
- :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
- :setOnClickAttackCallback(FightLogic.fightMultiplayerCallBack)
- end
- end
- --服务端战斗回放开始
- function FightLogic.startServerPlay(backData)
- if(FightLogic.battleData~=nil and FightLogic.battleData.attackType ~=nil)then
- FightLogic._statisticInfo._type = FightLogic.battleData.attackType
- else
- FightLogic._statisticInfo._type = globalConfig.BattleTag.ARENA_CHAMPION
- end
- --地下秘境特殊处理
- if(FightLogic._statisticInfo._type == globalConfig.BattleTag.PASS_TOWER)then
- --------------------------------------------
- local rewards = {}
- local _carbonId = WDConfig.CarbonTower.getItem(backData.defineid,"CarbonId")
- local _data = WDConfig.Carbon.getData(_carbonId)
- for i=1,4 do
- if _data["ItemID_"..i] ~= 0 then
- local _item = {}
- _item.key = _data["ItemID_"..i]
- _item.value = _data["ItemNum_"..i]
- table.insert(rewards, _item)
- end
- end
- ------------------------------------------------
- FightLogic.serverMuliteFightDataList = rewards
- end
- FightLogic._statisticInfo._bgspine = nil
- FightLogic._statisticInfo._enemyTeam = {} -- 防守方队形
- FightLogic._statisticInfo._background = nil
- FightLogic._statisticInfo._enemyTeam.pet = backData.dePetId
- FightLogic._statisticInfo._enemyTeam.petBaseData= backData.dePet
- --FightLogic._statisticInfo._enemyTeam.heros = Utils:table_deepcopy( backData.embattle[1].heroes )
- if( backData._enemyTeam~= nil)then
- FightLogic._statisticInfo._enemyTeam.playerInfo = backData._enemyTeam.playerInfo --防守方信息列表
- if(FightLogic._statisticInfo._enemyTeam.pet~=0)then
- local lv = 1
- for i,v in pairs(FightLogic._statisticInfo._enemyTeam.petBaseData) do
- if(v.id == FightLogic._statisticInfo._enemyTeam.pet)then
- lv = v.lv
- break
- end
- end
- local __enamyPetData={id = FightLogic._statisticInfo._enemyTeam.pet,l = lv}
- FightingServerDataConfig.setEnamyPetData(__enamyPetData)
- end
- end
- --攻击方
- FightLogic._statisticInfo._heroTeam = {} -- 攻击方队形
- FightLogic._statisticInfo._heroTeam.pet = backData.atPetId
- FightLogic._statisticInfo._heroTeam.petBaseData = backData.atPet
- --FightLogic._statisticInfo._heroTeam.heros = Utils:table_deepcopy(backData.battle[1].heroes)
- if(backData._heroTeam)then
- FightLogic._statisticInfo._heroTeam.playerInfo = backData._heroTeam.playerInfo --攻击方信息列表
- if(FightLogic._statisticInfo._heroTeam.pet~=0 )then
- local lv = 1
- for i,v in pairs(FightLogic._statisticInfo._heroTeam.petBaseData) do
- if(v.id == FightLogic._statisticInfo._heroTeam.pet)then
- lv = v.lv
- break
- end
- end
- local __heroPetData ={id = FightLogic._statisticInfo._heroTeam.pet,l = lv}
- FightingServerDataConfig.setHeroPetData(__heroPetData)
- end
- end
- end
- --服务端回放数据设置
- function FightLogic.setBackPlayDatas(_attackType,_playData,_backSightId,_backIndex1,_backIndex2,_backIndex,_muliteIndex,_defineid,_otherData)
- --先隐藏哥布林精英怪提示
- if sceneManager:isIdleScene() then
- local idleScene = sceneManager:getRunningScene()
- idleScene.bossGoblinTip:hideTip()
- end
- FightLogic.startFightType = 1
- FightLogic.battleData={}
- FightLogic.battleData.attackType = _attackType
- FightLogic.battleData._heroTeam={}
- FightLogic.battleData._enemyTeam={}
- --设置头像数据
- FightLogic.battleData._heroTeam.playerInfo = {iconId = _playData.ahead ,lv = _playData.alevel,name = _playData.aname,frameId = _playData.aframe}
- FightLogic.battleData._enemyTeam.playerInfo = {iconId = _playData.dhead,lv = _playData.dlevel,name = _playData.dname,frameId = _playData.dframe}
- FightLogic.backSightId = _backSightId --单场回放ID
- FightLogic.backIndex1 = _backIndex1 --军团对决数据index
- FightLogic.backIndex2 = _backIndex2 --军团对决数据index
- FightLogic.backIndex = _backIndex --多人回放支持
- FightLogic.muliteIndex = _muliteIndex --多人回放支持
- FightLogic.battleData.defineid = _defineid --地下秘境
- FightLogic.battleData.attackData = _otherData
- sceneManager:PushScene("LoadingScene",{true})
- end
- --创建一个英雄
- --__idleHeroControler : 挂机控制类
- --__index : 创建怪物的位置
- --__panel_models : 把创建的英雄添加至__panel_models
- function FightLogic.createHero( __idleHeroControler, __index, __panel_models)
- local hero = __idleHeroControler:createHero()
- return hero
- end
- --创建一个怪物
- --__statisticEnemys : 非挂机统计怪物信息列表
- --__index : 创建怪物的位置
- --__panel_models : 把创建的英雄添加至__panel_models
- function FightLogic.createEnemy( __statisticEnemys, __index, __panel_models)
- local enemy = nil
- local mosterData = globalManager._idleMap.moster[__index]
- if mosterData and mosterData.mosterId ~= 0 then
- enemy = HeroModel.new(mosterData.mosterId)
- enemy:initData(true, 0)
- __panel_models:addChild(enemy)
- enemy._battleId = 1
- enemy._prepare = true
- enemy.mosterData = mosterData
- end
- return enemy
- end
- --加載精英怪
- function FightLogic.loadSuperMoster()
- if globalManager._CommonData._boosMonData.isExist and globalManager._playerData.killSuperMosterCnt then
- globalManager._CommonData._boosMonData.isFight = true
- local idleScene = sceneManager:getRunningScene()
- idleScene.bossGoblinTip:hideTip()
- end
- if globalManager._CommonData._boosMonData.isFight then
- globalManager._idleMap.moster = {}
- if true then
- local mosterData = {}
- mosterData.mosterId = 0
- table.insert(globalManager._idleMap.moster, mosterData)
- end
- if true then
- local mosterData = {}
- --隨機出現精英怪
- local randomIndex = 3
- local HardRate_1 = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardRate_1")
- local HardRate_2 = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardRate_2")
- local HardRate_3 = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardRate_3")
- local randomNum = math.random(HardRate_1+HardRate_2+HardRate_3)
- if randomNum <= HardRate_1 then
- randomIndex = 1
- elseif randomNum <= HardRate_1+HardRate_2 then
- randomIndex = 2
- end
- mosterData.mosterId = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"MonHard_"..randomIndex)
- local dropitem = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardDrop_"..randomIndex)
- local dropcount = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardDropNum_"..randomIndex)
- if dropitem == globalConfig.generalItem.gold then
- mosterData.gold = dropcount
- mosterData.exp = 0
- mosterData.item = {}
- elseif dropitem == globalConfig.generalItem.gold then
- mosterData.gold = 0
- mosterData.exp = dropcount
- mosterData.item = {}
- else
- mosterData.item = {}
- local d = {}
- d.key = dropitem
- d.value = dropcount
- end
- table.insert(globalManager._idleMap.moster, mosterData)
- -- print("loadSuperMoster = ",randomNum,randomIndex)
- end
- -- print("loadSuperMoster = ",json.encode(globalManager._idleMap.moster))
- end
- end
- --------------------------------------------------------------------
- --------------------------------------------------------------------
- --------------------------------------------------------------------
- --获取一个未攻击过model
- function FightLogic.getFightModel(__modelList)
- --排序(速度 > 攻守 > 站位)
- local function modelsort(a,b)
- if a._att_property.Speed ~= b._att_property.Speed then
- return a._att_property.Speed > b._att_property.Speed
- else
- if a._sortNum ~= b._sortNum then
- return a._sortNum < b._sortNum
- else
- return a.static_index < b.static_index
- end
- end
- end
- table.sort(__modelList,modelsort)
- for i,_model in ipairs(__modelList) do
- if not _model._isAttacked and _model.activate then
- _model._isAttacked = true --设置为已经攻击过了
- return _model
- end
- end
- return nil
- end
- --获取技能或者buff的目标 结果可能有多个(根据Targ表筛选)
- function FightLogic.getTargetList(__modelList, __model, _targData, __notActivateOk)
- if not __notActivateOk then __notActivateOk = false end
- local _targetList = {}
- local _filtrate = true
- if not __model then
- _filtrate = false
- end
- --把所有model塞进去
- if _filtrate then
- for i,_model in ipairs(__modelList) do
- -- print( " getTargetList ----------- aa " .. _model._enemyName .. _model._heroId ..", index ".._model.static_index.."-".._model._uid,_model.activate)
- if (_model.activate or __notActivateOk ) then
- table.insert(_targetList, _model)
- end
- end
- end
- --根据目标类型筛选 (1.自身 2.受击方(且被命中) 3.攻击方 4.敌方 5.友方 6.受击方(且闪避) 9.全部)
- if _filtrate then
- if _targData.Enemy == 1 then
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if _target ~= __model then
- table.remove(_targetList,i)
- end
- end
- elseif _targData.Enemy == 2 then
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if not (_target._isDefender and _target._isBeit) then
- table.remove(_targetList,i)
- end
- end
- elseif _targData.Enemy == 3 then
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if not _target._isAttacker then
- table.remove(_targetList,i)
- end
- end
- elseif _targData.Enemy == 4 then
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if _target._isEnemy == __model._isEnemy then
- table.remove(_targetList,i)
- end
- end
- elseif _targData.Enemy == 5 then
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if _target._isEnemy ~= __model._isEnemy then
- table.remove(_targetList,i)
- end
- end
- elseif _targData.Enemy == 6 then
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if not (_target._isDefender and _target._isHaveDodge) then
- table.remove(_targetList,i)
- end
- end
- elseif _targData.Enemy == 7 then
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if not (_target._isBaoJi) then
- table.remove(_targetList,i)
- end
- end
- elseif _targData.Enemy == 9 then
- --do nothing
- end
- end
- --根据目标类型筛选 (0.无效 1.顺位 2.前排 3.后排 9.全部)
- if _filtrate then
- if _targData.Type == 0 then
- _filtrate = false
- elseif _targData.Type == 1 then
- --排序(站位)
- local function modelsort(a,b)
- return a.static_index < b.static_index
- end
- table.sort(_targetList,modelsort)
- for i=#_targetList,2,-1 do
- local _target = _targetList[i]
- table.remove(_targetList,i)
- end
- elseif _targData.Type == 2 then
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if _target.static_col ~= 1 then
- table.remove(_targetList,i)
- end
- end
- elseif _targData.Type == 3 then
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if _target.static_col ~= 2 then
- table.remove(_targetList,i)
- end
- end
- elseif _targData.Type == 9 then
- --do nothing
- end
- end
- --根据目标职业筛选 (0.无效 1.战士 2.刺客 3.游侠 4.牧师 5.法师 9.全部)
- if _filtrate then
- if _targData.Career == 0 then
- _filtrate = false
- elseif _targData.Career == 9 then
- --do nothing
- else
- for i=#_targetList,1,-1 do
- local _target = _targetList[i]
- if _targData.Career ~= _target._att_property._career then
- table.remove(_targetList,i)
- end
- end
- end
- end
- --根据目标属性条件筛选 (0.无效 6.能量 7.当前生命 9.攻击 10.护甲 11.速度)
- if _filtrate then
- if _targData.AtriId == 0 then
- --do nothing
- else
- local _sort = nil
- if _targData.AtriId == 6 then
- local function modelsort(a,b) --排序(能量 > 站位)
- if a._energyNum ~= b._energyNum then
- return a._energyNum < b._energyNum
- else
- return a.static_index < b.static_index
- end
- end
- _sort = modelsort
- elseif _targData.AtriId == 7 then
- local function modelsort(a,b) --排序(生命 > 站位)
- if (a._hpNum/a._att_property.MaxHp) ~= (b._hpNum/b._att_property.MaxHp) then
- return (a._hpNum/a._att_property.MaxHp) < (b._hpNum/b._att_property.MaxHp)
- else
- return a.static_index < b.static_index
- end
- end
- _sort = modelsort
- elseif _targData.AtriId == 9 then
- local function modelsort(a,b) --排序(攻击 > 站位)
- if a._att_property.Attack ~= b._att_property.Attack then
- return a._att_property.Attack < b._att_property.Attack
- else
- return a.static_index < b.static_index
- end
- end
- _sort = modelsort
- elseif _targData.AtriId == 10 then
- local function modelsort(a,b) --排序(护甲 > 站位)
- if a._att_property.Armor ~= b._att_property.Armor then
- return a._att_property.Armor < b._att_property.Armor
- else
- return a.static_index < b.static_index
- end
- end
- _sort = modelsort
- elseif _targData.AtriId == 11 then
- local function modelsort(a,b) --排序(速度 > 站位)
- if a._att_property.Speed ~= b._att_property.Speed then
- return a._att_property.Speed < b._att_property.Speed
- else
- return a.static_index < b.static_index
- end
- end
- _sort = modelsort
- end
- table.sort(_targetList,_sort)
- for i=#_targetList,2,-1 do
- local _target = _targetList[i]
- table.remove(_targetList,i)
- end
- end
- end
- --根据目标数量类型筛选 (0.无效 1.随机 2.全部)
- if _filtrate then
- if _targData.NumType == 0 then
- _filtrate = false
- elseif _targData.NumType == 1 then
- --do nothing
- elseif _targData.NumType == 2 then
- --do nothing
- end
- end
- --根据目标数量筛选 (0.无效 n.数量)
- if _filtrate then
- if _targData.NumType ~= 0 and _targData.Num ~= 0 then
- --如果需要选取的数量大于剩余的数量 则全部选取
- if #_targetList <= _targData.Num then
- _filtrate = false
- else
- local diffNum = #_targetList - _targData.Num
- for i=1,diffNum do
- FightLogic.debugLog("check->".."call FightingRandom a")
- local randRemoveNum = FightLogic.FightingRandom(#_targetList+1)
- table.remove(_targetList,randRemoveNum)
- end
- end
- end
- end
- return _targetList
- end
- --判断一个buff的执行者和一个model的关系
- --__executorProperty : buff的执行者属性
- function FightLogic.getBuffTargWithModel( __executorProperty, __model )
- if __executorProperty._static_index == __model.static_index and __executorProperty._isEnemy == __model._isEnemy and __executorProperty._battleId == __model._battleId then
- return 1 --自身
- elseif __executorProperty._isEnemy ~= __model._isEnemy then
- return 2 --任意敌方
- elseif __executorProperty._isEnemy == __model._isEnemy then
- return 3 --任意友方不包括自己
- end
- return 0
- end
- --判断一个buff是否可以被触发
- -- __type : 触发类型(时机)
- -- __targ : 触发目标
- -- __targType : 触发目标类型
- -- __buff : __buff
- function FightLogic.isBuffCanBeTrig(__type, __targ, __targType, __buff)
- local _buffTrigData = WDConfig.BuffTrig.getData(__buff.TrigId)
- -- print(" isBuffCanBeTrig " .. __buff.TrigId)
- -- print(" isBuffCanBeTrig " .. json.encode(_buffTrigData))
- --筛选触发类型
- if _buffTrigData.Type ~= __type then
- -- print(" isBuffCanBeTrig false 1 ")
- return false
- end
- --1.面板触发/3.开始战斗触发 要特殊处理
- if __type ~= 1 and __type ~= 3 then
- --筛选触发目标类型
- if _buffTrigData.TargType ~= __targType and _buffTrigData.TargType ~= 0 then
- -- print(" isBuffCanBeTrig false 2 ")
- return false
- end
- if(_buffTrigData.Targ == 4 and FightLogic.getBuffTargWithModel(__buff.ExecutorProperty, __targ) ~= 1)then
- return true
- end
- --筛选触发目标
- if _buffTrigData.Targ ~= FightLogic.getBuffTargWithModel(__buff.ExecutorProperty, __targ) then
- -- print(" isBuffCanBeTrig false 3 ")
- return false
- end
- end
- --普攻或者技能时,如果是承受效果方 __targ必须处于命中状态
- if (__type == 4 or __type == 5 or __type == 6) and _buffTrigData.TargType == 2 then
- if not __targ._isBeit then
- return false
- end
- end
- --筛选位置条件
- if _buffTrigData.Pos ~= 0 and
- _buffTrigData.Pos ~= 9 and
- _buffTrigData.Pos ~= __targ.static_col then
- -- print(" isBuffCanBeTrig false 4 ")
- return false
- end
- --筛选属性条件(0/99说明不需要检测属性)
- if _buffTrigData.AtriId == 0 or _buffTrigData.AtriId == 99 then
- -- print(" isBuffCanBeTrig true 1 ")
- return true
- end
- --筛选属性条件(能量低于指定值,ok)
- if _buffTrigData.AtriId == 6 and __targ._energyNum <= _buffTrigData.AtriValue then
- -- print(" isBuffCanBeTrig true 2 ")
- return true
- end
- --筛选属性条件(生命低于指定值,ok)
- if _buffTrigData.AtriId == 7 and __targ._hpNum <= _buffTrigData.AtriValue * __targ._att_property.MaxHp then
- -- print(" isBuffCanBeTrig true 3 ")
- return true
- end
- -- print(" isBuffCanBeTrig false 5 ")
- return false
- end
- --获取一个目标可以被触发的buff
- -- __type : 触发类型(时机)
- -- __targ : 触发目标
- -- __targType : 触发目标类型
- -- __allBuffs : 需要检测的所有buff
- -- __retBuffs : 符合条件的所有buff
- function FightLogic.getTargAllCanBeTrigBuff(__type, __targ, __targType, __allBuffs, __retBuffs, deathNum)
- for i=#__allBuffs,1,-1 do
- local _buff = __allBuffs[i]
- -- print(" getTargAllCanBeTrigBuff __type = " .. __type..", __targType = "..__targType..", _buff.ExecutorProperty._static_index = ".._buff.ExecutorProperty._static_index..", _buff.ExecutorProperty._isEnemy = ",_buff.ExecutorProperty._isEnemy)
- if FightLogic.isBuffCanBeTrig(__type, __targ, __targType, _buff) then
- if _buff.TrigId == 1524700 then
- deathNum = deathNum or 1
- for i=1, deathNum do
- table.insert(__retBuffs, _buff)
- end
- table.remove(__allBuffs, i)
- else
- table.insert(__retBuffs, _buff)
- table.remove(__allBuffs, i)
- end
- end
- end
- end
- --获取所有英雄身上所有可以被触发的buff(触发类型(时机))
- -- __type : 触发类型(时机)
- -- __allBuffs : 需要检测的所有buff
- -- __retBuffs : 符合条件的所有buff
- -- __defenseDefault : 默认防守方
- function FightLogic.getAllCanBeTrigBuff(__type, __allBuffs, __retBuffs, __modelList, __defenseDefault, deathNum)
- for i,_model in ipairs(__modelList) do
- if __defenseDefault then
- FightLogic.getTargAllCanBeTrigBuff(__type,_model,2,__allBuffs,__retBuffs, deathNum)
- else
- if _model._isAttacker then
- -- print(" " .. _model._enemyName, _model._heroId, "index = ".._model.static_index, "_isAttacker"..", _isEnemy = ",_model._isEnemy,", static_col = ".._model.static_col)
- FightLogic.getTargAllCanBeTrigBuff(__type,_model,1,__allBuffs,__retBuffs)
- elseif _model._isDefender then
- -- print(" " .. _model._enemyName, _model._heroId, "index = ".._model.static_index, "_isDefender"..", _isEnemy = ",_model._isEnemy,", static_col = ".._model.static_col)
- FightLogic.getTargAllCanBeTrigBuff(__type,_model,2,__allBuffs,__retBuffs)
- end
- end
- end
- return _retBuffs
- end
- --检测所有 model 是否死亡(生命值 <= 0 视为死亡)
- function FightLogic.checkAllModelDeath(__modelList)
- for i,_model in ipairs(__modelList) do
- if _model.activate then
- if _model._hpNum <= 0 then
- _model:markedDeath()
- end
- end
- end
- end
- --检测所有 model 生命值 <= 0 立刻执行死亡方法
- function FightLogic.checkAllModelRealDeath(__modelList)
- for i,_model in ipairs(__modelList) do
- FightLogic.debugLog(" ------ checkAllModelRealDeath " .. _model._enemyName.._model._heroId.." index = ".._model.static_index.." ".._model._energyNum.." ".._model._energyMax.." ".._model._hpNum)
- -- if _model.activate then
- if _model._hpNum <= 0 then
- if _model.activate then
- _model.activate = false
- end
- _model:runDeath()
- end
- -- end
- end
- end
- --获取所有英雄身上所有buff
- function FightLogic.getAllModelBuff(__modelList)
- local _allBuffs = {}
- for i,_model in ipairs(__modelList) do
- for i,_buff in ipairs(_model._giveBuffList) do
- if _model.activate then
- table.insert(_allBuffs, _buff)
- end
- end
- end
- return _allBuffs
- end
- --获取一个buff的执行者(发出buff的那个model)
- --__executorProperty : buff的执行者属性
- --__notActivateOk : true 表示可以筛选activate=false的model
- function FightLogic.getBuffExecutor(__modelList, __executorProperty,__notActivateOk)
- if not __notActivateOk then __notActivateOk = false end
- -- print(" getBuffExecutor : "..__executorProperty._static_index,__executorProperty._isEnemy,__executorProperty._battleId,__notActivateOk)
- for i,_model in ipairs(__modelList) do
- -- print(" getBuffExecutor : ".._model.static_index,_model._isEnemy,_model._battleId,_model.activate)
- if (_model.activate or __notActivateOk) and __executorProperty._static_index == _model.static_index and __executorProperty._isEnemy == _model._isEnemy and __executorProperty._battleId == _model._battleId then
- -- print(" ret ")
- return _model
- end
- end
- return nil
- end
- --buff是否命中
- function FightLogic.isBuffHit(__buff, __buffTarget)
- local _hitRate = FightLogic.getBuffHitRate(__buff, __buffTarget)
- -- --print("isBuffHit _hitRate is ", _hitRate)
- if _hitRate >= 1 then
- return true
- elseif _hitRate <= 0 then
- return false
- end
- FightLogic.debugLog("call FightingRandom c")
- return FightLogic.FightingRandom() < _hitRate
- end
- --添加buff到model
- -- __getbuffs 需要添加的buff
- -- __attackTargets 当前被攻击者(不需要了)
- -- __notActivateOk 是否添加到not activate的model
- function FightLogic.addBuffToModels(__modelList, __getbuffs, __attackTargets, __notActivateOk)
- --添加buff到英雄
- for i,_buff in ipairs(__getbuffs) do
- -- print("_buff ", json.encode(_buff))
- -- print("TargetId ", json.encode(_buff.TargetId))
- local _targetData = Utils:table_deepcopy(WDConfig.Targ.getData(_buff.TargetId))
- local _buffExecutor = FightLogic.getBuffExecutor(__modelList, _buff.ExecutorProperty, __notActivateOk)
- local _buffTargetList = FightLogic.getTargetList(__modelList, _buffExecutor, _targetData, __notActivateOk)
- if #_buffTargetList == 0 then
- if _targetData.Type == 2 then
- _targetData.Type = 3
- elseif _targetData.Type == 3 then
- _targetData.Type = 2
- end
- _buffTargetList = FightLogic.getTargetList(__modelList, _buffExecutor, _targetData, __notActivateOk)
- end
- -- print(" ".._buff.TrigId.." "..json.encode(_targetData))
- -- print(" "..#_buffTargetList)
- for j,_buffTarget in ipairs(_buffTargetList) do
- -- print(" addBuffToModels check ".._buffTarget._enemyName, _buffTarget._heroId, "index = ".._buffTarget.static_index)
- --计算buff是否命中
- local _buffEffData = WDConfig.BuffEff.getData(_buff.EffectId)
- local _condiData = WDConfig.BuffCondi.getData(_buff.CondiId)
- if FightLogic.isBuffHit(_buff, _buffTarget) then
- --添加至英雄的buff预备执行列表
- local _prepareBuff = {}
- _prepareBuff.Value = _buff.Value --效果值
- _prepareBuff.IsNew = true --是否是新加入的
- _prepareBuff.aniType = false --动画是否已经执行
- _prepareBuff.ExecutorProperty = Utils:table_deepcopy(_buff.ExecutorProperty) --执行者属性
- _prepareBuff.BuffId = _buff.TrigId.."-".._buff.TargetId.."-".._buff.EffectId.."-".._buff.CondiId .."-".._buff.Value --用于区分buff 检测叠加 重复等
- _prepareBuff.EffType = _buffEffData.EffType
- _prepareBuff.EffAtriId = _buffEffData.EffAtriId
- _prepareBuff.EffStatId = _buffEffData.EffStatId
- _prepareBuff.Icon = _buffEffData.Icon
- _prepareBuff.HitSpec = _buffEffData.HitSpec
- _prepareBuff.EndSpec = _buffEffData.EndSpec
- _prepareBuff.LastSpec = _buffEffData.LastSpec
- _prepareBuff.Priority = _buffEffData.Priority
- _prepareBuff.StealStart = _buffEffData.StealStart
- _prepareBuff.StealFly = _buffEffData.StealFly
- _prepareBuff.StealEnd = _buffEffData.StealEnd
- _prepareBuff.EffSignId = _buffEffData.EffSignId
- _prepareBuff.CanSuperPos = _condiData.CanSuperPos
- _prepareBuff.CanRetrig = _condiData.CanRetrig
- _prepareBuff.CanUseOnline = _condiData.CanUseOnline
- _prepareBuff.EndBout = _condiData.EndType == 1 and _condiData.EndValue or 99999
- _prepareBuff.Global = false --全局buffer,一般用于被动,或者永久存在的buffer
- _buffTarget:addBuff(_prepareBuff)
- else
- -- BoShen 2019-3-20 11:18:45 不可重复触发的buff特殊处理
- if _condiData.CanRetrig == 2 then
- --添加至英雄的buff预备执行列表
- local _prepareBuff = {}
- _prepareBuff.Value = _buff.Value --效果值
- _prepareBuff.IsNew = true --是否是新加入的
- _prepareBuff.aniType = false --动画是否已经执行
- _prepareBuff.ExecutorProperty = Utils:table_deepcopy(_buff.ExecutorProperty) --执行者属性
- _prepareBuff.BuffId = _buff.TrigId.."-".._buff.TargetId.."-".._buff.EffectId.."-".._buff.CondiId .."-".._buff.Value --用于区分buff 检测叠加 重复等
- _prepareBuff.EffType = _buffEffData.EffType
- _prepareBuff.EffAtriId = _buffEffData.EffAtriId
- _prepareBuff.EffStatId = _buffEffData.EffStatId
- _prepareBuff.Icon = _buffEffData.Icon
- _prepareBuff.HitSpec = _buffEffData.HitSpec
- _prepareBuff.EndSpec = _buffEffData.EndSpec
- _prepareBuff.LastSpec = _buffEffData.LastSpec
- _prepareBuff.Priority = _buffEffData.Priority
- _prepareBuff.StealStart = _buffEffData.StealStart
- _prepareBuff.StealFly = _buffEffData.StealFly
- _prepareBuff.StealEnd = _buffEffData.StealEnd
- _prepareBuff.EffSignId = _buffEffData.EffSignId
- _prepareBuff.CanSuperPos = _condiData.CanSuperPos
- _prepareBuff.CanRetrig = _condiData.CanRetrig
- _prepareBuff.CanUseOnline = _condiData.CanUseOnline
- _prepareBuff.EndBout = _condiData.EndType == 1 and _condiData.EndValue or 99999
- _prepareBuff.Global = false --全局buffer,一般用于被动,或者永久存在的buffer
- _buffTarget:addBuffByMissHandle(_prepareBuff)
- end
- end
- end
- end
- end
- --遍历所有model身上的buff,根据条件执行
- --__isNew 是否只执行新加入的buff
- --__runLimit -1 只执行异常状态(5.眩晕 6.冰冻 7.石化)的buff / 1 只执行非异常状态(5.眩晕 6.冰冻 7.石化)的buff / 0 全部执行
- --__notActivateOk true 表示model处于非activate状态下课执行
- --__note 注释
- function FightLogic.executeAllModelsBuffs(__modelList, __isNew,__runLimit,__notActivateOk,__note)
- if not __notActivateOk then __notActivateOk = false end
- __note = __note and __note or ""
- -- print("")
- -- print(" ============ executeBuff start ("..__note..") ============")
- for i,_model in ipairs(__modelList) do
- local isExecuteBuffs = false
- if(__runLimit == 2 )then
- --如果是暴击印记但是不暴击就不执行
- if( _model._isBaoJi)then
- isExecuteBuffs = true
- end
- elseif (_model.activate or __notActivateOk) then
- -- print(" " .. _model._enemyName, _model._heroId, "index = ".._model.static_index)
- isExecuteBuffs = true
- end
- if(isExecuteBuffs)then
- _model:executeBuffs(__isNew,__runLimit)
- end
- end
- -- print(" ============ executeBuff end ("..__note..") ============")
- -- print("")
- end
- --获取英雄身上开始战斗时就触发的buff(1.面板触发/3.开始战斗触发)
- function FightLogic.getOnFightingCanBeTrigBuff(__modelList, __target)
- local _getbuffs = {}
- FightLogic.getTargAllCanBeTrigBuff(1,__target,0,__target._giveBuffList,_getbuffs)
- FightLogic.getTargAllCanBeTrigBuff(3,__target,0,__target._giveBuffList,_getbuffs)
- FightLogic.addBuffToModels(__modelList, _getbuffs, {}, true)
- FightLogic.executeAllModelsBuffs(__modelList, true, 0, true, "开始战斗时,检测执行新加入的buff")
- end
- --检测所有 model (4.普攻 5.技能 6.普攻或技能 7.普攻闪避 8.//技能闪避 9.闪避 10.普攻暴击 11.技能暴击 12.暴击)buff
- --__baojiOne 是否存在暴击
- --__ShanbiOne 是否存在闪避
- function FightLogic.checkAttackBuff(__modelList, __isNormalAttack,__baojiOne,__ShanbiOne,__attackTargets)
- -- print("checkAttackBuff ",__isNormalAttack,__baojiOne)
- --检测可以触发的buff(4.普攻 5.技能 6.普攻或技能 7.普攻闪避 8.//技能闪避 9.闪避 10.普攻暴击 11.技能暴击 12.暴击)
- local _allbuffs = FightLogic.getAllModelBuff(__modelList)
- local _getbuffs = {}
- --检测普攻或者主动技能可以被触发的buff
- FightLogic.getAllCanBeTrigBuff(__isNormalAttack and 4 or 5, _allbuffs, _getbuffs, __modelList)
- FightLogic.getAllCanBeTrigBuff(6, _allbuffs, _getbuffs, __modelList)
- --检测普攻闪避或者主动技能闪避可以被触发的buff
- if __ShanbiOne then
- FightLogic.getAllCanBeTrigBuff(__isNormalAttack and 7 or 8, _allbuffs, _getbuffs, __modelList)
- FightLogic.getAllCanBeTrigBuff(9, _allbuffs, _getbuffs, __modelList)
- end
- --检测普攻暴击或者主动技能暴击可以被触发的buff
- if __baojiOne then
- FightLogic.getAllCanBeTrigBuff(__isNormalAttack and 10 or 11, _allbuffs, _getbuffs, __modelList)
- FightLogic.getAllCanBeTrigBuff(12, _allbuffs, _getbuffs, __modelList)
- end
- -- print("_getbuffs ", json.encode(_getbuffs))
- FightLogic.addBuffToModels(__modelList, _getbuffs,__attackTargets)
- --触发buff
- FightLogic.executeAllModelsBuffs(__modelList, true, 1, false, "攻击命中或闪避时,检测执行新加入的buff")
- end
- --检测所有 model (13.任何伤害,15.死亡时触发)buff
- function FightLogic.checkHurtAndDeathBuff(__modelList, __attackTargets,__defenseDefault)
- --检测可以触发的buff(13.任何伤害)
- if true then
- local _allbuffs = FightLogic.getAllModelBuff(__modelList)
- local _getbuffs = {}
- --检测任何伤害的buff(生命值低于一定范围)
- FightLogic.getAllCanBeTrigBuff(13, _allbuffs, _getbuffs, __modelList,__defenseDefault)
- -- print("_getbuffs ", json.encode(_getbuffs))
- --添加buff到英雄
- FightLogic.addBuffToModels(__modelList, _getbuffs,__attackTargets)
- FightLogic.executeAllModelsBuffs(__modelList, true, 0, false, "受到任何伤害时,检测执行新加入的buff")
- end
- local __modelNum = #__modelList
- -- 检测所有 model 是否死亡(生命值 <= 0 视为死亡) 要在buff执行之前执行
- FightLogic.checkAllModelDeath(__modelList)
- -- 大于现在数量,说明有英雄死亡
- if __modelNum > #__modelList then
- -- 检测可以触发的buff(15.死亡时触发的buff)
- local deathNum = __modelNum - #__modelList
- FightLogic.checkDeathBuff(__modelList,true,deathNum)
- end
- end
- --检测所有 model (15.死亡时触发)buff
- function FightLogic.checkDeathBuff(__modelList, __defenseDefault, deathNum)
- --检测可以触发的buff(15.死亡时触发的buff)
- if true then
- local _allbuffs = FightLogic.getAllModelBuff(__modelList)
- local _getbuffs = {}
- --检测任何伤害的buff(生命值低于一定范围)
- FightLogic.getAllCanBeTrigBuff(15, _allbuffs, _getbuffs, __modelList, __defenseDefault, deathNum)
- -- print("_getbuffs ", json.encode(_getbuffs))
- --添加buff到英雄
- FightLogic.addBuffToModels(__modelList, _getbuffs)
- --检测所有 model 是否死亡(生命值 <= 0 视为死亡) 要在buff执行之前执行
- FightLogic.checkAllModelDeath(__modelList)
- FightLogic.executeAllModelsBuffs(__modelList, true, 0, false, "model死亡时,检测执行新加入的buff")
- end
- end
- --是否所有英雄怪物全部激活
- function FightLogic.modelAllActivated(__modelList)
- local allActivated = true
- for i,_model in ipairs(__modelList) do
- if not _model.activate then
- allActivated = false
- break
- end
- end
- return allActivated
- end
- --是否英雄全部未激活
- function FightLogic.heroAllNonactivated(__modelList)
- local allNonactivated = true
- for i,_model in ipairs(__modelList) do
- if not _model._isEnemy and _model.activate then
- allNonactivated = false
- end
- end
- return allNonactivated
- end
- --是否怪物全部未激活
- function FightLogic.enemyAllNonactivated(__modelList)
- -- for i,_model in ipairs(__modelList) do
- -- FightLogic.debugLog(" ------ enemyAllNonactivated " .. _model._enemyName.._model._heroId.." index = ".._model.static_index.." ".._model._energyNum.." ".._model._energyMax.." ".._model._hpNum)
- -- end
- local allNonactivated = true
- for i,_model in ipairs(__modelList) do
- if _model._isEnemy and _model.activate then
- allNonactivated = false
- end
- end
- return allNonactivated
- end
- --是否英雄全部阵亡
- function FightLogic.heroAllDeath(__modelList)
- -- for i,_model in ipairs(__modelList) do
- -- FightLogic.debugLog(" ------ heroAllDeath " .. _model._enemyName.._model._heroId.." index = ".._model.static_index.." ".._model._energyNum.." ".._model._energyMax.." ".._model._hpNum)
- -- end
- local allDeath = true
- for i,_model in ipairs(__modelList) do
- if not _model._isEnemy then
- allDeath = false
- end
- end
- return allDeath
- end
- --是否怪物全部阵亡
- function FightLogic.enemyAllDeath(__modelList)
- -- for i,_model in ipairs(__modelList) do
- -- FightLogic.debugLog(" ------ enemyAllDeath " .. _model._enemyName.._model._heroId.." index = ".._model.static_index.." ".._model._energyNum.." ".._model._energyMax.." ".._model._hpNum)
- -- end
- local allDeath = true
- for i,_model in ipairs(__modelList) do
- if _model._isEnemy then
- allDeath = false
- break
- end
- end
- return allDeath
- end
- --如果存在攻击者或者被攻击者,视为正在战斗中
- function FightLogic.isFighting(__modelList)
- for i,_model in ipairs(__modelList) do
- if _model._isAttacker then
- return true
- elseif _model._isDefender then
- return true
- end
- end
- return false
- end
- --计算伤害值
- -- •主伤害=(攻击-防御*(1-攻击方破甲)/5)*效果值[1]*暴击伤害系数[2]*减伤系数[3]*(1+技能伤害增加[7](如果是主动技能))
- -- •次要伤害1(职业伤害)=主伤害*职业伤害系数-主伤害
- -- *如果<=0则不显示
- -- •次要伤害2(阵营伤害)=主伤害*职业伤害系数*阵营伤害系数-主伤害-次要伤害1
- -- *如果<=0则不显示
- -- •次要伤害3(状态伤害)=主伤害*职业伤害系数*阵营伤害系数*状态伤害系数-主伤害-次要伤害1-次要伤害2
- -- *如果<=0则不显示
- -- __isBaoji 是否暴击
- -- __value 技能或者buff的效果值
- -- __isActiveSkill 是否主动技能
- -- __executeProperty 攻击方或者buff执行者的属性
- -- __model 是防守方
- function FightLogic.getHurtNum(__model, __isBaoji, __value, __isActiveSkill, __executeProperty)
- local _attackerProperty = __executeProperty --攻击方属性
- local _defenderProperty = __model._att_property --防守方属性
- --职业伤害系数=1+攻击方职业额外伤害-防守方职业减少伤害
- local _careerRate = 1 + _attackerProperty["CareerExt_".._defenderProperty._career] - _defenderProperty["CareerRedu_".._attackerProperty._career]
- --阵营伤害系数=1+30%(如果阵营克制)
- local _factionRate = 1 + (_attackerProperty._advanFact == _defenderProperty._faction and _attackerProperty._advanExDama or 0)
- --状态伤害系数=攻击方.对流血单位额外伤害(如果受击方处于流血状态)]*…燃烧…*…中毒…*…禁魔…*…眩晕…*…冰冻…*…石化…
- local _state = {__model._isBleedState,__model._isFireState,__model._isPoisonState,__model._isForbidMagicState,__model._isStunState,__model._isFrozenState > 0,__model._isStoneState > 0}
- local _stateRate = 1
- for i=1,#_state do
- if _state[i] then
- _stateRate = _stateRate + _attackerProperty["StateExt_"..i]
- end
- end
- --暴击伤害系数
- local _baojiRate = __isBaoji and (1.5 + math.max(_attackerProperty.CritDamage, WDConfig.Atri.getItem("25","Min"))) or 1
- --技能伤害增加=(1+技能伤害增加[7](如果是主动技能))
- local _skillDamage = __value + ( __isActiveSkill and math.max(_attackerProperty.SkillDamage, WDConfig.Atri.getItem("21","Min")) or 0)
- --主伤害1=(攻击-防御*(1-攻击方破甲)/5)
- --local _mainHurt = _attackerProperty.Attack - _defenderProperty.Armor * (1 - math.min(_attackerProperty.ArmorBreak, WDConfig.Atri.getItem("26","Max"))) / 5
- --LLH修改
- --护甲减伤 =1-(防御方护甲等级-攻击方破甲等级+20)*0.01
- local _ReduceDamage = (math.min(_defenderProperty.Armor, WDConfig.Atri.getItem("10","Max")) - math.min(_attackerProperty.ArmorBreak, WDConfig.Atri.getItem("26","Max"))+20)*0.01
- _ReduceDamage = 1 - FightLogic.getMiddleValue(tonumber(FightLogic._ReduceDamageLimit[2]),tonumber(FightLogic._ReduceDamageLimit[1]),_ReduceDamage)
- --变更:【造成总伤害=攻击*护甲减伤[1]*(效果值+技能伤害增加(如果是主动技能)[2])*暴击伤害系数*减伤系数*职业伤害系数*阵营伤害系数*状态伤害系数】
- local _mainHurt = _attackerProperty.Attack * _ReduceDamage
- --减伤系数=(1-减伤率)+(1+真实伤害)
- local _reduceRate = (1 - math.min(_defenderProperty.ReduceDamage, WDConfig.Atri.getItem("28","Max")) ) * (1 + math.max(_attackerProperty.TrueDamage, WDConfig.Atri.getItem("21","Min")))
- --主伤害
- -- local _hurtNum = (_mainHurt < 1 and _attackerProperty.Attack*0.6 or _mainHurt)
- -- * __value
- -- * _baojiRate
- -- * _reduceRate
- -- * _skillDamage
- local _hurtNum = _mainHurt * _skillDamage * _baojiRate * _reduceRate * _careerRate * _factionRate * _stateRate
- --次要伤害1
- local _hurtNum1 = 0-- _hurtNum * _careerRate - _hurtNum
- --次要伤害2
- local _hurtNum2 = 0-- _hurtNum * _careerRate * _factionRate - _hurtNum - _hurtNum1
- --次要伤害3
- local _hurtNum3 = 0--_hurtNum * _careerRate * _factionRate * _stateRate - _hurtNum - _hurtNum1 - _hurtNum2
- FightLogic.debugLog("getHurtNum ",__model._enemyName..__model._heroId.." index = "..__model.static_index,__model._hpNum,(_hurtNum+_hurtNum1+_hurtNum2+_hurtNum3))
- ------------------------------------------------------
- --伤害数值
- _hurtNum = _hurtNum < 0 and 0 or _hurtNum
- _hurtNum1 = _hurtNum1 < 0 and 0 or _hurtNum1
- _hurtNum2 = _hurtNum2 < 0 and 0 or _hurtNum2
- _hurtNum3 = _hurtNum3 < 0 and 0 or _hurtNum3
- local ret1 = {math.floor(_hurtNum),math.floor(_hurtNum1),math.floor(_hurtNum2),math.floor(_hurtNum3)}
- --是否发生克制
- local ret2 = false
- if _careerRate > 1 or _factionRate > 1 then
- ret2 = true
- end
- return ret1,ret2
- end
- --取中间的值
- function FightLogic.getMiddleValue(min,max,nowValue)
- if(min > nowValue)then
- return min
- elseif(max < nowValue)then
- return max
- end
- return nowValue
- end
- -- Buff对敌方命中率=Buff表配置的命中率-受击方状态抗性(如果是状态类buff)- 受击方控制抗性(如果是控制类buff)
- -- Buff对友方命中率=Buff表配置的命中率
- -- *如果附加命中为必中,必中
- function FightLogic.getBuffHitRate(__buff, __buffTarget)
- local _hitRate = nil
- if __buff.ExHit == 1 and __buffTarget._att_property._career == 1 then
- _hitRate = 1
- elseif __buff.ExHit == 2 and __buffTarget._att_property._career == 2 then
- _hitRate = 1
- elseif __buff.ExHit == 3 and __buffTarget._att_property._career == 3 then
- _hitRate = 1
- elseif __buff.ExHit == 4 and __buffTarget._att_property._career == 4 then
- _hitRate = 1
- elseif __buff.ExHit == 5 and __buffTarget._att_property._career == 5 then
- _hitRate = 1
- elseif __buff.ExHit == 9 then
- _hitRate = 1
- else
- _hitRate = __buff.Hit
- if __buff.ExecutorProperty._isEnemy ~= __buffTarget._isEnemy then
- local _buffEffData = WDConfig.BuffEff.getData(__buff.EffectId)
- --状态类buff 1.流血 2.燃烧 3.中毒 4.禁魔 5.眩晕 6.冰冻 7.石化
- if _buffEffData.EffStatId >=1 and _buffEffData.EffStatId <= 7 then
- _hitRate = _hitRate - __buffTarget._att_property["StateRisi_".._buffEffData.EffStatId]
- end
- --控制类buff 4.禁魔 5.眩晕 6.冰冻 7.石化
- if _buffEffData.EffStatId >=4 and _buffEffData.EffStatId <= 7 then
- _hitRate = _hitRate - __buffTarget._att_property.ControlImmune
- end
- end
- end
- return math.floor(_hitRate*10000)/10000
- end
- --设置随机种子(正整数)(战斗中使用)
- function FightLogic.FightingRandomSeed(seed)
- gameSeedRandom(1, seed)
- -- globalManager.__index = 1
- -- print("yyp Fighting ",seed)
- end
- -- 取得随机数(战斗中使用)
- -- 无参调用, 产生 (0,1) 之间的浮点随机数
- -- 只有参数a, 产生 1-a(不包含) 之间的整数
- -- 有两个参数a, b, 产生 a-b(不包含) 之间的随机整数
- -- cclog(FightLogic:FightingRandom(0,10000))
- -- cclog(FightLogic:FightingRandom())
- -- cclog(FightLogic:FightingRandom(10))
- function FightLogic.FightingRandom(a,b)
- local ret = 0
- if not a and not b then
- local min = 0
- local max = 10000
- ret = gameRandom(1, min,max)/max
- elseif not b then
- local min = 1
- local max = a
- ret = gameRandom(1, min,max)
- else
- local min = a
- local max = b
- ret = gameRandom(1, min,max)
- end
- -- globalManager.__index = globalManager.__index + 1
- return ret
- end
- function FightLogic.debugLog(...)
- -- debugManager:addLog(...)
- end
- --------------------------------------------------------------------
- --------------------------------------------------------------------
- --------------------------------------------------------------------
- --是否解锁加速
- function FightLogic.speedUpIsUnlock(__lv)
- if __lv == nil then
- __lv = globalManager._playerData.playerLevel
- end
- local ret = (__lv >= globalManager._CommonData._funcData.speedLv) or
- (globalManager._playerData.vipLevel >= globalManager._CommonData._funcData.speedVip)
- return ret
- end
- --是否解锁跳过战斗
- function FightLogic.SkipIsUnlock(__lv)
- if __lv == nil then
- __lv = globalManager._playerData.playerLevel
- end
- local ret = (__lv >= globalManager._CommonData._funcData.skipLv) or
- (globalManager._playerData.vipLevel >= globalManager._CommonData._funcData.skipVip)
- return ret
- end
- return FightLogic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement