(client) feat:实现子弹的生成

This commit is contained in:
m0_75251201
2025-08-17 11:16:55 +08:00
parent 12a4f9efaa
commit ed7ecdb226
22 changed files with 436 additions and 182 deletions

View File

@ -77,7 +77,7 @@ namespace AI
public class TrackPlayerJob : JobBase
{
private EntityPrefab currentTarget; // 当前追踪的目标玩家
private List<EntityPrefab> players; // 玩家实体列表
private LinkedList<EntityPrefab> players; // 玩家实体列表
public override void StartJob(Entity.Entity target)
{
@ -87,13 +87,13 @@ namespace AI
protected override void UpdateJob()
{
if (currentTarget == null || currentTarget.entity.IsDead)
if (!currentTarget || currentTarget.entity.IsDead)
{
// 如果当前目标无效,则重新查找最近的玩家
UpdateTarget();
}
if (currentTarget != null)
if (currentTarget)
{
var targetPosition = new Vector3(currentTarget.Position.x, currentTarget.Position.y, 0);
entity.SetTarget(targetPosition);
@ -114,7 +114,7 @@ namespace AI
currentTarget = GetNearestPlayer(players);
}
private EntityPrefab GetNearestPlayer(List<EntityPrefab> players)
private EntityPrefab GetNearestPlayer(LinkedList<EntityPrefab> players)
{
EntityPrefab nearestPlayer = null;
float minDistance = float.MaxValue;
@ -144,7 +144,7 @@ namespace AI
protected override void UpdateJob()
{
if (player == null || !IsPlayerInRange())
if (!player || !IsPlayerInRange())
{
StopJob(); // 如果玩家不在范围内,停止攻击工作
return;
@ -167,11 +167,11 @@ namespace AI
base.StartJob(target);
// 查找最近的玩家作为目标
List<EntityPrefab> players = Managers.EntityManage.Instance.FindEntitiesByFaction("Player");
LinkedList<EntityPrefab> players = Managers.EntityManage.Instance.FindEntitiesByFaction("Player");
player = GetNearestPlayer(players);
}
private EntityPrefab GetNearestPlayer(List<EntityPrefab> players)
private EntityPrefab GetNearestPlayer(LinkedList<EntityPrefab> players)
{
EntityPrefab nearestPlayer = null;
float minDistance = float.MaxValue;
@ -197,7 +197,7 @@ namespace AI
private bool IsPlayerValid(EntityPrefab player)
{
return player != null && !player.entity.IsDead;
return player && !player.entity.IsDead;
}
}
public class RangedAttackJob : JobBase
@ -206,7 +206,7 @@ namespace AI
protected override void UpdateJob()
{
if (player == null || !IsPlayerValid(player))
if (!player || !IsPlayerValid(player))
{
StopJob(); // 如果当前目标无效,停止工作
return;
@ -256,11 +256,11 @@ namespace AI
base.StartJob(target);
// 查找最近的玩家作为目标
List<EntityPrefab> players = Managers.EntityManage.Instance.FindEntitiesByFaction("Player");
var players = Managers.EntityManage.Instance.FindEntitiesByFaction("Player");
player = GetNearestPlayer(players);
}
private EntityPrefab GetNearestPlayer(List<EntityPrefab> players)
private EntityPrefab GetNearestPlayer(LinkedList<EntityPrefab> players)
{
EntityPrefab nearestPlayer = null;
float minDistance = float.MaxValue;
@ -286,7 +286,7 @@ namespace AI
private bool IsPlayerValid(EntityPrefab player)
{
return player != null && !player.entity.IsDead;
return player && !player.entity.IsDead;
}
private const float MaxTrackDistance = 20f; // 最大追踪距离