Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NPCFollowState.cs
Go to the documentation of this file.
1using System.IO;
3
5
6public class NPCFollowState
7{
8 private NPC _npc;
9
11
13
15
17
19 {
20 get
21 {
22 if (_playerIndexBeingFollowed.HasValue)
23 {
25 }
26 return null;
27 }
28 }
29
30 public void FollowPlayer(int playerIndex)
31 {
32 _playerIndexBeingFollowed = playerIndex;
33 _floorBreadcrumb = Main.player[playerIndex].Bottom;
34 _npc.netUpdate = true;
35 }
36
37 public void StopFollowing()
38 {
41 _npc.netUpdate = true;
42 }
43
44 public void Clear(NPC npcToBelongTo)
45 {
46 _npc = npcToBelongTo;
48 _floorBreadcrumb = default(Vector2);
49 }
50
51 private bool ShouldSync()
52 {
53 return _npc.isLikeATownNPC;
54 }
55
56 public void WriteTo(BinaryWriter writer)
57 {
58 int num = (_playerIndexBeingFollowed.HasValue ? _playerIndexBeingFollowed.Value : (-1));
59 writer.Write((short)num);
60 }
61
62 public void ReadFrom(BinaryReader reader)
63 {
64 short num = reader.ReadInt16();
65 if (Main.player.IndexInRange(num))
66 {
68 }
69 }
70
71 private void MoveNPCBackHome()
72 {
73 _npc.ai[0] = 20f;
74 _npc.ai[1] = 0f;
75 _npc.ai[2] = 0f;
76 _npc.ai[3] = 0f;
77 _npc.netUpdate = true;
78 }
79
80 public void Update()
81 {
83 {
84 Player playerBeingFollowed = PlayerBeingFollowed;
85 if (!playerBeingFollowed.active || playerBeingFollowed.dead)
86 {
88 return;
89 }
90 UpdateBreadcrumbs(playerBeingFollowed);
92 }
93 }
94
95 private void UpdateBreadcrumbs(Player player)
96 {
97 Vector2? vector = null;
98 if (player.velocity.Y == 0f && player.gravDir == 1f)
99 {
100 vector = player.Bottom;
101 }
102 int num = 8;
103 if (vector.HasValue && Vector2.Distance(vector.Value, _floorBreadcrumb) >= (float)num)
104 {
105 _floorBreadcrumb = vector.Value;
106 _npc.netUpdate = true;
107 }
108 }
109}
virtual short ReadInt16()
void WriteTo(BinaryWriter writer)
void ReadFrom(BinaryReader reader)
static Dust QuickDust(int x, int y, Color color)
Definition Dust.cs:263
Vector2 Bottom
Definition Entity.cs:115
Vector2 velocity
Definition Entity.cs:16
static Player[] player
Definition Main.cs:1803
bool isLikeATownNPC
Definition NPC.cs:822
float[] ai
Definition NPC.cs:447
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91