Advertisement
Guest User

FightLogic.lua

a guest
Jul 25th, 2019
1,832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 68.13 KB | None | 0 0
  1.  
  2. local HeroInfoHelper = require("app.DataManager.HeroInfoHelper")
  3. local HeroModel = require("app.fighting.HeroModel")
  4.  
  5. local FightLogic = {}
  6. FightLogic._ReduceDamageLimit = string.split(WDConfig.Common.getItem(113, "Content"), ',')
  7. FightLogic.showType = 0    --0 nothing 1 召唤英雄 2 升级英雄 3 强化装备
  8. FightLogic._statisticInfo = {}
  9. FightLogic._statisticPlaybackInfo = {}
  10. FightLogic._statisticResult = {}
  11. FightLogic._statisticHeros = {}
  12. FightLogic._statisticEnemys = {}
  13. --LLH添加多人战斗支持
  14. --------------------------------  
  15. FightLogic.battleData=nil                               --战斗缓存数据  
  16. --多人服务器战斗数据
  17. FightLogic.serverMulitePlayData = {}                    --玩家数据
  18. FightLogic.serverMuliteFightAllResult = false           --最后总结果胜负
  19. --这一段数据多人与单人服务器战斗通用
  20. FightLogic.serverMuliteFightDataList    = {}            --战斗完成的物品
  21. FightLogic.serverMuliteFightResult      = {}            --单场结果的胜负
  22. FightLogic.serverMuliteFightMD5         = nil           --MD5数据
  23. FightLogic.serverMuliteFightLen         = nil           --数据总长度
  24. FightLogic.serverMuliteFightPoint       = nil           --双方得分
  25. --好友boss,工会bosss,非通用数据
  26. FightLogic.serverEnemyId                = nil
  27. ---讨伐战伤害统计
  28. FightLogic.worldBossHurtValue           = 0
  29. -------服务端战斗
  30. FightLogic.serverFightJsonData = ""                     --服务器下发的字符串
  31. FightLogic.serverMuliteFightIndex = 0                   --多人战斗进行到第几场
  32. FightLogic.startFightType  = -1                         --0单人,1回放,2多人
  33. FightLogic.backIndex = nil                              --回放下标
  34. FightLogic.muliteIndex = nil                            --多人里面的回放下标
  35. FightLogic.backSightId = nil                            --单人回放的id  
  36. ------兼容分享或者其他的战斗
  37. FightLogic.backIndex1 = nil
  38. FightLogic.backIndex2 = nil
  39. --初始化服务器战斗数据
  40. function FightLogic.initServerFightData()
  41.     FightLogic.serverMuliteFightDataList = {}                  
  42.     FightLogic.serverMuliteFightResult = {}    
  43.     FightLogic.serverMulitePlayData = {}              
  44.     FightLogic.serverMuliteFightAllResult = false              
  45.     FightLogic.serverMuliteFightMD5 = nil                    
  46.     FightLogic.serverMuliteFightLen = nil                    
  47.     FightLogic.serverMuliteFightPoint = nil                    
  48.     FightLogic.serverJsonData = ""
  49.     FightLogic.serverMuliteFightIndex = 0
  50.     FightLogic.serverFightJsonData = ""  
  51.     FightLogic.worldBossHurtValue = 0
  52.     FightLogic.serverEnemyId = nil
  53. end
  54.  
  55. --服务端多人战斗处理
  56. function FightLogic.fightServerMultiplayerCallBack(__battleData,_index)
  57.     --单场数据设置
  58.     FightLogic.startFightType = 2
  59.     FightLogic.battleData = __battleData  
  60.     FightLogic._statisticInfo._enemyTeam            = {}        -- 防守方队形
  61.     FightLogic._statisticInfo._enemyTeam.pet        = __battleData.embattle[_index].petId        
  62.     FightLogic._statisticInfo._enemyTeam.petBaseData= __battleData.embattle[_index].petBaseData                                 --宠物id
  63.     FightLogic._statisticInfo._enemyTeam.heros      = Utils:table_deepcopy( __battleData.embattle[_index].heroes )                --英雄列表
  64.     FightLogic._statisticInfo._enemyTeam.playerInfo = Utils:table_deepcopy( __battleData.embattle[_index].player )                --防守方信息列表
  65.     --攻击方
  66.     FightLogic._statisticInfo._heroTeam             = {}        -- 攻击方队形
  67.     FightLogic._statisticInfo._heroTeam.pet         = __battleData.battle[_index].petId
  68.     FightLogic._statisticInfo._heroTeam.petBaseData = __battleData.battle[_index].petBaseData                       --宠物id
  69.     FightLogic._statisticInfo._heroTeam.heros       = Utils:table_deepcopy(__battleData.battle[_index].heroes)      --英雄列表
  70.     FightLogic._statisticInfo._heroTeam.playerInfo  = Utils:table_deepcopy( __battleData.battle[_index].player )    --攻击方信息列表
  71.     --设置宠物数据
  72.     if(FightLogic._statisticInfo._enemyTeam.pet~=0)then
  73.         local __enamyPetData={id = FightLogic._statisticInfo._enemyTeam.pet,l = __battleData.embattle[_index].petLv }
  74.         FightingServerDataConfig.setEnamyPetData(__enamyPetData)
  75.     else
  76.         FightingServerDataConfig.setNilEnamyPetData()
  77.     end
  78.     if(FightLogic._statisticInfo._heroTeam.pet~=0 )then
  79.         local __heroPetData ={id = FightLogic._statisticInfo._heroTeam.pet,l = __battleData.battle[_index].petLv}
  80.         FightingServerDataConfig.setHeroPetData(__heroPetData)
  81.     else
  82.         FightingServerDataConfig.setNilHeroPetData()
  83.     end
  84. end
  85.  
  86. --多人战斗响应按钮回调
  87. function FightLogic.fightMultiplayerCallBack(__battleData,__playback,_index,isMulte)
  88.     if(globalManager._userMulitServer )then
  89.         FightLogic.startFightType = 2
  90.     end
  91.     FightLogic.battleData = __battleData
  92.     if sceneManager:isIdleScene() then
  93.         local idleScene = sceneManager:getRunningScene()
  94.         idleScene.bossGoblinTip:hideTip()
  95.  
  96.         if __battleData.attackType == globalConfig.BattleTag.HANG_BOSS then
  97.             idleScene._fighting_Layer._battle_layer.btn_boss:setTouchEnabled(false)
  98.         end
  99.     end  
  100.     --战斗基本信息
  101.     FightLogic._statisticInfo = {}
  102.     FightLogic._statisticInfo._type         = __battleData.attackType           -- 战斗类型
  103.     FightLogic._statisticInfo._beAttackId   = __battleData.attackId             -- 副本id
  104.     FightLogic._statisticInfo._randseed     = __battleData.randseed             -- 随机种子
  105.     FightLogic._statisticInfo._lineupindex  = __battleData.idx                  -- 我的阵营索引
  106.     FightLogic._statisticInfo._playback     = __battleData.playback or false    -- 回放模式  
  107.     --兼容原来的数据
  108.     local index = 1
  109.     if(_index)then
  110.         index = _index
  111.     end  
  112.     -- 即将进行的战斗的背景
  113.     FightLogic._statisticInfo._bgspine  = __battleData.embattle[index].bgspine 
  114.     FightLogic._statisticInfo._background   = __battleData.embattle[index].background  
  115.     if not FightLogic._statisticInfo._background then
  116.         FightLogic._statisticInfo._background = WDConfig.BattlePVPBg.getItem(math.random(WDConfig.BattlePVPBg._length),"Background")
  117.     end
  118.     --防守方
  119.     FightLogic._statisticInfo._enemyTeam            = {}        -- 防守方队形
  120.     FightLogic._statisticInfo._enemyTeam.circleId   = __battleData.embattle[index].circleId                                         --阵营光环
  121.     FightLogic._statisticInfo._enemyTeam.pet        = __battleData.embattle[index].petId        
  122.     FightLogic._statisticInfo._enemyTeam.petData    = Utils:table_deepcopy( __battleData.embattle[index].petData )                  --宠物数据
  123.     FightLogic._statisticInfo._enemyTeam.petBaseData = __battleData.embattle[index].petBaseData                                 --宠物id
  124.     FightLogic._statisticInfo._enemyTeam.heros      = Utils:table_deepcopy( __battleData.embattle[index].heroes )                --英雄列表
  125.     FightLogic._statisticInfo._enemyTeam.playerInfo = Utils:table_deepcopy( __battleData.embattle[index].player )                --防守方信息列表
  126.     --判断是否是多人
  127.     if(FightLogic._statisticInfo._type ~= globalConfig.BattleTag.ARENA_CHAMPION)then
  128.         index = __battleData.idx
  129.     end
  130.     --攻击方
  131.     FightLogic._statisticInfo._heroTeam             = {}        -- 攻击方队形
  132.     FightLogic._statisticInfo._heroTeam.circleId    = __battleData.battle[index].circleId                           --阵营光环
  133.     FightLogic._statisticInfo._heroTeam.pet         = __battleData.battle[index].petId     
  134.     FightLogic._statisticInfo._heroTeam.petData    = Utils:table_deepcopy( __battleData.battle[index].petData )                     --宠物数据
  135.     FightLogic._statisticInfo._heroTeam.petBaseData = __battleData.battle[index].petBaseData                        --宠物id
  136.     FightLogic._statisticInfo._heroTeam.heros       = Utils:table_deepcopy(__battleData.battle[index].heroes)      --英雄列表
  137.     FightLogic._statisticInfo._heroTeam.playerInfo  = Utils:table_deepcopy( __battleData.battle[index].player )    --攻击方信息列表
  138.     --talkingdata记录
  139.     --开始loading
  140.     if(isMulte)then
  141.         sceneManager:GotoScene("LoadingScene")
  142.     else
  143.         sceneManager:PushScene("LoadingScene",{true})
  144.     end
  145. end
  146. --单人服务器战斗回调
  147. function FightLogic.fightServerCallBack(__battleData,__playback, isSkip)
  148.     isSkip = isSkip or false
  149.     FightLogic.battleData = __battleData
  150.     FightLogic.startFightType = 0
  151.     if sceneManager:isIdleScene() then
  152.         local idleScene = sceneManager:getRunningScene()
  153.         idleScene.bossGoblinTip:hideTip()
  154.         if __battleData.attackType == globalConfig.BattleTag.HANG_BOSS then
  155.             idleScene._fighting_Layer._battle_layer:hideWidgetWithStatus(2,true)
  156.         end
  157.     end
  158.     --战斗基本信息
  159.     FightLogic._statisticInfo = {}
  160.     FightLogic._statisticInfo._type         = __battleData.attackType           -- 战斗类型
  161.     FightLogic._statisticInfo._beAttackId   = __battleData.attackId             -- 副本id
  162.     FightLogic._statisticInfo._randseed     = __battleData.randseed             -- 随机种子
  163.     FightLogic._statisticInfo._lineupindex  = __battleData.idx                  -- 我的阵营索引
  164.     FightLogic._statisticInfo._playback     = __battleData.playback or false    -- 回放模式
  165.     -- 即将进行的战斗的背景
  166.     FightLogic._statisticInfo._bgspine  = __battleData.embattle[1].bgspine 
  167.     FightLogic._statisticInfo._background   = __battleData.embattle[1].background  
  168.     if not FightLogic._statisticInfo._background then
  169.         FightLogic._statisticInfo._background = WDConfig.BattlePVPBg.getItem(math.random(WDConfig.BattlePVPBg._length),"Background")
  170.     end
  171.     --战斗数据双方的数据
  172.     FightLogic._statisticInfo._enemyTeam            = {}        -- 防守方队形
  173.     FightLogic._statisticInfo._enemyTeam.pet        = __battleData.embattle[1].petId        
  174.     FightLogic._statisticInfo._bgspine              = __battleData.embattle[1].bgspine 
  175.     FightLogic._statisticInfo._enemyTeam.petBaseData= Utils:table_deepcopy( __battleData.embattle[1].petBaseData )                    
  176.     FightLogic._statisticInfo._enemyTeam.heros      = Utils:table_deepcopy( __battleData.embattle[1].heroes )
  177.     FightLogic._statisticInfo._enemyTeam.playerInfo = Utils:table_deepcopy( __battleData.embattle[1].player )          --防守方信息列表
  178.     --攻击方
  179.     FightLogic._statisticInfo._heroTeam             = {}        -- 攻击方队形
  180.     FightLogic._statisticInfo._heroTeam.pet         = __battleData.battle[__battleData.idx].petId  
  181.     FightLogic._statisticInfo._heroTeam.petBaseData = Utils:table_deepcopy(__battleData.battle[__battleData.idx].petBaseData )    
  182.     FightLogic._statisticInfo._heroTeam.heros       = Utils:table_deepcopy(__battleData.battle[__battleData.idx].heroes)  --英雄列表
  183.     FightLogic._statisticInfo._heroTeam.playerInfo  = Utils:table_deepcopy( __battleData.battle[__battleData.idx].player )--攻击方信息列表
  184.     if(FightLogic._statisticInfo._enemyTeam.pet~=0)then
  185.         local __enamyPetData={id = FightLogic._statisticInfo._enemyTeam.pet,l = __battleData.embattle[1].petLv }
  186.         FightingServerDataConfig.setEnamyPetData(__enamyPetData)
  187.     end
  188.     if(FightLogic._statisticInfo._heroTeam.pet~=0 )then
  189.         local __heroPetData ={id = FightLogic._statisticInfo._heroTeam.pet,l = __battleData.battle[__battleData.idx].petLv }
  190.         FightingServerDataConfig.setHeroPetData(__heroPetData)
  191.     end    
  192.  
  193.     --talkingdata记录
  194.     if __battleData.attackType     == globalConfig.BattleTag.HANG_BOSS then            -- 挂机战斗boss
  195.         nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
  196.     elseif __battleData.attackType == globalConfig.BattleTag.ACTIVITY_MAP then         -- 活动副本
  197.         nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
  198.     elseif __battleData.attackType == globalConfig.BattleTag.PASS_TOWER then           -- 地下秘境
  199.         Utils:sendTDEvent("event_tower_"..__battleData.attackId) --talkingdata        
  200.         nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
  201.     elseif __battleData.attackType == globalConfig.BattleTag.PASS_TOWER then           -- 星之试炼
  202.         nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
  203.     elseif __battleData.attackType == globalConfig.BattleTag.GUILD_BOSS then           -- 公会boss
  204.         Utils:sendTDEvent("event_guild_boss_battle") --talkingdata        
  205.     elseif __battleData.attackType == globalConfig.BattleTag.FREIND_BOSS then          -- 好友boss
  206.     elseif __battleData.attackType == globalConfig.BattleTag.GUILD_MILL then           -- 矿脉掠夺(__carbonId 被掠夺工会id)
  207.     elseif __battleData.attackType == globalConfig.BattleTag.GUILD_MILL_REVENGE then   -- 矿脉复仇(__carbonId 矿脉复仇界面传递过来的数据)
  208.     elseif __battleData.attackType == globalConfig.BattleTag.TRIALS_BRAVE then         -- 远征(__carbonId 试炼界面传递过来的数据)
  209.         Utils:sendTDEvent("event_expedition_fight") --talkingdata        
  210.         nativeManager:LoggerCustomerChangeAttack(__battleData.attackId, __battleData.attackType, __battleData.battle[1]["force"] or 0)
  211.     elseif __battleData.attackType == globalConfig.BattleTag.ARENA_NORMAL then         -- 单人竞技
  212.         Utils:sendTDEvent("event_arena_battle") --talkingdata        
  213.     elseif __battleData.attackType == globalConfig.BattleTag.ARENA_CHAMPION then       -- 军团之争(多人竞技)
  214.     elseif __battleData.attackType == globalConfig.BattleTag.FREIND_BOSS then          -- 好友boss            
  215.     elseif __battleData.attackType == globalConfig.BattleTag.FREIND_PK then            -- 好友PK
  216.     end
  217.     --开始loading
  218.     if isSkip then
  219.         if __battleData.attackType == globalConfig.BattleTag.FREIND_BOSS then
  220.             require("app.layers.friend.FriendFightSettlement"):create()
  221.                 :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  222.                 :setOnCloseCallBack(function()
  223.                     Request:sendFBossEnterRequest()
  224.                 end)
  225.         end
  226.     else
  227.         sceneManager:PushScene("LoadingScene")
  228.     end
  229. end
  230.  
  231. --开始战斗
  232. --__battleType 战斗类型
  233. --__carbonId   PVE副本id
  234. function FightLogic.startPVEFight(__battleType,__carbonId, isSkip)
  235.     if __battleType == globalConfig.BattleTag.HANG_BOSS then                --挂机战斗boss
  236.         require("app.layers.formatModule.FormatInfo")
  237.             :create(globalConfig.BattleTag.HANG_BOSS, __carbonId)
  238.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  239.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  240.  
  241.     elseif __battleType == globalConfig.BattleTag.ACTIVITY_MAP then         --活动副本
  242.         require("app.layers.formatModule.FormatInfo")
  243.             :create(globalConfig.BattleTag.ACTIVITY_MAP, __carbonId)
  244.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  245.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  246.            
  247.     elseif __battleType == globalConfig.BattleTag.PASS_TOWER then            --地下秘境
  248.         require("app.layers.formatModule.FormatInfo")
  249.             :create(globalConfig.BattleTag.PASS_TOWER, __carbonId)
  250.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  251.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  252.  
  253.     elseif __battleType == globalConfig.BattleTag.DUNGEON then               --星之试炼
  254.         require("app.layers.formatModule.FormatInfo")
  255.             :create(globalConfig.BattleTag.DUNGEON, __carbonId)
  256.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  257.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  258.  
  259.     elseif __battleType == globalConfig.BattleTag.GUILD_BOSS then            --公会boss
  260.         require("app.layers.formatModule.FormatInfo")
  261.             :create(globalConfig.BattleTag.GUILD_BOSS, __carbonId)
  262.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  263.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  264.            
  265.     elseif __battleType == globalConfig.BattleTag.FREIND_BOSS then            --好友boss
  266.         require("app.layers.formatModule.FormatInfo")
  267.             :create(globalConfig.BattleTag.FREIND_BOSS, __carbonId)
  268.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  269.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  270.  
  271.     elseif __battleType == globalConfig.BattleTag.GUILD_MILL then            --公会矿脉掠夺(__carbonId 被掠夺工会id)
  272.  
  273.         require("app.layers.formatModule.FormatInfo")
  274.             :create(globalConfig.BattleTag.GUILD_MILL, __carbonId)
  275.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  276.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  277.  
  278.     elseif __battleType == globalConfig.BattleTag.GUILD_MILL_REVENGE then            --公会矿脉复仇(__carbonId 公会矿脉复仇界面传递过来的数据)
  279.  
  280.         require("app.layers.formatModule.FormatInfo")
  281.             :create(globalConfig.BattleTag.GUILD_MILL_REVENGE, __carbonId)
  282.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  283.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  284.  
  285.     elseif __battleType == globalConfig.BattleTag.TRIALS_BRAVE then            --远征(__carbonId 试炼界面传递过来的数据)
  286.  
  287.         require("app.layers.formatModule.FormatInfo")
  288.             :create(globalConfig.BattleTag.TRIALS_BRAVE, __carbonId)
  289.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  290.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  291.        
  292.     elseif __battleType == globalConfig.BattleTag.ARENA_NORMAL then            --勇士联赛
  293.         --单人战斗切换
  294.         require("app.layers.formatModule.FormatInfo")
  295.             :create(globalConfig.BattleTag.ARENA_NORMAL, __carbonId)
  296.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  297.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  298.  
  299.     elseif __battleType == globalConfig.BattleTag.ARENA_CHAMPION then            -- 冠军竞技
  300.  
  301.         require("app.layers.formatModule.FormatInfo")
  302.             :create(globalConfig.BattleTag.ARENA_CHAMPION, __carbonId)
  303.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  304.             :setOnClickAttackCallback(FightLogic.fightMultiplayerCallBack)
  305.             --:setOnClickAttackCallback(function()
  306.             --    print("战斗结束...........")
  307.             --end)
  308.  
  309.     elseif __battleType == globalConfig.BattleTag.ARENA_TEAM then            -- 组队竞技
  310.         require("app.layers.formatModule.FormatInfo")
  311.             :create(globalConfig.BattleTag.ARENA_TEAM, __carbonId)
  312.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  313.             :setOnClickAttackCallback(FightLogic.fightMultiplayerCallBack)
  314.             --:setOnClickAttackCallback(function()
  315.             --    print("战斗结束...........")
  316.             --end)
  317.     elseif __battleType == globalConfig.BattleTag.FREIND_BOSS then            --好友boss
  318.  
  319.         require("app.layers.formatModule.FormatInfo")
  320.             :create(globalConfig.BattleTag.FREIND_BOSS, __carbonId)
  321.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  322.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  323.            
  324.     elseif __battleType == globalConfig.BattleTag.FREIND_PK then            --好友PK
  325.  
  326.         require("app.layers.formatModule.FormatInfo")
  327.             :create(globalConfig.BattleTag.FREIND_PK, __carbonId)
  328.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  329.             :setOnClickAttackCallback(FightLogic.fightServerCallBack)
  330.     elseif __battleType == globalConfig.BattleTag.WORLD_BOSS then          -- 讨伐战
  331.         require("app.layers.formatModule.FormatInfo")
  332.             :create(globalConfig.BattleTag.WORLD_BOSS, __carbonId, isSkip)
  333.             :addToNode(sceneManager:getRunningScene(), globalConfig.ZOrderControl.Dialog)
  334.             :setOnClickAttackCallback(FightLogic.fightMultiplayerCallBack)
  335.     end
  336. end
  337.  
  338. --服务端战斗回放开始
  339. function FightLogic.startServerPlay(backData)
  340.     if(FightLogic.battleData~=nil and FightLogic.battleData.attackType ~=nil)then
  341.         FightLogic._statisticInfo._type = FightLogic.battleData.attackType
  342.     else
  343.         FightLogic._statisticInfo._type = globalConfig.BattleTag.ARENA_CHAMPION  
  344.     end
  345.     --地下秘境特殊处理
  346.     if(FightLogic._statisticInfo._type  == globalConfig.BattleTag.PASS_TOWER)then
  347.         --------------------------------------------
  348.         local rewards    = {}
  349.         local _carbonId = WDConfig.CarbonTower.getItem(backData.defineid,"CarbonId")
  350.         local _data = WDConfig.Carbon.getData(_carbonId)
  351.         for i=1,4 do
  352.             if _data["ItemID_"..i] ~= 0 then
  353.                 local _item = {}
  354.                 _item.key = _data["ItemID_"..i]
  355.                 _item.value = _data["ItemNum_"..i]
  356.                 table.insert(rewards, _item)
  357.             end
  358.         end
  359.         ------------------------------------------------
  360.         FightLogic.serverMuliteFightDataList = rewards
  361.     end
  362.     FightLogic._statisticInfo._bgspine  = nil
  363.     FightLogic._statisticInfo._enemyTeam            = {}        -- 防守方队形
  364.     FightLogic._statisticInfo._background           = nil
  365.     FightLogic._statisticInfo._enemyTeam.pet        = backData.dePetId          
  366.     FightLogic._statisticInfo._enemyTeam.petBaseData= backData.dePet    
  367.     --FightLogic._statisticInfo._enemyTeam.heros      = Utils:table_deepcopy( backData.embattle[1].heroes )
  368.     if( backData._enemyTeam~= nil)then
  369.         FightLogic._statisticInfo._enemyTeam.playerInfo = backData._enemyTeam.playerInfo         --防守方信息列表
  370.         if(FightLogic._statisticInfo._enemyTeam.pet~=0)then
  371.             local lv = 1
  372.             for i,v in pairs(FightLogic._statisticInfo._enemyTeam.petBaseData) do
  373.                 if(v.id == FightLogic._statisticInfo._enemyTeam.pet)then
  374.                     lv = v.lv
  375.                     break
  376.                 end
  377.             end
  378.             local __enamyPetData={id = FightLogic._statisticInfo._enemyTeam.pet,l = lv}
  379.             FightingServerDataConfig.setEnamyPetData(__enamyPetData)
  380.         end
  381.     end
  382.     --攻击方
  383.     FightLogic._statisticInfo._heroTeam             = {}        -- 攻击方队形
  384.     FightLogic._statisticInfo._heroTeam.pet         = backData.atPetId  
  385.     FightLogic._statisticInfo._heroTeam.petBaseData = backData.atPet               
  386.     --FightLogic._statisticInfo._heroTeam.heros       = Utils:table_deepcopy(backData.battle[1].heroes)
  387.     if(backData._heroTeam)then
  388.         FightLogic._statisticInfo._heroTeam.playerInfo  = backData._heroTeam.playerInfo --攻击方信息列表  
  389.         if(FightLogic._statisticInfo._heroTeam.pet~=0 )then
  390.             local lv = 1
  391.             for i,v in pairs(FightLogic._statisticInfo._heroTeam.petBaseData) do
  392.                 if(v.id == FightLogic._statisticInfo._heroTeam.pet)then
  393.                     lv = v.lv
  394.                     break
  395.                 end
  396.             end
  397.             local __heroPetData ={id = FightLogic._statisticInfo._heroTeam.pet,l = lv}
  398.             FightingServerDataConfig.setHeroPetData(__heroPetData)
  399.         end
  400.     end
  401. end
  402. --服务端回放数据设置
  403. function FightLogic.setBackPlayDatas(_attackType,_playData,_backSightId,_backIndex1,_backIndex2,_backIndex,_muliteIndex,_defineid,_otherData)
  404.     --先隐藏哥布林精英怪提示
  405.     if sceneManager:isIdleScene() then
  406.         local idleScene = sceneManager:getRunningScene()
  407.         idleScene.bossGoblinTip:hideTip()
  408.     end
  409.     FightLogic.startFightType = 1
  410.     FightLogic.battleData={}
  411.     FightLogic.battleData.attackType = _attackType
  412.     FightLogic.battleData._heroTeam={}
  413.     FightLogic.battleData._enemyTeam={}
  414.     --设置头像数据
  415.     FightLogic.battleData._heroTeam.playerInfo = {iconId = _playData.ahead ,lv = _playData.alevel,name = _playData.aname,frameId = _playData.aframe}
  416.     FightLogic.battleData._enemyTeam.playerInfo = {iconId = _playData.dhead,lv = _playData.dlevel,name = _playData.dname,frameId = _playData.dframe}  
  417.     FightLogic.backSightId = _backSightId           --单场回放ID
  418.     FightLogic.backIndex1 = _backIndex1             --军团对决数据index
  419.     FightLogic.backIndex2 = _backIndex2             --军团对决数据index
  420.     FightLogic.backIndex = _backIndex               --多人回放支持
  421.     FightLogic.muliteIndex  = _muliteIndex          --多人回放支持
  422.     FightLogic.battleData.defineid = _defineid      --地下秘境
  423.     FightLogic.battleData.attackData = _otherData
  424.     sceneManager:PushScene("LoadingScene",{true})  
  425. end
  426.  
  427. --创建一个英雄
  428. --__idleHeroControler : 挂机控制类
  429. --__index             : 创建怪物的位置
  430. --__panel_models      : 把创建的英雄添加至__panel_models
  431. function FightLogic.createHero( __idleHeroControler, __index, __panel_models)
  432.     local hero = __idleHeroControler:createHero()
  433.     return hero
  434. end
  435.  
  436. --创建一个怪物
  437. --__statisticEnemys   : 非挂机统计怪物信息列表
  438. --__index             : 创建怪物的位置
  439. --__panel_models      : 把创建的英雄添加至__panel_models
  440. function FightLogic.createEnemy( __statisticEnemys, __index, __panel_models)
  441.     local enemy = nil
  442.     local mosterData = globalManager._idleMap.moster[__index]
  443.     if mosterData and mosterData.mosterId ~= 0 then
  444.         enemy = HeroModel.new(mosterData.mosterId)
  445.         enemy:initData(true, 0)
  446.         __panel_models:addChild(enemy)
  447.  
  448.         enemy._battleId = 1
  449.         enemy._prepare = true
  450.         enemy.mosterData = mosterData
  451.     end  
  452.     return enemy
  453. end
  454.  
  455. --加載精英怪
  456. function FightLogic.loadSuperMoster()
  457.     if globalManager._CommonData._boosMonData.isExist and globalManager._playerData.killSuperMosterCnt then
  458.         globalManager._CommonData._boosMonData.isFight = true
  459.        
  460.         local idleScene = sceneManager:getRunningScene()
  461.         idleScene.bossGoblinTip:hideTip()
  462.     end
  463.     if globalManager._CommonData._boosMonData.isFight then
  464.         globalManager._idleMap.moster = {}
  465.         if true then
  466.             local mosterData = {}
  467.             mosterData.mosterId = 0
  468.             table.insert(globalManager._idleMap.moster, mosterData)
  469.         end
  470.         if true then
  471.             local mosterData = {}
  472.             --隨機出現精英怪
  473.             local randomIndex = 3
  474.             local HardRate_1 = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardRate_1")
  475.             local HardRate_2 = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardRate_2")
  476.             local HardRate_3 = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardRate_3")
  477.             local randomNum = math.random(HardRate_1+HardRate_2+HardRate_3)
  478.             if randomNum <= HardRate_1 then
  479.                 randomIndex = 1
  480.             elseif randomNum <= HardRate_1+HardRate_2 then
  481.                 randomIndex = 2
  482.             end
  483.             mosterData.mosterId = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"MonHard_"..randomIndex)
  484.  
  485.             local dropitem = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardDrop_"..randomIndex)
  486.             local dropcount = WDConfig.IdleCarbon.getItem(globalManager._CommonData._boosMonData.carbonId,"HardDropNum_"..randomIndex)
  487.  
  488.             if dropitem == globalConfig.generalItem.gold then
  489.                 mosterData.gold = dropcount
  490.                 mosterData.exp = 0
  491.                 mosterData.item = {}
  492.             elseif dropitem == globalConfig.generalItem.gold then
  493.                 mosterData.gold = 0
  494.                 mosterData.exp = dropcount
  495.                 mosterData.item = {}
  496.             else
  497.                 mosterData.item = {}
  498.                 local d = {}
  499.                 d.key = dropitem
  500.                 d.value = dropcount
  501.             end
  502.             table.insert(globalManager._idleMap.moster, mosterData)
  503.             -- print("loadSuperMoster = ",randomNum,randomIndex)
  504.         end
  505.         -- print("loadSuperMoster = ",json.encode(globalManager._idleMap.moster))
  506.     end
  507. end
  508.  
  509. --------------------------------------------------------------------
  510. --------------------------------------------------------------------
  511. --------------------------------------------------------------------
  512.  
  513. --获取一个未攻击过model
  514. function FightLogic.getFightModel(__modelList)
  515.  
  516.     --排序(速度 > 攻守 > 站位)
  517.     local function modelsort(a,b)
  518.         if a._att_property.Speed ~= b._att_property.Speed then
  519.             return a._att_property.Speed > b._att_property.Speed
  520.         else
  521.             if a._sortNum ~= b._sortNum then
  522.                 return a._sortNum < b._sortNum
  523.             else
  524.                 return a.static_index < b.static_index
  525.             end
  526.         end
  527.     end
  528.     table.sort(__modelList,modelsort)
  529.  
  530.     for i,_model in ipairs(__modelList) do
  531.         if not _model._isAttacked and _model.activate then
  532.             _model._isAttacked = true  --设置为已经攻击过了
  533.             return _model
  534.         end
  535.     end
  536.     return nil
  537. end
  538.  
  539. --获取技能或者buff的目标 结果可能有多个(根据Targ表筛选)
  540. function FightLogic.getTargetList(__modelList, __model, _targData, __notActivateOk)
  541.     if not __notActivateOk then __notActivateOk = false end
  542.  
  543.     local _targetList = {}
  544.  
  545.     local _filtrate = true
  546.     if not __model then
  547.         _filtrate = false
  548.     end
  549.  
  550.     --把所有model塞进去
  551.     if _filtrate then
  552.         for i,_model in ipairs(__modelList) do
  553.             -- print( "    getTargetList ----------- aa " .. _model._enemyName .. _model._heroId ..", index ".._model.static_index.."-".._model._uid,_model.activate)
  554.             if (_model.activate or __notActivateOk ) then
  555.                 table.insert(_targetList, _model)
  556.             end
  557.         end
  558.     end
  559.  
  560.     --根据目标类型筛选 (1.自身 2.受击方(且被命中) 3.攻击方 4.敌方 5.友方 6.受击方(且闪避) 9.全部)
  561.     if _filtrate then
  562.         if _targData.Enemy == 1 then
  563.             for i=#_targetList,1,-1 do
  564.                 local _target = _targetList[i]
  565.                 if _target ~= __model then
  566.                     table.remove(_targetList,i)
  567.                 end
  568.             end
  569.  
  570.         elseif _targData.Enemy == 2 then
  571.             for i=#_targetList,1,-1 do
  572.                 local _target = _targetList[i]
  573.                 if not (_target._isDefender and _target._isBeit) then
  574.                     table.remove(_targetList,i)
  575.                 end
  576.             end
  577.            
  578.         elseif _targData.Enemy == 3 then
  579.             for i=#_targetList,1,-1 do
  580.                 local _target = _targetList[i]
  581.                 if not _target._isAttacker then
  582.                     table.remove(_targetList,i)
  583.                 end
  584.             end
  585.  
  586.         elseif _targData.Enemy == 4 then
  587.             for i=#_targetList,1,-1 do
  588.                 local _target = _targetList[i]
  589.                 if _target._isEnemy == __model._isEnemy then
  590.                     table.remove(_targetList,i)
  591.                 end
  592.             end
  593.  
  594.         elseif _targData.Enemy == 5 then
  595.             for i=#_targetList,1,-1 do
  596.                 local _target = _targetList[i]
  597.                 if _target._isEnemy ~= __model._isEnemy then
  598.                     table.remove(_targetList,i)
  599.                 end
  600.             end
  601.  
  602.         elseif _targData.Enemy == 6 then
  603.             for i=#_targetList,1,-1 do
  604.                 local _target = _targetList[i]
  605.                 if not (_target._isDefender and _target._isHaveDodge) then
  606.                     table.remove(_targetList,i)
  607.                 end
  608.             end
  609.         elseif _targData.Enemy == 7 then
  610.             for i=#_targetList,1,-1 do
  611.                 local _target = _targetList[i]
  612.                 if not (_target._isBaoJi) then
  613.                     table.remove(_targetList,i)
  614.                 end
  615.             end
  616.         elseif _targData.Enemy == 9 then
  617.             --do nothing
  618.         end
  619.     end
  620.  
  621.     --根据目标类型筛选 (0.无效 1.顺位 2.前排 3.后排 9.全部)
  622.     if _filtrate then
  623.  
  624.         if _targData.Type == 0 then
  625.             _filtrate = false
  626.  
  627.         elseif _targData.Type == 1 then
  628.             --排序(站位)
  629.             local function modelsort(a,b)
  630.                 return a.static_index < b.static_index
  631.             end
  632.             table.sort(_targetList,modelsort)
  633.  
  634.             for i=#_targetList,2,-1 do
  635.                 local _target = _targetList[i]
  636.                 table.remove(_targetList,i)
  637.             end
  638.         elseif _targData.Type == 2 then
  639.             for i=#_targetList,1,-1 do
  640.                 local _target = _targetList[i]
  641.                 if _target.static_col ~= 1 then
  642.                     table.remove(_targetList,i)
  643.                 end
  644.             end
  645.         elseif _targData.Type == 3 then
  646.             for i=#_targetList,1,-1 do
  647.                 local _target = _targetList[i]
  648.                 if _target.static_col ~= 2 then
  649.                     table.remove(_targetList,i)
  650.                 end
  651.             end
  652.         elseif _targData.Type == 9 then
  653.             --do nothing
  654.         end
  655.     end
  656.  
  657.     --根据目标职业筛选 (0.无效 1.战士 2.刺客 3.游侠 4.牧师 5.法师 9.全部)
  658.     if _filtrate then
  659.         if _targData.Career == 0 then
  660.             _filtrate = false
  661.         elseif _targData.Career == 9 then
  662.             --do nothing
  663.         else
  664.             for i=#_targetList,1,-1 do
  665.                 local _target = _targetList[i]
  666.                 if _targData.Career ~= _target._att_property._career then
  667.                     table.remove(_targetList,i)
  668.                 end
  669.             end
  670.         end
  671.     end
  672.  
  673.     --根据目标属性条件筛选 (0.无效 6.能量 7.当前生命 9.攻击 10.护甲 11.速度)
  674.     if _filtrate then
  675.         if _targData.AtriId == 0 then
  676.             --do nothing
  677.         else
  678.             local _sort = nil
  679.             if _targData.AtriId == 6 then
  680.                 local function modelsort(a,b) --排序(能量 > 站位)
  681.                     if a._energyNum ~= b._energyNum then
  682.                         return a._energyNum < b._energyNum
  683.                     else
  684.                         return a.static_index < b.static_index
  685.                     end
  686.                 end
  687.                 _sort = modelsort
  688.  
  689.             elseif _targData.AtriId == 7 then
  690.                 local function modelsort(a,b) --排序(生命 > 站位)
  691.                     if (a._hpNum/a._att_property.MaxHp) ~= (b._hpNum/b._att_property.MaxHp) then
  692.                         return (a._hpNum/a._att_property.MaxHp) < (b._hpNum/b._att_property.MaxHp)
  693.                     else
  694.                         return a.static_index < b.static_index
  695.                     end
  696.                 end
  697.                 _sort = modelsort
  698.                
  699.             elseif _targData.AtriId == 9 then
  700.                 local function modelsort(a,b) --排序(攻击 > 站位)
  701.                     if a._att_property.Attack ~= b._att_property.Attack then
  702.                         return a._att_property.Attack < b._att_property.Attack
  703.                     else
  704.                         return a.static_index < b.static_index
  705.                     end
  706.                 end
  707.                 _sort = modelsort
  708.                
  709.             elseif _targData.AtriId == 10 then
  710.                 local function modelsort(a,b) --排序(护甲 > 站位)
  711.                     if a._att_property.Armor ~= b._att_property.Armor then
  712.                         return a._att_property.Armor < b._att_property.Armor
  713.                     else
  714.                         return a.static_index < b.static_index
  715.                     end
  716.                 end
  717.                 _sort = modelsort
  718.                
  719.             elseif _targData.AtriId == 11 then
  720.                 local function modelsort(a,b) --排序(速度 > 站位)
  721.                     if a._att_property.Speed ~= b._att_property.Speed then
  722.                         return a._att_property.Speed < b._att_property.Speed
  723.                     else
  724.                         return a.static_index < b.static_index
  725.                     end
  726.                 end
  727.                 _sort = modelsort
  728.  
  729.             end
  730.             table.sort(_targetList,_sort)
  731.  
  732.             for i=#_targetList,2,-1 do
  733.                 local _target = _targetList[i]
  734.                 table.remove(_targetList,i)
  735.             end
  736.         end
  737.     end
  738.  
  739.     --根据目标数量类型筛选 (0.无效 1.随机 2.全部)
  740.     if _filtrate then
  741.         if _targData.NumType == 0 then
  742.             _filtrate = false
  743.         elseif _targData.NumType == 1 then
  744.             --do nothing
  745.         elseif _targData.NumType == 2 then
  746.             --do nothing
  747.         end
  748.     end
  749.  
  750.     --根据目标数量筛选 (0.无效 n.数量)
  751.     if _filtrate then
  752.         if _targData.NumType ~= 0 and _targData.Num ~= 0 then
  753.             --如果需要选取的数量大于剩余的数量 则全部选取
  754.             if #_targetList <= _targData.Num then
  755.                 _filtrate = false
  756.             else
  757.                 local diffNum = #_targetList - _targData.Num
  758.                 for i=1,diffNum do
  759.                     FightLogic.debugLog("check->".."call FightingRandom a")
  760.                     local randRemoveNum = FightLogic.FightingRandom(#_targetList+1)
  761.                     table.remove(_targetList,randRemoveNum)
  762.                 end
  763.             end
  764.         end
  765.     end
  766.  
  767.     return _targetList
  768. end
  769.  
  770. --判断一个buff的执行者和一个model的关系
  771. --__executorProperty : buff的执行者属性
  772. function FightLogic.getBuffTargWithModel( __executorProperty, __model )
  773.  
  774.     if __executorProperty._static_index == __model.static_index and __executorProperty._isEnemy == __model._isEnemy and __executorProperty._battleId == __model._battleId then
  775.         return 1  --自身
  776.     elseif __executorProperty._isEnemy ~= __model._isEnemy then
  777.         return 2  --任意敌方
  778.     elseif __executorProperty._isEnemy == __model._isEnemy then
  779.         return 3  --任意友方不包括自己
  780.     end
  781.  
  782.     return 0
  783. end
  784.  
  785. --判断一个buff是否可以被触发
  786. -- __type : 触发类型(时机)
  787. -- __targ : 触发目标
  788. -- __targType : 触发目标类型
  789. -- __buff : __buff
  790. function FightLogic.isBuffCanBeTrig(__type, __targ, __targType, __buff)
  791.  
  792.     local _buffTrigData = WDConfig.BuffTrig.getData(__buff.TrigId)
  793.  
  794.     -- print("          isBuffCanBeTrig " .. __buff.TrigId)
  795.     -- print("          isBuffCanBeTrig " .. json.encode(_buffTrigData))
  796.     --筛选触发类型
  797.     if _buffTrigData.Type ~= __type then
  798.         -- print("              isBuffCanBeTrig false 1 ")
  799.         return false
  800.     end
  801.  
  802.     --1.面板触发/3.开始战斗触发 要特殊处理
  803.     if __type ~= 1 and __type ~= 3 then
  804.         --筛选触发目标类型
  805.         if _buffTrigData.TargType ~= __targType and _buffTrigData.TargType ~= 0 then
  806.             -- print("              isBuffCanBeTrig false 2 ")
  807.             return false
  808.         end
  809.         if(_buffTrigData.Targ == 4 and FightLogic.getBuffTargWithModel(__buff.ExecutorProperty, __targ) ~= 1)then
  810.             return true
  811.         end
  812.         --筛选触发目标
  813.         if _buffTrigData.Targ ~= FightLogic.getBuffTargWithModel(__buff.ExecutorProperty, __targ) then
  814.             -- print("              isBuffCanBeTrig false 3 ")
  815.             return false
  816.         end
  817.     end
  818.  
  819.     --普攻或者技能时,如果是承受效果方 __targ必须处于命中状态
  820.     if (__type == 4 or __type == 5 or __type == 6) and _buffTrigData.TargType == 2 then
  821.         if not __targ._isBeit then
  822.             return false
  823.         end
  824.     end
  825.     --筛选位置条件
  826.     if _buffTrigData.Pos ~= 0 and
  827.        _buffTrigData.Pos ~= 9 and
  828.        _buffTrigData.Pos ~= __targ.static_col then
  829.         -- print("              isBuffCanBeTrig false 4 ")
  830.         return false
  831.     end
  832.  
  833.     --筛选属性条件(0/99说明不需要检测属性)
  834.     if _buffTrigData.AtriId == 0 or _buffTrigData.AtriId == 99 then
  835.         -- print("              isBuffCanBeTrig true 1 ")
  836.         return true
  837.     end
  838.  
  839.     --筛选属性条件(能量低于指定值,ok)
  840.     if _buffTrigData.AtriId == 6 and __targ._energyNum <= _buffTrigData.AtriValue then
  841.         -- print("              isBuffCanBeTrig true 2 ")
  842.         return true
  843.     end
  844.  
  845.     --筛选属性条件(生命低于指定值,ok)
  846.     if _buffTrigData.AtriId == 7 and __targ._hpNum <= _buffTrigData.AtriValue * __targ._att_property.MaxHp then
  847.         -- print("              isBuffCanBeTrig true 3 ")
  848.         return true
  849.     end
  850.  
  851.         -- print("              isBuffCanBeTrig false 5 ")
  852.     return false
  853. end
  854.  
  855. --获取一个目标可以被触发的buff
  856. -- __type : 触发类型(时机)
  857. -- __targ : 触发目标
  858. -- __targType : 触发目标类型
  859. -- __allBuffs : 需要检测的所有buff
  860. -- __retBuffs : 符合条件的所有buff
  861. function FightLogic.getTargAllCanBeTrigBuff(__type, __targ, __targType, __allBuffs, __retBuffs, deathNum)
  862.  
  863.     for i=#__allBuffs,1,-1 do
  864.         local _buff = __allBuffs[i]
  865.         -- print("          getTargAllCanBeTrigBuff __type = " .. __type..", __targType = "..__targType..", _buff.ExecutorProperty._static_index = ".._buff.ExecutorProperty._static_index..", _buff.ExecutorProperty._isEnemy = ",_buff.ExecutorProperty._isEnemy)
  866.         if FightLogic.isBuffCanBeTrig(__type, __targ, __targType, _buff) then
  867.             if _buff.TrigId == 1524700 then
  868.                 deathNum = deathNum or 1
  869.                 for i=1, deathNum do
  870.                     table.insert(__retBuffs, _buff)
  871.                 end
  872.                 table.remove(__allBuffs, i)
  873.             else
  874.                 table.insert(__retBuffs, _buff)
  875.                 table.remove(__allBuffs, i)
  876.             end
  877.         end
  878.     end
  879.  
  880. end
  881.  
  882. --获取所有英雄身上所有可以被触发的buff(触发类型(时机))
  883. -- __type : 触发类型(时机)
  884. -- __allBuffs : 需要检测的所有buff
  885. -- __retBuffs : 符合条件的所有buff
  886. -- __defenseDefault : 默认防守方
  887. function FightLogic.getAllCanBeTrigBuff(__type, __allBuffs, __retBuffs, __modelList, __defenseDefault, deathNum)
  888.  
  889.     for i,_model in ipairs(__modelList) do
  890.         if __defenseDefault then
  891.             FightLogic.getTargAllCanBeTrigBuff(__type,_model,2,__allBuffs,__retBuffs, deathNum)
  892.         else
  893.             if _model._isAttacker then
  894.                 -- print("      " .. _model._enemyName, _model._heroId, "index = ".._model.static_index, "_isAttacker"..", _isEnemy = ",_model._isEnemy,", static_col = ".._model.static_col)
  895.                 FightLogic.getTargAllCanBeTrigBuff(__type,_model,1,__allBuffs,__retBuffs)
  896.             elseif _model._isDefender then
  897.                 -- print("      " .. _model._enemyName, _model._heroId, "index = ".._model.static_index, "_isDefender"..", _isEnemy = ",_model._isEnemy,", static_col = ".._model.static_col)
  898.                 FightLogic.getTargAllCanBeTrigBuff(__type,_model,2,__allBuffs,__retBuffs)
  899.             end
  900.         end
  901.     end
  902.  
  903.     return _retBuffs
  904. end
  905.  
  906. --检测所有 model 是否死亡(生命值 <= 0 视为死亡)
  907. function FightLogic.checkAllModelDeath(__modelList)
  908.     for i,_model in ipairs(__modelList) do
  909.         if _model.activate then
  910.             if _model._hpNum <= 0 then
  911.                 _model:markedDeath()
  912.             end
  913.         end
  914.     end
  915. end
  916.  
  917. --检测所有 model 生命值 <= 0 立刻执行死亡方法
  918. function FightLogic.checkAllModelRealDeath(__modelList)
  919.     for i,_model in ipairs(__modelList) do
  920.         FightLogic.debugLog("        ------ checkAllModelRealDeath " .. _model._enemyName.._model._heroId.." index = ".._model.static_index.." ".._model._energyNum.." ".._model._energyMax.." ".._model._hpNum)
  921.         -- if _model.activate then
  922.             if _model._hpNum <= 0 then
  923.                 if _model.activate then
  924.                     _model.activate = false
  925.                 end
  926.                 _model:runDeath()
  927.             end
  928.         -- end
  929.     end
  930. end
  931.  
  932. --获取所有英雄身上所有buff
  933. function FightLogic.getAllModelBuff(__modelList)
  934.     local _allBuffs = {}
  935.  
  936.     for i,_model in ipairs(__modelList) do
  937.         for i,_buff in ipairs(_model._giveBuffList) do
  938.             if _model.activate then
  939.                 table.insert(_allBuffs, _buff)
  940.             end
  941.         end
  942.     end
  943.  
  944.     return _allBuffs
  945. end
  946.  
  947. --获取一个buff的执行者(发出buff的那个model)
  948. --__executorProperty : buff的执行者属性
  949. --__notActivateOk : true 表示可以筛选activate=false的model
  950. function FightLogic.getBuffExecutor(__modelList, __executorProperty,__notActivateOk)
  951.     if not __notActivateOk then __notActivateOk = false end
  952.  
  953.     -- print("   getBuffExecutor : "..__executorProperty._static_index,__executorProperty._isEnemy,__executorProperty._battleId,__notActivateOk)
  954.     for i,_model in ipairs(__modelList) do
  955.         -- print("       getBuffExecutor : ".._model.static_index,_model._isEnemy,_model._battleId,_model.activate)
  956.         if (_model.activate or __notActivateOk) and __executorProperty._static_index == _model.static_index and __executorProperty._isEnemy == _model._isEnemy and __executorProperty._battleId == _model._battleId then
  957.             -- print("        ret ")
  958.             return _model
  959.         end
  960.     end
  961.  
  962.     return nil
  963. end
  964.  
  965. --buff是否命中
  966. function FightLogic.isBuffHit(__buff, __buffTarget)
  967.     local _hitRate = FightLogic.getBuffHitRate(__buff, __buffTarget)
  968.     -- --print("isBuffHit _hitRate is ", _hitRate)
  969.     if _hitRate >= 1 then
  970.         return true
  971.     elseif _hitRate <= 0 then
  972.         return false
  973.     end
  974.  
  975.     FightLogic.debugLog("call FightingRandom c")
  976.     return FightLogic.FightingRandom() < _hitRate
  977. end
  978.  
  979. --添加buff到model
  980. -- __getbuffs       需要添加的buff
  981. -- __attackTargets  当前被攻击者(不需要了)
  982. -- __notActivateOk  是否添加到not activate的model
  983. function FightLogic.addBuffToModels(__modelList, __getbuffs, __attackTargets, __notActivateOk)
  984.  
  985.     --添加buff到英雄
  986.     for i,_buff in ipairs(__getbuffs) do
  987.         -- print("_buff ", json.encode(_buff))
  988.         -- print("TargetId ", json.encode(_buff.TargetId))
  989.         local _targetData = Utils:table_deepcopy(WDConfig.Targ.getData(_buff.TargetId))
  990.         local _buffExecutor = FightLogic.getBuffExecutor(__modelList, _buff.ExecutorProperty, __notActivateOk)
  991.         local _buffTargetList = FightLogic.getTargetList(__modelList, _buffExecutor, _targetData, __notActivateOk)
  992.         if #_buffTargetList == 0 then
  993.             if _targetData.Type == 2 then
  994.                 _targetData.Type = 3
  995.             elseif _targetData.Type == 3 then
  996.                 _targetData.Type = 2
  997.             end
  998.             _buffTargetList = FightLogic.getTargetList(__modelList, _buffExecutor, _targetData, __notActivateOk)
  999.         end
  1000.         -- print("  ".._buff.TrigId.." "..json.encode(_targetData))
  1001.         -- print("  "..#_buffTargetList)
  1002.         for j,_buffTarget in ipairs(_buffTargetList) do
  1003.             -- print("    addBuffToModels check ".._buffTarget._enemyName, _buffTarget._heroId, "index = ".._buffTarget.static_index)
  1004.             --计算buff是否命中
  1005.             local _buffEffData = WDConfig.BuffEff.getData(_buff.EffectId)
  1006.             local _condiData = WDConfig.BuffCondi.getData(_buff.CondiId)
  1007.             if FightLogic.isBuffHit(_buff, _buffTarget)  then
  1008.                 --添加至英雄的buff预备执行列表
  1009.                 local _prepareBuff = {}
  1010.                 _prepareBuff.Value = _buff.Value    --效果值
  1011.                 _prepareBuff.IsNew = true           --是否是新加入的
  1012.                 _prepareBuff.aniType = false           --动画是否已经执行
  1013.                 _prepareBuff.ExecutorProperty = Utils:table_deepcopy(_buff.ExecutorProperty) --执行者属性
  1014.                 _prepareBuff.BuffId = _buff.TrigId.."-".._buff.TargetId.."-".._buff.EffectId.."-".._buff.CondiId .."-".._buff.Value  --用于区分buff 检测叠加 重复等
  1015.  
  1016.                 _prepareBuff.EffType    = _buffEffData.EffType
  1017.                 _prepareBuff.EffAtriId  = _buffEffData.EffAtriId
  1018.                 _prepareBuff.EffStatId  = _buffEffData.EffStatId
  1019.                 _prepareBuff.Icon       = _buffEffData.Icon
  1020.                 _prepareBuff.HitSpec    = _buffEffData.HitSpec
  1021.                 _prepareBuff.EndSpec    = _buffEffData.EndSpec
  1022.                 _prepareBuff.LastSpec   = _buffEffData.LastSpec
  1023.                 _prepareBuff.Priority   = _buffEffData.Priority
  1024.                 _prepareBuff.StealStart = _buffEffData.StealStart
  1025.                 _prepareBuff.StealFly   = _buffEffData.StealFly
  1026.                 _prepareBuff.StealEnd   = _buffEffData.StealEnd
  1027.                 _prepareBuff.EffSignId  = _buffEffData.EffSignId
  1028.  
  1029.                 _prepareBuff.CanSuperPos    = _condiData.CanSuperPos
  1030.                 _prepareBuff.CanRetrig      = _condiData.CanRetrig
  1031.                 _prepareBuff.CanUseOnline   = _condiData.CanUseOnline
  1032.                 _prepareBuff.EndBout        = _condiData.EndType == 1 and _condiData.EndValue or 99999
  1033.                 _prepareBuff.Global         = false                             --全局buffer,一般用于被动,或者永久存在的buffer
  1034.  
  1035.                 _buffTarget:addBuff(_prepareBuff)
  1036.             else
  1037.                 -- BoShen 2019-3-20 11:18:45 不可重复触发的buff特殊处理
  1038.                 if _condiData.CanRetrig == 2 then
  1039.                     --添加至英雄的buff预备执行列表
  1040.                     local _prepareBuff = {}
  1041.                     _prepareBuff.Value = _buff.Value    --效果值
  1042.                     _prepareBuff.IsNew = true           --是否是新加入的
  1043.                     _prepareBuff.aniType = false           --动画是否已经执行
  1044.                     _prepareBuff.ExecutorProperty = Utils:table_deepcopy(_buff.ExecutorProperty) --执行者属性
  1045.                     _prepareBuff.BuffId = _buff.TrigId.."-".._buff.TargetId.."-".._buff.EffectId.."-".._buff.CondiId .."-".._buff.Value  --用于区分buff 检测叠加 重复等
  1046.  
  1047.                     _prepareBuff.EffType    = _buffEffData.EffType
  1048.                     _prepareBuff.EffAtriId  = _buffEffData.EffAtriId
  1049.                     _prepareBuff.EffStatId  = _buffEffData.EffStatId
  1050.                     _prepareBuff.Icon       = _buffEffData.Icon
  1051.                     _prepareBuff.HitSpec    = _buffEffData.HitSpec
  1052.                     _prepareBuff.EndSpec    = _buffEffData.EndSpec
  1053.                     _prepareBuff.LastSpec   = _buffEffData.LastSpec
  1054.                     _prepareBuff.Priority   = _buffEffData.Priority
  1055.                     _prepareBuff.StealStart = _buffEffData.StealStart
  1056.                     _prepareBuff.StealFly   = _buffEffData.StealFly
  1057.                     _prepareBuff.StealEnd   = _buffEffData.StealEnd
  1058.                     _prepareBuff.EffSignId  = _buffEffData.EffSignId
  1059.  
  1060.                     _prepareBuff.CanSuperPos    = _condiData.CanSuperPos
  1061.                     _prepareBuff.CanRetrig      = _condiData.CanRetrig
  1062.                     _prepareBuff.CanUseOnline   = _condiData.CanUseOnline
  1063.                     _prepareBuff.EndBout        = _condiData.EndType == 1 and _condiData.EndValue or 99999
  1064.                     _prepareBuff.Global         = false                             --全局buffer,一般用于被动,或者永久存在的buffer
  1065.                    
  1066.                     _buffTarget:addBuffByMissHandle(_prepareBuff)
  1067.                 end
  1068.             end
  1069.         end
  1070.     end
  1071. end
  1072.  
  1073. --遍历所有model身上的buff,根据条件执行
  1074. --__isNew 是否只执行新加入的buff
  1075. --__runLimit -1 只执行异常状态(5.眩晕 6.冰冻 7.石化)的buff / 1 只执行非异常状态(5.眩晕 6.冰冻 7.石化)的buff / 0 全部执行
  1076. --__notActivateOk true 表示model处于非activate状态下课执行
  1077. --__note 注释
  1078. function FightLogic.executeAllModelsBuffs(__modelList, __isNew,__runLimit,__notActivateOk,__note)
  1079.     if not __notActivateOk then __notActivateOk = false end
  1080.     __note = __note and __note or ""
  1081.     -- print("")
  1082.     -- print("            ============ executeBuff start ("..__note..") ============")
  1083.     for i,_model in ipairs(__modelList) do
  1084.         local isExecuteBuffs = false
  1085.         if(__runLimit == 2 )then
  1086.             --如果是暴击印记但是不暴击就不执行
  1087.             if( _model._isBaoJi)then
  1088.                 isExecuteBuffs = true
  1089.             end
  1090.         elseif (_model.activate or __notActivateOk) then
  1091.             -- print("   " .. _model._enemyName, _model._heroId, "index = ".._model.static_index)
  1092.             isExecuteBuffs = true
  1093.         end
  1094.         if(isExecuteBuffs)then
  1095.             _model:executeBuffs(__isNew,__runLimit)
  1096.         end
  1097.     end
  1098.     -- print("            ============ executeBuff   end ("..__note..") ============")
  1099.     -- print("")
  1100. end
  1101.  
  1102. --获取英雄身上开始战斗时就触发的buff(1.面板触发/3.开始战斗触发)
  1103. function FightLogic.getOnFightingCanBeTrigBuff(__modelList, __target)
  1104.     local _getbuffs = {}
  1105.    
  1106.     FightLogic.getTargAllCanBeTrigBuff(1,__target,0,__target._giveBuffList,_getbuffs)
  1107.     FightLogic.getTargAllCanBeTrigBuff(3,__target,0,__target._giveBuffList,_getbuffs)
  1108.  
  1109.     FightLogic.addBuffToModels(__modelList, _getbuffs, {}, true)
  1110.  
  1111.     FightLogic.executeAllModelsBuffs(__modelList, true, 0, true, "开始战斗时,检测执行新加入的buff")
  1112. end
  1113.  
  1114. --检测所有 model (4.普攻 5.技能 6.普攻或技能 7.普攻闪避 8.//技能闪避 9.闪避 10.普攻暴击 11.技能暴击 12.暴击)buff
  1115. --__baojiOne  是否存在暴击
  1116. --__ShanbiOne 是否存在闪避
  1117. function FightLogic.checkAttackBuff(__modelList, __isNormalAttack,__baojiOne,__ShanbiOne,__attackTargets)
  1118.    
  1119.     -- print("checkAttackBuff ",__isNormalAttack,__baojiOne)
  1120.     --检测可以触发的buff(4.普攻 5.技能 6.普攻或技能 7.普攻闪避 8.//技能闪避 9.闪避 10.普攻暴击 11.技能暴击 12.暴击)
  1121.     local _allbuffs = FightLogic.getAllModelBuff(__modelList)
  1122.     local _getbuffs = {}
  1123.  
  1124.     --检测普攻或者主动技能可以被触发的buff
  1125.     FightLogic.getAllCanBeTrigBuff(__isNormalAttack and 4 or 5, _allbuffs, _getbuffs, __modelList)
  1126.     FightLogic.getAllCanBeTrigBuff(6, _allbuffs, _getbuffs, __modelList)
  1127.  
  1128.     --检测普攻闪避或者主动技能闪避可以被触发的buff
  1129.     if __ShanbiOne then
  1130.         FightLogic.getAllCanBeTrigBuff(__isNormalAttack and 7 or 8, _allbuffs, _getbuffs, __modelList)
  1131.         FightLogic.getAllCanBeTrigBuff(9, _allbuffs, _getbuffs, __modelList)
  1132.     end
  1133.  
  1134.     --检测普攻暴击或者主动技能暴击可以被触发的buff
  1135.     if __baojiOne then
  1136.         FightLogic.getAllCanBeTrigBuff(__isNormalAttack and 10 or 11, _allbuffs, _getbuffs, __modelList)
  1137.         FightLogic.getAllCanBeTrigBuff(12, _allbuffs, _getbuffs, __modelList)
  1138.     end
  1139.  
  1140.     -- print("_getbuffs ", json.encode(_getbuffs))
  1141.  
  1142.     FightLogic.addBuffToModels(__modelList, _getbuffs,__attackTargets)
  1143.  
  1144.     --触发buff
  1145.     FightLogic.executeAllModelsBuffs(__modelList, true, 1, false, "攻击命中或闪避时,检测执行新加入的buff")
  1146. end
  1147.  
  1148. --检测所有 model (13.任何伤害,15.死亡时触发)buff
  1149. function FightLogic.checkHurtAndDeathBuff(__modelList, __attackTargets,__defenseDefault)
  1150.  
  1151.     --检测可以触发的buff(13.任何伤害)
  1152.     if true then
  1153.         local _allbuffs = FightLogic.getAllModelBuff(__modelList)
  1154.         local _getbuffs = {}
  1155.  
  1156.         --检测任何伤害的buff(生命值低于一定范围)
  1157.         FightLogic.getAllCanBeTrigBuff(13, _allbuffs, _getbuffs, __modelList,__defenseDefault)
  1158.         -- print("_getbuffs ", json.encode(_getbuffs))
  1159.        
  1160.         --添加buff到英雄
  1161.         FightLogic.addBuffToModels(__modelList, _getbuffs,__attackTargets)
  1162.  
  1163.         FightLogic.executeAllModelsBuffs(__modelList, true, 0, false, "受到任何伤害时,检测执行新加入的buff")
  1164.  
  1165.     end
  1166.  
  1167.    
  1168.     local __modelNum = #__modelList
  1169.     -- 检测所有 model 是否死亡(生命值 <= 0 视为死亡) 要在buff执行之前执行
  1170.     FightLogic.checkAllModelDeath(__modelList)
  1171.     -- 大于现在数量,说明有英雄死亡
  1172.     if __modelNum > #__modelList then
  1173.         -- 检测可以触发的buff(15.死亡时触发的buff)
  1174.         local deathNum = __modelNum - #__modelList
  1175.         FightLogic.checkDeathBuff(__modelList,true,deathNum)
  1176.     end
  1177. end
  1178.  
  1179. --检测所有 model (15.死亡时触发)buff
  1180. function FightLogic.checkDeathBuff(__modelList, __defenseDefault, deathNum)
  1181.     --检测可以触发的buff(15.死亡时触发的buff)
  1182.     if true then
  1183.         local _allbuffs = FightLogic.getAllModelBuff(__modelList)
  1184.         local _getbuffs = {}
  1185.         --检测任何伤害的buff(生命值低于一定范围)
  1186.         FightLogic.getAllCanBeTrigBuff(15, _allbuffs, _getbuffs, __modelList, __defenseDefault, deathNum)
  1187.         -- print("_getbuffs ", json.encode(_getbuffs))
  1188.        
  1189.         --添加buff到英雄
  1190.         FightLogic.addBuffToModels(__modelList, _getbuffs)
  1191.  
  1192.         --检测所有 model 是否死亡(生命值 <= 0 视为死亡) 要在buff执行之前执行
  1193.         FightLogic.checkAllModelDeath(__modelList)
  1194.  
  1195.         FightLogic.executeAllModelsBuffs(__modelList, true, 0, false, "model死亡时,检测执行新加入的buff")
  1196.  
  1197.     end
  1198. end
  1199.  
  1200. --是否所有英雄怪物全部激活
  1201. function FightLogic.modelAllActivated(__modelList)
  1202.     local allActivated = true
  1203.     for i,_model in ipairs(__modelList) do
  1204.         if not _model.activate then
  1205.             allActivated = false
  1206.             break
  1207.         end
  1208.     end
  1209.     return allActivated
  1210. end
  1211.  
  1212. --是否英雄全部未激活
  1213. function FightLogic.heroAllNonactivated(__modelList)
  1214.     local allNonactivated = true
  1215.     for i,_model in ipairs(__modelList) do
  1216.         if not _model._isEnemy and _model.activate then
  1217.             allNonactivated = false
  1218.         end
  1219.     end
  1220.     return allNonactivated
  1221. end
  1222.  
  1223. --是否怪物全部未激活
  1224. function FightLogic.enemyAllNonactivated(__modelList)
  1225.     -- for i,_model in ipairs(__modelList) do
  1226.     --     FightLogic.debugLog("        ------ enemyAllNonactivated " .. _model._enemyName.._model._heroId.." index = ".._model.static_index.." ".._model._energyNum.." ".._model._energyMax.." ".._model._hpNum)
  1227.     -- end
  1228.     local allNonactivated = true
  1229.     for i,_model in ipairs(__modelList) do
  1230.         if _model._isEnemy and _model.activate then
  1231.             allNonactivated = false
  1232.         end
  1233.     end
  1234.     return allNonactivated
  1235. end
  1236.  
  1237. --是否英雄全部阵亡
  1238. function FightLogic.heroAllDeath(__modelList)
  1239.     -- for i,_model in ipairs(__modelList) do
  1240.     --     FightLogic.debugLog("        ------ heroAllDeath " .. _model._enemyName.._model._heroId.." index = ".._model.static_index.." ".._model._energyNum.." ".._model._energyMax.." ".._model._hpNum)
  1241.     -- end
  1242.     local allDeath = true
  1243.     for i,_model in ipairs(__modelList) do
  1244.         if not _model._isEnemy then
  1245.             allDeath = false
  1246.         end
  1247.     end
  1248.     return allDeath
  1249. end
  1250.  
  1251. --是否怪物全部阵亡
  1252. function FightLogic.enemyAllDeath(__modelList)
  1253.     -- for i,_model in ipairs(__modelList) do
  1254.     --     FightLogic.debugLog("        ------ enemyAllDeath " .. _model._enemyName.._model._heroId.." index = ".._model.static_index.." ".._model._energyNum.." ".._model._energyMax.." ".._model._hpNum)
  1255.     -- end
  1256.     local allDeath = true
  1257.     for i,_model in ipairs(__modelList) do
  1258.         if _model._isEnemy then
  1259.             allDeath = false
  1260.             break
  1261.         end
  1262.     end
  1263.     return allDeath
  1264. end
  1265.  
  1266. --如果存在攻击者或者被攻击者,视为正在战斗中
  1267. function FightLogic.isFighting(__modelList)
  1268.     for i,_model in ipairs(__modelList) do
  1269.         if _model._isAttacker then
  1270.             return true
  1271.         elseif _model._isDefender then
  1272.             return true
  1273.         end
  1274.     end
  1275.  
  1276.     return false
  1277. end
  1278.  
  1279. --计算伤害值
  1280. -- •主伤害=(攻击-防御*(1-攻击方破甲)/5)*效果值[1]*暴击伤害系数[2]*减伤系数[3]*(1+技能伤害增加[7](如果是主动技能))
  1281. -- •次要伤害1(职业伤害)=主伤害*职业伤害系数-主伤害    
  1282. -- *如果<=0则不显示
  1283. -- •次要伤害2(阵营伤害)=主伤害*职业伤害系数*阵营伤害系数-主伤害-次要伤害1
  1284. --  *如果<=0则不显示
  1285. -- •次要伤害3(状态伤害)=主伤害*职业伤害系数*阵营伤害系数*状态伤害系数-主伤害-次要伤害1-次要伤害2
  1286. --  *如果<=0则不显示
  1287.  
  1288. -- __isBaoji            是否暴击
  1289. -- __value              技能或者buff的效果值
  1290. -- __isActiveSkill      是否主动技能
  1291. -- __executeProperty    攻击方或者buff执行者的属性
  1292. -- __model 是防守方
  1293. function FightLogic.getHurtNum(__model, __isBaoji, __value, __isActiveSkill, __executeProperty)
  1294.     local _attackerProperty = __executeProperty     --攻击方属性
  1295.     local _defenderProperty = __model._att_property     --防守方属性
  1296.  
  1297.     --职业伤害系数=1+攻击方职业额外伤害-防守方职业减少伤害
  1298.     local _careerRate   = 1 + _attackerProperty["CareerExt_".._defenderProperty._career] - _defenderProperty["CareerRedu_".._attackerProperty._career]
  1299.  
  1300.     --阵营伤害系数=1+30%(如果阵营克制)
  1301.     local _factionRate  = 1 + (_attackerProperty._advanFact == _defenderProperty._faction and _attackerProperty._advanExDama or 0)
  1302.  
  1303.     --状态伤害系数=攻击方.对流血单位额外伤害(如果受击方处于流血状态)]*…燃烧…*…中毒…*…禁魔…*…眩晕…*…冰冻…*…石化…
  1304.     local _state = {__model._isBleedState,__model._isFireState,__model._isPoisonState,__model._isForbidMagicState,__model._isStunState,__model._isFrozenState > 0,__model._isStoneState > 0}
  1305.     local _stateRate = 1
  1306.     for i=1,#_state do
  1307.         if _state[i] then
  1308.             _stateRate = _stateRate + _attackerProperty["StateExt_"..i]
  1309.         end
  1310.     end
  1311.  
  1312.     --暴击伤害系数
  1313.     local _baojiRate = __isBaoji and (1.5 + math.max(_attackerProperty.CritDamage, WDConfig.Atri.getItem("25","Min"))) or 1
  1314.  
  1315.     --技能伤害增加=(1+技能伤害增加[7](如果是主动技能))
  1316.     local _skillDamage = __value + ( __isActiveSkill and math.max(_attackerProperty.SkillDamage, WDConfig.Atri.getItem("21","Min")) or 0)
  1317.  
  1318.     --主伤害1=(攻击-防御*(1-攻击方破甲)/5)
  1319.     --local _mainHurt = _attackerProperty.Attack - _defenderProperty.Armor * (1 - math.min(_attackerProperty.ArmorBreak, WDConfig.Atri.getItem("26","Max"))) / 5
  1320.    
  1321.     --LLH修改
  1322.     --护甲减伤 =1-(防御方护甲等级-攻击方破甲等级+20)*0.01
  1323.     local _ReduceDamage = (math.min(_defenderProperty.Armor, WDConfig.Atri.getItem("10","Max")) - math.min(_attackerProperty.ArmorBreak, WDConfig.Atri.getItem("26","Max"))+20)*0.01
  1324.    
  1325.     _ReduceDamage = 1 - FightLogic.getMiddleValue(tonumber(FightLogic._ReduceDamageLimit[2]),tonumber(FightLogic._ReduceDamageLimit[1]),_ReduceDamage)
  1326.     --变更:【造成总伤害=攻击*护甲减伤[1]*(效果值+技能伤害增加(如果是主动技能)[2])*暴击伤害系数*减伤系数*职业伤害系数*阵营伤害系数*状态伤害系数】
  1327.     local _mainHurt =  _attackerProperty.Attack * _ReduceDamage
  1328.     --减伤系数=(1-减伤率)+(1+真实伤害)
  1329.     local _reduceRate = (1 - math.min(_defenderProperty.ReduceDamage, WDConfig.Atri.getItem("28","Max")) ) * (1 + math.max(_attackerProperty.TrueDamage, WDConfig.Atri.getItem("21","Min")))
  1330.  
  1331.     --主伤害
  1332.     -- local _hurtNum = (_mainHurt < 1 and _attackerProperty.Attack*0.6 or _mainHurt)
  1333.     --              * __value
  1334.     --              * _baojiRate
  1335.     --              * _reduceRate
  1336.     --              * _skillDamage
  1337.     local _hurtNum = _mainHurt * _skillDamage  * _baojiRate * _reduceRate * _careerRate * _factionRate * _stateRate
  1338.  
  1339.     --次要伤害1
  1340.     local _hurtNum1 =  0-- _hurtNum * _careerRate - _hurtNum
  1341.  
  1342.     --次要伤害2
  1343.     local _hurtNum2 =  0-- _hurtNum * _careerRate * _factionRate - _hurtNum - _hurtNum1
  1344.  
  1345.     --次要伤害3
  1346.     local _hurtNum3 = 0--_hurtNum * _careerRate * _factionRate * _stateRate - _hurtNum - _hurtNum1 - _hurtNum2
  1347.  
  1348.     FightLogic.debugLog("getHurtNum ",__model._enemyName..__model._heroId.." index = "..__model.static_index,__model._hpNum,(_hurtNum+_hurtNum1+_hurtNum2+_hurtNum3))
  1349. ------------------------------------------------------
  1350.  
  1351.     --伤害数值
  1352.     _hurtNum = _hurtNum < 0 and 0 or _hurtNum
  1353.     _hurtNum1 = _hurtNum1 < 0 and 0 or _hurtNum1
  1354.     _hurtNum2 = _hurtNum2 < 0 and 0 or _hurtNum2
  1355.     _hurtNum3 = _hurtNum3 < 0 and 0 or _hurtNum3
  1356.     local ret1 = {math.floor(_hurtNum),math.floor(_hurtNum1),math.floor(_hurtNum2),math.floor(_hurtNum3)}
  1357.  
  1358.     --是否发生克制
  1359.     local ret2 = false
  1360.     if _careerRate > 1 or _factionRate > 1 then
  1361.         ret2 = true
  1362.     end
  1363.  
  1364.     return ret1,ret2
  1365. end
  1366. --取中间的值
  1367. function FightLogic.getMiddleValue(min,max,nowValue)
  1368.     if(min > nowValue)then
  1369.         return min
  1370.     elseif(max < nowValue)then
  1371.         return max
  1372.     end
  1373.     return nowValue
  1374. end
  1375. -- Buff对敌方命中率=Buff表配置的命中率-受击方状态抗性(如果是状态类buff)- 受击方控制抗性(如果是控制类buff)
  1376. -- Buff对友方命中率=Buff表配置的命中率
  1377. -- *如果附加命中为必中,必中
  1378. function FightLogic.getBuffHitRate(__buff, __buffTarget)
  1379.     local _hitRate = nil
  1380.  
  1381.     if __buff.ExHit == 1     and __buffTarget._att_property._career == 1 then
  1382.         _hitRate = 1
  1383.     elseif __buff.ExHit == 2 and __buffTarget._att_property._career == 2 then
  1384.         _hitRate = 1
  1385.     elseif __buff.ExHit == 3 and __buffTarget._att_property._career == 3 then
  1386.         _hitRate = 1
  1387.     elseif __buff.ExHit == 4 and __buffTarget._att_property._career == 4 then
  1388.         _hitRate = 1
  1389.     elseif __buff.ExHit == 5 and __buffTarget._att_property._career == 5 then
  1390.         _hitRate = 1
  1391.     elseif __buff.ExHit == 9 then
  1392.         _hitRate = 1
  1393.     else
  1394.         _hitRate = __buff.Hit
  1395.         if __buff.ExecutorProperty._isEnemy ~= __buffTarget._isEnemy then
  1396.  
  1397.             local _buffEffData = WDConfig.BuffEff.getData(__buff.EffectId)
  1398.  
  1399.             --状态类buff 1.流血 2.燃烧 3.中毒 4.禁魔 5.眩晕 6.冰冻 7.石化
  1400.             if _buffEffData.EffStatId >=1 and _buffEffData.EffStatId <= 7 then
  1401.                 _hitRate = _hitRate - __buffTarget._att_property["StateRisi_".._buffEffData.EffStatId]
  1402.             end
  1403.  
  1404.             --控制类buff 4.禁魔 5.眩晕 6.冰冻 7.石化
  1405.             if _buffEffData.EffStatId >=4 and _buffEffData.EffStatId <= 7 then
  1406.                 _hitRate = _hitRate - __buffTarget._att_property.ControlImmune
  1407.             end
  1408.         end
  1409.     end
  1410.  
  1411.     return math.floor(_hitRate*10000)/10000
  1412. end
  1413.  
  1414. --设置随机种子(正整数)(战斗中使用)
  1415. function FightLogic.FightingRandomSeed(seed)
  1416.     gameSeedRandom(1, seed)
  1417.     -- globalManager.__index = 1
  1418.     -- print("yyp Fighting ",seed)
  1419. end
  1420.  
  1421. -- 取得随机数(战斗中使用)
  1422. -- 无参调用, 产生 (0,1) 之间的浮点随机数
  1423. -- 只有参数a, 产生 1-a(不包含) 之间的整数
  1424. -- 有两个参数a, b, 产生 a-b(不包含) 之间的随机整数
  1425. -- cclog(FightLogic:FightingRandom(0,10000))
  1426. -- cclog(FightLogic:FightingRandom())
  1427. -- cclog(FightLogic:FightingRandom(10))
  1428. function FightLogic.FightingRandom(a,b)
  1429.     local ret = 0
  1430.     if not a and not b then
  1431.         local min = 0
  1432.         local max = 10000
  1433.         ret = gameRandom(1, min,max)/max
  1434.     elseif not b then
  1435.         local min = 1
  1436.         local max = a
  1437.         ret = gameRandom(1, min,max)
  1438.     else
  1439.         local min = a
  1440.         local max = b
  1441.         ret = gameRandom(1, min,max)
  1442.     end
  1443.     -- globalManager.__index = globalManager.__index + 1
  1444.  
  1445.     return ret
  1446. end
  1447.  
  1448. function FightLogic.debugLog(...)
  1449.     -- debugManager:addLog(...)
  1450. end
  1451.  
  1452. --------------------------------------------------------------------
  1453. --------------------------------------------------------------------
  1454. --------------------------------------------------------------------
  1455.  
  1456. --是否解锁加速
  1457. function FightLogic.speedUpIsUnlock(__lv)
  1458.     if __lv == nil then
  1459.         __lv = globalManager._playerData.playerLevel
  1460.     end
  1461.  
  1462.     local ret = (__lv >= globalManager._CommonData._funcData.speedLv) or
  1463.                 (globalManager._playerData.vipLevel >= globalManager._CommonData._funcData.speedVip)
  1464.  
  1465.     return ret
  1466. end
  1467.  
  1468. --是否解锁跳过战斗
  1469. function FightLogic.SkipIsUnlock(__lv)
  1470.     if __lv == nil then
  1471.         __lv = globalManager._playerData.playerLevel
  1472.     end
  1473.  
  1474.     local ret = (__lv >= globalManager._CommonData._funcData.skipLv) or
  1475.                 (globalManager._playerData.vipLevel >= globalManager._CommonData._funcData.skipVip)
  1476.  
  1477.     return ret
  1478. end
  1479. return FightLogic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement