TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches
TETrainingDummy.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.IO;
3using Microsoft.Xna.Framework;
5
7
8public sealed class TETrainingDummy : TileEntity
9{
11
12 private static bool playerBoxFilled;
13
14 private static byte _myEntityID;
15
16 public int npc;
17
18 public override void RegisterTileEntityID(int assignedID)
19 {
20 _myEntityID = (byte)assignedID;
21 TileEntity._UpdateStart += ClearBoxes;
22 }
23
24 public override void NetPlaceEntityAttempt(int x, int y)
25 {
26 NetPlaceEntity(x, y);
27 }
28
29 public static void NetPlaceEntity(int x, int y)
30 {
31 Place(x, y);
32 }
33
34 public override TileEntity GenerateInstance()
35 {
36 return new TETrainingDummy();
37 }
38
39 public override bool IsTileValidForEntity(int x, int y)
40 {
41 return ValidTile(x, y);
42 }
43
44 public static void ClearBoxes()
45 {
46 playerBox.Clear();
47 playerBoxFilled = false;
48 }
49
50 public override void Update()
51 {
52 //IL_001e: Unknown result type (might be due to invalid IL or missing references)
53 //IL_0025: Unknown result type (might be due to invalid IL or missing references)
54 //IL_00f7: Unknown result type (might be due to invalid IL or missing references)
55 //IL_00fc: Unknown result type (might be due to invalid IL or missing references)
56 //IL_0100: Unknown result type (might be due to invalid IL or missing references)
57 Rectangle value = default(Rectangle);
58 ((Rectangle)(ref value))._002Ector(0, 0, 32, 48);
59 ((Rectangle)(ref value)).Inflate(1600, 1600);
60 int x = value.X;
61 int y = value.Y;
62 if (npc != -1)
63 {
64 if (!Main.npc[npc].active || Main.npc[npc].type != 488 || Main.npc[npc].ai[0] != (float)Position.X || Main.npc[npc].ai[1] != (float)Position.Y)
65 {
66 Deactivate();
67 }
68 return;
69 }
71 value.X = Position.X * 16 + x;
72 value.Y = Position.Y * 16 + y;
73 bool flag = false;
75 {
76 Rectangle value2 = item.Value;
77 if (((Rectangle)(ref value2)).Intersects(value))
78 {
79 flag = true;
80 break;
81 }
82 }
83 if (flag)
84 {
85 Activate();
86 }
87 }
88
89 private static void FillPlayerHitboxes()
90 {
91 //IL_0027: Unknown result type (might be due to invalid IL or missing references)
93 {
94 return;
95 }
96 for (int i = 0; i < 255; i++)
97 {
98 if (Main.player[i].active)
99 {
100 playerBox[i] = Main.player[i].getRect();
101 }
102 }
103 playerBoxFilled = true;
104 }
105
106 public static bool ValidTile(int x, int y)
107 {
108 if (!Main.tile[x, y].active() || Main.tile[x, y].type != 378 || Main.tile[x, y].frameY != 0 || Main.tile[x, y].frameX % 36 != 0)
109 {
110 return false;
111 }
112 return true;
113 }
114
116 {
117 npc = -1;
118 }
119
120 public static int Place(int x, int y)
121 {
123 tETrainingDummy.Position = new Point16(x, y);
124 tETrainingDummy.ID = TileEntity.AssignNewID();
125 tETrainingDummy.type = _myEntityID;
127 {
130 }
131 return tETrainingDummy.ID;
132 }
133
134 public static int Hook_AfterPlacement(int x, int y, int type = 378, int style = 0, int direction = 1, int alternate = 0)
135 {
136 if (Main.netMode == 1)
137 {
138 NetMessage.SendTileSquare(Main.myPlayer, x - 1, y - 2, 2, 3);
139 NetMessage.SendData(87, -1, -1, null, x - 1, y - 2, (int)_myEntityID);
140 return -1;
141 }
142 return Place(x - 1, y - 2);
143 }
144
145 public static void Kill(int x, int y)
146 {
147 if (TileEntity.ByPosition.TryGetValue(new Point16(x, y), out var value) && value.type == _myEntityID)
148 {
150 {
151 TileEntity.ByID.Remove(value.ID);
152 TileEntity.ByPosition.Remove(new Point16(x, y));
153 }
154 }
155 }
156
157 public static int Find(int x, int y)
158 {
159 if (TileEntity.ByPosition.TryGetValue(new Point16(x, y), out var value) && value.type == _myEntityID)
160 {
161 return value.ID;
162 }
163 return -1;
164 }
165
166 public override void WriteExtraData(BinaryWriter writer, bool networkSend)
167 {
168 writer.Write((short)npc);
169 }
170
171 public override void ReadExtraData(BinaryReader reader, bool networkSend)
172 {
173 npc = reader.ReadInt16();
174 }
175
176 public void Activate()
177 {
178 int num = NPC.NewNPC(new EntitySource_TileEntity(this), Position.X * 16 + 16, Position.Y * 16 + 48, 488, 100);
179 Main.npc[num].ai[0] = Position.X;
180 Main.npc[num].ai[1] = Position.Y;
181 Main.npc[num].netUpdate = true;
182 npc = num;
183 if (Main.netMode != 1)
184 {
185 NetMessage.SendData(86, -1, -1, null, ID, Position.X, Position.Y);
186 }
187 }
188
189 public void Deactivate()
190 {
191 if (npc != -1)
192 {
193 Main.npc[npc].active = false;
194 }
195 npc = -1;
196 if (Main.netMode != 1)
197 {
198 NetMessage.SendData(86, -1, -1, null, ID, Position.X, Position.Y);
199 }
200 }
201
202 public override string ToString()
203 {
204 return Position.X + "x " + Position.Y + "y npc: " + npc;
205 }
206}
static Dictionary< int, TileEntity > ByID
Definition TileEntity.cs:20
static Dictionary< Point16, TileEntity > ByPosition
Definition TileEntity.cs:22
override void WriteExtraData(BinaryWriter writer, bool networkSend)
static int Hook_AfterPlacement(int x, int y, int type=378, int style=0, int direction=1, int alternate=0)
override void ReadExtraData(BinaryReader reader, bool networkSend)
static Dictionary< int, Rectangle > playerBox
static int myPlayer
The index in F:Terraria.Main.player of this client's Player. If this is 255, this client is the ser...
Definition Main.cs:1958
static int netMode
Denotes the current network mode: 0 for single player client, 1 for multiplayer client,...
Definition Main.cs:2182
static NPC[] npc
Definition Main.cs:1830
static Tilemap tile
Definition Main.cs:1820
static Player[] player
Definition Main.cs:1960
static int NewNPC(IEntitySource source, int X, int Y, int Type, int Start=0, float ai0=0f, float ai1=0f, float ai2=0f, float ai3=0f, int Target=255)
Spawns an NPC into the game world with the given type. This method should not be called on multipla...
Definition NPC.cs:91239
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)
static void SendTileSquare(int whoAmi, int tileX, int tileY, int xSize, int ySize, TileChangeType changeType=TileChangeType.None)