Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TeleportPylonsSystem.cs
Go to the documentation of this file.
2using System.Linq;
4using Terraria.Chat;
9using Terraria.Net;
10
11namespace Terraria.GameContent;
12
14{
16
18
20
21 private const int CooldownTimePerPylonsListUpdate = int.MaxValue;
22
24
26
27 public void Update()
28 {
29 if (Main.netMode != 1)
30 {
32 {
34 return;
35 }
36 _cooldownForUpdatingPylonsList = int.MaxValue;
38 }
39 }
40
42 {
43 return _pylons.Any((TeleportPylonInfo x) => x.TypeOfPylon == pylonType);
44 }
45
46 public bool HasAnyPylon()
47 {
48 return _pylons.Count > 0;
49 }
50
52 {
53 if (Main.netMode != 1)
54 {
55 _cooldownForUpdatingPylonsList = int.MaxValue;
57 }
58 }
59
61 {
63 _pylons.Clear();
64 foreach (TileEntity value in TileEntity.ByPosition.Values)
65 {
67 {
69 teleportPylonInfo.PositionInTiles = tETeleportationPylon.Position;
70 teleportPylonInfo.TypeOfPylon = pylonType;
72 _pylons.Add(item);
73 }
74 }
76 foreach (TeleportPylonInfo item2 in _pylons.Except(_pylonsOld))
77 {
79 }
81 {
83 }
84 }
85
87 {
88 if (!_pylons.Contains(info))
89 {
90 _pylons.Add(info);
91 }
92 }
93
95 {
96 _pylons.RemoveAll((TeleportPylonInfo x) => x.Equals(info));
97 }
98
100 {
101 Player player = Main.player[playerIndex];
102 string key = null;
103 bool flag = true;
104 if (flag)
105 {
106 flag &= IsPlayerNearAPylon(player);
107 if (!flag)
108 {
109 key = "Net.CannotTeleportToPylonBecausePlayerIsNotNearAPylon";
110 }
111 }
112 if (flag)
113 {
116 if (!flag)
117 {
118 key = "Net.CannotTeleportToPylonBecauseNotEnoughNPCs";
119 }
120 }
121 if (flag)
122 {
124 if (!flag)
125 {
126 key = "Net.CannotTeleportToPylonBecauseThereIsDanger";
127 }
128 }
129 if (flag)
130 {
131 if (!NPC.downedPlantBoss && (double)info.PositionInTiles.Y > Main.worldSurface && Framing.GetTileSafely(info.PositionInTiles.X, info.PositionInTiles.Y).wall == 87)
132 {
133 flag = false;
134 }
135 if (!flag)
136 {
137 key = "Net.CannotTeleportToPylonBecauseAccessingLihzahrdTempleEarly";
138 }
139 }
140 if (flag)
141 {
143 {
144 VisualScanArea = null,
145 BiomeScanCenterPositionInWorld = info.PositionInTiles.ToWorldCoordinates(),
146 ScanOreFinderData = false
147 });
148 flag = DoesPylonAcceptTeleportation(info, player);
149 if (!flag)
150 {
151 key = "Net.CannotTeleportToPylonBecauseNotMeetingBiomeRequirements";
152 }
153 }
154 if (flag)
155 {
156 bool flag2 = false;
157 int num = 0;
158 for (int i = 0; i < _pylons.Count; i++)
159 {
161 if (!player.InInteractionRange(info2.PositionInTiles.X, info2.PositionInTiles.Y, TileReachCheckSettings.Pylons))
162 {
163 continue;
164 }
165 if (num < 1)
166 {
167 num = 1;
168 }
171 {
172 if (num < 2)
173 {
174 num = 2;
175 }
177 {
178 VisualScanArea = null,
179 BiomeScanCenterPositionInWorld = info2.PositionInTiles.ToWorldCoordinates(),
180 ScanOreFinderData = false
181 });
183 {
184 flag2 = true;
185 break;
186 }
187 }
188 }
189 if (!flag2)
190 {
191 flag = false;
192 key = num switch
193 {
194 1 => "Net.CannotTeleportToPylonBecauseNotEnoughNPCsAtCurrentPylon",
195 2 => "Net.CannotTeleportToPylonBecauseNotMeetingBiomeRequirements",
196 _ => "Net.CannotTeleportToPylonBecausePlayerIsNotNearAPylon",
197 };
198 }
199 }
200 if (flag)
201 {
202 Vector2 newPos = info.PositionInTiles.ToWorldCoordinates() - new Vector2(0f, player.HeightOffsetBoost);
203 int num2 = 9;
204 int typeOfPylon = (int)info.TypeOfPylon;
205 int number = 0;
207 player.velocity = Vector2.Zero;
208 if (Main.netMode == 2)
209 {
211 NetMessage.SendData(65, -1, -1, null, 0, player.whoAmI, newPos.X, newPos.Y, num2, number, typeOfPylon);
212 }
213 }
214 else
215 {
217 }
218 }
219
220 public static bool IsPlayerNearAPylon(Player player)
221 {
223 }
224
226 {
227 if (necessaryNPCCount <= 0)
228 {
229 return true;
230 }
231 Point16 positionInTiles = info.PositionInTiles;
233 }
234
236 {
238 int num = necessaryNPCCount;
239 for (int i = 0; i < 200; i++)
240 {
241 NPC nPC = Main.npc[i];
242 if (!nPC.active || !nPC.isLikeATownNPC || nPC.homeless || !rectangle.Contains(nPC.homeTileX, nPC.homeTileY))
243 {
244 continue;
245 }
246 Vector2 value = new Vector2(nPC.homeTileX, nPC.homeTileY);
247 Vector2 value2 = new Vector2(nPC.Center.X / 16f, nPC.Center.Y / 16f);
248 if (Vector2.Distance(value, value2) < 100f)
249 {
250 num--;
251 if (num == 0)
252 {
253 return true;
254 }
255 }
256 }
257 return false;
258 }
259
261 {
263 }
264
266 {
267 if (Main.netMode != 2 && Main.DroneCameraTracker != null && Main.DroneCameraTracker.IsInUse())
268 {
269 return false;
270 }
271 switch (info.TypeOfPylon)
272 {
273 case TeleportPylonType.SurfacePurity:
274 {
275 bool flag = (double)info.PositionInTiles.Y <= Main.worldSurface;
276 if (Main.remixWorld)
277 {
278 flag = (double)info.PositionInTiles.Y > Main.rockLayer && info.PositionInTiles.Y < Main.maxTilesY - 350;
279 }
280 bool flag2 = info.PositionInTiles.X >= Main.maxTilesX - 380 || info.PositionInTiles.X <= 380;
281 if (!flag || flag2)
282 {
283 return false;
284 }
286 {
287 return false;
288 }
289 return true;
290 }
291 case TeleportPylonType.Jungle:
293 case TeleportPylonType.Snow:
295 case TeleportPylonType.Desert:
297 case TeleportPylonType.Beach:
298 {
299 bool flag3 = (double)info.PositionInTiles.Y <= Main.worldSurface && (double)info.PositionInTiles.Y > Main.worldSurface * 0.3499999940395355;
300 bool flag4 = info.PositionInTiles.X >= Main.maxTilesX - 380 || info.PositionInTiles.X <= 380;
301 if (Main.remixWorld)
302 {
303 flag3 |= (double)info.PositionInTiles.Y > Main.rockLayer && info.PositionInTiles.Y < Main.maxTilesY - 350;
304 flag4 |= (double)info.PositionInTiles.X < (double)Main.maxTilesX * 0.43 || (double)info.PositionInTiles.X > (double)Main.maxTilesX * 0.57;
305 }
306 return flag4 && flag3;
307 }
308 case TeleportPylonType.GlowingMushroom:
309 if (Main.remixWorld && info.PositionInTiles.Y >= Main.maxTilesY - 200)
310 {
311 return false;
312 }
314 case TeleportPylonType.Hallow:
316 case TeleportPylonType.Underground:
317 return (double)info.PositionInTiles.Y >= Main.worldSurface;
318 case TeleportPylonType.Victory:
319 return true;
320 default:
321 return true;
322 }
323 }
324
326 {
327 TeleportPylonType typeOfPylon = info.TypeOfPylon;
328 if (typeOfPylon != TeleportPylonType.Victory)
329 {
330 return 2;
331 }
332 return 0;
333 }
334
335 public void Reset()
336 {
337 _pylons.Clear();
339 }
340
348
350 {
351 float r = 1f;
352 float g = 1f;
353 float b = 1f;
354 switch ((TeleportPylonType)(byte)tileStyle)
355 {
356 case TeleportPylonType.SurfacePurity:
357 r = 0.05f;
358 g = 0.8f;
359 b = 0.3f;
360 break;
361 case TeleportPylonType.Jungle:
362 r = 0.7f;
363 g = 0.8f;
364 b = 0.05f;
365 break;
366 case TeleportPylonType.Hallow:
367 r = 0.5f;
368 g = 0.3f;
369 b = 0.7f;
370 break;
371 case TeleportPylonType.Underground:
372 r = 0.4f;
373 g = 0.4f;
374 b = 0.6f;
375 break;
376 case TeleportPylonType.Beach:
377 r = 0.2f;
378 g = 0.2f;
379 b = 0.95f;
380 break;
381 case TeleportPylonType.Desert:
382 r = 0.85f;
383 g = 0.45f;
384 b = 0.1f;
385 break;
386 case TeleportPylonType.Snow:
387 r = 1f;
388 g = 1f;
389 b = 1.2f;
390 break;
391 case TeleportPylonType.GlowingMushroom:
392 r = 0.4f;
393 g = 0.7f;
394 b = 1.2f;
395 break;
396 case TeleportPylonType.Victory:
397 r = 0.7f;
398 g = 0.7f;
399 b = 0.7f;
400 break;
401 }
402 int num = Dust.NewDust(dustBox.TopLeft(), dustBox.Width, dustBox.Height, 43, 0f, 0f, 254, new Color(r, g, b, 1f), 0.5f);
403 Main.dust[num].velocity *= 0.1f;
404 Main.dust[num].velocity.Y -= 0.2f;
405 }
406}
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
void Add(TKey key, TValue value)
static void SendChatMessageToClient(NetworkText text, Color color, int playerId)
Definition ChatHelper.cs:28
static Dictionary< Point16, TileEntity > ByPosition
Definition TileEntity.cs:20
static int NewDust(Vector2 Position, int Width, int Height, int Type, float SpeedX=0f, float SpeedY=0f, int Alpha=0, Color newColor=default(Color), float Scale=1f)
Definition Dust.cs:73
Vector2 position
Definition Entity.cs:14
static Tile GetTileSafely(Vector2 position)
Definition Framing.cs:419
static NetPacket SerializePylonWasAddedOrRemoved(TeleportPylonInfo info, SubPacketType packetType)
static NetPacket SerializeUseRequest(TeleportPylonInfo info)
void HandleTeleportRequest(TeleportPylonInfo info, int playerIndex)
void RequestTeleportation(TeleportPylonInfo info, Player player)
int HowManyNPCsDoesPylonNeed(TeleportPylonInfo info, Player player)
static bool DoesPositionHaveEnoughNPCs(int necessaryNPCCount, Point16 centerPoint)
bool DoesPylonAcceptTeleportation(TeleportPylonInfo info, Player player)
bool DoesPylonHaveEnoughNPCsAroundIt(TeleportPylonInfo info, int necessaryNPCCount)
bool HasPylonOfType(TeleportPylonType pylonType)
static void SpawnInWorldDust(int tileStyle, Rectangle dustBox)
static NetworkText FromKey(string key, params object[] substitutions)
static int maxTilesY
Definition Main.cs:1116
static int buffScanAreaWidth
Definition Main.cs:764
static double worldSurface
Definition Main.cs:1272
static int netMode
Definition Main.cs:2095
static double rockLayer
Definition Main.cs:1274
static DroneCameraTracker DroneCameraTracker
Definition Main.cs:1878
static NPC[] npc
Definition Main.cs:1685
static int buffScanAreaHeight
Definition Main.cs:766
static Player[] player
Definition Main.cs:1803
static bool remixWorld
Definition Main.cs:349
static Dust[] dust
Definition Main.cs:1677
static bool AnyDanger(bool quickBossNPCCheck=false, bool ignorePillarsAndMoonlordCountdown=false)
Definition NPC.cs:77014
static bool downedPlantBoss
Definition NPC.cs:363
static void SendData(int msgType, int remoteClient=-1, int ignoreClient=-1, NetworkText text=null, int number=0, float number2=0f, float number3=0f, float number4=0f, int number5=0, int number6=0, int number7=0)
Definition NetMessage.cs:88
static readonly NetManager Instance
Definition NetManager.cs:18
bool IsTileTypeInInteractionRange(int targetTileType, TileReachCheckSettings settings)
Definition Player.cs:33928
void Teleport(Vector2 newPos, int Style=0, int extraInfo=0)
Definition Player.cs:35567
int HeightOffsetBoost
Definition Player.cs:2799
bool InInteractionRange(int interactX, int interactY, TileReachCheckSettings settings)
Definition Player.cs:29774
static void CheckSection(int playerIndex, Vector2 position, int fluff=1)
void ScanAndExportToMain(SceneMetricsScanSettings settings)
static float Distance(Vector2 value1, Vector2 value2)
Definition Vector2.cs:91
bool Equals(TeleportPylonInfo other)