Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TrackedProjectileReference.cs
Go to the documentation of this file.
1using System.IO;
2
4
6{
7 public int ProjectileLocalIndex { get; private set; }
8
9 public int ProjectileOwnerIndex { get; private set; }
10
11 public int ProjectileIdentity { get; private set; }
12
13 public int ProjectileType { get; private set; }
14
15 public bool IsTrackingSomething { get; private set; }
16
17 public void Set(Projectile proj)
18 {
22 ProjectileType = proj.type;
24 }
25
26 public void Clear()
27 {
31 ProjectileType = -1;
32 IsTrackingSomething = false;
33 }
34
35 public void Write(BinaryWriter writer)
36 {
37 writer.Write((short)ProjectileOwnerIndex);
38 if (ProjectileOwnerIndex != -1)
39 {
40 writer.Write((short)ProjectileIdentity);
41 writer.Write((short)ProjectileType);
42 }
43 }
44
45 public bool IsTracking(Projectile proj)
46 {
47 return proj.whoAmI == ProjectileLocalIndex;
48 }
49
50 public void TryReading(BinaryReader reader)
51 {
52 int num = reader.ReadInt16();
53 if (num == -1)
54 {
55 Clear();
56 return;
57 }
58 int expectedIdentity = reader.ReadInt16();
59 int expectedType = reader.ReadInt16();
60 Projectile projectile = FindMatchingProjectile(num, expectedIdentity, expectedType);
61 if (projectile == null)
62 {
63 Clear();
64 }
65 else
66 {
67 Set(projectile);
68 }
69 }
70
71 private Projectile FindMatchingProjectile(int expectedOwner, int expectedIdentity, int expectedType)
72 {
73 if (expectedOwner == -1)
74 {
75 return null;
76 }
77 for (int i = 0; i < 1000; i++)
78 {
79 Projectile projectile = Main.projectile[i];
80 if (projectile.type == expectedType && projectile.owner == expectedOwner && projectile.identity == expectedIdentity)
81 {
82 return projectile;
83 }
84 }
85 return null;
86 }
87
88 public override bool Equals(object obj)
89 {
90 if (!(obj is TrackedProjectileReference other))
91 {
92 return false;
93 }
94 return Equals(other);
95 }
96
98 {
99 if (ProjectileLocalIndex == other.ProjectileLocalIndex && ProjectileOwnerIndex == other.ProjectileOwnerIndex && ProjectileIdentity == other.ProjectileIdentity)
100 {
101 return ProjectileType == other.ProjectileType;
102 }
103 return false;
104 }
105
106 public override int GetHashCode()
107 {
108 return (((((ProjectileLocalIndex * 397) ^ ProjectileOwnerIndex) * 397) ^ ProjectileIdentity) * 397) ^ ProjectileType;
109 }
110
112 {
113 return c1.Equals(c2);
114 }
115
117 {
118 return !c1.Equals(c2);
119 }
120}
virtual short ReadInt16()
static Projectile[] projectile
Definition Main.cs:1691
static bool operator==(TrackedProjectileReference c1, TrackedProjectileReference c2)
static bool operator!=(TrackedProjectileReference c1, TrackedProjectileReference c2)
Projectile FindMatchingProjectile(int expectedOwner, int expectedIdentity, int expectedType)