(client)feat:实现子弹定义以及生成,实现初始化动画,实现血条 (#43)
Co-authored-by: zzdxxz <2079238449@qq.com> Co-committed-by: zzdxxz <2079238449@qq.com>
This commit is contained in:
@ -11,7 +11,7 @@ namespace AI
|
||||
public abstract JobBase GetJob(Entity.Entity target);
|
||||
}
|
||||
|
||||
public class Selector : AIBase
|
||||
public class ThinkNode_Selector : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
@ -24,13 +24,13 @@ namespace AI
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public class ConditionalAI : Selector
|
||||
public class ThinkNode_Conditional : ThinkNode_Selector
|
||||
{
|
||||
// 条件函数,返回 true 表示满足条件
|
||||
private Func<Entity.Entity, bool> condition;
|
||||
|
||||
// 构造函数,传入条件函数
|
||||
public ConditionalAI(Func<Entity.Entity, bool> conditionFunc)
|
||||
public ThinkNode_Conditional(Func<Entity.Entity, bool> conditionFunc)
|
||||
{
|
||||
condition = conditionFunc;
|
||||
}
|
||||
@ -48,7 +48,7 @@ namespace AI
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public class SequenceAI : AIBase
|
||||
public class ThinkNode_Sequence : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
@ -61,33 +61,5 @@ namespace AI
|
||||
return null; // 所有子节点完成时返回 null
|
||||
}
|
||||
}
|
||||
public class ContinuousMove : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
return new MoveJob();
|
||||
}
|
||||
}
|
||||
|
||||
public class TrackPlayer : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
return new TrackPlayerJob();
|
||||
}
|
||||
}
|
||||
public class RandomWander : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
return new WanderJob();
|
||||
}
|
||||
}
|
||||
public class Idel : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
return new IdleJob();
|
||||
}
|
||||
}
|
||||
}
|
@ -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; // 最大追踪距离
|
||||
|
33
Client/Assets/Scripts/AI/JobGiver.cs
Normal file
33
Client/Assets/Scripts/AI/JobGiver.cs
Normal file
@ -0,0 +1,33 @@
|
||||
namespace AI
|
||||
{
|
||||
public class JobGiver_ContinuousMove : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
return new MoveJob();
|
||||
}
|
||||
}
|
||||
|
||||
public class JobGiver_Enemies : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
return new TrackPlayerJob();
|
||||
}
|
||||
}
|
||||
public class JobGiver_RandomWander : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
return new WanderJob();
|
||||
}
|
||||
}
|
||||
public class JobGiver_Idel : AIBase
|
||||
{
|
||||
public override JobBase GetJob(Entity.Entity target)
|
||||
{
|
||||
return new IdleJob();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
3
Client/Assets/Scripts/AI/JobGiver.cs.meta
Normal file
3
Client/Assets/Scripts/AI/JobGiver.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30648f750dce43e493f5e94cb735988c
|
||||
timeCreated: 1754974329
|
Reference in New Issue
Block a user