diff --git a/DungeonShooting_Godot/src/game/activity/role/Role.cs b/DungeonShooting_Godot/src/game/activity/role/Role.cs
index 1767014..7b36d4d 100644
--- a/DungeonShooting_Godot/src/game/activity/role/Role.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/Role.cs
@@ -451,6 +451,20 @@
{
}
+ public override void EnterTree()
+ {
+ if (!World.Role_InstanceList.Contains(this))
+ {
+ World.Role_InstanceList.Add(this);
+ }
+ }
+
+ public override void ExitTree()
+ {
+ World.Role_InstanceList.Remove(this);
+ }
+
+
public override void OnInit()
{
RoleState = OnCreateRoleState();
diff --git a/DungeonShooting_Godot/src/game/activity/role/ai/AiRole.cs b/DungeonShooting_Godot/src/game/activity/role/ai/AiRole.cs
index 56766a5..a459fe4 100644
--- a/DungeonShooting_Godot/src/game/activity/role/ai/AiRole.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/ai/AiRole.cs
@@ -86,6 +86,11 @@
///
public bool HasMoveDesire { get; private set; } = true;
+ ///
+ /// 临时存储攻击目标, 获取该值请调用 GetAttackTarget() 函数
+ ///
+ protected Role AttackTarget { get; set; } = null;
+
public override void OnInit()
{
base.OnInit();
@@ -115,7 +120,18 @@
///
public virtual Role GetAttackTarget()
{
- return World.Player;
+ if (AttackTarget == null || AttackTarget.IsDestroyed || !IsEnemy(AttackTarget))
+ {
+ foreach (var role in World.Role_InstanceList)
+ {
+ if (role.AffiliationArea == AffiliationArea && IsEnemy(role))
+ {
+ AttackTarget = role;
+ break;
+ }
+ }
+ }
+ return AttackTarget;
}
///
diff --git a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs
index c17d753..9db906b 100644
--- a/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs
+++ b/DungeonShooting_Godot/src/game/activity/role/enemy/Enemy.cs
@@ -91,20 +91,7 @@
roleState.Gold = Mathf.Max(0, Utils.Random.RandomConfigRange(enemyBase.Gold));
return roleState;
}
-
- public override void EnterTree()
- {
- if (!World.Role_InstanceList.Contains(this))
- {
- World.Role_InstanceList.Add(this);
- }
- }
-
- public override void ExitTree()
- {
- World.Role_InstanceList.Remove(this);
- }
-
+
protected override void OnDie()
{
var effPos = Position + new Vector2(0, -Altitude);