--- 此脚本基本是抄写的 Decision_WorldBossFight ,而 Decision_WorldBossFight 又是基本抄写的 Decision_TargetOnlyBossFight 。 --- local BuffSkillSystem = require"Battle/Logic/Entity/System/BuffSkillSystem" local base = require("Battle/Logic/AI/Decision/Decision_Base") local Decision_WorldBossRobotFight = class("Decision_WorldBossRobotFight", base) local SEARCH_ENEMY_DIS_SQR = FP.newV1(10000) local NEW_WANDER_POS_POSIBILITY = FP.newV1(0.05) local KEY_POS_GODBEAST = LuaConst.ESkillKeyPosition.BuffSkill2 function Decision_WorldBossRobotFight:initialize(entity) base.initialize(self,entity) --类型 self.Type = LuaConst.DecisionType.WorldBossRobotFight --瞬时 self.IsOnce = false self.SCENE_RADIUS = FP.newV1(22) self.CENTER = FP.newV2(90,0) self.REFRESH_FORCE_TARGET_FRAME_INTERVAL = DataSheetManager.ConstData:GetDataByID("WorldBossAvengeSearchForEnemyInterval").IntValue self.AVENGE_POSSIBLE = DataSheetManager.ConstData:GetDataByID("WorldBossAvengePossible").FloatValue -- 复仇概率 end local MY_CAMPID_WHEN_TUTORIAL = 1 local ENEMY_CAMPID_WHEN_TUTORIAL = 2 --[[ 进入该Decision --]] function Decision_WorldBossRobotFight:DecisionIn(entity, decisionData) base.DecisionIn(self,entity,decisionData) SystemManager.SetTarget(entity,nil) --机器人支持↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ if entity._logicInitData.BattleMemberType == LuaConst.BattleMemberType.Robot_Hero then local campID = entity:GetCampID() if campID == MY_CAMPID_WHEN_TUTORIAL then --如果是我方机器人,则是来助战的,就盯着对面的人打,所以需要设置ForceTeam entity.components.target:SetForceTeam(1000) end end --↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ --由于死亡时不会调用DecisionOut,所以这里需要清除一下 entity.components.aiBase:ClearDecisionRecord(decisionData) end --[[ 退出该Decision --]] function Decision_WorldBossRobotFight:DecisionOut(entity, decisionData) SystemManager.SetTarget(entity,nil) entity.components.target:SetForceTarget(nil) entity.components.aiBase:ClearDecisionRecord(decisionData) end --[[ 能否进入 --]] function Decision_WorldBossRobotFight:CanEnter(entity, decisionData, command) local autoFightComponent = entity.components.autoFight return autoFightComponent.IsSyncAuto end --[[ 能否退出 --]] function Decision_WorldBossRobotFight:CanExit(entity, decisionData, command) local autoFightComponent = entity.components.autoFight return not autoFightComponent.IsSyncAuto end function Decision_WorldBossRobotFight:IntervalRefreshForceTarget(decisionRecordDic, aiBaseComponent, targetComponent, entity) if decisionRecordDic.refreshForceTargetEla == nil then decisionRecordDic.refreshForceTargetEla = 0 -- 首次进入此AI决策,不要立即刷新,等self.REFRESH_FORCE_TARGET_FRAME_INTERVAL长时间 return end if decisionRecordDic.refreshForceTargetEla >= self.REFRESH_FORCE_TARGET_FRAME_INTERVAL then decisionRecordDic.refreshForceTargetEla = 0 if decisionRecordDic.isAvenge and decisionRecordDic.avengeEntity:IsAlive() then return end decisionRecordDic.isAvenge = false decisionRecordDic.avengeEntity = nil -- 复仇对象 targetComponent:SetForceTarget(nil) local lastHurtMeEntity = entity.components.record.lastHurtMeEnemy if lastHurtMeEntity then lastHurtMeEntity = lastHurtMeEntity:GetOriginEntity() end if lastHurtMeEntity and not lastHurtMeEntity.isBoss and lastHurtMeEntity:IsAlive() and lastHurtMeEntity:IsActive() then local randomVal = LogicRandom.GetRandom01(entity, 20240520) if randomVal <= self.AVENGE_POSSIBLE then -- 需要找最近时间打过我的敌人 targetComponent:SetForceTarget(lastHurtMeEntity) targetComponent:SetTarget(targetComponent.ForceTarget) decisionRecordDic.isAvenge = true -- 在复仇状态 decisionRecordDic.avengeEntity = lastHurtMeEntity end end else decisionRecordDic.refreshForceTargetEla = decisionRecordDic.refreshForceTargetEla + aiBaseComponent:GetAiUpdateInterval() end end local MONSTER_TYPE_2_SERACH_TYPE_PLUS = 100 function Decision_WorldBossRobotFight:SearchBoss(entity, targetComponent) local mainBoss = BattleDataGetter.GetMainBoss() if mainBoss then --找寻主Boss SystemManager.OnSearchTarget(entity, 1, SEARCH_ENEMY_DIS_SQR, 1, mainBoss._logicInitData._characterData.MonsterType + LuaConst.MONSTER_TYPE_2_SERACH_TYPE_PLUS) targetComponent:SetForceTarget(targetComponent.Target) end end local PAUSE_FRAME_AFTER_USER_INPUT = 10 --有玩家输入后,该Decision暂停几帧 --[[ 输出指令 --]] function Decision_WorldBossRobotFight:SetCommand(entity, decisionData, command) repeat local aiBaseComponent = entity.components.aiBase local decisionRecordDic = aiBaseComponent:GetDecisionRecordDic(decisionData) if command.MoveDir ~= FP.Const.Vector2_Zero or command.SkillIndex ~= 0 then --如果有玩家输入,记录这个输入的时间,并跳出AI运行 decisionRecordDic.lastUserInputFrame = LogicUpdateManager._clientHandleFrame entity.components.target:SetForceTarget(nil) command.DontHandle = true break end if decisionRecordDic.lastUserInputFrame and LogicUpdateManager._clientHandleFrame - decisionRecordDic.lastUserInputFrame < PAUSE_FRAME_AFTER_USER_INPUT then --策划需求:如果玩家有输入,就得暂停AI运行一段时间 command.DontHandle = true break end local targetComponent = entity.components.target self:IntervalRefreshForceTarget(decisionRecordDic, aiBaseComponent, targetComponent, entity)--间隔一定时间根据强制队伍刷新强制目标 if decisionRecordDic.avengeEntity and decisionRecordDic.avengeEntity ~= targetComponent.ForceTarget then targetComponent:SetForceTarget(decisionRecordDic.avengeEntity) end if targetComponent.ForceTarget and targetComponent.ForceTarget:IsAlive() and targetComponent.ForceTarget:IsActive() then if targetComponent.Target ~= targetComponent.ForceTarget then SystemManager.SetTarget(entity,targetComponent.ForceTarget) end end if targetComponent.Target == nil then self:SearchBoss(entity, targetComponent) end if targetComponent.Target then --有目标就追击目标 self:CommandChaseUseSkill(entity,command,decisionData,decisionRecordDic) if self:CanUseBuffSkill(entity, decisionRecordDic, 2) then BuffSkillSystem.ReleaseBuffSkill(entity, KEY_POS_GODBEAST) --无脑调,如果放不了就不会放 end end until true end return Decision_WorldBossRobotFight