Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Characters/AICharacter.cs
1 using Microsoft.Xna.Framework;
2 
3 namespace Barotrauma
4 {
5  partial class AICharacter : Character
6  {
7  private AIController aiController;
8 
9  public override AIController AIController
10  {
11  get { return aiController; }
12  }
13 
14  public AICharacter(CharacterPrefab prefab, Vector2 position, string seed, CharacterInfo characterInfo = null, ushort id = Entity.NullEntityID, bool isNetworkPlayer = false, RagdollParams ragdoll = null, bool spawnInitialItems = true)
15  : base(prefab, position, seed, characterInfo, id: id, isRemotePlayer: isNetworkPlayer, ragdollParams: ragdoll, spawnInitialItems)
16  {
17  InitProjSpecific();
18  }
19 
20  partial void InitProjSpecific();
21 
22  public void SetAI(AIController aiController)
23  {
24  if (AIController != null)
25  {
27  }
28 
29  this.aiController = aiController;
30  if (aiController != null)
31  {
32  OnAttacked += aiController.OnAttacked;
33  }
34  }
35 
36  public override void Update(float deltaTime, Camera cam)
37  {
38  base.Update(deltaTime, cam);
39 
40  if (!Enabled) { return; }
42  {
43  enemyAi.PetBehavior?.Update(deltaTime);
44  }
45  if (IsDead || Vitality <= 0.0f || Stun > 0.0f || IsIncapacitated)
46  {
47  //don't enable simple physics on dead/incapacitated characters
48  //the ragdoll controls the movement of incapacitated characters instead of the collider,
49  //but in simple physics mode the ragdoll would get disabled, causing the character to not move at all
51  return;
52  }
53 
55  {
56  float characterDistSqr = GetDistanceSqrToClosestPlayer();
57  if (characterDistSqr > MathUtils.Pow2(Params.DisableDistance * 0.5f))
58  {
60  }
61  else if (characterDistSqr < MathUtils.Pow2(Params.DisableDistance * 0.5f * 0.9f))
62  {
64  }
65  }
66  else
67  {
69  }
70 
71  if (GameMain.NetworkMember != null && !GameMain.NetworkMember.IsServer) { return; }
72  if (Controlled == this) { return; }
73 
74  if (!IsRemotelyControlled && aiController != null && aiController.Enabled)
75  {
76  aiController.Update(deltaTime);
77  }
78  }
79  }
80 }
AICharacter(CharacterPrefab prefab, Vector2 position, string seed, CharacterInfo characterInfo=null, ushort id=Entity.NullEntityID, bool isNetworkPlayer=false, RagdollParams ragdoll=null, bool spawnInitialItems=true)
override void Update(float deltaTime, Camera cam)
virtual void OnAttacked(Character attacker, AttackResult attackResult)
bool IsRemotelyControlled
Is the character controlled remotely (either by another player, or a server-side AIController)
float GetDistanceSqrToClosestPlayer()
How far the character is from the closest human player (including spectators)
bool IsRemotePlayer
Is the character controlled by another human player (should always be false in single player)
Stores information about the Character that is needed between rounds in the menu etc....
const ushort NullEntityID
Definition: Entity.cs:14
static NetworkMember NetworkMember
Definition: GameMain.cs:190