Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
PressurePlateHelper.cs
Go to the documentation of this file.
2using System.Linq;
4
6
8{
9 public static object EntityCreationLock = new object();
10
12
13 public static bool NeedsFirstUpdate;
14
15 private static Vector2[] PlayerLastPosition = new Vector2[255];
16
17 private static Rectangle pressurePlateBounds = new Rectangle(0, 0, 16, 10);
18
19 public static void Update()
20 {
22 {
23 return;
24 }
25 foreach (Point key in PressurePlatesPressed.Keys)
26 {
27 PokeLocation(key);
28 }
30 NeedsFirstUpdate = false;
31 }
32
33 public static void Reset()
34 {
36 for (int i = 0; i < PlayerLastPosition.Length; i++)
37 {
39 }
40 }
41
42 public static void ResetPlayer(int player)
43 {
44 Point[] array = PressurePlatesPressed.Keys.ToArray();
45 for (int i = 0; i < array.Length; i++)
46 {
47 MoveAwayFrom(array[i], player);
48 }
49 }
50
51 public static void UpdatePlayerPosition(Player player)
52 {
53 Point p = new Point(1, 1);
54 Vector2 vector = p.ToVector2();
57 Rectangle hitbox = player.Hitbox;
58 Rectangle hitbox2 = player.Hitbox;
59 hitbox.Inflate(-p.X, -p.Y);
60 hitbox2.Inflate(-p.X, -p.Y);
61 hitbox2.X = (int)PlayerLastPosition[player.whoAmI].X;
62 hitbox2.Y = (int)PlayerLastPosition[player.whoAmI].Y;
63 for (int i = 0; i < tilesIn.Count; i++)
64 {
65 Point point = tilesIn[i];
66 Tile tile = Main.tile[point.X, point.Y];
67 if (tile.active() && tile.type == 428)
68 {
69 pressurePlateBounds.X = point.X * 16;
70 pressurePlateBounds.Y = point.Y * 16 + 16 - pressurePlateBounds.Height;
71 if (!hitbox.Intersects(pressurePlateBounds) && !tilesIn2.Contains(point))
72 {
73 MoveAwayFrom(point, player.whoAmI);
74 }
75 }
76 }
77 for (int j = 0; j < tilesIn2.Count; j++)
78 {
81 if (tile2.active() && tile2.type == 428)
82 {
83 pressurePlateBounds.X = point2.X * 16;
84 pressurePlateBounds.Y = point2.Y * 16 + 16 - pressurePlateBounds.Height;
85 if (hitbox.Intersects(pressurePlateBounds) && (!tilesIn.Contains(point2) || !hitbox2.Intersects(pressurePlateBounds)))
86 {
87 MoveInto(point2, player.whoAmI);
88 }
89 }
90 }
91 PlayerLastPosition[player.whoAmI] = player.position;
92 }
93
94 public static void DestroyPlate(Point location)
95 {
96 if (PressurePlatesPressed.TryGetValue(location, out var _))
97 {
100 }
101 }
102
103 private static void UpdatePlatePosition(Point location, int player, bool onIt)
104 {
105 if (onIt)
106 {
107 MoveInto(location, player);
108 }
109 else
110 {
111 MoveAwayFrom(location, player);
112 }
113 }
114
115 private static void MoveInto(Point location, int player)
116 {
117 if (PressurePlatesPressed.TryGetValue(location, out var value))
118 {
119 value[player] = true;
120 return;
121 }
123 {
124 PressurePlatesPressed[location] = new bool[255];
125 }
126 PressurePlatesPressed[location][player] = true;
128 }
129
130 private static void MoveAwayFrom(Point location, int player)
131 {
132 if (!PressurePlatesPressed.TryGetValue(location, out var value))
133 {
134 return;
135 }
136 value[player] = false;
137 bool flag = false;
138 for (int i = 0; i < value.Length; i++)
139 {
140 if (value[i])
141 {
142 flag = true;
143 break;
144 }
145 }
146 if (!flag)
147 {
149 {
151 }
153 }
154 }
155
156 private static void PokeLocation(Point location)
157 {
158 if (Main.netMode != 1)
159 {
160 Wiring.blockPlayerTeleportationForOneIteration = true;
162 NetMessage.SendData(59, -1, -1, null, location.X, location.Y);
163 }
164 }
165}
bool ICollection< KeyValuePair< TKey, TValue > >. Contains(KeyValuePair< TKey, TValue > keyValuePair)
static List< Point > GetTilesIn(Vector2 TopLeft, Vector2 BottomRight)
Vector2 BottomRight
Definition Entity.cs:139
Vector2 Size
Definition Entity.cs:151
Vector2 TopLeft
Definition Entity.cs:91
Rectangle Hitbox
Definition Entity.cs:164
Vector2 position
Definition Entity.cs:14
static void MoveAwayFrom(Point location, int player)
static Dictionary< Point, bool[]> PressurePlatesPressed
static void UpdatePlayerPosition(Player player)
static void UpdatePlatePosition(Point location, int player, bool onIt)
static void MoveInto(Point location, int player)
static int netMode
Definition Main.cs:2095
static Tile[,] tile
Definition Main.cs:1675
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
ushort type
Definition Tile.cs:8
bool active()
Definition Tile.cs:565
static void HitSwitch(int i, int j)
Definition Wiring.cs:237