Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryGoingThroughPortals()

static void Terraria.GameContent.PortalHelper.TryGoingThroughPortals ( Entity ent)
inlinestatic

Definition at line 100 of file PortalHelper.cs.

101 {
102 if (!anyPortalAtAll)
103 {
104 return;
105 }
106 float collisionPoint = 0f;
107 _ = ent.velocity;
108 int width = ent.width;
109 int height = ent.height;
110 int num = 1;
111 if (ent is Player)
112 {
113 num = (int)((Player)ent).gravDir;
114 }
115 for (int i = 0; i < FoundPortals.GetLength(0); i++)
116 {
117 if (FoundPortals[i, 0] == -1 || FoundPortals[i, 1] == -1 || (ent is Player && (i >= PortalCooldownForPlayers.Length || PortalCooldownForPlayers[i] > 0)) || (ent is NPC && (i >= PortalCooldownForNPCs.Length || PortalCooldownForNPCs[i] > 0)))
118 {
119 continue;
120 }
121 for (int j = 0; j < 2; j++)
122 {
123 Projectile projectile = Main.projectile[FoundPortals[i, j]];
124 GetPortalEdges(projectile.Center, projectile.ai[0], out var start, out var end);
125 if (!Collision.CheckAABBvLineCollision(ent.position + ent.velocity, ent.Size, start, end, 2f, ref collisionPoint))
126 {
127 continue;
128 }
129 Projectile projectile2 = Main.projectile[FoundPortals[i, 1 - j]];
130 float num2 = ent.Hitbox.Distance(projectile.Center);
131 int bonusX;
132 int bonusY;
134 Vector2 vector2 = Vector2.UnitX * 16f;
135 if (Collision.TileCollision(vector - vector2, vector2, width, height, fallThrough: true, fall2: true, num) != vector2)
136 {
137 continue;
138 }
139 vector2 = -Vector2.UnitX * 16f;
140 if (Collision.TileCollision(vector - vector2, vector2, width, height, fallThrough: true, fall2: true, num) != vector2)
141 {
142 continue;
143 }
144 vector2 = Vector2.UnitY * 16f;
145 if (Collision.TileCollision(vector - vector2, vector2, width, height, fallThrough: true, fall2: true, num) != vector2)
146 {
147 continue;
148 }
149 vector2 = -Vector2.UnitY * 16f;
150 if (Collision.TileCollision(vector - vector2, vector2, width, height, fallThrough: true, fall2: true, num) != vector2)
151 {
152 continue;
153 }
154 float num3 = 0.1f;
155 if (bonusY == -num)
156 {
157 num3 = 0.1f;
158 }
159 if (ent.velocity == Vector2.Zero)
160 {
161 ent.velocity = (projectile.ai[0] - (float)Math.PI / 2f).ToRotationVector2() * num3;
162 }
163 if (ent.velocity.Length() < num3)
164 {
165 ent.velocity.Normalize();
166 ent.velocity *= num3;
167 }
169 if (vector3.HasNaNs() || vector3 == Vector2.Zero)
170 {
171 vector3 = Vector2.UnitX * ent.direction;
172 }
173 ent.velocity = vector3 * ent.velocity.Length();
174 if ((bonusY == -num && Math.Sign(ent.velocity.Y) != -num) || Math.Abs(ent.velocity.Y) < 0.1f)
175 {
176 ent.velocity.Y = (float)(-num) * 0.1f;
177 }
178 int num4 = (int)((float)(projectile2.owner * 2) + projectile2.ai[1]);
179 int lastPortalColorIndex = num4 + ((num4 % 2 == 0) ? 1 : (-1));
180 if (ent is Player)
181 {
182 Player player = (Player)ent;
183 player.lastPortalColorIndex = lastPortalColorIndex;
184 player.Teleport(vector, 4, num4);
185 if (Main.netMode == 1)
186 {
187 NetMessage.SendData(96, -1, -1, null, player.whoAmI, vector.X, vector.Y, num4);
188 NetMessage.SendData(13, -1, -1, null, player.whoAmI);
189 }
191 }
192 else if (ent is NPC)
193 {
194 NPC nPC = (NPC)ent;
195 nPC.lastPortalColorIndex = lastPortalColorIndex;
196 nPC.Teleport(vector, 4, num4);
197 if (Main.netMode == 2)
198 {
199 NetMessage.SendData(100, -1, -1, null, nPC.whoAmI, vector.X, vector.Y, num4);
200 NetMessage.SendData(23, -1, -1, null, nPC.whoAmI);
201 }
203 if (bonusY == -1 && ent.velocity.Y > -3f)
204 {
205 ent.velocity.Y = -3f;
206 }
207 }
208 return;
209 }
210 }
211 }
static double Abs(double value)
const double PI
Definition Math.cs:16
static int Sign(decimal value)
Definition Math.cs:1202
static Vector2 GetPortalOutingPoint(Vector2 objectSize, Vector2 portalPosition, float portalAngle, out int bonusX, out int bonusY)
static void GetPortalEdges(Vector2 position, float angle, out Vector2 start, out Vector2 end)

References System.Math.Abs(), Terraria.Projectile.ai, Terraria.GameContent.PortalHelper.anyPortalAtAll, Terraria.Entity.Center, Terraria.Collision.CheckAABBvLineCollision(), Terraria.GameContent.PortalHelper.FoundPortals, Terraria.GameContent.PortalHelper.GetPortalEdges(), Terraria.GameContent.PortalHelper.GetPortalOutingPoint(), Terraria.Main.netMode, Microsoft.Xna.Framework.Vector2.Normalize(), System.Math.PI, Terraria.GameContent.PortalHelper.PortalCooldownForNPCs, Terraria.GameContent.PortalHelper.PortalCooldownForPlayers, Terraria.Main.projectile, Terraria.NetMessage.SendData(), System.Math.Sign(), System.start, Terraria.Player.Teleport(), Terraria.Collision.TileCollision(), Terraria.Entity.whoAmI, and Microsoft.Xna.Framework.Vector2.Zero.

Referenced by Terraria.NPC.TryPortalJumping(), and Terraria.Player.TryPortalJumping().