一.MobilePartyAI&AgentAI
Mission中Agent的AI行为为AgentAI,有常见的跟随,冲锋,坚守等AIBehavior.
大地图中Party的AI行为为MobilePartyAI,有常见的附着,追击等AIBehavior.
二.AgentAI
<1.单个Agent的AI控制
通过IMBAgent提供接口实现单个Agent的AI行为,可设置单个AI的目的地和目标。
[EngineMethod("set_scripted_flags", false)]
void SetScriptedFlags(UIntPtr agentPointer, int flags);
[EngineMethod("get_scripted_combat_flags", false)]
int GetScriptedCombatFlags(UIntPtr agentPointer);
[EngineMethod("set_scripted_combat_flags", false)]
void SetScriptedCombatFlags(UIntPtr agentPointer, int flags);
[EngineMethod("set_scripted_position_and_direction", false)]
bool SetScriptedPositionAndDirection(UIntPtr agentPointer, ref WorldPosition targetPosition, float targetDirection, bool addHumanLikeDelay, int additionalFlags);
[EngineMethod("set_scripted_position", false)]
bool SetScriptedPosition(UIntPtr agentPointer, ref WorldPosition targetPosition, bool addHumanLikeDelay, int additionalFlags);
为每个Agent添加HumanAIComponent实现对Agent的AI动态组装和拼接,定义了单个Agent中AI的坚守,冲锋,混战等行为。
public enum AISimpleBehaviorKind
{
GoToPos,
Melee,
Ranged,
ChargeHorseback,
RangedHorseback,
AttackEntityMelee,
AttackEntityRanged,
Count
}
public enum BehaviorValueSet
{
Default,
DefensiveArrangementMove,
Follow,
DefaultMove,
Charge,
DefaultDetached,
Count
}
public enum UsableObjectInterestKind
{
None,
MovingTo,
Defending,
Count
}
<2.阵营AI-TeamAI
通过在Mission初始化时设置Agent对应TeamNo,批量AgentAI行为,添加TeamAIComponent实现对阵营AI的动态切换和组装。
例如围城AI-TeamAISiegeComponent,通过重写OnTick,OnDeploymentFinished()实现具体的AI行为控制
<3.分组AI-FormationAI
通过对同一Team下的分组形成不同的Formation(步兵,骑兵,射手),实现对不同兵种的AI控制。
三.AgentAI-导航网格
在游戏场景Scene编辑中,为对应场景添加预制的NavigationMesh,实现AI自动寻路,自动攻击等相关功能。
四.MobilePartyAI
大地图中军团移动,坚守,围城等AI行为定义在AiBehavior中,实现了不同种类军团如商队,NPC,野怪等不同MobileParty的AI行为
public enum AiBehavior
{
Hold,
None,
GoToSettlement,
AssaultSettlement,
RaidSettlement,
BesiegeSettlement,
EngageParty,
JoinParty,
GoAroundParty,
GoToPoint,
FleeToPoint,
FleeToGate,
FleeToParty,
PatrolAroundPoint,
EscortParty,
DefendSettlement,
DoOperation,
NumAiBehaviors
}
通过MobilePartyAi.GetBehaviors实时刷新MobileParty对应的CurrentPosition和NextPosition,实现对MobileParty的坐标实时更新。
[SaveableField(25)]
private Vec2 _formationPosition;
[SaveableField(28)]
private Vec2 _moveTargetPoint;
[SaveableField(29)]
private Vec2 _aiPathLastPosition;
[SaveableField(30)]
private IMapEntity _aiBehaviorMapEntity;
[CachedData]
private PathFaceRecord _targetAiFaceIndex = PathFaceRecord.NullFaceRecord;
[CachedData]
private PathFaceRecord _moveTargetAiFaceIndex = PathFaceRecord.NullFaceRecord;
[CachedData]
private PathFaceRecord _aiPathLastFace;
[CachedData]
private List<MobileParty> _lastTargetedParties;
五.MobilePartyAI-导航网格
在游戏场景Scene编辑中,为对应场景添加预制的NavigationMesh,实现AI自动寻路,自动攻击等相关功能。