TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches
Actions.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using Microsoft.Xna.Framework;
4using Microsoft.Xna.Framework.Graphics;
7
9
10public static class Actions
11{
13 {
15
20
21 public override bool Apply(Point origin, int x, int y, params object[] args)
22 {
23 //IL_0006: Unknown result type (might be due to invalid IL or missing references)
24 //IL_0012: Unknown result type (might be due to invalid IL or missing references)
25 _action.Apply(origin, x, y, args);
26 return UnitApply(origin, x, y, args);
27 }
28 }
29
30 public class Count : GenAction
31 {
33
34 public Count(Ref<int> count)
35 {
36 _count = count;
37 }
38
39 public override bool Apply(Point origin, int x, int y, params object[] args)
40 {
41 //IL_0014: Unknown result type (might be due to invalid IL or missing references)
42 _count.Value++;
43 return UnitApply(origin, x, y, args);
44 }
45 }
46
47 public class Scanner : GenAction
48 {
50
51 public Scanner(Ref<int> count)
52 {
53 _count = count;
54 }
55
56 public override bool Apply(Point origin, int x, int y, params object[] args)
57 {
58 //IL_0014: Unknown result type (might be due to invalid IL or missing references)
59 _count.Value++;
60 return UnitApply(origin, x, y, args);
61 }
62 }
63
64 public class TileScanner : GenAction
65 {
66 private ushort[] _tileIds;
67
69
70 public TileScanner(params ushort[] tiles)
71 {
72 _tileIds = tiles;
74 for (int i = 0; i < tiles.Length; i++)
75 {
76 _tileCounts[_tileIds[i]] = 0;
77 }
78 }
79
80 public override bool Apply(Point origin, int x, int y, params object[] args)
81 {
82 //IL_004c: Unknown result type (might be due to invalid IL or missing references)
83 Tile tile = GenBase._tiles[x, y];
84 if (tile.active() && _tileCounts.ContainsKey(tile.type))
85 {
86 _tileCounts[tile.type]++;
87 }
88 return UnitApply(origin, x, y, args);
89 }
90
92 {
94 for (int i = 0; i < _tileIds.Length; i++)
95 {
96 if (!_tileCounts.ContainsKey(_tileIds[i]))
97 {
98 _tileCounts[_tileIds[i]] = 0;
99 }
100 }
101 return this;
102 }
103
105 {
106 return _tileCounts;
107 }
108
109 public int GetCount(ushort tileId)
110 {
111 if (!_tileCounts.ContainsKey(tileId))
112 {
113 return -1;
114 }
115 return _tileCounts[tileId];
116 }
117 }
118
119 public class Blank : GenAction
120 {
121 public override bool Apply(Point origin, int x, int y, params object[] args)
122 {
123 //IL_0001: Unknown result type (might be due to invalid IL or missing references)
124 return UnitApply(origin, x, y, args);
125 }
126 }
127
128 public class Custom : GenAction
129 {
130 private CustomPerUnitAction _perUnit;
131
132 public Custom(CustomPerUnitAction perUnit)
133 {
135 }
136
137 public override bool Apply(Point origin, int x, int y, params object[] args)
138 {
139 //IL_0010: Unknown result type (might be due to invalid IL or missing references)
140 return _perUnit(x, y, args) | UnitApply(origin, x, y, args);
141 }
142 }
143
145 {
146 public override bool Apply(Point origin, int x, int y, params object[] args)
147 {
148 //IL_0015: Unknown result type (might be due to invalid IL or missing references)
149 GenBase._tiles[x, y].ClearMetadata();
150 return UnitApply(origin, x, y, args);
151 }
152 }
153
154 public class Clear : GenAction
155 {
156 public override bool Apply(Point origin, int x, int y, params object[] args)
157 {
158 //IL_0015: Unknown result type (might be due to invalid IL or missing references)
159 GenBase._tiles[x, y].ClearEverything();
160 return UnitApply(origin, x, y, args);
161 }
162 }
163
164 public class ClearTile : GenAction
165 {
166 private bool _frameNeighbors;
167
168 public ClearTile(bool frameNeighbors = false)
169 {
171 }
172
173 public override bool Apply(Point origin, int x, int y, params object[] args)
174 {
175 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
177 return UnitApply(origin, x, y, args);
178 }
179 }
180
181 public class ClearWall : GenAction
182 {
183 private bool _frameNeighbors;
184
185 public ClearWall(bool frameNeighbors = false)
186 {
188 }
189
190 public override bool Apply(Point origin, int x, int y, params object[] args)
191 {
192 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
194 return UnitApply(origin, x, y, args);
195 }
196 }
197
198 public class HalfBlock : GenAction
199 {
200 private bool _value;
201
202 public HalfBlock(bool value = true)
203 {
204 _value = value;
205 }
206
207 public override bool Apply(Point origin, int x, int y, params object[] args)
208 {
209 //IL_001b: Unknown result type (might be due to invalid IL or missing references)
210 GenBase._tiles[x, y].halfBrick(_value);
211 return UnitApply(origin, x, y, args);
212 }
213 }
214
215 public class SetTile : GenAction
216 {
217 private ushort _type;
218
219 private bool _doFraming;
220
221 private bool _doNeighborFraming;
222
223 public SetTile(ushort type, bool setSelfFrames = false, bool setNeighborFrames = true)
224 {
225 _type = type;
228 }
229
230 public override bool Apply(Point origin, int x, int y, params object[] args)
231 {
232 //IL_005c: Unknown result type (might be due to invalid IL or missing references)
233 GenBase._tiles[x, y].Clear(~(TileDataType.Wiring | TileDataType.Actuator));
234 GenBase._tiles[x, y].type = _type;
235 GenBase._tiles[x, y].active(active: true);
236 if (_doFraming)
237 {
239 }
240 return UnitApply(origin, x, y, args);
241 }
242 }
243
245 {
246 private ushort _type;
247
248 private bool _doFraming;
249
250 private bool _doNeighborFraming;
251
252 public SetTileKeepWall(ushort type, bool setSelfFrames = false, bool setNeighborFrames = true)
253 {
254 _type = type;
257 }
258
259 public override bool Apply(Point origin, int x, int y, params object[] args)
260 {
261 //IL_00e0: Unknown result type (might be due to invalid IL or missing references)
262 ushort wall = GenBase._tiles[x, y].wall;
263 int wallFrameX = GenBase._tiles[x, y].wallFrameX();
264 int wallFrameY = GenBase._tiles[x, y].wallFrameY();
265 GenBase._tiles[x, y].Clear(~(TileDataType.Wiring | TileDataType.Actuator));
266 GenBase._tiles[x, y].type = _type;
267 GenBase._tiles[x, y].active(active: true);
268 if (wall > 0)
269 {
270 GenBase._tiles[x, y].wall = wall;
271 GenBase._tiles[x, y].wallFrameX(wallFrameX);
272 GenBase._tiles[x, y].wallFrameY(wallFrameY);
273 }
274 if (_doFraming)
275 {
277 }
278 return UnitApply(origin, x, y, args);
279 }
280 }
281
282 public class DebugDraw : GenAction
283 {
284 private Color _color;
285
286 private SpriteBatch _spriteBatch;
287
288 public DebugDraw(SpriteBatch spriteBatch, Color color = default(Color))
289 {
290 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
291 //IL_000f: Unknown result type (might be due to invalid IL or missing references)
292 _spriteBatch = spriteBatch;
293 _color = color;
294 }
295
296 public override bool Apply(Point origin, int x, int y, params object[] args)
297 {
298 //IL_0032: Unknown result type (might be due to invalid IL or missing references)
299 //IL_0038: Unknown result type (might be due to invalid IL or missing references)
300 //IL_0043: Unknown result type (might be due to invalid IL or missing references)
301 _spriteBatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle((x << 4) - (int)Main.screenPosition.X, (y << 4) - (int)Main.screenPosition.Y, 16, 16), _color);
302 return UnitApply(origin, x, y, args);
303 }
304 }
305
306 public class SetSlope : GenAction
307 {
308 private int _slope;
309
310 public SetSlope(int slope)
311 {
312 _slope = slope;
313 }
314
315 public override bool Apply(Point origin, int x, int y, params object[] args)
316 {
317 //IL_0010: Unknown result type (might be due to invalid IL or missing references)
319 return UnitApply(origin, x, y, args);
320 }
321 }
322
323 public class SetHalfTile : GenAction
324 {
325 private bool _halfTile;
326
328 {
330 }
331
332 public override bool Apply(Point origin, int x, int y, params object[] args)
333 {
334 //IL_001b: Unknown result type (might be due to invalid IL or missing references)
335 GenBase._tiles[x, y].halfBrick(_halfTile);
336 return UnitApply(origin, x, y, args);
337 }
338 }
339
341 {
342 public override bool Apply(Point origin, int x, int y, params object[] args)
343 {
344 //IL_0034: Unknown result type (might be due to invalid IL or missing references)
346 GenBase._tiles[x, y].color(paintIDForPosition);
347 GenBase._tiles[x, y].wallColor(paintIDForPosition);
348 return UnitApply(origin, x, y, args);
349 }
350
351 private byte GetPaintIDForPosition(int x, int y)
352 {
353 int num = x % 52 + y % 52;
354 num %= 26;
355 if (num > 12)
356 {
357 num = 12 - (num - 12);
358 }
359 num = Math.Min(12, Math.Max(1, num));
360 return (byte)(12 + num);
361 }
362 }
363
364 public class PlaceTile : GenAction
365 {
366 private ushort _type;
367
368 private int _style;
369
370 public PlaceTile(ushort type, int style = 0)
371 {
372 _type = type;
373 _style = style;
374 }
375
376 public override bool Apply(Point origin, int x, int y, params object[] args)
377 {
378 //IL_0018: Unknown result type (might be due to invalid IL or missing references)
379 WorldGen.PlaceTile(x, y, _type, mute: true, forced: false, -1, _style);
380 return UnitApply(origin, x, y, args);
381 }
382 }
383
384 public class RemoveWall : GenAction
385 {
386 public override bool Apply(Point origin, int x, int y, params object[] args)
387 {
388 //IL_0017: Unknown result type (might be due to invalid IL or missing references)
389 GenBase._tiles[x, y].wall = 0;
390 return UnitApply(origin, x, y, args);
391 }
392 }
393
394 public class PlaceWall : GenAction
395 {
396 private ushort _type;
397
398 private bool _neighbors;
399
400 public PlaceWall(ushort type, bool neighbors = true)
401 {
402 _type = type;
404 }
405
406 public override bool Apply(Point origin, int x, int y, params object[] args)
407 {
408 //IL_0054: Unknown result type (might be due to invalid IL or missing references)
409 GenBase._tiles[x, y].wall = _type;
411 if (_neighbors)
412 {
413 WorldGen.SquareWallFrame(x + 1, y);
414 WorldGen.SquareWallFrame(x - 1, y);
415 WorldGen.SquareWallFrame(x, y - 1);
416 WorldGen.SquareWallFrame(x, y + 1);
417 }
418 return UnitApply(origin, x, y, args);
419 }
420 }
421
422 public class SetLiquid : GenAction
423 {
424 private int _type;
425
426 private byte _value;
427
428 public SetLiquid(int type = 0, byte value = byte.MaxValue)
429 {
430 _value = value;
431 _type = type;
432 }
433
434 public override bool Apply(Point origin, int x, int y, params object[] args)
435 {
436 //IL_0036: Unknown result type (might be due to invalid IL or missing references)
437 GenBase._tiles[x, y].liquidType(_type);
438 GenBase._tiles[x, y].liquid = _value;
439 return UnitApply(origin, x, y, args);
440 }
441 }
442
444 {
445 private ushort _type;
446
447 public SwapSolidTile(ushort type)
448 {
449 _type = type;
450 }
451
452 public override bool Apply(Point origin, int x, int y, params object[] args)
453 {
454 //IL_0023: Unknown result type (might be due to invalid IL or missing references)
455 Tile tile = GenBase._tiles[x, y];
456 if (WorldGen.SolidTile(tile))
457 {
458 tile.ResetToType(_type);
459 return UnitApply(origin, x, y, args);
460 }
461 return Fail();
462 }
463 }
464
465 public class SetFrames : GenAction
466 {
467 private bool _frameNeighbors;
468
469 public SetFrames(bool frameNeighbors = false)
470 {
472 }
473
474 public override bool Apply(Point origin, int x, int y, params object[] args)
475 {
476 //IL_000e: Unknown result type (might be due to invalid IL or missing references)
478 return UnitApply(origin, x, y, args);
479 }
480 }
481
482 public class Smooth : GenAction
483 {
484 private bool _applyToNeighbors;
485
486 public Smooth(bool applyToNeighbors = false)
487 {
489 }
490
491 public override bool Apply(Point origin, int x, int y, params object[] args)
492 {
493 //IL_000f: Unknown result type (might be due to invalid IL or missing references)
495 return UnitApply(origin, x, y, args);
496 }
497 }
498
499 public static GenAction Chain(params GenAction[] actions)
500 {
501 for (int i = 0; i < actions.Length - 1; i++)
502 {
503 actions[i].NextAction = actions[i + 1];
504 }
505 return actions[0];
506 }
507
509 {
510 return new ContinueWrapper(action);
511 }
512}
static Asset< Texture2D > MagicPixel
static Vector2 screenPosition
The position of the top left corner of the screen in world coordinates. Modify in M:Terraria....
Definition Main.cs:1864
T Value
Definition Ref.cs:5
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:121
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:146
ClearTile(bool frameNeighbors=false)
Definition Actions.cs:168
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:173
ClearWall(bool frameNeighbors=false)
Definition Actions.cs:185
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:190
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:156
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:21
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:39
Custom(CustomPerUnitAction perUnit)
Definition Actions.cs:132
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:137
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:296
DebugDraw(SpriteBatch spriteBatch, Color color=default(Color))
Definition Actions.cs:288
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:207
PlaceTile(ushort type, int style=0)
Definition Actions.cs:370
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:376
PlaceWall(ushort type, bool neighbors=true)
Definition Actions.cs:400
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:406
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:386
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:56
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:474
SetFrames(bool frameNeighbors=false)
Definition Actions.cs:469
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:332
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:434
SetLiquid(int type=0, byte value=byte.MaxValue)
Definition Actions.cs:428
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:315
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:342
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:259
SetTileKeepWall(ushort type, bool setSelfFrames=false, bool setNeighborFrames=true)
Definition Actions.cs:252
SetTile(ushort type, bool setSelfFrames=false, bool setNeighborFrames=true)
Definition Actions.cs:223
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:230
Smooth(bool applyToNeighbors=false)
Definition Actions.cs:486
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:491
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:452
TileScanner Output(Dictionary< ushort, int > resultsOutput)
Definition Actions.cs:91
override bool Apply(Point origin, int x, int y, params object[] args)
Definition Actions.cs:80
TileScanner(params ushort[] tiles)
Definition Actions.cs:70
Dictionary< ushort, int > _tileCounts
Definition Actions.cs:68
Dictionary< ushort, int > GetResults()
Definition Actions.cs:104
static GenAction Chain(params GenAction[] actions)
Definition Actions.cs:499
static GenAction Continue(GenAction action)
Definition Actions.cs:508
bool UnitApply(Point origin, int x, int y, params object[] args)
Definition GenAction.cs:15
bool Apply(Point origin, int x, int y, params object[] args)
static ref Tilemap _tiles
Definition GenBase.cs:11
static void TileFrame(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:69
static void ClearTile(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:45
static void ClearWall(int x, int y, bool frameNeighbors=false)
Definition WorldUtils.cs:57
static bool SolidTile(Tile testTile)
static bool PlaceTile(int i, int j, int Type, bool mute=false, bool forced=false, int plr=-1, int style=0)
static void SquareWallFrame(int i, int j, bool resetFrame=true)
static bool SlopeTile(int i, int j, int slope=0, bool noEffects=false)
static void SmoothSlope(int x, int y, bool applyToNeighbors=true, bool sync=false)
Slopes a tile based on the tiles adjacent to it.
Definition Tile.cs:793
ref ushort type
Legacy code, use P:Terraria.Tile.TileType instead.
Definition Tile.cs:522
void ResetToType(ushort type)
Resets all of the data at this position except for the P:Terraria.Tile.WallType, and sets P:Terraria....
Definition Tile.cs:641
bool active()
Legacy code, use P:Terraria.Tile.HasTile instead.
Definition Tile.cs:999
A data structure used for accessing information about tiles, walls, wires, and liquids at a single po...
Definition Tile.cs:15