diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/AdvancedEnemy.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/AdvancedEnemy.cs index 46b5c5c..5104a60 100644 --- a/DungeonShooting_Godot/src/game/activity/role/enemy/AdvancedEnemy.cs +++ b/DungeonShooting_Godot/src/game/activity/role/enemy/AdvancedEnemy.cs @@ -170,7 +170,7 @@ if (AttackState == AiAttackState.LockingTime) //锁定玩家状态 { - var aiLockRemainderTime = weapon.GetAiLockRemainderTime(); + var aiLockRemainderTime = GetLockRemainderTime(); MountLookTarget = aiLockRemainderTime >= weapon.Attribute.AiAttackAttr.LockAngleTime; //更新瞄准辅助线 if (weapon.Attribute.AiAttackAttr.ShowSubline) @@ -354,7 +354,10 @@ return false; } - public override void Attack() + /// + /// 敌人发动攻击 + /// + public virtual void EnemyAttack() { var weapon = WeaponPack.ActiveItem; if (weapon != null) @@ -498,6 +501,19 @@ { return _lockTargetTime; } + + /// + /// 获取锁定目标的剩余时间 + /// + public float GetLockRemainderTime() + { + var weapon = WeaponPack.ActiveItem; + if (weapon == null) + { + return 0; + } + return weapon.Attribute.AiAttackAttr.LockingTime - _lockTargetTime; + } /// /// 强制设置锁定目标时间 diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs index a27cedc..70780b3 100644 --- a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs +++ b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs @@ -55,9 +55,21 @@ /// Ai攻击状态, 调用 Attack() 函数后会刷新 /// public AiAttackState AttackState { get; private set; } + + /// + /// 攻击时间间隔 + /// + public float AttackInterval { get; set; } = 3; + + /// + /// 锁定目标时间 + /// + public float LockingTime { get; set; } = 2; //锁定目标时间 private float _lockTargetTime = 0; + //攻击冷却计时器 + private float _attackTimer = 0; public override void OnInit() { @@ -95,7 +107,60 @@ public override void Attack() { + if (_attackTimer > 0) //开火间隙 + { + AttackState = AiAttackState.AttackInterval; + } + else if (GetLockRemainderTime() > 0) //锁定目标时间 + { + AttackState = AiAttackState.LockingTime; + } + else //正常攻击 + { + AttackState = AiAttackState.Attack; + _attackTimer = AttackInterval; + EnemyAttack(); + } + } + + /// + /// 敌人发动攻击 + /// + public virtual void EnemyAttack() + { Debug.Log("触发攻击"); + + } + + protected override void Process(float delta) + { + base.Process(delta); + if (IsDie) + { + return; + } + + if (_attackTimer > 0) + { + _attackTimer -= delta; + } + //目标在视野内的时间 + var currState = StateController.CurrState; + if (currState == AiStateEnum.AiSurround || currState == AiStateEnum.AiFollowUp) + { + if (_attackTimer <= 0) //必须在可以开火时记录时间 + { + _lockTargetTime += delta; + } + else + { + _lockTargetTime = 0; + } + } + else + { + _lockTargetTime = 0; + } } protected override void OnHit(int damage, bool realHarm) @@ -213,6 +278,14 @@ } /// + /// 获取锁定目标的剩余时间 + /// + public float GetLockRemainderTime() + { + return LockingTime - _lockTargetTime; + } + + /// /// 强制设置锁定目标时间 /// public void SetLockTargetTime(float time) diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/advancedState/AiFollowUpState.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/advancedState/AiFollowUpState.cs index 904b327..f635a9d 100644 --- a/DungeonShooting_Godot/src/game/activity/role/enemy/advancedState/AiFollowUpState.cs +++ b/DungeonShooting_Godot/src/game/activity/role/enemy/advancedState/AiFollowUpState.cs @@ -109,7 +109,7 @@ if (inAttackRange) //在攻击范围内 { //发起攻击 - Master.Attack(); + Master.EnemyAttack(); //距离够近, 可以切换到环绕模式 if (Master.GlobalPosition.DistanceSquaredTo(playerPos) <= Mathf.Pow(Utils.GetConfigRangeStart(weapon.Attribute.Bullet.DistanceRange), 2) * 0.7f) diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/advancedState/AiSurroundState.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/advancedState/AiSurroundState.cs index 39cdf6c..a7b2fe4 100644 --- a/DungeonShooting_Godot/src/game/activity/role/enemy/advancedState/AiSurroundState.cs +++ b/DungeonShooting_Godot/src/game/activity/role/enemy/advancedState/AiSurroundState.cs @@ -158,7 +158,7 @@ else { //发起攻击 - Master.Attack(); + Master.EnemyAttack(); } } } diff --git a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs index 43295bc..ae423dc 100644 --- a/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/activity/weapon/Weapon.cs @@ -2070,19 +2070,6 @@ return flag; } - /// - /// 获取Ai锁定目标的剩余时间 - /// - public float GetAiLockRemainderTime() - { - if (Master is AdvancedEnemy enemy) - { - return Attribute.AiAttackAttr.LockingTime - enemy.GetLockTime(); - } - - return 0; - } - // /// // /// 获取 Ai 对于该武器的评分, 评分越高, 代表 Ai 会越优先选择该武器, 如果为 -1, 则表示 Ai 不会使用该武器 // ///